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

#1886 added fix within processed variable #1894

Merged
merged 9 commits into from
Jan 17, 2022

Conversation

Scottmar93
Copy link
Contributor

Description

During the solver setup, the list of inputs/sensitivities is sorted by string and then used to assign elements of the y-array to each sensitivity. This applies the same sorting of the list before extracting the sensitivities during the process variables stage.

I haven't added a test because I couldn't think of a good way without having a full integration test (passing a full model through the pipeline and then checking that the sensitivities are independent of the order of the inputs dictionary). However, I can add it if you think this is worth it for this.

Fixes #1886

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: $ flake8
  • All tests pass: $ python run-tests.py --unit
  • The documentation builds: $ cd docs and then $ make clean; make html

You can run all three 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 Jan 10, 2022

Codecov Report

Merging #1894 (2396ed3) into develop (751c18d) will increase coverage by 0.00%.
The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff            @@
##           develop    #1894   +/-   ##
========================================
  Coverage    99.28%   99.28%           
========================================
  Files          345      345           
  Lines        19116    19119    +3     
========================================
+ Hits         18980    18983    +3     
  Misses         136      136           
Impacted Files Coverage Δ
pybamm/solvers/base_solver.py 99.35% <100.00%> (+<0.01%) ⬆️
pybamm/solvers/processed_variable.py 99.68% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 751c18d...2396ed3. Read the comment docs.

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.

Thanks @Scottmar93 . I checked changing the order in this test and indeed it fails, so it only used to work because p,q,r,s is already sorted. Could you change the order of the sensitivities in the test to make sure it still works with your fix?

@Scottmar93
Copy link
Contributor Author

@tinosulzer ah nice!! Yeah will do!

@Scottmar93
Copy link
Contributor Author

Okay, the original fix passed for some variables but not all so I have just changed it so that the inputs dictionary is sorted straight away upon being passed to the solver. This now passes the test with the dictionary keys in a different order.

Copy link
Contributor

@martinjrobins martinjrobins left a comment

Choose a reason for hiding this comment

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

thanks @Scottmar93 , this looks good, getting some strange errors in python 3.8 and 3.9 on ubuntu. I was unable to replicate this on my machine (ubuntu, python 3.8).

@valentinsulzer
Copy link
Member

I think the test error is unrelated, so happy to merge this

CHANGELOG.md Outdated Show resolved Hide resolved
@Scottmar93
Copy link
Contributor Author

I've tried merging from develop so hopefully that solves the testing issue. It looked like something that was failing on other branches as well though.

@valentinsulzer valentinsulzer merged commit 393ff5d into develop Jan 17, 2022
@valentinsulzer valentinsulzer deleted the issue-1886-order-of-sensitivities branch January 17, 2022 16:26
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.

Order of sensitivites
3 participants