When simulating an experiment in liionpack, and when the voltage limits are hit, the CasadiManager attempts to go through all the events
def log_event(self):
event_change = np.asarray(self.actors[0].get_event_change())
Nr, Nc = event_change.shape
event_names = self.actors[0].get_event_names()
for r in range(Nr):
if np.any(event_change[r, :]):
lp.logger.warning(
event_names[r]
+ ", Batteries: "
+ str(np.where(event_change[r, :])[0].tolist())
)
This will often raise a list index out of range error, as I have found that there are four event names, but Nr holds a value larger than that (I have seen 17 on one example).
I am unsure how event_change is structured internally, but it appears to have too many event_names.
Steps to Reproduce
Go to the JellyBaMM Repo and open the example notebook "03 Running A Simulation"
Set the experiment length to something long enough where a voltage cutoff is hit.
Run the simulation.
Expected behaviour
The voltage cutoff should be hit, and it should be reported that a limit has been reached. Next, it will go through three event names and list which cells hit the Maximum voltage limit, Maximum voltage limit switch, and Minimum voltage limit switch. It will try to log another event but because then length of event_names is shorter than Nr (as described above), it will raise an index out of range error.
From my own research, it appears to be a related to the generation of the casadi_objs variable in the cco() function call (see these lines of code ).
I don't quite understand the logic behind:
all_vars = sorted(sim.model.variables.keys())
event_vars = [v for v in all_vars if "Event" in v]
if len(event_vars) > 0:
where if len(event_vars) > 0: is true, then a repeat of the creation of variables functions is performed code with the only difference being they are now named events_fn.
It may be my ignorance in understanding how the code works, but this appears to be directly related to the best of my knowledge. I would think that only n number of events_fn items would be created so that there are the same number of events_names.
liionpack Version
0.3.9
Python Version
3.10.0
Describe the bug
When simulating an experiment in liionpack, and when the voltage limits are hit, the
CasadiManager
attempts to go through all the eventsThis will often raise a list index out of range error, as I have found that there are four event names, but Nr holds a value larger than that (I have seen 17 on one example).
I am unsure how event_change is structured internally, but it appears to have too many event_names.
Steps to Reproduce
Expected behaviour
The voltage cutoff should be hit, and it should be reported that a limit has been reached. Next, it will go through three event names and list which cells hit the Maximum voltage limit, Maximum voltage limit switch, and Minimum voltage limit switch. It will try to log another event but because then length of
event_names
is shorter thanNr
(as described above), it will raise an index out of range error.Relevant log output
Additional context
From my own research, it appears to be a related to the generation of the
casadi_objs
variable in thecco()
function call (see these lines of code ).I don't quite understand the logic behind:
where
if len(event_vars) > 0:
is true, then a repeat of the creation of variables functions is performed code with the only difference being they are now namedevents_fn
.It may be my ignorance in understanding how the code works, but this appears to be directly related to the best of my knowledge. I would think that only n number of
events_fn
items would be created so that there are the same number ofevents_names
.