|
1 | | -# Must be run from the HSPsquared source directory, the h5 file has already been setup with hsp import_uci test10.uci |
2 | | -# bare bones tester - must be run from the HSPsquared source directory |
3 | | -import os |
| 1 | +# this is a simple tester that should be kept up to date with the code in main.py |
| 2 | +# alternative to step debugger |
| 3 | +fpath = "./tests/testcbp/HSP2results/JL1_6562_6560.h5" |
4 | 4 |
|
5 | | -import numpy |
6 | 5 | from hsp2.hsp2.main import * |
7 | 6 | from hsp2.hsp2.om import * |
8 | 7 | from hsp2.hsp2io.hdf import HDF5 |
9 | 8 | from hsp2.hsp2io.io import IOManager |
10 | 9 | from hsp2.state.state import * |
11 | 10 |
|
12 | | -fpath = "./tests/testcbp/HSP2results/JL1_6562_6560.h5" |
13 | 11 | # try also: |
14 | 12 | # fpath = './tests/testcbp/HSP2results/JL1_6562_6560.h5' |
15 | 13 | # sometimes when testing you may need to close the file, so try: |
16 | 14 | # f = h5py.File(fpath,'a') # use mode 'a' which allows read, write, modify |
17 | 15 | # # f.close() |
18 | 16 | hdf5_instance = HDF5(fpath) |
19 | 17 | io_manager = IOManager(hdf5_instance) |
20 | | -uci_obj = io_manager.read_uci() |
21 | | -siminfo = uci_obj.siminfo |
22 | | -opseq = uci_obj.opseq |
| 18 | +parameter_obj = io_manager.read_parameters() |
| 19 | +siminfo = parameter_obj.siminfo |
| 20 | +opseq = parameter_obj.opseq |
23 | 21 | # Note: now that the UCI is read in and hdf5 loaded, you can see things like: |
24 | 22 | # - hdf5_instance._store.keys() - all the paths in the UCI/hdf5 |
25 | 23 | # - finally stash specactions in state, not domain (segment) dependent so do it once |
26 | 24 | # now load state and the special actions |
27 | 25 | state = init_state_dicts() |
28 | | -state_initialize_om(state) |
29 | | -state["specactions"] = uci_obj.specactions # stash the specaction dict in state |
30 | | - |
31 | | -state_siminfo_hsp2(uci_obj, siminfo) |
| 26 | +state_siminfo_hsp2(parameter_obj, siminfo, io_manager, state) |
32 | 27 | # Add support for dynamic functions to operate on STATE |
33 | 28 | # - Load any dynamic components if present, and store variables on objects |
34 | 29 | state_load_dynamics_hsp2(state, io_manager, siminfo) |
35 | 30 | # Iterate through all segments and add crucial paths to state |
36 | 31 | # before loading dynamic components that may reference them |
37 | 32 | state_init_hsp2(state, opseq, activities) |
38 | | -state_load_dynamics_specl(state, io_manager, siminfo) # traditional special actions |
| 33 | +# - finally stash specactions in state, not domain (segment) dependent so do it once |
| 34 | +state["specactions"] = specactions # stash the specaction dict in state |
| 35 | +om_init_state(state) # set up operational model specific state entries |
| 36 | +specl_load_state(state, io_manager, siminfo) # traditional special actions |
39 | 37 | state_load_dynamics_om( |
40 | 38 | state, io_manager, siminfo |
41 | 39 | ) # operational model for custom python |
42 | | -state_om_model_run_prep( |
43 | | - state, io_manager, siminfo |
44 | | -) # this creates all objects from the UCI and previous loads |
45 | | -# state['model_root_object'].find_var_path('RCHRES_R001') |
46 | | -# Get the timeseries naked, without an object |
47 | | -Rlocal = state["model_object_cache"]["/STATE/RCHRES_R001/Rlocal"] |
48 | | -Rlocal_ts = Rlocal.read_ts() |
49 | | -rchres1 = state["model_object_cache"]["/STATE/RCHRES_R001"] |
50 | | -Rlocal_check = ModelLinkage( |
51 | | - "Rlocal1", rchres1, {"right_path": "/TIMESERIES/TS010", "link_type": 3} |
52 | | -) |
53 | | -# Calls: |
54 | | -# - ts = Rlocal.io_manager.read_ts(Category.INPUTS, None, Rlocal.ts_name) |
55 | | -# - ts = transform(ts, Rlocal.ts_name, 'SAME', Rlocal.siminfo) |
56 | | -Rlocal.io_manager._output._store.keys() |
57 | | -# write it back. We can give an arbitrary name or it will default to write back to the source path in right_path variable |
58 | | -ts1 = ( |
59 | | - precip_ts.read_ts() |
60 | | -) # same as precip_ts.ts_ix[precip_ts.ix], same as state['ts_ix'][precip_ts.ix] |
61 | | -# we can specify a custom path to write this TS to |
62 | | -precip_ts.write_path = "/RESULTS/test_TS039" |
63 | | -precip_ts.write_ts() |
64 | | -# precip_ts.write_ts is same as: |
65 | | -# ts4 = precip_ts.format_ts(ts1, ['tsvalue'], siminfo['tindex']) |
66 | | -# ts4.to_hdf(precip_ts.io_manager._output._store, precip_ts.write_path, format='t', data_columns=True, complevel=precip_ts.complevel) |
67 | | - |
68 | | -start = time.time() |
69 | | -iterate_models( |
70 | | - model_exec_list, op_tokens, state_ix, dict_ix, ts_ix, siminfo["steps"], -1 |
71 | | -) |
72 | | -end = time.time() |
73 | | -print( |
74 | | - len(model_exec_list), |
75 | | - "components iterated over state_ix", |
76 | | - siminfo["steps"], |
77 | | - "time steps took", |
78 | | - end - start, |
79 | | - "seconds", |
80 | | -) |
| 40 | +# finalize all dynamically loaded components and prepare to run the model |
| 41 | +state_om_model_run_prep(state, io_manager, siminfo) |
0 commit comments