-
-
Notifications
You must be signed in to change notification settings - Fork 572
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]: IDAKLU SOLVER output_variables long simulation and state issues #4743
Comments
Hi @aaltno, thanks for raising these issues! I'm going to try and summarise some of your points, let me know if I've misunderstood anything. 1. There's a bug which means you can't access variables from individual cycles when using the
raises a key error:
2. When combining the
Relevant error:
3. You're finding errors with the |
(1) Is fairly easily fixed, I'm going to link a draft PR where that bug should be solved if you'd like to try it out and check it does what you're expecting. I'll take a look at (2); @aaltno could you provide a minimum working example and traceback for the errors you allude to for (3)? You can use the code in the PR first to see if some of your issues are fixed first. |
PyBaMM Version
24.11.2
Python Version
3.12.4
Describe the bug
IDAKLU SOLVER output_variables long simulation and state issues:
Hi! I have been running ageing simulations with CASADI for a while and wanted to use IDAKLU for CC ageing or calendar ageing as it is faster. With the new option for output_variables, the memory allocation is much smaller (x10), good for parallel or threaded computing.
Now, two issues arise. Importantly, none of these errors occur with Casadi or IDAKLU (when output_variables are not specified)
So basically using last_state in looped simulations and using .cycles to retrieve cycle specif data does not work too well with IDAKLU when output_variables is active :)
1) When using cycles and selecting output_variables, one cannot use the previous way of working:
for example like this: simulation_IDA3_checkup.solution.cycles[-1]['Throughput capacity [A.h]'].entries
but instead must go with a work around like this:
capacity_full_checkup = simulation_IDA3_checkup.solution.get_data_dict()['Throughput capacity [A.h]']
cycles = simulation_IDA3_checkup.solution.get_data_dict()['Cycle']
capacity_discharge_section= [d for d, c in zip(capacity_full_checkup, cycles) if c == 2]
I find this work around inconvenient and would prefer that what works with CASADI and IDAKLU (without output_Variables selected) works also with output_variables selected
2) when using cycling and for example using last states, I get an error with starting_solution
example:
this will give me an error if simulation_IDA3_ageing_cylic = pybamm.Simulation(... , solver=solver_IDAKLU2 , ....)
but it will not give me an error if simulation_IDA3_ageing_cylic = pybamm.Simulation(... , solver=solver_IDAKLU1 , ....)
solver_IDAKLU1 = pybamm.IDAKLUSolver(rtol=0.00001, atol=1e-07, root_method='casadi', root_tol=1e-07, extrap_tol=None)
solver_IDAKLU2 = pybamm.IDAKLUSolver(rtol=0.00001, atol=1e-07, root_method='casadi', root_tol=1e-07, extrap_tol=None, output_variables=['Time [s]', 'Current [A]', "Voltage [V]" ], options=None)
for this last example I have a work around which is to use starting_solution = simulation_IDA3_ageing_calendar.solution, so using the whole solution instead of the last_state (which is I think more efficient and has a smaller memory footprint)
for 2) this means passing on a simulation object which, iteration by iteration, will grow in size. Using save_cycles in the simulation options only leads to more errors which I will not address here. all in all, I can
Ideally, I would like to be able to activate output_variable in the IDAKLU solver, while retaining the capability of calling and using:
Am I getting this wrong? I.e., recongizning that it might not work just as if I swapped CASADI, are there other workarounds possibile? Let me know :) Thanks for the help
Alessio Lodge, TNO - Imperial
Steps to Reproduce
Code is above. Use any experiment and run with this:
model = pybamm.lithium_ion.DFN()
solver_CasadiSolverSafe = pybamm.CasadiSolver(dt_max = 100,mode = "safe", rtol=1e-7 ,atol=1e-7)
solver_IDAKLU1 = pybamm.IDAKLUSolver(rtol=0.00001, atol=1e-07, root_method='casadi', root_tol=1e-07, extrap_tol=None)
solver_IDAKLU2 = pybamm.IDAKLUSolver(rtol=0.00001, atol=1e-07, root_method='casadi', root_tol=1e-07, extrap_tol=None, output_variables=['Time [s]', 'Current [A]', "Voltage [V]" ], options=None)
solver_IDAKLU3 = pybamm.IDAKLUSolver(rtol=0.00001, atol=1e-07, root_method='casadi', root_tol=1e-07, extrap_tol=None, output_variables=['Time [s]', 'Current [A]', "Voltage [V]", 'Throughput capacity [A.h]', 'Discharge capacity [A.h]'], options= {"dt_max": 1000.0})
FOR CASADI OR IDAKLU WITHOUT OUTPUT VARS
simulation_IDA3_checkup.solution.cycles[-1]['Throughput capacity [A.h]'].entries
FOR IDAKLU WITH OUTPUT VARS 1)
#I find this work around inconvenient and would prefer that what works with CASADI and IDAKLU (without output_Variables selected) works also with #output_variables selected
FOR IDAKLU WITH OUTPUT VARS 2)
starting_solution = simulation_IDA3_ageing_calendar.solution #
Relevant log output
The text was updated successfully, but these errors were encountered: