Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

runtime iteration controllers #45

Closed
rburghol opened this issue Dec 15, 2022 · 0 comments
Closed

runtime iteration controllers #45

rburghol opened this issue Dec 15, 2022 · 0 comments

Comments

@rburghol
Copy link

rburghol commented Dec 15, 2022

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")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant