Qualification¶
qualification
¶
Opt-in, eager numerical qualification of compiled RHS functions.
This module checks user-supplied fixtures against independent equations and optional balance and JAX directional-derivative checks. It does not replace structural validation or establish scientific validity or integration accuracy.
ArrayComparison
¶
Bases: NamedTuple
Reference parity, shape/dtype preservation, and finite-value diagnostics.
FixtureQualification(fixture, evaluator, backend, time, rtol, atol, arrays=(), invariants=(), derivative=None, errors=())
dataclass
¶
Qualification of one named fixture through one evaluator.
All diagnostics are host values: this report is an eager authoring tool, even when the evaluated RHS uses JAX or Torch arrays.
ok
property
¶
Whether every requested check passed.
InvariantCheck
¶
Bases: NamedTuple
A residual-to-zero balance check with explicit applicability conditions.
NumericalCheck
¶
Bases: NamedTuple
A named numerical check and any informative failure messages.
QualificationConfig(rtol=1e-07, atol=1e-09, derivative_step=1e-05, derivative_rtol=0.0001, derivative_atol=1e-06)
dataclass
¶
Reference and derivative tolerances for eager qualification.
Defaults assume double precision. Choose wider tolerances and a larger finite-difference step for float32 fixtures.
__post_init__()
¶
Validate controls.
Raises:
| Type | Description |
|---|---|
ValueError
|
If a tolerance or finite-difference step is invalid. |
Source code in src/op_system/qualification.py
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 | |
QualificationFixture
¶
Bases: NamedTuple
Named structured state/parameter fixture and optional state direction.
QualificationReport(fixtures)
dataclass
¶
Inspectable results for all requested fixture/evaluator combinations.
ok
property
¶
Whether all fixtures and requested evaluators qualified.
to_dict()
¶
Return JSON-compatible fields, including per-fixture pass/fail status.
Returns:
| Type | Description |
|---|---|
dict[str, object]
|
A mapping suitable for |
Source code in src/op_system/qualification.py
164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 | |
qualify_rhs(compiled, fixtures, reference, *, evaluators=('flat', 'structured'), config=None, invariants=())
¶
Compare compiled layouts against independently supplied equations.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
compiled
|
CompiledRhs
|
Compiled RHS to inspect; structural validation is separate. |
required |
fixtures
|
Sequence[QualificationFixture]
|
Named structured state/parameter fixtures. Supply a JAX
state |
required |
reference
|
ReferenceRhs
|
Independent |
required |
evaluators
|
Sequence[Evaluator]
|
Requested layouts. Unavailable layouts produce failed records rather than silently falling back to another evaluator. |
('flat', 'structured')
|
config
|
QualificationConfig | None
|
Reference and derivative tolerances. Defaults assume double precision; adjust the tolerances and difference step for float32. |
None
|
invariants
|
Sequence[InvariantCheck]
|
Residual-to-zero callbacks with stated conditions and individual absolute tolerances, such as closed-system balance. |
()
|
Returns:
| Type | Description |
|---|---|
QualificationReport
|
Eager host diagnostics for every requested combination. Fixture-based |
QualificationReport
|
agreement is not a proof of scientific validity or solution accuracy. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If fixtures/evaluators are empty, fixture names/time are invalid, or an invariant lacks valid conditions/tolerances. |
Examples:
>>> import numpy as np
>>> from op_system import compile_spec
>>> compiled = compile_spec({
... "kind": "expr",
... "state": ["x"],
... "equations": {"x": "-rate*x"},
... })
>>> fixture = QualificationFixture(
... "decay", {"x": np.array(4.0)}, {"rate": 0.5}
... )
>>> def reference(time, state, params):
... return {"x": -params["rate"] * state["x"]}
>>> report = qualify_rhs(compiled, [fixture], reference)
>>> report.ok
True
>>> len(report.fixtures)
2
Source code in src/op_system/qualification.py
525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 | |