Support generic initial_state in simulate config#220
Closed
jc-macdonald wants to merge 2 commits intomainfrom
Closed
Support generic initial_state in simulate config#220jc-macdonald wants to merge 2 commits intomainfrom
jc-macdonald wants to merge 2 commits intomainfrom
Conversation
Allow simulate specs to declare an initial_state dict instead of relying on the hardcoded s0/i0/r0 parameter convention. When initial_state is present in the simulate block, its values are used directly as the state vector and its keys are excluded from params. Falls back to the legacy s0/i0/r0 lookup when initial_state is absent.
Collaborator
TimothyWillard
left a comment
There was a problem hiding this comment.
Conceptual question, also this should be a squashed commit if merging
| ) | ||
| target_name = target or next(iter(config_model.simulate)) | ||
| sim_spec = config_model.simulate[target_name] | ||
| raw_initial: dict[str, float] | None = getattr(sim_spec, "initial_state", None) |
Collaborator
Contributor
Author
|
superseded by #226. |
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.
Summary
Generalize the
SimulateCommandto support arbitrary-length initial state vectors instead of the hardcodeds0/i0/r0convention.Problem
The simulate CLI command hardcodes initial state extraction to exactly three SIR compartments (
s0,i0,r0). This makes it impossible to useflepimop2 simulatewith models that have more (or fewer) than 3 states — e.g., SIRHD (5 states) or vaccination-structured models (9+ states).Solution
When a simulate spec includes an
initial_statedict, its values are used directly as the state vector and its keys are excluded from the params dict. The legacys0/i0/r0fallback is preserved for backward compatibility.New config usage:
No schema changes were needed —
SimulateSpecificationModelalready hasConfigDict(extra="allow"), so theinitial_statekey is accepted and accessible viagetattr.Note on inference compatibility
The new
initial_statepath currently takes raw floats, bypassingParameterABC. This means initial conditions are fixed constants that cannot yet participate in sampling or optimization. However, this does not block future inference support — the dict-of-names structure is well-positioned for it. A future extension just needs to check whether each value is a bare number or a parameter module reference (e.g.,{module: distribution, ...}) and route accordingly. The key names are the actual state names, which is a better foundation than the ad-hocs0/i0/r0convention.Changes
src/flepimop2/_cli/_simulate_command.py: Generalized initial state extraction (+22/-12 lines)CHANGELOG.md: Added entry under ChangedTesting