Hello Dear Colleagues,
First of all, thank you for PyBaMM! I really enjoy working with it.
I have a question regarding performance optimization and the proper assembly of a pipeline (model + solver). I’ve been following the user guide on parallel simulation with threading:
https://docs.pybamm.org/en/stable/source/examples/notebooks/performance/07-multithreading.html
For my task, I want to assemble a dataset generator that does the following: I sample a random current profile (charge/discharge with slopes) as a function of time.
def pybamm_simulate(gen_func=generate_current_seq):
# Extract random sequence and time points where behaviour changes
tseq, current_interp = generate_current_seq(t_max=t_max, n_points=n_points)
model = pb.lithium_ion.DFN({
"current collector": "potential pair", # Laplace in y-z
"thermal": "isothermal", # 1-node T (can switch to x-lumped)
"dimensionality": 2, # y-z resolution
"SEI": "ec reaction limited",
"SEI porosity change": "true",
# "loss of active material": "stress-driven",
# "lithium plating": "reversible",
})
param = pb.ParameterValues("Chen2020")
CHEN = {
# other constants ...
"Current function [A]": current_interp, # using pb.Interpolant
}
param.update(CHEN)
sim = pb.Simulation(model, parameter_values=param)
sol = sim.solve()
return sol
Now, since I want to run many simulations with the same model, I’d like to use threading. The idea was to update:
params[“Current function [A]”] = { "Current function [A]": "[input]", }“
and feed either an array of (time, current) values or a pb.Interpolant object. However, this approach does not seem to work (neither arrays nor interpolants). Like it was done in user guide:
sim = pybamm.Simulation(model, solver=solver, parameter_values=params)
sol = sim.solve([0, 3600], inputs=current_inputs)
My question:
Is it possible to implement the “threading trick” while feeding the model a time sequence (array of current values) or an interpolant as the current input, in order to accelerate simulations?
Thank you very much in advance!
Kind Regards, Stephen