-
Notifications
You must be signed in to change notification settings - Fork 20
Open
Description
Developmental Code: https://github.com/HARPgroup/HSPsquared/blob/develop-state-class/src/hsp2/hsp2/
This branch will perform some code reorganization and add class-based state data structures, I think it will enhance readability and organization. Specifically:
- Move src/hsp2/hsp2/state* to src/hsp2/state/
- Create a class
ModelSTATEwhich contains all state related entities (state_ix,dict_ix,state_paths, ...) as attributes - Reduce the number of arguments passed to functions
- Organize high-performance functions under the object to make it explicit when a function is
jit-ed.- i.e., if a function is called as
state.func_name()it is guaranteed to bejitcompatible
- i.e., if a function is called as
- See example of
jit-able object with these properties in https://github.com/HARPgroup/HSPsquared/blob/develop-hydrclass/src/hsp2/hsp2/classes/model.test.class.py
Goals
- Re-organize code for STATE model classes and function files to reside in a sub-directory
Info
- Data Model for STATE: Data Model for Shared STATE (supports model modularity) RFC #112
- Current code base in fork, will PR when ready: https://github.com/HARPgroup/HSPsquared/tree/develop-state-tidy/src/hsp2/
Tasks
- Document Needed functions and classes to implement How to Implement New Module in STATE system #127
- Prototype full workflow for using shared STATE and all helper object-classes/runtime exec routines from OM
- Migrate code from OM into state sub-module for ModelObject, ModelConstant, Timer, and SpecialAction
- Create sub-directory module with state support and object model component code
- migrate
importstatements - Create base class for state and helper function to make class attributes
- Migrate old references to new object:
-
init_state_dicts -
state_siminfo_hsp2(parameter_obj, siminfo, io_manager, state) - Separate
model_object_cachefrom state and go intoom_operationsor just be separate argument (these objects cannot be jitted)- in
omis fairly simple, asom_operationscan be created and passed around - in
ModelObjectand children classes, this can be more challenging. Will need to pass in at creation, or modify the state that is passed in... maybe pass inom_operationsinstead of state, or as a container that includes state?- If we make a state container that combines
om_operations, this should be fine and propagate all changes up to the actual state object?
- If we make a state container that combines
- in
-
model_root_object- Where to store instead of on state? In
om_operations
- Where to store instead of on state? In
-
state_load_dynamics_hsp2(state, io_manager, siminfo) model_data- put intoom_operations-
state_init_hsp2(state, opseq, activities) -
model_input_dependencies- this function is actually unused, but maye will be used for timeseries? Add timeseries/other DSN access to STATE/specl HARPgroup/HSPsquared#60 (comment) -
state_context_hsp2:- includes
operation,segmentactivity, anddomain
- includes
-
siminfo['tindex']- This is passed into state, creatin a complex object (dict), so not possible in
jit - Only
tindexis actually needed, and that could be obtained elsewhere - However, thinking forward, the
SimTimerobject needs to have itstindexupdated each time that the time step switches, so we should tackle all of this at once if possible. - (YES it is in dict_ix) Is tindex gotten from state in simtimer anywhere?
- Update
ModelLinkageto Load SimTimer from model_object_cache and get, or, just grab from thedict_ixof SimTimer
- This is passed into state, creatin a complex object (dict), so not possible in
-
om_init_state(state) # set up operational model specific state entries -- now Inom_operations` -
specactions: this was in state only to pass to the specl parsing routine at startup, and really, can be passed as an argument anyway. Easy fix.-
specl_load_state(state, specactions) # traditional special actions -
specl_load_om
-
- Migrate
model_exec_listfrom inside functions to prep routine. Stored as domain_action specific array- In
HYDR - In
SEDTRN
- In
-
state_load_dynamics_om(state, io_manager, siminfo ) # operational model for custom python -
state_om_model_run_prep(state, io_manager, siminfo) - add
timerto state, which eliminates the need to implementdict_ixat this time which is most likely going to be far better as an object with runtime declarednparray -
HYDR -
SEDMNT -
SEDTRN -
RQUAL_class -
om -
om_model_object -
om_special_action -
om_equation -
om_model_linkage -
om_sim_timer
-
Module Declaration / Outline
- THIS IS OLD INFORMATION - MAY NO LONGER BE RELEVANT
- via: https://docs.python.org/3/tutorial/modules.html#packages
- Note, in the above outlines how to support
from state.state import *
- Note, in the above outlines how to support
state /
__init__.py
state.py
specl.py
om.py
model_object.py
actions.py
SEDTRN, HYDR adaptation to new state object class
- State-Mutable Variables Existing
SEDTRN,HYDRneed to load the pointers to state-mutable variables from stateSEDTRN:RSED4,RSED5andRSED6HYDR:- Future version will use an object based
SEDTRNwhich will:- Store pointers to state as properties of the object in order to facilitate simultaneous simulations, but for now, we want to support the old model, but with using
stateclass methods to obtain the indices. domainwill similarly be obsolete since the domain will be associated with theSEDTRNobjectstate_pathproperty
- Store pointers to state as properties of the object in order to facilitate simultaneous simulations, but for now, we want to support the old model, but with using
- Functional
domain: For now, we passdomainin as a property of thestateobject, but this will also be obsolete as we move to an object based system for functional areas. - Dynamic Code: experimental support for dynamically loaded python code and the operational models is supported in the
state_infodictionary as:model_exec_listhas been replaced as an array on thestateobject, keyed byixvalue for eachdomain+function, like/STATE/RCHRES_R001/HYDR, somodel_exec_list = state.op_exec_lists[op_ix]will contain the list of dynamically executed operations for that function area. In the future this could- the variable
state_step_hydris a stringenabledordisabled, and determines if a function calledstate_step_hydro()has been defined in a local code file (in the h5 directory)-- this is now located onstate.state_step_hydr. The string variablestate_step_hydris actually somewhat superfluous as we could maybe call the stub functionstate_step_hydr()which does nothing. But we will keep it onstatefor now as it costs nothing and will keep code changes smaller. Also, it may be that the process of using that functon will require a recompile every time regardless of whether or not the function is new, just the location of the include forces it in thejited function. state.state_step_hydris also passed in tohydr()as part of the oldstatedicionary, and this contains the actual function passed into the non-jitted parent functionhydr()(which callsjittedfunction_hydr()--
sedtrn_ix = sedtrn_get_ix(state_ix, state_paths, state_info["domain"])
# these are integer placeholders faster than calling the array look each timestep
rsed4_ix, rsed5_ix, rsed6_ix = (
sedtrn_ix["RSED4"],
sedtrn_ix["RSED5"],
sedtrn_ix["RSED6"],
)
- to:
Metadata
Metadata
Assignees
Labels
No labels