Evaluate observable rules in SI, not in declared units - #37
Merged
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A rule is written in the model's declared units and is dimensionally consistent only after conversion.
V_TaddsV_Tminin mL to a cell count timesvol_cellin 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:
That target could never move and would have read as total misfit against any real measurement.
Change:
_classifyreadsget_si_factorfor every parameter, species and compartment.emitconverts 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 visibleSI_FACTORtable 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, not7.0) and a native-units round trip.