Historical state access

In previous versions of cadCAD, when you wanted to access the previous state’s value in a mechanism or behavior, you could use the sL[‘stateName’] to access the last timestep’s state value. In the most recent version of cadCAD, the UI has changed somewhat to include a special utility that lets you define what individual partial state update block you would like to retrieve a value from. The official documentation shows how to use this powerful feature: https://github.com/BlockScience/cadCAD/blob/master/documentation/Historically_State_Access.md but for the sake of simplicity, if you don’t need a specific partial state update block and just want the last timestep value (after the last partial state update has been completed) the code snippet below can be used:

from cadCAD.configuration.utils import access_block
access_block(sL, “last_x”, -1)[-1][‘stateOfInterest’]

3 Likes

I’m having problems getting this to work. I’m just sticking in a variable for testing for now, and have a PSUB that calls this:
def updateLookback(params, step, sL, s, _input):
y = ‘lookback’
x = access_block(sL, “last_x”, -1)[-1][‘stateVariable’]
return(y,x)

When I run the execution, my jupyter notebook just hangs - that cell doesn’t resolve.

For future reference, this seems to have been solved (source: Having trouble getting previous value for a variable)