Skip to content

Comments

Named StateSpaceModel v2 – rebase and updates after #607#654

Open
opherdonchin wants to merge 2 commits intopymc-devs:mainfrom
opherdonchin:named-statespace-v2
Open

Named StateSpaceModel v2 – rebase and updates after #607#654
opherdonchin wants to merge 2 commits intopymc-devs:mainfrom
opherdonchin:named-statespace-v2

Conversation

@opherdonchin
Copy link

Summary

This PR reintroduces the Named StateSpaceModel changes after rebasing onto main following the merge of #607.

The previous version was submitted as #611. This update incorporates the changes introduced in #607 and resolves the resulting conflicts while preserving the intended named state space behavior.

No new conceptual changes are introduced beyond what was discussed in #611.

Changes

Tests

Environment:

  • Linux (Fedora) and Windows 11
  • Python 3.14.2 (Linus) and 3.12 (Windows)
  • Commit: b173e6e

Results:

  • tests/statespace/core

    • 182 passed
    • 2 skipped (JAX tests require nutpie)
    • 0 failed
  • tests/statespace/filters

    • 59 passed
    • 1 failed (test_kalman_filter_jax[cholesky])

The single failing test occurs in the JAX Cholesky filter path and appears unrelated to the named model changes. All standard (non-JAX) filter paths and core state space tests pass.

Notes

@jessegrabowski
Copy link
Member

It looks like you checked in several files related to your local dev environment, could you clean it up?

…nique graph naming

Create a test to ensure multiple state space models can coexist with distinct names.
@opherdonchin
Copy link
Author

Sorry about that. The current PR includes only the changed files and a test:

statespace.py
data_tools.py
test_namespace.py

@codecov-commenter
Copy link

codecov-commenter commented Feb 21, 2026

Codecov Report

❌ Patch coverage is 75.75758% with 8 lines in your changes missing coverage. Please review.
✅ Project coverage is 69.24%. Comparing base (0bcccd5) to head (1bf3670).
⚠️ Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
pymc_extras/statespace/core/statespace.py 72.41% 8 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##             main     #654       +/-   ##
===========================================
+ Coverage   42.43%   69.24%   +26.81%     
===========================================
  Files          63       73       +10     
  Lines        7207     7738      +531     
===========================================
+ Hits         3058     5358     +2300     
+ Misses       4149     2380     -1769     
Files with missing lines Coverage Δ
pymc_extras/statespace/utils/data_tools.py 69.56% <100.00%> (+53.04%) ⬆️
pymc_extras/statespace/core/statespace.py 78.44% <72.41%> (+63.87%) ⬆️

... and 42 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Member

@jessegrabowski jessegrabowski left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, this is looking really clean. Just a few requests.

Also be sure to install pre-commit (pip install pre-commit; pre-commit install; pre-commit run --all) so your PR gets formatted and linted correctly.

)

if name in self._tensor_variable_info:
gname = self.graph_name(name)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As above. gname is too cryptic. Another option would be to change name to base_name and make name the prefixed version, since this will now be the "canonical" name that users see.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Under the new scheme (base_name for the unprefixed name and name for the name in the graph) it makes most sense to just call this variable name.

raise ValueError(
f"{name} is not a model parameter. All placeholder variables should correspond to model "
f"parameters."
f"{name} is not a model data-variable. All placeholder variables should correspond to model "
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
f"{name} is not a model data-variable. All placeholder variables should correspond to model "
f"{name} is not a model data variable. All placeholder variables should correspond to model "

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Corrected

f"{name} is not a model parameter. All placeholder variables should correspond to model "
f"parameters."
f"{name} is not a model data-variable. All placeholder variables should correspond to model "
f"data-variables."
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
f"data-variables."
f"data variables."

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Corrected.

n_obs=self.ssm.k_endog,
obs_coords=obs_coords,
register_data=True,
data_name=self.graph_name("data"),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's let users choose the data name in the PyMCStateSpace constructor in this PR as well, instead of hard coding it to "data". The default can still be data, but then this line becomes data_name = self.graph_name(self.data_name)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

from pymc_extras.statespace.core.statespace import PyMCStateSpace


def test_two_statespace_models_can_coexist_with_names(monkeypatch):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

put this test in the test_model file, it doesn't need a new file.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@opherdonchin
Copy link
Author

The new commit includes all changes suggested and the pre-commit processing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants