Datasets:
Modalities:
Text
Formats:
json
Size:
< 1K
Tags:
multilingual
mathematical-word-problems
natural-language-to-formal-language
multi-agent-systems
benchmark
conversational-interfaces
Download tests/test_topology.py from tailot/math-stratum: direct link, hf CLI and curl.
- Browser
- Download file 4.28 kB
-
https://huggingface.co/datasets/tailot/math-stratum/resolve/main/tests/test_topology.py
- Command line
-
hf download hf://datasets/tailot/math-stratum/tests/test_topology.py
-
curl -L -o test_topology.py https://huggingface.co/datasets/tailot/math-stratum/resolve/main/tests/test_topology.py
4.28 kB
| """Shape of the shipped topology, of the node datasets, and of the sources themselves.""" | |
| import ast | |
| import json | |
| from pathlib import Path | |
| import pytest | |
| from lingologos_stratum import agents | |
| ROOT = Path(__file__).resolve().parents[1] | |
| TOPOLOGY = json.loads((ROOT / "topology.json").read_text(encoding="utf-8")) | |
| NODE_IDS = [instance["id"] for instance in TOPOLOGY["instances"]] | |
| # The question and its language enter through the arbiter, exactly as the seed of a problem enters | |
| # through the arbiter of the math bundle: the stratum never invents a second entry point. | |
| SEED_NODE = "arbiter" | |
| def test_instances_are_the_eight_nodes_in_execution_order(): | |
| assert NODE_IDS == list(agents.ORDER) | |
| assert all(instance["role"] == instance["id"] for instance in TOPOLOGY["instances"]) | |
| assert sorted(NODE_IDS) == sorted(agents.STEPS) | |
| def test_routing_follows_the_execution_order_and_closes_the_cycle(): | |
| edges = [(row["from"], target) for row in TOPOLOGY["routingMatrix"] for target in row["to"]] | |
| assert [source for source, _ in edges] == NODE_IDS | |
| # A sender reads the latest output of its recipient: every node reads the node before it, and | |
| # the first one reads the seed the arbiter holds, so the arbiter closes the cycle. | |
| assert [target for _, target in edges] == [SEED_NODE] + NODE_IDS[:-1] | |
| assert TOPOLOGY["maxTurns"] == len(edges) | |
| def test_the_termination_condition_is_not_an_early_exit(): | |
| # The orchestrator stops on UNSAT_BREAKER or SAT_CONVERGENCE; here the cycle must run its full | |
| # length, so the shipped condition may not name either shortcut. | |
| condition = TOPOLOGY.get("terminationCondition", "") | |
| assert "UNSAT_BREAKER" not in condition | |
| assert "SAT_CONVERGENCE" not in condition | |
| def test_node_dataset_is_complete(node): | |
| folder = ROOT / "nodes" / node | |
| for name in ("grammar.gf", "ontology.smt2", "seed_payload.json"): | |
| assert (folder / name).is_file(), name | |
| seed = json.loads((folder / "seed_payload.json").read_text(encoding="utf-8")) | |
| assert seed["sender"] == node | |
| ontology = (folder / "ontology.smt2").read_text(encoding="utf-8") | |
| assert "(set-option :timeout" in ontology | |
| assert "(declare-" not in ontology | |
| def test_python_sources_are_ascii_only(): | |
| paths = (list((ROOT / "lingologos_stratum").glob("*.py")) + list((ROOT / "tools").glob("*.py")) | |
| + list((ROOT / "tests").glob("*.py")) + [ROOT / "agents" / "stratum_agent"]) | |
| for path in paths: | |
| path.read_text(encoding="ascii") | |
| def test_only_the_equivalence_referee_may_touch_the_math_code(): | |
| # The math verdict of a session reaches this bundle as the output of a separate process, so it | |
| # cannot be rewritten on the way in. One module is allowed to import the math package, and only | |
| # for its own SMT plumbing: compare.py asks whether two readings of a question say the same | |
| # thing, which is a claim about the readings and never about the answer. The modules that | |
| # decide, route and invoke are checked to hold no reference to that package at all. | |
| for path in (ROOT / "lingologos_stratum").glob("*.py"): | |
| tree = ast.parse(path.read_text(encoding="ascii")) | |
| for node in ast.walk(tree): | |
| if isinstance(node, ast.Import): | |
| names = [alias.name for alias in node.names] | |
| elif isinstance(node, ast.ImportFrom): | |
| names = [node.module or ""] | |
| else: | |
| continue | |
| for name in names: | |
| if name.startswith("lingologos_math"): | |
| assert path.name == "compare.py", "%s imports %s" % (path.name, name) | |
| for name in ("decide.py", "pipeline.py", "agents.py", "invoker.py", "protocol.py", "coverage.py"): | |
| assert "lingologos_math" not in (ROOT / "lingologos_stratum" / name).read_text(encoding="ascii"), name | |
| def test_the_math_bundle_is_reached_as_a_separate_process(): | |
| source = (ROOT / "lingologos_stratum" / "invoker.py").read_text(encoding="ascii") | |
| tree = ast.parse(source) | |
| calls = [ast.unparse(node) for node in ast.walk(tree) if isinstance(node, ast.Call)] | |
| assert any("subprocess.run" in call for call in calls) | |
| assert any("tools" in call and "solve.py" in call for call in calls) | |