Skip to content

Conversation

@SarahRo
Copy link
Contributor

@SarahRo SarahRo commented Jan 6, 2026

Description

Introduces a MarginalDistribution class (subclass of Distribution) that is constructed from a BaseMultivariateDistribution. This is achieved by adding a method called 'marginal' to the multivariate distributions that returns the marginal distribution. The pybop.MarginalDistribution retains the original multivariate distribution in the parent_distribution attribute.

The MultivariateParameters class is removed. Instead, a check_multivariate method is added to pybop.Parameters() that checks whether a MarginalDistribution is present and if so whether all parameters have a MarginalDistribution with the same parent_distribution. This method is called in the constructor, the set method and the add method. The call to the method can be disabled in the add and set method by setting the parameter check_multivariate to false. This is, for example, used in the constructor in order to only call the method once all parameters have been added.

The edits to the Parameters class are a little bit hacky. However, this approach means the Problem and Simulator classes do not explicitly need to be aware whether they are dealing with mulitvariate parameters.

An alternative approach would be to discard the changes to pybop.Parameters, reintroduce the MultivariateParameters class and construct the MulitvariateParameters class in pybop.pybamm.Simulator if any parameters of type MultivariateParameter are provided to the constructor as part of the ParameterValues object. This means that Problem and MetaProblem need to distinguish between MultivariateParameters and Parameters as well (this would only require minor edits).

Fixes #856

Type of change

Please add a line in the relevant section of CHANGELOG.md to document the change (include PR #).

Important checks:

Please confirm the following before marking the PR as ready for review:

  • No style issues: $ pre-commit run or $ nox -s pre-commit (see CONTRIBUTING.md for how to set this up to run automatically when committing locally, in just two lines of code)
  • All tests pass: nox -s tests
  • The documentation builds: nox -s doctest
  • Code is commented for hard-to-understand areas
  • Tests added that prove fix is effective or that feature works

@codecov
Copy link

codecov bot commented Jan 6, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.89%. Comparing base (4628a65) to head (3df8386).
⚠️ Report is 19 commits behind head on develop.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop     #862      +/-   ##
===========================================
+ Coverage    89.41%   90.89%   +1.47%     
===========================================
  Files           63       66       +3     
  Lines         4857     5291     +434     
===========================================
+ Hits          4343     4809     +466     
+ Misses         514      482      -32     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

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

@SarahRo SarahRo marked this pull request as ready for review January 21, 2026 13:50
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.

Allow MultivariateParameters to be set within ParameterValues

2 participants