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

#2368 overload numpy functions #3205

Merged
merged 5 commits into from Aug 2, 2023
Merged

#2368 overload numpy functions #3205

merged 5 commits into from Aug 2, 2023

Conversation

valentinsulzer
Copy link
Member

Description

  • Numpy functions can now be called on pybamm symbolic objects. This will return a pybamm symbolic object applying the same function (e.g. np.exp(x) returns pybamm.Exp(x)). Parameter sets in the library have been changed to use numpy functions, but they do not need to be (the old style of calling pybamm functions will still work)
  • Binary operators applied to a pybamm object and numpy array return a pybamm binary operator, where previously it raised an error. The numpy array gets converted to a pybamm Vector. This only works with 1D arrays (it could work with other objects, but restricting it to 1D arrays makes things easier for now

Fixes #2368

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 (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
  • The documentation builds: $ python run-tests.py --doctest

You can run unit and doctests together at once, using $ python run-tests.py --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 Jul 30, 2023

Codecov Report

Patch coverage: 100.00% and no project coverage change.

Comparison is base (61e04b3) 99.71% compared to head (4facad1) 99.71%.
Report is 6 commits behind head on develop.

Additional details and impacted files
@@           Coverage Diff            @@
##           develop    #3205   +/-   ##
========================================
  Coverage    99.71%   99.71%           
========================================
  Files          248      248           
  Lines        18808    18830   +22     
========================================
+ Hits         18754    18776   +22     
  Misses          54       54           
Files Changed Coverage Δ
pybamm/expression_tree/binary_operators.py 100.00% <100.00%> (ø)
pybamm/expression_tree/symbol.py 100.00% <100.00%> (ø)
pybamm/input/parameters/lead_acid/Sulzer2019.py 100.00% <100.00%> (ø)
pybamm/input/parameters/lithium_ion/Ai2020.py 100.00% <100.00%> (ø)
pybamm/input/parameters/lithium_ion/Chen2020.py 100.00% <100.00%> (ø)
...input/parameters/lithium_ion/Chen2020_composite.py 100.00% <100.00%> (ø)
pybamm/input/parameters/lithium_ion/Ecker2015.py 100.00% <100.00%> (ø)
pybamm/input/parameters/lithium_ion/Marquis2019.py 100.00% <100.00%> (ø)
pybamm/input/parameters/lithium_ion/Mohtat2020.py 100.00% <100.00%> (ø)
pybamm/input/parameters/lithium_ion/NCA_Kim2011.py 100.00% <100.00%> (ø)
... and 5 more

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

Copy link
Sponsor 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! Just a very small comment (you will have to update the CHANGELOG too).

examples/scripts/compare_lithium_ion.py Outdated Show resolved Hide resolved
@valentinsulzer valentinsulzer merged commit 525db23 into develop Aug 2, 2023
20 of 22 checks passed
@valentinsulzer valentinsulzer deleted the issue-2368-numpy branch August 2, 2023 22:06
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.

Overload numpy functions
2 participants