Skip to content

Parametrize offset models#265

Open
CeliaBenquet wants to merge 7 commits intoAdaptiveMotorControlLab:mainfrom
CeliaBenquet:celia/simplify-offset-models
Open

Parametrize offset models#265
CeliaBenquet wants to merge 7 commits intoAdaptiveMotorControlLab:mainfrom
CeliaBenquet:celia/simplify-offset-models

Conversation

@CeliaBenquet
Copy link
Copy Markdown
Member

@CeliaBenquet CeliaBenquet commented Aug 22, 2025

  • Parametrize offset models into a single OffsetNModel class so that we don't have to recreate a specific model for each new receptive field wanted. Instead, it can just be added to the list of parameters in the parametrize decorator.
  • This handles both odd and even receptive field sizes.
  • Also restructured the tests/ folder so that deprecation test code is grouped in a subfolder.

@CeliaBenquet CeliaBenquet self-assigned this Aug 22, 2025
@CeliaBenquet CeliaBenquet added the enhancement New feature or request label Aug 22, 2025
@cla-bot cla-bot Bot added the CLA signed label Aug 22, 2025
Copy link
Copy Markdown
Member

@stes stes left a comment

Choose a reason for hiding this comment

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

Good initiative, thanks --- but add tests that confirm that the previously hardcoded models are 1:1 the same. You can do this by:

  • copy pasting the old model code to the test folder as reference implementation
  • instantiate with the new code, and check that all kinds of properties match 1:1

If this is hard to achieve, the alternative is to just let old and new models co-exist :)

e.g. use "varoffset-10-model" or so for the new ones?

@MMathisLab
Copy link
Copy Markdown
Member

@CeliaBenquet lets wrap this one up?

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR refactors multiple offset model classes into a single parametrized OffsetNModel class that dynamically generates models with different receptive field sizes. This reduces code duplication by consolidating 7 separate model class definitions (Offset5Model, Offset10Model, Offset15Model, Offset20Model, Offset36Model, Offset40Model, Offset50Model) into one parameterized class that handles both odd and even receptive field sizes.

Changes:

  • Introduced OffsetNModel class with parametrize decorator to generate models for receptive fields of 5, 10, 15, 18, 20, 31, 36, 40, and 50 samples
  • Removed 7 redundant offset model class definitions
  • Updated documentation to reflect the new available model names

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
cebra/models/model.py Replaced multiple offset model classes with a single parametrized OffsetNModel class and removed deprecated implementations
docs/source/usage.rst Updated the example output to show the new parametrized model names available

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

Comment thread cebra/models/model.py Outdated
Comment thread cebra/models/model.py Outdated
Comment thread cebra/models/model.py Outdated
@stes stes force-pushed the celia/simplify-offset-models branch from c771677 to 66c8872 Compare January 18, 2026 12:38
@MMathisLab MMathisLab requested a review from stes April 2, 2026 14:19
@CeliaBenquet
Copy link
Copy Markdown
Member Author

I got this error, related to my changes, but results from an existing latent bug in registry.py:

FAILED tests/test_solver.py::test_single_session[demo-discrete-offset10-model-DiscreteDataLoader-SingleSessionSolver] - TypeError: OffsetNModel.__init__() got multiple values for argument 'num_neurons'
FAILED tests/test_solver.py::test_single_session[demo-continuous-offset10-model-ContinuousDataLoader-SingleSessionSolver] - TypeError: OffsetNModel.__init__() got multiple values for argument 'num_neurons'
FAILED tests/test_solver.py::test_single_session[demo-mixed-offset10-model-MixedDataLoader-SingleSessionSolver] - TypeError: OffsetNModel.__init__() got multiple values for argument 'num_neurons'
FAILED tests/test_solver.py::test_single_session_hybrid[demo-continuous-offset10-model-HybridDataLoader-SingleSessionHybridSolver] - TypeError: OffsetNModel.__init__() got multiple values for argument 'num_neurons'
FAILED tests/test_solver.py::test_multi_session[demo-discrete-multisession-offset10-model-DiscreteMultiSessionDataLoader-MultiSessionSolver] - TypeError: OffsetNModel.__init__() got multiple values for argument 'num_neurons'
FAILED tests/test_solver.py::test_multi_session[demo-continuous-multisession-offset10-model-ContinuousMultiSessionDataLoader-MultiSessionSolver] - TypeError: OffsetNModel.__init__() got multiple values for argument 'num_neurons'
FAILED tests/test_solver.py::test_unified_session[demo-continuous-unified-offset10-model-UnifiedLoader-UnifiedSolver] - TypeError: OffsetNModel.__init__() got multiple values for argument 'num_neurons'
= 7 failed, 1525 passed, 1399 skipped, 31 deselected, 108 warnings in 72.44s (0:01:12) =
make: *** [Makefile:45: test_reduced] Error 1
Error: Process completed with exit code 2.

This was due to the @parametrize wrapper. The default_kwargs dictionary is updated in-place rather than constructing one per call. Appears here because I instantiate the OffsetNModel class multiple times across tests.

Solved by removing the in-place update() and constructing a "fresh" kwargs per instance instead.

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

Labels

CLA signed enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants