Open rburghol opened 1 year ago
Making the actions work with STATE.
specl(ui, ts, step, state_info, state_paths, state_ix, specactions)
state_ix
arrayO1
in HYDR
:
O1
/STATE/RCHRES_R001/HYDR/O1
state_paths[/STATE/RCHRES_R001/HYDR/O1]
= integer key for value in state_ix
operation
and segment
, but the activity
is not included.activity
could modify the same variable?yr = state_ix[state_paths['STATE/timer/year']]
mo = state_ix[state_paths['STATE/timer/month']]
da = state_ix[state_paths['STATE/timer/day']]
hr = state_ix[state_paths['STATE/timer/hour']]
mi = state_ix[state_paths['STATE/timer/minute']]
se= state_ix[state_paths['STATE/timer/second']]
ACTIONS
table for those modifying the given domain and timeTable 1: Example for class ACTIONS that increases IVOL by 1.0 on January 1st, 1984 . | index | OPTYP | RANGE1 | RANGE2 | DC | DS | YR | MO | DA | HR | MN | D | T | VARI | S1 | S2 | AC | VALUE | TC | TS | NUM | CURLVL |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | RCHRES | 1 | DY | 1984 | 1 | 1 | 12 | 2 | 3 | IVOL | += | 1.000000 | 1 |
specactions
Dict that gets sent in when executing HYDR for RCHRES1 has already been sorted thru, /SPEC_ACTIONS/ACTIONS/table
?function
in HSP2 main.py (other than HYDR)
[function]_init_ix(state_ix, state_paths, domain)
domain = "/STATE/" + operation + "_" + segment + "/" + activity
; per hsp2 convention in hdf5 (see domain setup in https://github.com/respec/HSPsquared/blob/4431180ebf8f61b8a24e7572f8f76d8ffb13f55d/HSP2/state.py#L124)[function]_init_ix()
at the beginning of the run through of the function for a given domain
Tasks
hdf5 Data Model
/SPEC_ACTIONS/ACTIONS/table
HSPF UCI Data Model
Execution Code
Runtime steps to integrate with STATE
state_ix
get_state(state_ix, state_paths, var_path)
; wherevar_path
is the full hdf5 path to the data quantityif var_ix == False: var_ix = set_state(state_ix, state_paths, var_path, default_value)
state_ix
)var_value = state_ix[var_ix]
var_value = some_function(var_value, some_other_operand)
state_ix[var_ix] = var_value
Manual STATE Example
Using
ModelObject
STATE ExampleThis outlines a process that use an object class to handle pre-run parsing of operation data to tokenization and runtime execution and state integration via the variable
op_tokens
. Details of this can be found in branchhydrocomp
https://github.com/HARPgroup/HSPsquared/tree/hydrocompModelObject
class SpeclAction(ModelObject):
state_paths
andstate_ix
op_codes
, 'model_exec_list`)model_object = [new class name](model_props.get('name'), container, model_props)
[new class name]
is the class defined for the specact handler i.e.SpeclAction
function
is used inmain.py
to dynamically call model activity functions.model_loader_recursive(model_data, model_root_object)
model_path_loader(model_object_cache)
model_tokenizer_recursive(model_root_object, model_object_cache, model_exec_list)
tokenization
in an integer Dict with individual integer values referring to the state_ix of source and destination variables, function types and operators (if a function has multiple modes).model_tokenizer_recursive()
Handles hierarchical execution, sorts operators prior to runtime based on dependencies, stored in an ordered listmodel_exec_list
Supporting STATE inside an hsp2
njit
functionhydr()
) must allow argumentstate
which contains all persistent state info as well as domain specific info, like the current function, operation, and segment.njit
function (ex:_hydr()
) must allow arguments:state_ix
,state_paths
, andstate_info
state_info
is Dict with character key and character value, containingdomain
infodomain
is defined asstate['domain'] = "/STATE/" + operation + "_" + segment + "/" + activity
main.py
via call tostate_context_hsp2(state, operation, segment, activity)
domain
is essentially thehdf5
path to the state variables for the given activity/segment and operationstate_ix
is Dict with integer key and floating point value for containing actual runtime data state for scalar variablesstate_info
is Dict with character key (the hdf5 path of the variable) and integer value, with value being a pointer to the integer key of the variable in thestate_ix
Dictnjit
function must explicitly define which variables will be modifiable via the state facility.hydr_ix = hydr_get_ix(state_ix, state_paths, state_info['domain'])
hydr_get_ix()
returns a Dict with local variable character name as a key, and integer value of the key in state_ixstate_info['domain'] = '/RCHRES/...
Testing / Debugging
Parse UCI
Parser now successfully handle simple "classic" actions.
hsp2 import_uci hwmA51800.uci hwmA51800.h5
Verify ACTIONS parsing in R
UCI 1: Excerpt of ACTION block
Code 1: View contents of uci parsed to hdf5 in R.
Outputs:
View contents of uci parsed to hdf5 in python.
Code 2: Print in python, and convert byte encoding.
Outputs: