HARPgroup / HSPsquared

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

verify exec ordering #59

Closed rburghol closed 1 year ago

rburghol commented 1 year ago

Tasks:

Explore the exec order

# create a small nhd based trib
Rscript.exe /c/usr/local/home/git/vahydro/R/modeling/nhd/nhdplus_nested.R 8567213
# load NHD subsheds from file
jfile = open("C:/Workspace/tmp/8567213.json")
model_data = json.load(jfile)
# in future, we may load the whole dang model, but for now 
# this json file has only the trib info 
trib_data = model_data['RCHRES_R001']
model_loader_recursive(trib_data, river)

trib2 = river.get_object('nhd_8566731')
trib1 = trib2.get_object('nhd_8566705')
# trib1 is upstream flows into trib2
trib1.get_object('Qlocal').get_exec_order() # 20
trib1.get_exec_order('Qout') # 24 - exec order 24, is before the Qtrib var of trib2, which is good
trib2.get_exec_order('Qtrib') # 25
# and the broadcast channel that sets Qtrib also execs on 25
trib2.get_object('hydroObject').get_object('Qtrib').get_exec_order() # 25  
trib2.get_object('Qin').equation # 'Qlocal + Qtrib' 
trib2.get_object('Qin').get_exec_order() # 26 -- this is good too, since it suggests that Qtrib should be loaded before 
# Except -- the object that is connected to the Qtrib Register is the equation for Qout.,
trib2.get_object('hydroObject').get_object('Qtrib').get_object('Qtrib67').name # Qout
trib2.get_object('hydroObject').get_object('Qtrib').get_object('Qtrib67').ops # returns: [1, 64, 1, 3, 63, 82]
# says this is an equation -- but where is the push linkage setter? It is located on the upstream trib1
trib1.get_object('send_to_parent').get_object('Qtrib').left_path
trib1.get_object('send_to_parent').get_object('Qtrib').right_path
# and it's exec order is waaaay down the line 
trib1.get_object('send_to_parent').get_object('Qtrib').get_exec_order()
# so the input we added to the model is the wrong one. should have been the pusher

trib2.get_object('hydroObject').get_object('Qtrib').get_exec_order()

step = 1 pre_step_model(model_exec_list, op_tokens, state_ix, dict_ix, ts_ix, step)

i = 20 # start at the Qlocal of Trib1 print("Exec order", i,"is object",get_ix_path(state_paths, model_exec_list[i])) model = model_exec_list[i]; i = i+1 step_one(op_tokens, op_tokens[model], state_ix, dict_ix, ts_ix, step) trib2.get_object('hydroObject').get_object('Qtrib').get_object('Qtrib67').get_state() print("Qtrib(2) at exec step", i, "=",trib2.get_state('Qtrib')) print("Qtrib(2) at exec step", i, "=",trib2.get_state('Qtrib')) trib1.get_state('Qlocal')

rburghol commented 1 year ago

Debug ordering:

trib2.get_state('local_area_sqmi')
# 0.7380725832
trib2.get_state('trib_area_sqmi')
# 3.3810952139999992
trib2.get_state('drainage_area_sqmi')
# 3.7810582757999995
trib2.get_object('drainage_area_sqmi').equation
'local_area_sqmi + trib_area_sqmi'
# verify the ops:
trib2.get_object('drainage_area_sqmi').ops #returns:  [1, 52, 1, 2, 44, 48]
# ops look good, since ix 44 and 48 point to the right state vars:
get_ix_path(state_paths,44) # returns: '/STATE/RCHRES_R001/nhd_8566731/local_area_sqmi'
get_ix_path(state_paths,48) # returns: '/STATE/RCHRES_R001/nhd_8566731/hydroObject/trib_area_sqmi'
# now, run it again, in case it is a funny ordering thing?
step_one(op_tokens, op_tokens[trib2.get_object('drainage_area_sqmi').ix], state_ix, dict_ix, ts_ix, 1)
# get the result:
trib2.get_state('drainage_area_sqmi') # returns the correct value: 4.119167797199999
# now if I run the next step?
pre_step_model(model_exec_list, op_tokens, state_ix, dict_ix, ts_ix, 2)
step_model(model_exec_list, op_tokens, state_ix, dict_ix, ts_ix, 2)
trib2.get_state('drainage_area_sqmi') # returns bad value: 3.7810582757999995
rburghol commented 1 year ago

Iterate through checking the value of the drainage_area_sqmi continuously till it goes wrong (or right).

step = 1
pre_step_model(model_exec_list, op_tokens, state_ix, dict_ix, ts_ix, step)
i = 0
model=model_exec_list[i];print("The ",i,"th element is ID", model);step_one(op_tokens, op_tokens[model], state_ix, dict_ix, ts_ix, step); i=i+1;trib2.get_state('drainage_area_sqmi')