quantum-reasoning-skill 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,128 @@
1
+ from __future__ import annotations
2
+
3
+ import importlib.util
4
+ from pathlib import Path
5
+ import sys
6
+ import unittest
7
+
8
+
9
+ ROOT = Path(__file__).resolve().parents[1]
10
+ SPEC = importlib.util.spec_from_file_location(
11
+ "branch_controller", ROOT / "reference" / "branch_controller.py"
12
+ )
13
+ assert SPEC and SPEC.loader
14
+ bc = importlib.util.module_from_spec(SPEC)
15
+ sys.modules[SPEC.name] = bc
16
+ SPEC.loader.exec_module(bc)
17
+
18
+
19
+ class BranchControllerTests(unittest.TestCase):
20
+ def metrics(self, **overrides):
21
+ values = {
22
+ "evidence": 0.8,
23
+ "verification": 0.8,
24
+ "independence": 0.9,
25
+ "information_gain": 0.6,
26
+ "contradiction": 0.1,
27
+ "unresolved_assumptions": 0.1,
28
+ "normalized_cost": 0.2,
29
+ "shared_assumption_ratio": 0.0,
30
+ "semantic_similarity_to_leader": 0.0,
31
+ }
32
+ values.update(overrides)
33
+ return bc.BranchMetrics(**values)
34
+
35
+ def test_score_penalizes_shared_assumptions(self):
36
+ independent = self.metrics(shared_assumption_ratio=0.0)
37
+ correlated = self.metrics(shared_assumption_ratio=0.8)
38
+ self.assertGreater(bc.branch_score(independent), bc.branch_score(correlated))
39
+
40
+ def test_high_contradiction_rejects_branch(self):
41
+ branch = bc.Branch("bad", self.metrics(contradiction=0.95))
42
+ updated = bc.classify_branch(branch)
43
+ self.assertEqual(updated.state, bc.BranchState.REJECTED)
44
+
45
+ def test_material_evidence_change_revives_dormant_branch(self):
46
+ previous = self.metrics(evidence=0.30, verification=0.35, contradiction=0.50)
47
+ current = self.metrics(evidence=0.50, verification=0.35, contradiction=0.50)
48
+ branch = bc.Branch(
49
+ "revive",
50
+ current,
51
+ state=bc.BranchState.DORMANT,
52
+ previous_metrics=previous,
53
+ )
54
+ self.assertTrue(bc.should_revive(branch))
55
+ self.assertEqual(bc.update_branch_state(branch).state, bc.BranchState.ACTIVE)
56
+
57
+ def test_collapse_requires_clear_verified_leader(self):
58
+ leader = bc.Branch(
59
+ "leader",
60
+ self.metrics(
61
+ evidence=1.0,
62
+ verification=1.0,
63
+ independence=1.0,
64
+ information_gain=0.8,
65
+ contradiction=0.0,
66
+ unresolved_assumptions=0.0,
67
+ normalized_cost=0.0,
68
+ ),
69
+ )
70
+ weak = bc.Branch(
71
+ "weak",
72
+ self.metrics(
73
+ evidence=0.35,
74
+ verification=0.30,
75
+ independence=0.5,
76
+ information_gain=0.2,
77
+ contradiction=0.4,
78
+ unresolved_assumptions=0.5,
79
+ normalized_cost=0.4,
80
+ ),
81
+ )
82
+ can_collapse, reason, selected = bc.collapse_decision([leader, weak])
83
+ self.assertTrue(can_collapse, reason)
84
+ self.assertEqual(selected.branch_id, "leader")
85
+
86
+ def test_close_competitor_blocks_collapse(self):
87
+ first = bc.Branch(
88
+ "a",
89
+ self.metrics(
90
+ evidence=1.0,
91
+ verification=1.0,
92
+ independence=1.0,
93
+ contradiction=0.0,
94
+ unresolved_assumptions=0.0,
95
+ normalized_cost=0.0,
96
+ ),
97
+ )
98
+ second = bc.Branch(
99
+ "b",
100
+ self.metrics(
101
+ evidence=0.95,
102
+ verification=0.95,
103
+ independence=1.0,
104
+ contradiction=0.0,
105
+ unresolved_assumptions=0.0,
106
+ normalized_cost=0.0,
107
+ ),
108
+ )
109
+ can_collapse, reason, _ = bc.collapse_decision([first, second])
110
+ self.assertFalse(can_collapse)
111
+ self.assertIn("margin", reason)
112
+
113
+ def test_uncertainty_controls_width(self):
114
+ self.assertEqual(bc.recommended_width(0.10), (2, 3))
115
+ self.assertEqual(bc.recommended_width(0.40), (4, 6))
116
+ self.assertEqual(bc.recommended_width(0.90), (6, 10))
117
+
118
+ def test_diversity_ratio_detects_duplicates(self):
119
+ ratio = bc.diversity_ratio([0.2, 0.9, 0.4, 0.95], duplicate_threshold=0.85)
120
+ self.assertEqual(ratio, 0.5)
121
+
122
+ def test_invalid_metric_fails_fast(self):
123
+ with self.assertRaises(ValueError):
124
+ bc.branch_score(self.metrics(evidence=1.2))
125
+
126
+
127
+ if __name__ == "__main__":
128
+ unittest.main()
@@ -0,0 +1,78 @@
1
+ from __future__ import annotations
2
+ import importlib.util, json, sys, tempfile, unittest
3
+ from pathlib import Path
4
+
5
+ ROOT = Path(__file__).resolve().parents[1]
6
+ for name, path in (
7
+ ("evaluate", ROOT / "benchmark" / "evaluate.py"),
8
+ ("validate_submission", ROOT / "benchmark" / "validate_submission.py"),
9
+ ):
10
+ spec = importlib.util.spec_from_file_location(name, path)
11
+ module = importlib.util.module_from_spec(spec)
12
+ sys.modules[name] = module
13
+ assert spec.loader is not None
14
+ spec.loader.exec_module(module)
15
+
16
+ evaluate = sys.modules["evaluate"]
17
+ validator = sys.modules["validate_submission"]
18
+
19
+
20
+ class SubmissionValidationTests(unittest.TestCase):
21
+ def make_bundle(self, root: Path) -> Path:
22
+ bundle = root / "provider-model-2026-09-07"
23
+ bundle.mkdir()
24
+ cases = [{"id": "c1", "domain": "math", "prompt": "1+1?", "accepted_answers": ["2"]}]
25
+ baseline = [{"case_id": "c1", "answer": "2", "tokens": 10, "tool_calls": 0, "latency_ms": 100}]
26
+ skill = [{"case_id": "c1", "answer": "2", "tokens": 12, "tool_calls": 0, "latency_ms": 110}]
27
+ (bundle / "cases.jsonl").write_text(json.dumps(cases[0]) + "\n", encoding="utf-8")
28
+ (bundle / "baseline.jsonl").write_text(json.dumps(baseline[0]) + "\n", encoding="utf-8")
29
+ (bundle / "skill.jsonl").write_text(json.dumps(skill[0]) + "\n", encoding="utf-8")
30
+ meta = {
31
+ "provider": "example",
32
+ "model": "model",
33
+ "run_date": "2026-09-07",
34
+ "skill_version": "0.3.0",
35
+ "repetitions_per_case": 1,
36
+ "failures_recorded": True,
37
+ "baseline": {"instruction_config": "baseline", "sampling": {}, "tool_availability": [], "context_limit": 1000, "output_limit": 100},
38
+ "skill": {"instruction_config": "SKILL.md", "sampling": {}, "tool_availability": [], "context_limit": 1000, "output_limit": 100},
39
+ }
40
+ (bundle / "metadata.json").write_text(json.dumps(meta), encoding="utf-8")
41
+ payload = {"skill": evaluate.summarize(cases, skill), "baseline": evaluate.summarize(cases, baseline)}
42
+ payload["comparison"] = evaluate.compare(payload["baseline"], payload["skill"])
43
+ (bundle / "comparison.json").write_text(json.dumps(payload, sort_keys=True), encoding="utf-8")
44
+ (bundle / "README.md").write_text("Reproducible test bundle.\n", encoding="utf-8")
45
+ return bundle
46
+
47
+ def test_valid_bundle(self):
48
+ with tempfile.TemporaryDirectory() as tmp:
49
+ validator.validate_bundle(self.make_bundle(Path(tmp)))
50
+
51
+ def test_missing_artifact_fails(self):
52
+ with tempfile.TemporaryDirectory() as tmp:
53
+ bundle = self.make_bundle(Path(tmp))
54
+ (bundle / "README.md").unlink()
55
+ with self.assertRaises(ValueError):
56
+ validator.validate_bundle(bundle)
57
+
58
+ def test_tampered_comparison_fails(self):
59
+ with tempfile.TemporaryDirectory() as tmp:
60
+ bundle = self.make_bundle(Path(tmp))
61
+ payload = json.loads((bundle / "comparison.json").read_text())
62
+ payload["comparison"]["accuracy_delta"] = 99
63
+ (bundle / "comparison.json").write_text(json.dumps(payload), encoding="utf-8")
64
+ with self.assertRaises(ValueError):
65
+ validator.validate_bundle(bundle)
66
+
67
+ def test_unrecorded_failures_flag_fails(self):
68
+ with tempfile.TemporaryDirectory() as tmp:
69
+ bundle = self.make_bundle(Path(tmp))
70
+ meta = json.loads((bundle / "metadata.json").read_text())
71
+ meta["failures_recorded"] = False
72
+ (bundle / "metadata.json").write_text(json.dumps(meta), encoding="utf-8")
73
+ with self.assertRaises(ValueError):
74
+ validator.validate_bundle(bundle)
75
+
76
+
77
+ if __name__ == "__main__":
78
+ unittest.main()