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]: pybamm.ScipySolver fails to run experiment #4429

Closed
martinjrobins opened this issue Sep 9, 2024 · 3 comments
Closed

[Bug]: pybamm.ScipySolver fails to run experiment #4429

martinjrobins opened this issue Sep 9, 2024 · 3 comments
Labels
bug Something isn't working

Comments

@martinjrobins
Copy link
Contributor

PyBaMM Version

develop

Python Version

3.10

Describe the bug

the pybamm.ScipySolver aborts early on the experiment given below, whereas the casadi and idaklu solver solve it correctly

Steps to Reproduce

import pybamm
import numpy as np
import matplotlib.pyplot as plt

experiment_2step = pybamm.Experiment(
    [
        (
            "Discharge at C/20 for 1 hour",
            "Charge at 1 A until 4.1 V",
            "Hold at 4.1 V until C/2",
            "Discharge at 2 W for 30 min",
            "Discharge at 2 W for 30 min",  # repeat to cover this case (changes initialisation)
        ),
    ]
    * 2,
)

solutions = []
for solver in [
    pybamm.CasadiSolver(),
    pybamm.IDAKLUSolver(),
    pybamm.ScipySolver(),
]:
      model = pybamm.lithium_ion.SPM()
      param = model.default_parameter_values
      input_param_name = "Negative electrode active material volume fraction"
      input_param_value = param[input_param_name]
      param.update({input_param_name: "[input]"})
      sim = pybamm.Simulation(
          model,
          experiment=experiment_2step,
          solver=solver,
          parameter_values=param,
      )
      solution = sim.solve(
          inputs={input_param_name: input_param_value},
      )
      solutions.append(solution)

for i, s in enumerate(solutions):
    plt.plot(s.t, s["Voltage [V]"](s.t) + float(i), label=f"Solver {i}")
plt.savefig("test.png")


for i in range(1, len(solutions)):
    np.testing.assert_allclose(
        solutions[0]["Voltage [V]"].data[:-1],
        solutions[i]["Voltage [V]"](solutions[0].t[:-1]),
        rtol=5e-2,
        equal_nan=True,
    )

test

Relevant log output

No response

@martinjrobins martinjrobins added the bug Something isn't working label Sep 9, 2024
@rtimms
Copy link
Contributor

rtimms commented Sep 9, 2024

This is because voltage control turns the model from an ODE to a DAE. Surprised we don't get a better error message here?

@martinjrobins
Copy link
Contributor Author

ahh yes, and the scipy solver doesn't support DAEs. Ok, so the main thing here is raising an error (and updating the relevent test in #4415)

@martinjrobins
Copy link
Contributor Author

my bad. All the noise from my assertions hid the error, which was perfectly fine. Closing this one as done

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

No branches or pull requests

2 participants