Download tests/test_decision.py from tailot/lingologos-physics: direct link, hf CLI and curl.
- Browser
- Download file 9.68 kB
-
https://huggingface.co/datasets/tailot/lingologos-physics/resolve/main/tests/test_decision.py
- Command line
-
hf download hf://datasets/tailot/lingologos-physics/tests/test_decision.py
-
curl -L -o test_decision.py https://huggingface.co/datasets/tailot/lingologos-physics/resolve/main/tests/test_decision.py
9.68 kB
| """The ladder of verdicts: what the dataset is allowed to claim, and how much confidence goes with it. | |
| The rule the arbiter applies is small enough to state here. A failure of a burden that belongs to the | |
| world, to the guard of a law, or to the content of the sentence is a refusal the chain is confident | |
| about. A failure that is only a disagreement between two nodes, or a soundness hole in a single node, | |
| leaves the chain with nothing to claim: UNKNOWN, zero confidence. Two roads agreeing give confidence | |
| 2, one road alone gives 1, and a level of 3 is never shown, because the chain has no third source | |
| that is not itself. | |
| """ | |
| import pytest | |
| from lingologos_phys import agents, families, faults, invoker, pipeline | |
| CONVERT = "convert 3 km to m" | |
| REFUSED = "convert 3 m to s" | |
| SERIES = ("potential node 1 circuit 3 resistors [ 1 2 10 ; 2 3 20 ] sources [ 1 1 ]" | |
| " size 1/10 frequency 50") | |
| def _clean_environment(monkeypatch): | |
| faults.configure("") | |
| monkeypatch.delenv("LINGOLOGOS_PHYS_FAULTS", raising=False) | |
| monkeypatch.delenv("LINGOLOGOS_PHYS_MATH_BACKEND", raising=False) | |
| yield | |
| faults.configure("") | |
| def test_a_question_answered_by_two_roads_and_by_math_is_verified_with_the_top_confidence(): | |
| out = pipeline.run(CONVERT) | |
| assert out["decision"]["status"] == agents.VERIFIED | |
| assert out["decision"]["assurance"] == 2 | |
| assert out["dossier"]["math"]["status"] == "VERIFIED" | |
| def test_a_chain_that_lost_its_second_reader_keeps_the_answer_but_loses_the_confidence(): | |
| alone = [name for name in agents.ALL_AGENTS if name != "reader_b"] | |
| out = pipeline.run(CONVERT, agents_order=alone) | |
| decision = out["decision"] | |
| assert decision["status"] == agents.SINGLE_PROVER | |
| assert decision["assurance"] == 1 | |
| assert sorted(out["dossier"]["roads"]) == ["read_a"] | |
| # The answer is still the right one; only the confidence in it changed. | |
| assert out["dossier"]["answer"]["value"] == "3000" | |
| def test_a_chain_that_lost_the_node_which_produces_the_answer_certifies_nothing(): | |
| """An audit needs no arithmetic, so with the invoker gone every check that remains still holds. | |
| What is missing is the answer: no node handed one over. A verdict of verified over an empty answer | |
| is the one thing the ladder must never do, so the chain closes with zero confidence instead. | |
| """ | |
| no_answer = [name for name in agents.ALL_AGENTS if name != "invoker"] | |
| out = pipeline.run("audit ( F * t ) = ( m * v )", agents_order=no_answer) | |
| decision = out["decision"] | |
| assert decision["status"] == agents.UNKNOWN | |
| assert decision["assurance"] == 0 | |
| assert "no_answer_was_recorded" in decision["reasons"] | |
| def test_confidence_two_is_carried_by_the_node_that_certifies_the_two_roads_agree(): | |
| """Two readers writing the same canonical text is a fact; a node that vouched for it is evidence. | |
| With the agreement node gone both roads are still read and still agree, but nobody compared them | |
| inside a claim of its own, so the chain keeps the answer it has and stops claiming two roads. | |
| """ | |
| full = pipeline.run(CONVERT)["decision"] | |
| assert full["status"] == agents.VERIFIED and full["assurance"] == 2, full | |
| alone = [name for name in agents.ALL_AGENTS if name != "equivalence"] | |
| out = pipeline.run(CONVERT, agents_order=alone)["decision"] | |
| assert out["status"] == agents.SINGLE_PROVER, out | |
| assert out["assurance"] == 1, out | |
| def test_a_burden_of_the_world_is_a_confident_refusal_while_a_disagreement_is_not(): | |
| refused = pipeline.run(REFUSED)["decision"] | |
| assert refused["status"] == agents.REFUSED and refused["assurance"] == 2 | |
| disagreed = pipeline.run(CONVERT, fault_spec="invoker:corrupt_answer")["decision"] | |
| assert disagreed["status"] == agents.UNKNOWN and disagreed["assurance"] == 0 | |
| def test_a_node_that_claims_a_green_check_that_z3_rejects_is_found_out_by_the_referee(): | |
| # A lie is only told where there is a failure to hide: here reader_a did fail a content check. | |
| out = pipeline.run(REFUSED, fault_spec="reader_a:lie") | |
| decision = out["decision"] | |
| assert list(faults.FIRED) == ["reader_a:lie"] | |
| assert decision["status"] == agents.UNKNOWN and decision["assurance"] == 0 | |
| assert "referee_disagreed_with_reader_a" in decision["reasons"] | |
| def test_a_lie_with_nothing_to_hide_stays_dormant_and_changes_nothing(): | |
| baseline = pipeline.run(CONVERT)["decision"] | |
| lying = pipeline.run(CONVERT, fault_spec="reader_a:lie")["decision"] | |
| assert list(faults.FIRED) == [] | |
| assert lying["status"] == baseline["status"] == agents.VERIFIED | |
| def test_the_arbiter_cannot_lift_a_refusal_by_reporting_the_answer_it_was_hoped_for(): | |
| out = pipeline.run(REFUSED, fault_spec="arbiter:force_accept") | |
| decision = out["decision"] | |
| assert decision["status"] == agents.REFUSED and decision["assurance"] == 2 | |
| assert "the_arbiter_reported_VERIFIED" in decision["reasons"] | |
| def test_a_question_that_needed_arithmetic_without_arithmetic_claims_nothing(monkeypatch): | |
| monkeypatch.setenv("LINGOLOGOS_PHYS_MATH_BACKEND", "none") | |
| assert invoker.backend() == "none" | |
| decision = pipeline.run(CONVERT)["decision"] | |
| assert decision["status"] == agents.UNKNOWN and decision["assurance"] == 0 | |
| assert "mathematics_backend_unavailable" in decision["reasons"] | |
| def test_a_question_that_never_needed_arithmetic_is_unaffected_by_its_absence(monkeypatch): | |
| monkeypatch.setenv("LINGOLOGOS_PHYS_MATH_BACKEND", "none") | |
| decision = pipeline.run("audit V = I * R")["decision"] | |
| assert decision["status"] == agents.VERIFIED and decision["assurance"] == 2 | |
| def test_the_confidence_the_dataset_shows_never_exceeds_two(): | |
| for problem in (CONVERT, REFUSED, SERIES, "audit P = E / t", "pi speed from length, gravity"): | |
| decision = pipeline.run(problem)["decision"] | |
| assert decision["assurance"] in (0, 1, 2), (problem, decision["assurance"]) | |
| # Which check of the adversary is the one that sees each deliberate mistake. A check that does not | |
| # hold is the healthy outcome for this role, so the reason below names the check that caught it. | |
| CAUGHT_BY = { | |
| "convert": {"off_by_one": "perturbation_visible", | |
| "wrong_dimension": "dimension_field_perturbation_visible", | |
| "dropped_factor": "perturbation_visible"}, | |
| "audit": {"off_by_one": "perturbation_visible", | |
| "wrong_dimension": "perturbation_visible"}, | |
| "pi": {"off_by_one": "perturbation_visible", | |
| "scaled_exponents": "perturbation_visible"}, | |
| "potential": {"off_by_one": "perturbation_visible", | |
| "wrong_node": "node_field_perturbation_visible", | |
| "dropped_guard": "guard_field_perturbation_visible"}, | |
| } | |
| def test_every_perturbation_in_the_catalogue_leaves_a_trace(): | |
| questions = {"convert": CONVERT, "audit": "audit ( F * t ) = ( m * v )", | |
| "pi": "pi period from mass, stiffness", "potential": SERIES} | |
| for kind, question in questions.items(): | |
| assert sorted(CAUGHT_BY[kind]) == sorted(families.family_for(kind).flavors), kind | |
| for flavor in families.family_for(kind).flavors: | |
| decision = pipeline.run(question, flavor=flavor)["decision"] | |
| reasons = decision["reasons"] | |
| assert decision["status"] == agents.VERIFIED, (kind, flavor, decision) | |
| assert "the_perturbation_was_visible" in reasons, (kind, flavor, reasons) | |
| assert "adversary_failed_" + CAUGHT_BY[kind][flavor] in reasons, (kind, flavor, reasons) | |
| # The network question whose declared regime band says the model does not hold, so the answer has to be | |
| # refused before any arithmetic is asked: the same circuit as SERIES, with size and frequency such that | |
| # size * frequency / c is not below the threshold of section 10. | |
| GUARDED = ("potential node 1 circuit 3 resistors [ 1 2 10 ; 2 3 20 ] sources [ 1 1 ]" | |
| " size 1000000 frequency 50000000000") | |
| def without(*gone: str): | |
| """The full chain with the named nodes taken out of it, the way the ablation does.""" | |
| return [name for name in agents.ALL_AGENTS if name not in gone] | |
| def test_the_last_witness_of_a_check_is_the_pair_of_nodes_that_opens_the_hole(): | |
| """Pin the boundary the ablation measured, instead of leaving it a number in a table. | |
| The arbiter restates two checks that belong to another node, the recomputation of the answer and the | |
| regime guard, so a chain missing the owner of one of them or missing the arbiter still has a witness | |
| and closes at UNKNOWN or at the refusal the gold line asks for. A chain missing both at once has no | |
| witness left, and then the honest reading of the sweep is the one section 10 states as a limit. | |
| """ | |
| faults.configure("invoker:corrupt_answer") | |
| for order in (list(agents.ALL_AGENTS), without("arbiter"), without("boundary")): | |
| decision = pipeline.run(CONVERT, agents_order=order)["decision"] | |
| assert decision["status"] == agents.UNKNOWN, (len(order), decision) | |
| hole = pipeline.run(CONVERT, agents_order=without("arbiter", "boundary")) | |
| assert hole["decision"]["status"] == agents.VERIFIED, hole["decision"] | |
| assert hole["dossier"]["answer"]["value"] != "3000", hole["dossier"]["answer"] | |
| faults.configure("reader_a:lie") | |
| for order in (list(agents.ALL_AGENTS), without("arbiter"), without("domain_a")): | |
| decision = pipeline.run(GUARDED, agents_order=order)["decision"] | |
| assert decision["status"] == agents.GUARD_BLOCKED, (len(order), decision) | |
| guard_hole = pipeline.run(GUARDED, agents_order=without("arbiter", "domain_a"))["decision"] | |
| assert guard_hole["status"] == agents.VERIFIED, guard_hole | |