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

I2217 idaklu #2444

Merged
merged 26 commits into from
Nov 21, 2022
Merged

I2217 idaklu #2444

merged 26 commits into from
Nov 21, 2022

Conversation

martinjrobins
Copy link
Contributor

@martinjrobins martinjrobins commented Nov 9, 2022

Description

Work related to #2217. Added an options argument to the idaklu solver:

    options: dict, optional
        Addititional options to pass to the solver, by default:
        {
            print_stats: False, # print statistics of the solver after every solve
            jacobian: "sparse", # jacobian form, can be "none", "dense", "sparse",
                                # "matrix-free"
            linear_solver: "SUNLinSol_KLU", # name of sundials linear solver to use
                                  # options are: "SUNLinSol_KLU",
                                  # "SUNLinSol_Dense", "SUNLinSol_LapackDense"
                                  # "SUNLinSol_SPBCGS", "SUNLinSol_SPFGMR",
                                  # "SUNLinSol_SPGMR", "SUNLinSol_SPTFQMR",
            preconditioner: "BBDP", # preconditioner for iterative solvers,
                                    # can be "none", "BBDP"
            linsol_max_iterations: 5, # for iterative linear solvers, max number of
                                      # iterations
            precon_half_bandwidth: 5, # for iterative linear solver preconditioner,
                                      # bandwidth of approximate jacobian
            precon_half_bandwidth_keep: 5 #for iterative linear solver preconditioner,
                                      # bandwidth of approximate jacobian that is kept

        }
        Note: These options only have an effect if model.convert_to_format == 'casadi'

The iterative solvers only seem to work well for SPM and SPMe models, my best guess atm is that the preconditioner I'm using is not suitable for DFN. Sundials unfortunately only has a single preconditioner (BBDP), but we could manually implement a preconditioner if anyone knows a good one for DFN

I've also built in support for sundials v5 and v6, as the api changed in v6

I've also generally restructured the idaklu C++ code (the casadi stuff, we are going to drop the python idaklu solver...) to be a bit nicer

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)

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

@valentinsulzer
Copy link
Member

we are going to drop the python idaklu solver

What does this mean? How will we interface to the C++ code?

@martinjrobins
Copy link
Contributor Author

we are going to drop the python idaklu solver

What does this mean? How will we interface to the C++ code?

Sorry, this statement wasn't very clear. We have two C++ solvers, one which is used for model.convert_to_format == 'casadi', and another (the original) that is used when model.convert_to_format == 'python'. The plan is to keep the former, and drop the latter. Rather than maintain two separate C++ solvers.

@codecov
Copy link

codecov bot commented Nov 9, 2022

Codecov Report

Base: 99.72% // Head: 99.72% // Increases project coverage by +0.00% 🎉

Coverage data is based on head (eed75ab) compared to base (d5547da).
Patch coverage: 100.00% of modified lines in pull request are covered.

❗ Current head eed75ab differs from pull request most recent head 2b80d6b. Consider uploading reports for the commit 2b80d6b to get more accurate results

Additional details and impacted files
@@           Coverage Diff            @@
##           develop    #2444   +/-   ##
========================================
  Coverage    99.72%   99.72%           
========================================
  Files          258      258           
  Lines        19184    19200   +16     
========================================
+ Hits         19131    19147   +16     
  Misses          53       53           
Impacted Files Coverage Δ
pybamm/solvers/idaklu_solver.py 99.06% <100.00%> (+0.07%) ⬆️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

Copy link
Contributor

@rtimms rtimms left a comment

Choose a reason for hiding this comment

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

thanks @martinjrobins looks good! should we do some checking of the options since it seems sundials doesn't raise and error if you pass a bad option for the jacobian or lin solver?

tests/unit/test_solvers/test_idaklu_solver.py Outdated Show resolved Hide resolved
tests/unit/test_solvers/test_idaklu_solver.py Show resolved Hide resolved
@martinjrobins
Copy link
Contributor Author

Running the failed benchmark (time to setup DFN for ORegan2022 param) on my machine shows no difference between develop and this branch. @rtimms @tinosulzer are you happy if I treat this as a false positive and merge this PR?

@martinjrobins martinjrobins merged commit c8f2890 into develop Nov 21, 2022
@martinjrobins martinjrobins deleted the i2217-idaklu branch November 21, 2022 13:39
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.

3 participants