Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disallow modifications to pybamm.Simulation object attributes after initialisation #3267

Merged

Conversation

agriyakhetarpal
Copy link
Member

Description

Removes the setter methods in the Simulation class, so that parameters defined in the initialisation of a pybamm.Simulation instance cannot be modified unless the instance is redefined

This way, attributes like sim.model or sim.parameter_values cannot be edited directly. A new sim object with the modified parameters is required to incorporate changes, i.e.,

import pybamm

model = pybamm.lithium_ion.DFN()
sim = pybamm.Simulation(model)

sim.model = pybamm.lithium_ion.DFN()  # no setter method for self.model(), will not work

model1 = pybamm.lithium_ion.SPM()
sim1 = pybamm.Simulation(model)  # new simulation object with the SPM, works

Fixes #3196

Type of change

Please add a line in the relevant section of CHANGELOG.md to document the change (include PR #) - note reverse order of PR #s. If necessary, also add to the list of breaking changes.

  • New feature (non-breaking change which adds functionality)
  • Optimization (back-end change that speeds up the code)
  • Bug fix (non-breaking change which fixes an issue)

Key checklist:

  • 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: $ python run-tests.py --all (or $ nox -s tests)
  • The documentation builds: $ python run-tests.py --doctest (or $ nox -s doctests)

You can run integration tests, unit tests, and doctests together at once, using $ python run-tests.py --quick (or $ nox -s quick).

Further checks:

  • Code is commented, particularly in hard-to-understand areas
  • Tests added that prove fix is effective or that feature works

@codecov
Copy link

codecov bot commented Aug 11, 2023

Codecov Report

Patch coverage: 100.00% and project coverage change: -0.02% ⚠️

Comparison is base (8af2430) 99.57% compared to head (5cdf00b) 99.56%.
Report is 4 commits behind head on develop.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #3267      +/-   ##
===========================================
- Coverage    99.57%   99.56%   -0.02%     
===========================================
  Files          253      253              
  Lines        19571    19546      -25     
===========================================
- Hits         19488    19461      -27     
- Misses          83       85       +2     
Files Changed Coverage Δ
pybamm/simulation.py 99.54% <100.00%> (-0.46%) ⬇️

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

@agriyakhetarpal
Copy link
Member Author

@tinosulzer let me know if this needs a CHANGELOG entry (my guess is that it does)

Copy link
Member

@brosaplanella brosaplanella left a comment

Choose a reason for hiding this comment

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

Looks good, thanks! Can you improve the coverage and add a CHANGELOG line? Happy to approve then :)

@agriyakhetarpal
Copy link
Member Author

I added a CHANGELOG entry. Could you help on improving the coverage? It passes locally for me

@brosaplanella
Copy link
Member

I added a CHANGELOG entry. Could you help on improving the coverage? It passes locally for me

Ok, then probably it is an issue with Codecov. Let's wait for a second review before merging in any case.

CHANGELOG.md Outdated Show resolved Hide resolved
Copy link
Member

@brosaplanella brosaplanella left a comment

Choose a reason for hiding this comment

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

Looks good, thanks!

@brosaplanella brosaplanella merged commit d75d0d5 into pybamm-team:develop Sep 21, 2023
29 of 32 checks passed
@agriyakhetarpal agriyakhetarpal deleted the fix-simulation-api-behaviour branch September 21, 2023 12:57
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.

pybamm.Simulation - private attributes ignore current state of public attributes in build() and solve()
2 participants