Skip to content

Issue 1221 convert to casadi - #1316

Merged
valentinsulzer merged 19 commits into
developfrom
issue-1221-convert-to-casadi
Dec 31, 2020
Merged

valentinsulzer merged 19 commits into
developfrom
issue-1221-convert-to-casadi

Conversation

@valentinsulzer

Copy link
Copy Markdown
Member

Description

Convert variables to casadi for faster post-processing.
The conversion is done the first time the variable is called, and the casadi function is then stored in the model (in model._variables_casadi. Therefore, when doing repeated solutions of the same model (e.g. for parameter sweeps) the conversion is only performed the first time.

Fixes #1221

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

codecov Bot commented Dec 31, 2020 •

Copy link
Copy Markdown

Codecov Report

Merging #1316 (4b84f39) into develop (66b9589) will increase coverage by 0.00%.
The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff            @@
##           develop    #1316   +/-   ##
========================================
  Coverage    98.10%   98.10%           
========================================
  Files          272      272           
  Lines        15277    15290   +13     
========================================
+ Hits         14988    15001   +13     
  Misses         289      289           
Impacted Files Coverage Δ
pybamm/models/base_model.py 99.11% <100.00%> (+0.03%) ⬆️
pybamm/simulation.py 96.91% <100.00%> (-0.05%) ⬇️
pybamm/solvers/base_solver.py 99.04% <100.00%> (+<0.01%) ⬆️
pybamm/solvers/casadi_solver.py 99.47% <100.00%> (-0.01%) ⬇️
pybamm/solvers/processed_symbolic_variable.py 100.00% <100.00%> (ø)
pybamm/solvers/processed_variable.py 99.59% <100.00%> (-0.03%) ⬇️
pybamm/solvers/solution.py 99.43% <100.00%> (+0.05%) ⬆️
pybamm/expression_tree/unary_operators.py 99.79% <0.00%> (-0.21%) ⬇️
pybamm/expression_tree/operations/evaluate.py 98.09% <0.00%> (ø)
pybamm/solvers/idaklu_solver.py 90.26% <0.00%> (+0.88%) ⬆️

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 66b9589...4b84f39. Read the comment docs.

@brosaplanella brosaplanella left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks good to me, happy to merge once the test passes. Thanks Tino!

solution = solver.solve(model, t_eval)
np.testing.assert_array_less(solution.y[0], 1.5)
np.testing.assert_array_less(solution.y[-1], 2.5 + 1e-10)
np.testing.assert_array_less(solution.y.full()[0], 1.5)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This test fails but I can't understand why it doesn't take the .full().

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

get_termination_reason had changed in #1300 and was returning a numpy array

@valentinsulzer
valentinsulzer merged commit 0926080 into develop Dec 31, 2020
@valentinsulzer
valentinsulzer deleted the issue-1221-convert-to-casadi branch December 31, 2020 22:45
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.

Optionally convert variable to casadi format before evaluating

2 participants