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

[Bug]: SolverError when simulating a half-cell and setting initial_soc #4868

Open
d-cogswell opened this issue Feb 21, 2025 · 3 comments · May be fixed by #4873
Open

[Bug]: SolverError when simulating a half-cell and setting initial_soc #4868

d-cogswell opened this issue Feb 21, 2025 · 3 comments · May be fixed by #4873
Labels
bug Something isn't working

Comments

@d-cogswell
Copy link
Contributor

d-cogswell commented Feb 21, 2025

PyBaMM Version

25.1.1

Python Version

3.12.4

Describe the bug

working electrode and initial_soc both work independently, but cause a SolverError when used together.

Steps to Reproduce

Here is a working example:

import pybamm

experiment = pybamm.Experiment(["Discharge at 1C until 3V"])
parameter_values = pybamm.ParameterValues("Xu2019")
parameter_values.update(
    pybamm.ParameterValues("Prada2013"), check_already_exists=False
)

# This works
model = pybamm.lithium_ion.SPM()
sim = pybamm.Simulation(model, parameter_values=parameter_values, experiment=experiment)
sol = sim.solve(initial_soc=0.8)

# This works
model = pybamm.lithium_ion.SPM(options={"working electrode": "positive"})
sim = pybamm.Simulation(model, parameter_values=parameter_values, experiment=experiment)
sol = sim.solve()

# This fails
model = pybamm.lithium_ion.SPM(options={"working electrode": "positive"})
sim = pybamm.Simulation(model, parameter_values=parameter_values, experiment=experiment)
sol = sim.solve(initial_soc=0.8)

Relevant log output

pybamm.expression_tree.exceptions.SolverError: Could not find acceptable solution: solver terminated successfully, but maximum solution error (0.00027437641369143506) above tolerance (1e-06)
@d-cogswell d-cogswell added the bug Something isn't working label Feb 21, 2025
@d-cogswell
Copy link
Contributor Author

d-cogswell commented Feb 24, 2025

Switching from scipy.optimize.root() to scipy.optimize.minimize() or scipy.optimize.least_squares() as the algebraic solver seems to fix the issue.

@martinjrobins
Copy link
Contributor

Are you happy with the fix of changing to a different algebraic solver @d-cogswell? If so I'll close this issue.

@agriyakhetarpal
Copy link
Member

I assume #4873 is supposed to close this, but it's a draft and isn't linked to this issue yet.

@martinjrobins martinjrobins linked a pull request Feb 26, 2025 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants