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

Issue 3051 - bpx activation energies #3242

Conversation

darryl-ad
Copy link
Contributor

@darryl-ad darryl-ad commented Aug 7, 2023

Description

Fixes a bug where E_a was used as the alias for multiple different activation energies in bpx, causing them to all take the final value. Also fixes bug where reaction rate constant activation energy was always set as 0.

  • Assigned unique variable names
  • Edited naming convention for better clarity
  • Updated variable name reaction rate activation energy -> reaction rate constant activation energy in bpx parameter search.

Fixes # 3051 and # 3225

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

Sorry, something went wrong.

@darryl-ad darryl-ad changed the title Issue3051 bpx diffusivity activation energies Issue 3051 - bpx diffusivity activation energies Aug 7, 2023
@darryl-ad darryl-ad changed the title Issue 3051 - bpx diffusivity activation energies Issue 3051 - bpx activation energies Aug 7, 2023
@darryl-ad
Copy link
Contributor Author

Added an additional commit to fix #3225 here. I was concerned separate PRs would cause a merge conflict.

@codecov
Copy link

codecov bot commented Aug 7, 2023

Codecov Report

Patch coverage: 100.00% and project coverage change: +0.05% 🎉

Comparison is base (a270b08) 99.55% compared to head (d130615) 99.60%.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #3242      +/-   ##
===========================================
+ Coverage    99.55%   99.60%   +0.05%     
===========================================
  Files          253      253              
  Lines        19553    19541      -12     
===========================================
- Hits         19466    19464       -2     
+ Misses          87       77      -10     
Files Changed Coverage Δ
pybamm/parameters/bpx.py 99.49% <100.00%> (+4.73%) ⬆️

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

Copy link
Member

@valentinsulzer valentinsulzer 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, can you add tests for coverage?

You could also reduce code duplication by defining the arrhenius function up front and just calling it everywhere e.g.

def arrhenius(Ea, T):
     return exp(Ea / constants.R * (1 / T_ref - 1 / T))

and later

return arrhenius(Ea_D_e, T) * ...

@darryl-ad
Copy link
Contributor Author

  • refactored code as suggested
  • added a simple unit test for coverage, and to validate arrhenius calculations

I've not made a test before, so please double check it's ok!

See separate discussion here #3225 about full testing requirements for BPX.

@brosaplanella
Copy link
Member

The test looks good to me. The issues with the coverage seem to be that for various parameters it never reaches the else statement. The two previous if statements check for callables and data, so I guess the else should be for constant values, but I am not sure why test_constant_functions is not covering those lines.

@darryl-ad
Copy link
Contributor Author

I agree, I'm not sure why test_constant_functions no longer covers those lines

@brosaplanella
Copy link
Member

Can you run it in debug mode and check why the constant case does not reach the else?

@darryl-ad
Copy link
Contributor Author

Sorry not sure what you mean by debug mode. However I tested it with print statements and the constant case does reach the else

@brosaplanella
Copy link
Member

I think the issue is that in test_constant_functions the parameter values are created from BPX but then not used. Therefore, the header of the function is covered (as the tests goes inside the if statement) but the return line doesn't as it is not get called. I think that if you add some additional tests after line 163 which check that the values are as expected it should be fine.

@darryl-ad
Copy link
Contributor Author

@brosaplanella I've added a test that I think addresses your previous comment, thanks!

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 to me! I couldn't tell why the doc tests are failing though, @agriyakhetarpal do you have any insight?

CHANGELOG.md Outdated
@@ -13,6 +13,7 @@
- Error generated when invalid parameter values are passed. ([#3132](https://github.com/pybamm-team/PyBaMM/pull/3132))
- Thevenin() model is now constructed with standard variables: `Time [s], Time [min], Time [h]` ([#3143](https://github.com/pybamm-team/PyBaMM/pull/3143))
- Fix SEI Example Notebook ([#3166](https://github.com/pybamm-team/PyBaMM/pull/3166))
- Fixed bug causing incorrect activation energies using `create_from_bpx()` ([#3242](https://github.com/pybamm-team/PyBaMM/pull/3242))
Copy link
Member

Choose a reason for hiding this comment

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

Can you move this up so they PRs are in decreasing order?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done!

@agriyakhetarpal
Copy link
Member

There is a reST syntax warning/error in the installation instructions for WSL. I am adding a link to the erroneous lines because I cannot suggest changes directly here:

https://github.com/pybamm-team/PyBaMM/blob/develop/docs/source/user_guide/installation/windows-wsl.rst?plain=1#L24-L36

Removing the extra colons in points 3 and 4 will fix it

@brosaplanella
Copy link
Member

Thanks Agriya! @darryl-ad, can you resolve the conflict with CHANGELOG so tests run, and do the small fix Agriya suggested?

@darryl-ad
Copy link
Contributor Author

@brosaplanella I've resolved the CHANGELOG conflict. All tests are passing on my end now. The erroneous lines in the docs that Agriya suggested aren't present in this branch - do I need to create an issue and branch for it?

@brosaplanella
Copy link
Member

Looks good to me! We will need @tinosulzer to approve it as he requested changes.

CHANGELOG.md Outdated
@@ -8,8 +8,8 @@
- Implement the MSMR model ([#3116](https://github.com/pybamm-team/PyBaMM/pull/3116))

## Bug fixes

- Fixed bug causing incorrect activation energies using `create_from_bpx()` ([#3242](https://github.com/pybamm-team/PyBaMM/pull/3242))
Copy link
Member

Choose a reason for hiding this comment

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

Can you move this line down so the PRs are sorted in decreasing order? Happy to merge after that

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done!

@brosaplanella brosaplanella merged commit 549deb7 into pybamm-team:develop Sep 19, 2023
31 of 32 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants