|
| 1 | +"""Algebraic topology operation declarations.""" |
| 2 | + |
| 3 | +from collections.abc import Callable |
| 4 | +from typing import Any |
| 5 | + |
| 6 | +from jacobian._models import StrictModel |
| 7 | +from jacobian.catalog._examples import example |
| 8 | +from jacobian.catalog.models import MathTool, OperationExample |
| 9 | +from jacobian.math.algebraic_topology_ops._models import ( |
| 10 | + EdgePathConcatenateRequest, |
| 11 | + EdgePathConcatenateResult, |
| 12 | + EdgePathWordRequest, |
| 13 | + EdgePathWordResult, |
| 14 | +) |
| 15 | +from jacobian.math.algebraic_topology_ops._operations import ( |
| 16 | + compute_edge_path_concatenate, |
| 17 | + compute_edge_path_word, |
| 18 | +) |
| 19 | + |
| 20 | + |
| 21 | +def _op[RequestT: StrictModel, ResultT: StrictModel]( |
| 22 | + operation_id: str, |
| 23 | + title: str, |
| 24 | + description: str, |
| 25 | + request_model: type[RequestT], |
| 26 | + result_model: type[ResultT], |
| 27 | + operation: Callable[[RequestT], ResultT], |
| 28 | + *tags: str, |
| 29 | + examples: tuple[OperationExample, ...] = (), |
| 30 | + version: str = "1", |
| 31 | +) -> MathTool[RequestT, ResultT]: |
| 32 | + return MathTool( |
| 33 | + operation_id=operation_id, |
| 34 | + version=version, |
| 35 | + title=title, |
| 36 | + description=description, |
| 37 | + request_type=request_model, |
| 38 | + result_type=result_model, |
| 39 | + run=operation, |
| 40 | + tags=tags, |
| 41 | + examples=examples, |
| 42 | + ) |
| 43 | + |
| 44 | + |
| 45 | +TOOLS: tuple[MathTool[Any, Any], ...] = ( |
| 46 | + _op( |
| 47 | + "topology.simplicial.edge_path.word.compute", |
| 48 | + "Compute the free group word for an edge path", |
| 49 | + "Compute the free group word representation of an edge path in a " |
| 50 | + "graph, where each edge corresponds to a generator and its inverse.", |
| 51 | + EdgePathWordRequest, |
| 52 | + EdgePathWordResult, |
| 53 | + compute_edge_path_word, |
| 54 | + "topology", |
| 55 | + "edge-path", |
| 56 | + "exact", |
| 57 | + examples=( |
| 58 | + example( |
| 59 | + "triangle_path", |
| 60 | + "Compute the word for path 0->1->2 in a triangle.", |
| 61 | + { |
| 62 | + "vertex_count": 3, |
| 63 | + "edges": [[0, 1], [1, 2], [2, 0]], |
| 64 | + "path": [0, 1, 2], |
| 65 | + }, |
| 66 | + ), |
| 67 | + ), |
| 68 | + ), |
| 69 | + _op( |
| 70 | + "topology.simplicial.edge_path.concatenate.compute", |
| 71 | + "Concatenate two edge paths", |
| 72 | + "Concatenate two edge paths in a graph, removing the shared vertex.", |
| 73 | + EdgePathConcatenateRequest, |
| 74 | + EdgePathConcatenateResult, |
| 75 | + compute_edge_path_concatenate, |
| 76 | + "topology", |
| 77 | + "edge-path", |
| 78 | + "exact", |
| 79 | + examples=( |
| 80 | + example( |
| 81 | + "concatenate_paths", |
| 82 | + "Concatenate [0,1] and [1,2] in a 3-vertex graph.", |
| 83 | + { |
| 84 | + "vertex_count": 3, |
| 85 | + "path_a": [0, 1], |
| 86 | + "path_b": [1, 2], |
| 87 | + }, |
| 88 | + ), |
| 89 | + ), |
| 90 | + ), |
| 91 | +) |
| 92 | + |
| 93 | +__all__ = ["TOOLS"] |
0 commit comments