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

#644 set atol and rtol #645

Merged
merged 6 commits into from
Oct 7, 2019
Merged

#644 set atol and rtol #645

merged 6 commits into from
Oct 7, 2019

Conversation

rtimms
Copy link
Contributor

@rtimms rtimms commented Oct 3, 2019

Description

Allows the user to set rtol and atol separately. For the defaults I've selected 1e-3 for rtol and 1e-6 for atol. This is the same as other solvers (e.g. scipy.integrate or MATLABs ODE15s) and provides a pretty significant speedup vs 1e-8 for both. I've also reduced the default number of points in x, as again this speed things up quite a bit. Both of these result in a RMS voltage error of around 1e-4 compared with the previous defaults, but the default DFN now runs in around 3 seconds vs 23 seconds (on my computer at least).

I think for most users, this kind of error is ok out of the box (the plots are indistinguishable), particularly if they are new users and just want to quickly run some examples. Users now have more control over both solver tolerances, so I think this is an ok compromise.

EDIT: I've decreased rtol to 1e-6 too. Seems like the thermal model and some other models didn't like rtol as low as 1e-3. Probably safer to have both set as 1e-6 so that the solvers don't immediately fall over when people add new physics.

Fixes #644

Type of change

Please delete options that are not relevant.

  • New feature (non-breaking change which adds functionality)

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
  • Any dependent changes have been merged and published in downstream modules

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 :)
Still think we need a better solution for examples vs results, making sure the right things are tested but without taking forever. Maybe separate repository is the solution

@@ -71,6 +71,10 @@ def test_solving(self, solver=None, t_eval=None):
# Overwrite solver if given
if solver is not None:
self.solver = solver
else:
Copy link
Member

Choose a reason for hiding this comment

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

should this be else or just default behaviour?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah probably should just be default.

I agree, I think a separate repository on pybamm-team with paper results and any undocumented (or poorly documented) examples would be good. Then make sure the examples that come as part of pybamm are actually really useful for learning how to use it/showcasing feature, rather than just a relatively random collection of scripts we make during development.

@codecov
Copy link

codecov bot commented Oct 4, 2019

Codecov Report

❗ No coverage uploaded for pull request base (master@8afc8f9). Click here to learn what that means.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff            @@
##             master     #645   +/-   ##
=========================================
  Coverage          ?   98.49%           
=========================================
  Files             ?      167           
  Lines             ?     8177           
  Branches          ?        0           
=========================================
  Hits              ?     8054           
  Misses            ?      123           
  Partials          ?        0
Impacted Files Coverage Δ
...m/models/full_battery_models/base_battery_model.py 100% <ø> (ø)
...l_battery_models/lead_acid/base_lead_acid_model.py 100% <100%> (ø)
pybamm/solvers/dae_solver.py 99.21% <100%> (ø)
pybamm/solvers/scikits_ode_solver.py 98.21% <100%> (ø)
pybamm/solvers/base_solver.py 98.61% <100%> (ø)
pybamm/solvers/scipy_solver.py 100% <100%> (ø)
pybamm/solvers/scikits_dae_solver.py 97.67% <100%> (ø)
pybamm/solvers/ode_solver.py 100% <100%> (ø)

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 8afc8f9...3da5c5d. Read the comment docs.

@rtimms rtimms merged commit 30c4f80 into master Oct 7, 2019
@rtimms rtimms deleted the issue-644-solver-tol branch October 7, 2019 08:18
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.

set relative and absolute tolerances separately for solver
2 participants