Add optional name parameter to PyMCStateSpace for multiple models #611
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
As discussed in [#602](#602), this PR adds an optional
nameparameter toPyMCStateSpace. When provided, it is used to prefix all variables and registered data created by that state-space model. This makes it possible to use multiple state-space models inside one PyMC model without name collisions.What this changes
Add
name: str | None = NonetoPyMCStateSpace.__init__.Add
_prefix_name(self, var_name: str) -> str, which:var_nameunchanged ifself.name is None"{name}_{var_name}".Apply
_prefix_namewhen:pm.Deterministicvariables,SequenceMvNormal,H_jittered,x0_slice,P0_slice,forecast_*,irf,initial_shock,Update data helpers (
add_data_to_active_model,register_data_with_pymc) so that state-space models can optionally pass prefixed data names.Backwards compatibility
nameis not provided, everything behaves exactly as before.PyMCStateSpaceshould work without any changes.Example
This results in variables such as
"vision_obs","motor_obs","vision_data", etc., allowing both models to coexist cleanly in the same PyMC model.Testing
tests/statespace/test_register_variable.pyto check the basic naming and variable-registration behavior.pytest tests/statespacein a cleanpip install -e ".[dev]"environment.FutureWarningerrors frompytensor.graph.basic.*imports (these have moved topytensor.graph.traversal.*). This appears unrelated to this PR and originates from existing imports in the codebase and test suite.