Skip to content

feat(measurement): make SBML assignment-rule observables resolvable so formula: <ruleVar> just works (option 2 of #464) #465

Closed

Description

@wshlavacek

Summary

Make a measurement-model formula that references an SBML assignment-rule variable work instead of being rejected. #464 landed option 1 (the smaller, safer fix): an assignment-rule variable is excluded from the formula namespace and a reference to it fails fast at config build with a reconstruct-from-species message. This issue tracks option 2 (the user-friendly path the maintainer wants): observable: Epo_cells, formula: Epo_cells should just work, since SBML authors define exactly these convenience variables (the D2D Epo_cells / Epo_medium observables are assignment rules — Epo_cells := Epo_EpoRi + dEpoi), so reaching for them by name is the obvious first attempt.

Background (what #464 already did)

  • pybnf/petab/_sbml.py::parse_model now scans <listOfRules> and records SbmlEntities.assignment_rules = {target -> frozenset(<ci> referent names)} (e.g. {'Epo_cells': {'Epo_EpoRi', 'dEpoi'}}); namespace_symbols excludes those targets.
  • pybnf/config.py::_model_expression_namespace returns the assignment-rule targets as unresolved; _load_measurement_models raises a pointed PybnfError (Configuration._raise_assignment_rule_formula) when a formula references one.

So the parse-time groundwork (target + its referents) already exists. What's missing is resolving the value at materialize time.

The two resolution strategies (from #464's "Suggested fix" option 2)

  1. Evaluate the rule in the measurement layer (preferred — backend-agnostic). The observation layer (ADR-0036) is deliberately backend-agnostic; neither RoadRunner nor bngsim is asked to expose a computed observable today. Evaluating an assignment rule as a post-simulation transform over the trajectory keeps that property and reuses the existing PEtab-math machinery: inline the rule's RHS into the formula (or pre-materialize the rule target as a derived column before the user's formula is applied). This needs the full rule RHS expression, not just the <ci> names — i.e. a MathML → PEtab-math (infix) translation of the <assignmentRule> body. _sbml.parse_model currently collects only the referent names; it would need to carry the serialized expression too.
  2. Surface the rule target as a simulation-output column. RoadRunner already exposes assignment-rule variables; bngsim would need to emit them. This is backend-specific and asymmetric (works on one backend, not the other), so it's the weaker option for a backend-agnostic layer.

Wrinkles to handle

Acceptance

References

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions