WIP - add aliases and alias elimination for ReactionSystems#1449
Open
isaacsas wants to merge 8 commits intoSciML:masterfrom
Open
WIP - add aliases and alias elimination for ReactionSystems#1449isaacsas wants to merge 8 commits intoSciML:masterfrom
isaacsas wants to merge 8 commits intoSciML:masterfrom
Conversation
Add species/variable/parameter aliasing with automatic elimination during
model conversion and problem construction. Aliases declared via `lhs ~ rhs`
are resolved by substitution, with eliminated unknowns becoming observables
and eliminated parameters removed throughout.
Key features:
- `aliases` field on ReactionSystem with `@aliases` DSL option
- AliasClass EnumX for type-safe classification and validation
- Cycle detection via DFS with path compression
- Stoichiometry merging, no-op reaction removal, IC transfer
- `eliminate_aliases` kwarg on all model/problem constructors
- `remap_alias_inputs` for user input remapping (Dict + Vector{Pair})
- Composition support (compose/extend/flatten)
- isequivalent comparison and serialization guard
- 85 tests across 21 test sets
- Developer docs: ReactionSystem field addition checklist
- Comprehensive HISTORY.md with known limitations
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Alias substitution maps survive in metadata after round-trip through MT.System; only the alias declarations field is cleared. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
The @enumx AliasClass macro generates a submodule that ExplicitImports.jl cannot analyze, same as PhysicalScale. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Symbols appearing only in aliases (not in reactions/equations) were not being added to the system unknowns/parameters during construction. This adds a collect_vars! loop over aliases in make_ReactionSystem_internal, matching the existing pattern for observables, events, etc. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
has_aliases now follows the MTK convention of indicating type-level support (always true for ReactionSystem). The new aliases_present function performs the value-level recursive check for whether any alias equations exist in the system tree. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
ss_ode_model: use fullrs instead of rs for bindings computation and differential equation check. sde_model: use flatrs instead of rs for completeness and spatial checks in legacy noise path. jump_model: make eliminate_aliases an explicit kwarg instead of extracting from kwargs. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
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.
NOTE: I still need to give this a comprehensive line by line review as I have primarily carefully reviewed/edited the plan for this and the implementation of select functions within the plan. So this is currently very WIP.
Alias Elimination for ReactionSystems
This PR adds support for declaring symbol aliases on
ReactionSystems and automatically eliminating them during model conversion and problem construction.Motivation
When composing multiple
ReactionSystems, users often need to declare that a species or parameter in one subsystem is the same as in another. Previously, this required algebraic equations for unknowns and had no built-in mechanism for parameters. This PR provides a first-class alias system with automatic resolution.How it works
An alias
A ~ Bdeclares thatA(the LHS) is eliminated in favor ofB(the RHS, the canonical/surviving symbol). During model conversion, all references toAare substituted withBthroughout reactions, equations, events, initial conditions, and observables. Eliminated unknowns become observables so they remain accessible in solutions viasol[A].Basic usage
Supported alias types (v1)
Key features
ode_model,sde_model,jump_model,hybrid_model,ss_ode_model) and problem constructors (ODEProblem,SDEProblem,JumpProblem,HybridProblem,NonlinearProblem,SteadyStateProblem)eliminate_aliaseskwarg (trueby default) on all conversion/problem functions. Set tofalseto materialize aliases as algebraic constraints (ODE/SDE only)u0/pmaps (bothDictandVector{Pair})remap_alias_inputs(u0_or_p, sys)public function for manual remapping when using the*_model→*Problem(::System, ...)workflowcompose(...; aliases=...),extend(unions aliases),flatten(collects with namespacing)A ~ B, B ~ Ccorrectly resolves bothAandBto canonicalCA → BwithA ~ B) are dropped2A + B → CwithA ~ Bbecomes3B → Cisequivalentcompares aliases (set equality)ConstantRateJump/VariableRateJumpare now rejected atReactionSystemconstruction timeKnown limitations (v1)
Unsupported alias types (rejected with informative error):
MassActionJumpin systems with aliases (stoichiometry remapping deferred)Other limitations:
eliminate_aliases=falseis not supported for jump systems*_model→*Problem(::System, ...)workflow requires manualremap_alias_inputscallssystem_to_reactionsystemreverse conversion produces an emptyaliasesfield (the original alias declarations are cleared after elimination, though the substitution maps survive in metadata forremap_alias_inputs)Files changed
src/alias_elimination.jl— AliasClass EnumX, classification, validation, resolution, elimination, remapping, conversion helpertest/reactionsystem_core/alias_elimination.jl— 85 tests across 21 test setssrc/reactionsystem.jl—aliasesfield, constructors, accessors, flatten/compose/extend, isequivalent, non-symbolic jump guardsrc/reactionsystem_conversions.jl—eliminate_aliaseskwarg threading,prepare_aliases_for_conversion, input remapping in all problem constructors, metadata forwarding,has_alg_equationsfixessrc/dsl.jl—@aliasesoptionsrc/Catalyst.jl— include, exportssrc/reactionsystem_serialisation/serialise_reactionsystem.jl— serialization guardtest/runtests.jl— added test setHISTORY.md— feature documentation with known limitationsdocs/src/devdocs/dev_guide.md— ReactionSystem field addition checklist