Skip to content

Add init_state arg to filtering API#264

Open
SamDuffield wants to merge 4 commits into
mainfrom
optional-init
Open

Add init_state arg to filtering API#264
SamDuffield wants to merge 4 commits into
mainfrom
optional-init

Conversation

@SamDuffield

Copy link
Copy Markdown
Contributor

As discussed in #253

This allows batched filtering starting from a specified init_state.

This adds the support without the major refactor that would be needed if we were to remove init_prepare from cuthbert.filter entirely (which is arguably cleaner: less code, no optional arg but slightly more load on the user).

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Adds an init_state optional argument to the offline filtering APIs (standard and factorial) to support batched filtering that starts from a caller-provided initial state, aligning with the direction discussed in #253 without removing init_prepare.

Changes:

  • Extend cuthbert.filter and cuthbert.factorial.filter to accept an optional init_state and adjust expected model_inputs length accordingly.
  • Update filtering implementations to skip init_prepare when an initial state is supplied.
  • Add/adjust tests to exercise filtering behavior when init_state is provided.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 9 comments.

File Description
cuthbert/filtering.py Adds init_state to the unified filtering API and updates the prep flow accordingly.
cuthbert/factorial/filtering.py Adds init_state support to factorial filtering and updates the initialization path.
tests/cuthbert/gaussian/test_kalman.py Adds coverage for providing init_state to the standard filter (seq + parallel).
tests/cuthbert/factorial/test_kalman.py Adds coverage for providing init_state to factorial filtering.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread cuthbert/filtering.py Outdated
Comment thread cuthbert/filtering.py Outdated
Comment thread cuthbert/filtering.py Outdated
Comment thread cuthbert/filtering.py Outdated
Comment thread cuthbert/factorial/filtering.py Outdated
Comment thread cuthbert/factorial/filtering.py Outdated
Comment thread cuthbert/factorial/filtering.py Outdated
Comment thread cuthbert/factorial/filtering.py Outdated
Comment thread tests/cuthbert/factorial/test_kalman.py
SamDuffield and others added 2 commits June 26, 2026 17:16
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>

@Sahel13 Sahel13 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This looks good. Since this is a user-facing change, one minor question is whether we should make the arguments that have defaults in cuthbert.filter keyword-only, so that users that currently use filter(obj, inputs, False, key) would get a clear error.

@SamDuffield

Copy link
Copy Markdown
Contributor Author

This looks good. Since this is a user-facing change, one minor question is whether we should make the arguments that have defaults in cuthbert.filter keyword-only, so that users that currently use filter(obj, inputs, False, key) would get a clear error.

Good idea, I like this!

@SamDuffield

Copy link
Copy Markdown
Contributor Author

@Sahel13 I made the args after model_inputs keyword-only, can you confirm that's what you meant?

@Sahel13

Sahel13 commented Jun 29, 2026

Copy link
Copy Markdown
Collaborator

Yup this is it!

@SamDuffield

Copy link
Copy Markdown
Contributor Author

As this is a user-facing change, it would be good to get @AdrienCorenflos' thoughts too

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