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 1015 algebraic solver #1059

Merged
merged 11 commits into from
Jun 24, 2020
Merged

Conversation

valentinsulzer
Copy link
Member

Description

I couldn't really get this working but thought I would merge what I have so far as it might be useful for another effort down the line (will require a better example)

  • Added some new kinds of algebraic solvers (posing a minimization problem instead of root-finding), which can be constrained
  • Added bounds attribute to the Variable object, to allow these constraints

The main problem is that the solvers tend to find local minima instead of roots.

Fixes #1015

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 Jun 16, 2020

Codecov Report

Merging #1059 into develop will increase coverage by 0.00%.
The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff            @@
##           develop    #1059   +/-   ##
========================================
  Coverage    97.73%   97.74%           
========================================
  Files          242      242           
  Lines        12476    12528   +52     
========================================
+ Hits         12193    12245   +52     
  Misses         283      283           
Impacted Files Coverage Δ
pybamm/expression_tree/state_vector.py 100.00% <ø> (ø)
pybamm/discretisations/discretisation.py 99.77% <100.00%> (+<0.01%) ⬆️
pybamm/expression_tree/array.py 100.00% <100.00%> (ø)
pybamm/expression_tree/concatenations.py 97.45% <100.00%> (ø)
pybamm/expression_tree/matrix.py 100.00% <100.00%> (ø)
pybamm/expression_tree/variable.py 100.00% <100.00%> (ø)
pybamm/expression_tree/vector.py 100.00% <100.00%> (ø)
pybamm/models/standard_variables.py 100.00% <100.00%> (ø)
pybamm/solvers/algebraic_solver.py 100.00% <100.00%> (ø)
pybamm/solvers/base_solver.py 100.00% <100.00%> (ø)
... and 2 more

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 5585046...d0e2487. Read the comment docs.

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 great Tino, thanks! I assume that, apart from the solver getting stuck in a local minimum, the rest works fine, right?

@valentinsulzer
Copy link
Member Author

It all works fine, yes, but I haven't yet found a case where rootfinding fails and minimization works instead. At least the bounds functionality is implemented, in case someone thinks of a hacky way to implement bounds for the rootfinder (e.g. artificially extending the function outside of the bounds)

@valentinsulzer valentinsulzer merged commit 7263f0a into develop Jun 24, 2020
@valentinsulzer valentinsulzer deleted the issue-1015-algebraic-solver branch June 24, 2020 02:02
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.

Adding constraints to algebraic solver
2 participants