存档求解器回归基线与当前改动

纳管 AMESim 对齐基线、发布锁、回归测试及当前物理门禁调整。

更新日志仅记录已完成成果,并注明当前 HEAD 尚待真实 production 复跑与远端 workflow 验证。
This commit is contained in:
lujingze committed 2026-08-18 15:20:42 +00:00
1 parent 53f8601fec
commit a8c733883c
32 files changed
+47241 -108

No files matched your search

+240 -6
View File
@@ -26,6 +26,13 @@ from app.simulation.benchmark_regression import (
)
PHYSICAL_STATE_V21_REPORT = (
DEFAULT_MANIFEST_PATH.parent
/ "runs"
/ "2026-08-18-production-physical-state-v2.1-0.2.json"
)
def _completed_result(request: RegressionCaseRequest, *, wall_seconds: float = 0.01):
signal_times = (
[0.04, 0.8]
@@ -125,16 +132,24 @@ class RegressionManifestTests(unittest.TestCase):
self.assertTrue(manifest["source"]["xmlIsAuthoritative"])
self.assertEqual(
manifest["source"]["sha256"],
"6eb2753a15af66fd8e91c169c4587e66b0ace2164c08c2cb23a67aab5fd09164",
"0a2d9331df9eb5974daec25a61c1238ba32b1742d933ffc8b16ce316c5627b0b",
)
self.assertEqual(Path(manifest["_sourcePath"]).name, "test-mql-8.xml")
self.assertEqual(
manifest["source"]["companionProject"]["sha256"],
"8d7a263691a9f09f39c92aba19ae1350911dc66b4904e98bae5f20592c5a3fcd",
"b44bf540ccd1c293fe2af2b9b9052b540abf83961ad955a0f6a4ab40fbe0bb18",
)
self.assertFalse(
manifest["source"]["companionProject"]["executionInput"]
)
self.assertEqual(
manifest["source"]["referenceArchive"]["role"],
"authoritativePhysicalBaseline",
)
self.assertEqual(
Path(manifest["_referenceArchivePath"]).name,
"test_mql.ame",
)
self.assertEqual(manifest["historicalReports"][0]["status"], "historicalOnly")
self.assertFalse(
manifest["historicalReports"][0]["compatibleWithCurrentSource"]
@@ -146,6 +161,86 @@ class RegressionManifestTests(unittest.TestCase):
self.assertFalse(
manifest["historicalReports"][2]["compatibleWithCurrentSource"]
)
physical_state_golden = manifest["_physicalStateV21Goldens"]["0.2s"][
"production"
]
self.assertEqual(physical_state_golden["approval"]["status"], "approved")
self.assertEqual(
physical_state_golden["_sha256"],
"6f0752afe8c1f7690599c2709a76d9a1342f99f726c6c8593321dc6267e175b2",
)
self.assertTrue(
physical_state_golden["amesimAlignmentAtGeneration"]["passed"]
)
self.assertEqual(
manifest["correctness"]["physicalBaselineAuthority"], "amesim"
)
self.assertTrue(manifest["correctness"]["compareAmesimOnEveryRun"])
self.assertEqual(
manifest["correctness"]["pythonGoldenRole"],
"determinismDiagnosticOnly",
)
self.assertEqual(
manifest["variants"]["0.2s"]["goldens"]["production"]["role"],
"pythonDeterminismRegression",
)
self.assertEqual(
manifest["variants"]["0.2s"]["physicalStateV21Goldens"][
"production"
]["role"],
"amesimPhysicalBaseline",
)
def test_manifest_rejects_physical_state_v21_golden_hash_mismatch(self) -> None:
manifest = json.loads(DEFAULT_MANIFEST_PATH.read_text(encoding="utf-8"))
manifest["variants"]["0.2s"]["physicalStateV21Goldens"]["production"][
"sha256"
] = "0" * 64
with tempfile.TemporaryDirectory(
dir=DEFAULT_MANIFEST_PATH.parents[4], prefix=".v21-manifest-test-"
) as temporary_directory:
manifest_path = Path(temporary_directory) / "manifest.json"
manifest_path.write_text(json.dumps(manifest), encoding="utf-8")
with self.assertRaisesRegex(
RegressionManifestError,
"physical-state-v2.1 golden hash mismatch",
):
load_regression_manifest(manifest_path)
def test_manifest_rejects_amesim_archive_hash_mismatch(self) -> None:
manifest = json.loads(DEFAULT_MANIFEST_PATH.read_text(encoding="utf-8"))
manifest["source"]["referenceArchive"]["sha256"] = "0" * 64
with tempfile.TemporaryDirectory(
dir=DEFAULT_MANIFEST_PATH.parents[4], prefix=".amesim-manifest-test-"
) as temporary_directory:
manifest_path = Path(temporary_directory) / "manifest.json"
manifest_path.write_text(json.dumps(manifest), encoding="utf-8")
with self.assertRaisesRegex(
RegressionManifestError,
"AMESim reference archive hash mismatch",
):
load_regression_manifest(manifest_path)
def test_manifest_rejects_amesim_golden_provenance_mismatch(self) -> None:
loaded = load_regression_manifest(DEFAULT_MANIFEST_PATH)
golden = json.loads(
json.dumps(loaded["_physicalStateV21Goldens"]["0.2s"]["production"])
)
golden["provenance"]["amesim"]["archiveSha256"] = "0" * 64
manifest = json.loads(DEFAULT_MANIFEST_PATH.read_text(encoding="utf-8"))
with tempfile.TemporaryDirectory(
dir=DEFAULT_MANIFEST_PATH.parents[4], prefix=".amesim-provenance-test-"
) as temporary_directory:
manifest_path = Path(temporary_directory) / "manifest.json"
manifest_path.write_text(json.dumps(manifest), encoding="utf-8")
with patch(
"app.simulation.benchmark_regression.load_physical_state_v21_golden",
return_value=golden,
), self.assertRaisesRegex(
RegressionManifestError,
"AMESim baseline provenance",
):
load_regression_manifest(manifest_path)
def test_in_memory_derivative_does_not_change_authoritative_xml(self) -> None:
manifest = load_regression_manifest(DEFAULT_MANIFEST_PATH)
@@ -159,9 +254,9 @@ class RegressionManifestTests(unittest.TestCase):
max_step=0.005,
)
self.assertEqual(source_simulation_config(before)["tStop"], 5.0)
self.assertEqual(source_simulation_config(before)["sampleStep"], 0.005)
self.assertEqual(source_simulation_config(before)["maxStep"], 0.005)
self.assertEqual(source_simulation_config(before)["tStop"], 10.0)
self.assertEqual(source_simulation_config(before)["sampleStep"], 0.01)
self.assertEqual(source_simulation_config(before)["maxStep"], 0.001)
self.assertEqual(source_simulation_config(derived)["tStop"], 1.0)
self.assertEqual(source_simulation_config(derived)["sampleStep"], 0.02)
self.assertEqual(source_simulation_config(derived)["maxStep"], 0.005)
@@ -399,6 +494,145 @@ class BoundedChildProcessTests(unittest.TestCase):
class ProgressiveSuiteTests(unittest.TestCase):
@staticmethod
def _physical_state_v21_result_executor():
source_report = json.loads(
PHYSICAL_STATE_V21_REPORT.read_text(encoding="utf-8")
)
results = {case["caseId"]: case for case in source_report["cases"]}
def execute(request: RegressionCaseRequest) -> dict[str, object]:
return json.loads(json.dumps(results[request.case_id]))
return execute
def test_production_report_replays_through_active_v21_acceptance(self) -> None:
report = run_regression_suite(
DEFAULT_MANIFEST_PATH,
lane="production",
case_ids=["0.2s"],
case_executor=self._physical_state_v21_result_executor(),
)
case = report["cases"][1]
evaluation = case["acceptance"]["physicalStateV21Golden"]
self.assertEqual(case["outcome"], "completed")
self.assertTrue(case["acceptance"]["passed"])
self.assertTrue(evaluation["configured"])
self.assertTrue(evaluation["evaluated"])
self.assertTrue(evaluation["passed"])
self.assertEqual(evaluation["baselineAuthority"], "amesim")
self.assertEqual(evaluation["metricCount"], 33)
self.assertEqual(evaluation["availableBaselineValueCount"], 27)
self.assertEqual(evaluation["unavailableBaselineValueCount"], 6)
self.assertEqual(evaluation["comparedValueCount"], 25)
self.assertEqual(evaluation["excludedValueCount"], 2)
self.assertAlmostEqual(
evaluation["maxToleranceRatio"], 0.6967416724836332
)
self.assertAlmostEqual(
evaluation["worstValue"]["relativeError"],
0.0013934852135053246,
)
self.assertTrue(
all(
"actual" in metric and "amesimBaseline" in metric
for metric in evaluation["metrics"]
)
)
self.assertEqual(evaluation["issues"], [])
self.assertTrue(evaluation["amesimAlignmentAtGenerationPassed"])
regression = case["acceptance"]["regressionGolden"]
self.assertEqual(regression["role"], "determinismDiagnosticOnly")
self.assertFalse(regression["affectsPhysicalCorrectness"])
def test_v21_conservation_drift_fails_runner_acceptance(self) -> None:
execute_source = self._physical_state_v21_result_executor()
def drifted(request: RegressionCaseRequest) -> dict[str, object]:
result = execute_source(request)
if request.case_id == "0.2s":
result["worker"]["summary"]["physicalStateV21"]["checkpoints"][-1][
"values"
]["conservation.p4node2_8.massBalance"] = 2.0e-9
return result
report = run_regression_suite(
DEFAULT_MANIFEST_PATH,
lane="production",
case_ids=["0.2s"],
case_executor=drifted,
)
case = report["cases"][1]
evaluation = case["acceptance"]["physicalStateV21Golden"]
self.assertEqual(case["outcome"], "correctness_failed")
self.assertFalse(case["acceptance"]["passed"])
self.assertIn(
"physicalStateV21LocalInvariantMismatch",
case["acceptance"]["issues"],
)
self.assertFalse(evaluation["passed"])
self.assertEqual(
evaluation["localInvariants"]["worstValue"]["key"],
"conservation.p4node2_8.massBalance",
)
def test_python_state_drift_is_diagnostic_when_amesim_gate_passes(self) -> None:
execute_source = self._physical_state_v21_result_executor()
def drifted(request: RegressionCaseRequest) -> dict[str, object]:
result = execute_source(request)
if request.case_id == "0.2s":
values = result["worker"]["summary"]["physicalContract"][
"checkpoints"
][-1]["stateValues"]
first_key = next(iter(values))
values[first_key] += 1.0
return result
report = run_regression_suite(
DEFAULT_MANIFEST_PATH,
lane="production",
case_ids=["0.2s"],
case_executor=drifted,
)
case = report["cases"][1]
diagnostic = case["acceptance"]["regressionGolden"]
self.assertEqual(case["outcome"], "completed")
self.assertTrue(case["acceptance"]["passed"])
self.assertFalse(diagnostic["passed"])
self.assertIn("stateCheckpointGoldenValueMismatch", diagnostic["issues"])
self.assertEqual(diagnostic["acceptanceIssues"], [])
self.assertTrue(case["acceptance"]["physicalStateV21Golden"]["passed"])
def test_amesim_baseline_drift_is_the_physical_acceptance_gate(self) -> None:
execute_source = self._physical_state_v21_result_executor()
def drifted(request: RegressionCaseRequest) -> dict[str, object]:
result = execute_source(request)
if request.case_id == "0.2s":
result["worker"]["summary"]["physicalStateV21"]["checkpoints"][-1][
"values"
]["pressure.pnch012_8.absolute"] += 1.0e6
return result
report = run_regression_suite(
DEFAULT_MANIFEST_PATH,
lane="production",
case_ids=["0.2s"],
case_executor=drifted,
)
case = report["cases"][1]
evaluation = case["acceptance"]["physicalStateV21Golden"]
self.assertEqual(case["outcome"], "correctness_failed")
self.assertFalse(case["acceptance"]["passed"])
self.assertIn("amesimReferenceToleranceMismatch", case["acceptance"]["issues"])
self.assertFalse(evaluation["passed"])
self.assertEqual(evaluation["worstValue"]["amesimBaseline"], 3625053.2009413484)
def test_requesting_late_case_also_runs_every_predecessor(self) -> None:
calls: list[str] = []
@@ -585,7 +819,7 @@ class ProgressiveSuiteTests(unittest.TestCase):
self.assertEqual(
seen,
[("solver-only", 0.02, 0.05), ("production", 0.005, 0.005)],
[("solver-only", 0.02, 0.05), ("production", 0.01, 0.001)],
)