Skip to content

Evaluate observable rules in SI, not in declared units - #37

Merged
jeliason merged 1 commit into
mainfrom
feature/observables-si-units
Aug 4, 2026
Merged

Evaluate observable rules in SI, not in declared units#37
jeliason merged 1 commit into
mainfrom
feature/observables-si-units

Conversation

@jeliason

@jeliason jeliason commented Aug 4, 2026

Copy link
Copy Markdown
Member

A rule is written in the model's declared units and is dimensionally consistent only after conversion. V_T adds V_Tmin in mL to a cell count times vol_cell in micrometre^3. SimBiology reconciles that by tracking units; the C++ emitter reconciles it by scaling every parameter on load (_class_parameter[P_vol_cell] = PFILE(QSP_vol_cell) * 602214.199). The Python emitter read the raw SBML numbers and applied nothing, so it was summing incompatible quantities.

Sharing an SBML parse was not enough to keep the two paths in step, because only one of them converted.

On the PDAC model all 13 constants in the live closure carry a factor, spanning 1.66e-24 to 6.02e5:

V_T at campaign p75:   2.16e13   ->  33.1 mL
stromal_fraction:      1.000000  ->  0.769  (and now varies with the patient)

That target could never move and would have read as total misfit against any real measurement.

Change: _classify reads get_si_factor for every parameter, species and compartment. emit converts inputs to SI, evaluates, and converts each requested output back, so the module takes and returns the model's own units. Factors appear as a visible SI_FACTOR table rather than folded into the arithmetic. Only inputs are required to declare units; an undeclared rule variable correctly defaults to 1.0.

Also stamps the emitter version plus a hash of its own source into the generated header, since the version alone does not move under an editable install.

Six new tests, including one pinning the exact failure (mL plus micrometre^3 giving 1.0 + 6e-12, not 7.0) and a native-units round trip.

A rule is written in the model's declared units and is dimensionally consistent
only after conversion. V_T adds V_Tmin in mL to a cell count times vol_cell in
micrometre^3; SimBiology reconciles that by tracking units, and the C++ emitter
reconciles it by scaling every parameter on load. The Python emitter read the raw
numbers, so it was summing incompatible quantities.

On the PDAC model all 13 constants in the live closure carry a factor, spanning
1.66e-24 to 6.02e5. V_T came out as 2.16e13 rather than 33 mL, which drove
stromal_fraction to exactly 1.0 for every patient: a calibration target that
could never move and would read as total misfit.

Inputs convert in, results convert back out, so the module takes and returns the
model's own units, which is what the simulator writes and what a target reads.
The factors are emitted as a visible SI_FACTOR table rather than folded into the
arithmetic.

Also stamps the emitter's version and a hash of its source into the header. The
version alone does not move under an editable install, and an artifact that does
not rebuild when its generator changes is the same drift this module exists to
prevent.
@jeliason
jeliason merged commit d4b1e99 into main Aug 4, 2026
2 checks passed
@jeliason
jeliason deleted the feature/observables-si-units branch August 4, 2026 23:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant