Accessing state_history

In a policy function, what’s the correct way to access a specific variable in state_history?
Simply aiming to calculate an average over time X.

Thanks!

Just re-posting my response here, for others who come across this thread:

the state history is a Python “2D” list or list of lists with the elements being the state variable dictionary for that timestep and substep. The first index is the timestep, and the second index is the substep (one for each partial state update block). So, for example, to access the previous timestep and the final substep: state_history[-1][-1] # [timestep][substep] . To calculate the average, it’s recommended to not re-calculate that each time for better performance, but accumulate the average in another state variable - created a basic example here: Access cadCAD state_history · GitHub