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

How to Debug a Model Object Loader #61

Open
rburghol opened this issue May 23, 2023 · 1 comment
Open

How to Debug a Model Object Loader #61

rburghol opened this issue May 23, 2023 · 1 comment

Comments

@rburghol
Copy link

rburghol commented May 23, 2023

  • Use code in https://github.com/HARPgroup/HSPsquared/blob/devstateom/tests/testcbp/HSP2results/test_object_json.py
    • change line el_pid = 7113514 to the PID of the facility entity (or river entity) in question
  • Get the json for the object (if it fails at model_loader_recursive() )
    • mjson = model_data['RCHRES_R001']['ARWA Chesdin Withdrawal']['historic_monthly_pct']
  • Find the object in your cache (if it loaded at all)
    • First, find the name in the list of model objects, just type: state_paths and hit enter
    • Once you find the state path, grab the corresponding handler object
    • mobj = model_object_cache['/STATE/RCHRES_R001/ARWA Chesdin Withdrawal/historic_monthly_pct']
  • Maybe it fails to find a config item? Test what it gets:
    • mobj.handle_prop(mjson,'valuetype')
  • Try to run the step_model() function from the command prompt (need to load libraries, not shown below but an example is here ):
    • step_model(model_exec_list, op_tokens, state_ix, dict_ix, ts_ix, 1)
  • call a flexible, non-jit debug step
    • test_model(model_exec_list, op_tokens, state_ix, dict_ix, ts_ix, step)
  • call an individual routine with debugging info
    • debug_tbl_eval(op_tokens, op_tokens[18], state_ix, dict_ix)
@rburghol rburghol changed the title How to Get Your Debug a Model Object Loader How to Debug a Model Object Loader May 24, 2023
@rburghol
Copy link
Author

rburghol commented Feb 14, 2024

New object loader:

# bare bones tester
import os
os.chdir("C:/usr/local/home/git/HSPsquared")
from HSP2.main import *
from HSP2.om import *
#from HSP2.om_equation import *

state = init_state_dicts()
# set up info and timer
siminfo = {}
siminfo['delt'] = 60
siminfo['tindex'] = date_range("1984-01-01", "2020-12-31", freq=Minute(siminfo['delt']))[1:]
steps = siminfo['steps'] = len(siminfo['tindex'])
# get any pre-loaded objects 
model_data = state['model_data']
( ModelObject.op_tokens, ModelObject.model_object_cache) = init_om_dicts()
ModelObject.state_paths, ModelObject.state_ix, ModelObject.dict_ix, ModelObject.ts_ix = state['state_paths'], state['state_ix'], state['dict_ix'], state['ts_ix']
( op_tokens, state_paths, state_ix, dict_ix, model_object_cache, ts_ix) = ( ModelObject.op_tokens, ModelObject.state_paths, ModelObject.state_ix, ModelObject.dict_ix, ModelObject.model_object_cache, ModelObject.ts_ix )
state_context_hsp2(state, 'RCHRES', 'R001', 'HYDR')
print("Init HYDR state context for domain", state['domain'])
hydr_init_ix(state, state['domain'])
# Now, assemble a test dataset
container = False 
state_om_model_root_object(state, siminfo)
model_root_object = state['model_root_object']

src_json_node = 'http://deq1.bse.vt.edu/d.dh/node/62'
el_pid = 7405974 # appalachia reservoir on Bens Branch
json_url = src_json_node + "/" + str(el_pid)
# authentication using rest un and pw
jfile = open("/var/www/python/auth.private")
jj = json.load(jfile)
rest_uname = jj[0]['rest_uname']
rest_pass = jj[0]['rest_pw']
basic = HTTPBasicAuth(rest_uname, rest_pass )
# Opening JSON file
jraw =  requests.get(json_url, auth=basic)
model_json = jraw.content.decode('utf-8')
# returns JSON object as Dicts
model_data = json.loads(model_json)
model_name = list(model_data.keys())[0]
model = model_object_cache['/STATE/' + model_name]
state['model_data'] = model_data
state_om_model_run_prep(state, False, siminfo) 
op_tokens = state['op_tokens']

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