HARPgroup / HSPsquared

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

runtime iteration controllers #45

Closed rburghol closed 1 year ago

rburghol commented 1 year ago

Tokenized, njit

@njit
def iterate_models(op_tokens, state_ix, dict_ix, ts_ix, steps):
    checksum = 0.0
    for step in range(steps):
        pre_step_model(op_tokens, state_ix, dict_ix, ts_ix)
        step_model(op_tokens, state_ix, dict_ix, ts_ix, step)
    return checksum

@njit
def pre_step_model(op_tokens, state_ix, dict_ix, ts_ix):
    for i in op_tokens.keys():
        if op_tokens[i][0] == 1:
            return False
        elif op_tokens[i][0] == 2:
            return False
        elif op_tokens[i][0] == 3:
            return False
        elif op_tokens[i][0] == 4:
            return False
        elif op_tokens[i][0] == 5:
            return False
    return

@njit 
def step_model(op_tokens, state_ix, dict_ix, ts_ix, step):
    val = 0
    for i in op_tokens.keys():
        if op_tokens[i][0] == 1:
            state_ix[i] = exec_eqn(op_tokens[i], state_ix)
        elif op_tokens[i][0] == 2:
            state_ix[i] = exec_tbl_values(op_tokens[i], state_ix, dict_ix)
        elif op_tokens[i][0] == 3:
            step_model_link(op_tokens[i], state_ix, ts_ix, step)
        elif op_tokens[i][0] == 4:
            val = 0
        elif op_tokens[i][0] == 5:
            step_sim_timer(op_tokens[i], state_ix, dict_ix, ts_ix, step)
        elif op_tokens[i][0] == 8:
            # since this accesses other table objects, gotta pass the entire op_tokens Dict 
            state_ix[i] = exec_tbl_eval(op_tokens, op_tokens[i], state_ix, dict_ix)
        elif op_tokens[i][0] == 9:
            # maybe this can be a Timeseries data input? 
            # not identical to local state value links since their ts can be relative past/future
            # op_tokens should contain a number of steps in the past or future if we wanted?
            # would have to calculate that based on the timestep and input time frame to lag or forecast
            # value = ts_ix[op_token[2]][step + ts_offset]
            # to aggregate we would need to combine this ts lookup with a stack object
            # state_ix[op_token[1]] = value 
            val = 0 
    return 

Run them all

from HSP2.utilities_specl import *
from HSP2.SPECL import specl, _specl_
from HSP2.om_model_object import *
from HSP2.om_equation import *
from HSP2.om_data_matrix import *
from HSP2.om_sim_timer import *
from HSP2.om_model_linkage import ModelLinkage, step_model_link

steps=40*365*24
start = time.time()
num = iterate_models(op_tokens, state_ix, dict_ix, ts_ix, steps)
end = time.time()
print(end - start, "seconds")