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

CasADi performance bottlenecks overview #3868

Open
valentinsulzer opened this issue Mar 6, 2024 · 8 comments
Open

CasADi performance bottlenecks overview #3868

valentinsulzer opened this issue Mar 6, 2024 · 8 comments

Comments

@valentinsulzer
Copy link
Member

Issue to add any minimum working examples related to improving the casadi solver

@valentinsulzer
Copy link
Member Author

For very simple models, it takes much longer to evaluate the outputs than it does to solve the model

import pybamm
import numpy as np


class Decay(pybamm.BaseModel):
    def __init__(self):
        super().__init__()
        x = pybamm.Variable("x")
        self.rhs = {x: -x}
        self.initial_conditions = {x: 1}
        self.variables = {"x": x}


model = Decay()
solver = pybamm.CasadiSolver()
t_data = np.linspace(0, 10, 1000)
# profile this line:
solution = solver.solve(model, t_data)["x"]
# currently about 10% solver / 90% evaluate
Screenshot 2024-03-05 at 9 35 57 PM

@valentinsulzer
Copy link
Member Author

SPMe with differential surface form and power mode fails to converge

import pybamm

pybamm.set_logging_level("INFO")
model = pybamm.lithium_ion.SPMe(
    {"surface form": "differential", "operating mode": "power"}
)
parameter_values = pybamm.ParameterValues("Chen2020")
parameter_values.update({"Power function [W]": 4}, check_already_exists=False)
sim = pybamm.Simulation(model, parameter_values=parameter_values)
sim.solve([0, 3600])

@valentinsulzer
Copy link
Member Author

#2173 (it now fails instead of hanging indefinitely)

@valentinsulzer
Copy link
Member Author

An example that takes a long time because it struggles near an event (sharp voltage drop-off)

import pybamm

pybamm.set_logging_level("INFO")

model = pybamm.lithium_ion.DFN()
parameter_values = pybamm.ParameterValues("Chen2020")
parameter_values["Positive electrode active material volume fraction"] = 0.1
sim = pybamm.Simulation(model, parameter_values=parameter_values)
sim.solve([0, 3600])
sim.plot(["Voltage [V]"])

@valentinsulzer
Copy link
Member Author

Linking #1996 , we probably don't want to use vertcat at all, instead store the ys separately

@valentinsulzer
Copy link
Member Author

Linking #1482 which only seems to happen with the casadi solver

@valentinsulzer
Copy link
Member Author

#3943

@valentinsulzer
Copy link
Member Author

#3960

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

No branches or pull requests

1 participant