HARPgroup / HSPsquared

Hydrologic Simulation Program Python (HSPsquared)
GNU Affero General Public License v3.0
1 stars 0 forks source link

Equation #25

Closed rburghol closed 8 months ago

rburghol commented 2 years ago

Overview

Tasks

Object Model

Explore method of using @jitclass objects or a more functional approach.

Handler Class

class Equation(modelObject):
    # the following are supplied by the parent class: name, log_path, attribute_path, state_path, inputs
    op_trios = [] # string array with sorted operand1, operand2, operator

test = Equation()
test.ncode_preStep() # generate the numba code for preStep() actions.

Execution Rendering

Parser

Data Model in hdf5

Solver

Decomposition/Optimization:

Eval

Pre-rendered Functions

rburghol commented 1 year ago

Add a group with hdf5 module in python

fpath = 'C:/Workspace/modeling/cbp/hsp2/river/OR1_7700_7980.h5'

close the already opened file first

f.close() f = h5py.File(fpath,'a') # use mode 'a' which allows read, write, modify objs = f.create_dataset("OBJECTS", (50,), dtype='f')

made a mistake, need to create a group, not a dataset

del f["OBJECTS"] grp = f.create_group("OBJECTS") grp.create_group("RCHRES_0001") rch = grp["RCHRES_0001"] rch.create_group("Qin") Qin = rch["Qin"]

attributes can simply be added here:

Qin.attrs['equation'] = 'Qup * 1.23' Qin.attrs['default_value'] = 0.0 Qin.attrs['state_path'] = "/STATE/RCHRES_0001/Qin" Qin.attrs['attribute_path'] = "/OBJECTS/RCHRES_0001/Qin" Qin.attrs['fn_step'] = "om_equation_step" # this can be used to specify any function whatsoever that takes the correct args, but might be difficult to use in njit? Qin.attrs['data_type'] = "f"

read attributes like this:

ts = f['TIMESERIES'].items() for a in ts: print(a[0], a[1])

dset = f['TIMESERIES/TS011/table'] dset[1]

(441766800000000000, 8.82848454)

dset[2]

(441770400000000000, 8.81089973)

dset[3]

(441774000000000000, 8.79396248)

dset[4]

(441777600000000000, 8.77740383)

rburghol commented 1 year ago

Now add a timeseries indexed by integers - ts_ix

- now, the Qin variable from the WDM can be found in the ts_ix array keyed as integer
  - we can get that integer by: `Qin_ix = get_state_ix(state_ix, state_paths, '/TIMESERIES/TS011')`
Iterate through the values for a simulation

Qin_ix = get_state_ix(state_ix, state_paths, '/TIMESERIES/TS011') for idx, x in np.ndenumerate(ts_ts): state_ix[Qin_ix] = ts_ix[Qin_ix][idx] # the timeseries inputs state get set here. must a special type of object to do this

view dict key:value pairs in console by rows

[print(key,':',value) for key, value in state_ix.items()]

rburghol commented 1 year ago

op_tokens, state_paths, state_ix, dict_ix = init_sim_dicts()

eqn_path = "/OBJECTS/RCHRES_0001/Qin"
eqn = "Qin * 1.21"
eq_ix = set_state(state_ix, state_paths, eqn_path, 0.0) # initialize this equation operator in the state_ix Dict, returns unique key

# NR uses weird global shit so we have to do this:
exprStack = []
exprStack[:] = []
ps = deconstruct_equation(eqn)