Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
384 commits
Select commit Hold shift + click to select a range
d499de3
one more state migration fix
Dec 29, 2025
89c003f
migrate RQUAL to new format
Dec 30, 2025
c7ccff7
debug off
Dec 30, 2025
7916fec
debug off
Dec 30, 2025
f59f92c
debug off
Dec 30, 2025
705f355
test no om
Dec 30, 2025
5702caf
reenable om
Dec 30, 2025
95b5f70
debug off
Dec 30, 2025
9cd4d7c
debug off
Dec 30, 2025
d034b05
added refresh for uci only command
Dec 31, 2025
53b077a
added a long running version of UCI
rburghol Dec 31, 2025
c4c0959
Merge branch 'develop-state-class' of github.com:HARPgroup/HSPsquared…
Dec 31, 2025
f891529
dont remove existing h5
Dec 31, 2025
1760357
add info
Dec 31, 2025
70ba943
add info
Dec 31, 2025
f1103a9
update uci test
rburghol Dec 31, 2025
07938cf
Add update_uci mode in CLI and test UCI files
rburghol Jan 2, 2026
da443d1
Removed extraneous coe that reads FILES blocks since no FILES updates…
rburghol Jan 5, 2026
f530fc6
Removed accidental paste
rburghol Jan 5, 2026
5f8a6d6
replace Dict to make explicit reference that hopefully numba will run…
Jan 5, 2026
7ea20fe
test different declaration style
Jan 5, 2026
42826d8
test different declaration style - fixe
Jan 5, 2026
ed13ec7
new declarations ready for model run testin
Jan 5, 2026
aa787de
removed extraneous package indicator since it is aliased
Jan 5, 2026
2b2bd27
add state_ix initialization
Jan 5, 2026
2225002
go to all numba types for number arrays
Jan 5, 2026
550874e
muste use numpy types when casting to numba arrays?
Jan 5, 2026
39ce8f7
use numpy types during resize too
Jan 5, 2026
0d50083
change all OM indices to 64 bit
Jan 5, 2026
a039364
timer debugging added
Jan 6, 2026
17dde1d
remove unused import
Jan 6, 2026
5670b61
detailed state tracking 1
Jan 6, 2026
372431a
detailed state tracking 2
Jan 6, 2026
7b26504
test caching objecdt in function
Jan 6, 2026
fa645cc
different reference will work?
Jan 6, 2026
3adaad0
set initial values externally
Jan 6, 2026
9468566
test simpler implementation
Jan 6, 2026
7e44c77
test simpler implementation
Jan 6, 2026
f019206
add num_ops
Jan 6, 2026
7f2042c
simpler spec
Jan 6, 2026
61ac913
simpler spec
Jan 6, 2026
fb71314
no complex setting in init
Jan 6, 2026
ffddc64
no complex setting in init
Jan 6, 2026
33ac79e
no complex setting in init
Jan 6, 2026
d9001b7
no complex setting in init
Jan 6, 2026
e728ae7
what happens if we dont return it?
Jan 6, 2026
fb36864
numba as source not types
Jan 6, 2026
175aed4
numba as source not types
Jan 6, 2026
ea92501
return nothing
Jan 6, 2026
9d6e7da
pass atts
Jan 6, 2026
a6cdeb1
pass atts
Jan 6, 2026
75e31f9
pass atts and return
Jan 6, 2026
8bad920
pass atts and return
Jan 6, 2026
9361030
try to use cache=true cause the google AI said it should work even th…
Jan 6, 2026
075d8b3
this is why you dont trust the silly AI
Jan 6, 2026
92e9abf
can compile state_init_true?
Jan 6, 2026
b60d263
can compile state_init_true?
Jan 6, 2026
aeb3c7e
can compile state_init_true?
Jan 6, 2026
1a87893
can compile state_context_hsp2
Jan 6, 2026
e6b4662
more info
Jan 6, 2026
f31ef35
no njit
Jan 6, 2026
01b4da9
remove redundant path creation
Jan 6, 2026
b4f8293
info
Jan 6, 2026
c414585
info
Jan 6, 2026
c40c0aa
eval prep with state as non jit
Jan 6, 2026
a2db292
eval prep with state as non jit
Jan 6, 2026
10da314
state class lite compiled and returned what is time impact?
Jan 6, 2026
fb22f75
also must compile state_class
Jan 6, 2026
2b09ca8
add field to lite
Jan 6, 2026
f3176c2
add field to lite
Jan 6, 2026
cfe0b7b
add field to lite
Jan 6, 2026
0a8f3d8
add field to lite
Jan 6, 2026
19d01b5
add field to lite
Jan 6, 2026
abd0bbe
add remaining needed fields to lite
Jan 6, 2026
5674ce0
add contextual fields to lite
Jan 6, 2026
4f0fc2f
where is lite
Jan 6, 2026
2ac85a9
now use lite with copier at start
Jan 6, 2026
500933a
typo
Jan 6, 2026
e27a153
typo
Jan 6, 2026
4ce465c
use non method function
Jan 6, 2026
6cf1552
dont forget to copy all needed
Jan 6, 2026
efc3f1b
de ubg and copy hsp active or not
Jan 6, 2026
162725e
jit off
Jan 6, 2026
923f9b3
debug
Jan 6, 2026
bf5bbe5
jit on, removed context call since that is a double function that is …
Jan 6, 2026
fc112df
info
Jan 6, 2026
3323804
info
Jan 6, 2026
7016e7e
add actual defaults
Jan 6, 2026
84d10b2
add model_root_name!
Jan 6, 2026
75131dc
use old function
Jan 6, 2026
eed2c12
copy root name
Jan 6, 2026
f365fcd
numbaize old support function
Jan 6, 2026
cb32862
no jit on base state class to speed up
Jan 6, 2026
17e21cc
use correct term
Jan 6, 2026
97baab9
cleaned up imports
Jan 7, 2026
1203557
better memory handling
Jan 7, 2026
1170c64
missing import
Jan 7, 2026
1dc0001
missing import
Jan 7, 2026
ea180cd
timer
Jan 7, 2026
a8f0103
need to pass state
Jan 7, 2026
70fdba5
nreposition
Jan 7, 2026
9205c57
oops overwrote state
Jan 7, 2026
4eebe6a
dont pass timer
Jan 7, 2026
480fa09
restore main.py and add timing alerts
Jan 7, 2026
1c6ab62
create timer
Jan 7, 2026
9f9ab0f
import def
Jan 7, 2026
c4d976b
fix args
Jan 7, 2026
dbb51d4
add numba compatible small state
Jan 7, 2026
2a1844b
add segments
Jan 7, 2026
8f5d9b4
reduce args for this empty function
Jan 7, 2026
8c37013
isable jit for debug
Jan 7, 2026
74c2ec4
isable jit for debug
Jan 7, 2026
563c858
debug
Jan 7, 2026
a92d57d
debug
Jan 7, 2026
005aa9b
need to include other pointer
Jan 7, 2026
b7c6942
need to include other pointer
Jan 7, 2026
57640e9
debug off
Jan 7, 2026
9008810
njiton
Jan 7, 2026
c826e9f
debug
Jan 7, 2026
251761b
jit on
Jan 7, 2026
0afb066
debug less
Jan 7, 2026
8a87929
debug less
Jan 7, 2026
42fdb4c
debug
Jan 7, 2026
77e6a74
debug
Jan 7, 2026
fe0b1bd
debug
Jan 7, 2026
6dd19b6
debug
Jan 7, 2026
417cfd8
handle other dict append too
Jan 7, 2026
f6680f8
oops missing arg
Jan 7, 2026
9dfaa64
oops missing arg
Jan 7, 2026
cffa44e
wrong target
Jan 7, 2026
39b9df9
wrong target
Jan 7, 2026
e101c8d
less debug
Jan 7, 2026
bb3eebd
jit fn to see if key exists in state
Jan 8, 2026
4eef404
jit part of fn to measure speed
Jan 8, 2026
54d1b4a
jit part of fn to measure speed
Jan 8, 2026
a401615
jit part of fn to measure speed
Jan 8, 2026
6c9806a
jit set value
Jan 8, 2026
b6c67a7
jit set value not append
Jan 8, 2026
ffc4bba
jit set value not append
Jan 8, 2026
5859220
return not set in ref
Jan 8, 2026
0911864
use np array
Jan 8, 2026
16cd73f
use DataFrame to as_nparray
Jan 8, 2026
66962c4
must call as function
Jan 8, 2026
1cde96a
make all ixs as df then convert
Jan 8, 2026
30502e9
import df
Jan 8, 2026
278de38
convert all to df
Jan 8, 2026
4f311c2
add a timer to single section
Jan 8, 2026
15d32e2
make timer a separate function file
Jan 8, 2026
667d7fa
missing import
Jan 8, 2026
d3cc126
debug
Jan 8, 2026
c575a78
debug timing
Jan 8, 2026
dfe6b31
debug timing
Jan 8, 2026
1df85cd
disambiguate
Jan 8, 2026
d11cd06
use faster state path check
Jan 8, 2026
321a917
include fn
Jan 8, 2026
469343f
debug less
Jan 8, 2026
46150bf
use fn in sim timer
Jan 8, 2026
2633f71
debugless
Jan 8, 2026
dafe319
less verbose
Jan 8, 2026
639b6e6
less verbose
Jan 8, 2026
b37f90d
less verbose
Jan 8, 2026
15f5dc8
less verbose
Jan 8, 2026
6f7bfd4
ad big test data set
Jan 9, 2026
fc0b362
debug
Jan 9, 2026
d868f28
replace nuneeded link
Jan 9, 2026
f0d49a5
debug
Jan 9, 2026
d5784b7
good WD test
Jan 9, 2026
b851d5b
good WD test
Jan 9, 2026
e8134bb
info
Jan 9, 2026
8158666
info
Jan 9, 2026
8fd53a0
debug
Jan 9, 2026
d791160
debug
Jan 9, 2026
f89c64a
do not conert ep_list to numpy cuz it is text!
Jan 9, 2026
ea37f23
debug
Jan 9, 2026
1675434
debug
Jan 9, 2026
e5194a8
debug
Jan 9, 2026
82d4a39
debug
Jan 9, 2026
89b9d33
copy domain too!
Jan 9, 2026
4eb1707
debug off
Jan 9, 2026
9b996dd
debug off
Jan 9, 2026
189b77f
debug off
Jan 9, 2026
4d57370
return on zero op type
Jan 9, 2026
74701bd
return on -1 initialize op_lists as such
Jan 9, 2026
46fb0af
debug
Jan 9, 2026
df32f75
multi dim not scalar
Jan 9, 2026
35adb5f
multi dim not scalar
Jan 9, 2026
058937f
check comparator efficiency
Jan 9, 2026
10254be
tiny withdrawal
Jan 9, 2026
459c1c6
Merge branch 'develop' into develop-state-class
rburghol Jan 9, 2026
9b636ca
rename import
Jan 9, 2026
4194fd9
Merge branch 'develop-state-class' of github.com:HARPgroup/HSPsquared…
Jan 9, 2026
aba5236
add import
Jan 9, 2026
aa601af
use non obj function version
Jan 9, 2026
a87371a
use non obj function version
Jan 9, 2026
c35d974
make sure all are jitted
Jan 9, 2026
a4549e5
dont jit stuff that shouldnt be!
Jan 9, 2026
369f341
parsing help
Jan 16, 2026
d8d2f2e
annotate and better handking
Jan 20, 2026
548c6e0
separated specl parser into its own file and added draft IF parser
Jan 20, 2026
3a40dea
added UCI setup to make testing possible
Jan 20, 2026
9ec5c13
added proper include
Jan 20, 2026
1044903
typo
Jan 20, 2026
79fac7a
fix bad IF block in UCI
Jan 20, 2026
1c5945e
fdebug
Jan 20, 2026
2b928a3
fdebug
Jan 20, 2026
e1207bb
fdebug
Jan 20, 2026
87d7b94
try strippin
Jan 20, 2026
82bc8cc
import fn and debug off
Jan 20, 2026
51cd395
import as new lib to avoid circularity
Jan 20, 2026
1af9bbe
correcdt syntax
Jan 20, 2026
78601b8
debug
Jan 20, 2026
f524f94
correct parse columns
Jan 20, 2026
7119fed
add index column
Jan 20, 2026
5821622
debug
Jan 20, 2026
48a13b2
fix oops
Jan 20, 2026
ea8a7a0
clean up line
Jan 20, 2026
c1853c5
do not clean line it is fixed width
Jan 20, 2026
ad70add
ddebug
Jan 20, 2026
6112736
appen the dict?
Jan 20, 2026
2fcf110
rename column for associated condition
Jan 20, 2026
80e8649
info
Jan 20, 2026
101e1e5
update name in dataframe for condition proper maping
Jan 20, 2026
b16a299
oops overwrite condition column
Jan 20, 2026
24cf32b
extra non-IFed conditions
Jan 20, 2026
219cf4a
does specl lock need a custom END getter?
Jan 20, 2026
8cb060d
debug off. rename functions for better understanding.
Jan 20, 2026
a435ed7
debug off.
Jan 20, 2026
20a4da4
remove unneeded comment change
Jan 20, 2026
53c2092
reorg to work around testing file location trouble
Jan 20, 2026
8e8986e
reformat
rburghol Jan 20, 2026
88c2675
remove reference to class in parallel branch
Jan 20, 2026
7fef9a5
merge and further clean
Jan 20, 2026
5305487
typo
Jan 21, 2026
687e9f5
Move exploratory code from tests to examples to avoid triggering spur…
Jan 21, 2026
ca3cd99
close hdf at end of demo script
Jan 21, 2026
95d4203
change name from test so not auto triggered
Jan 21, 2026
dd7eb61
initialize HSP2 rchres etc earlier in the process
Jan 21, 2026
e8fd513
use direct dictionary referecnes instead of copies (which should pass…
Jan 21, 2026
edc451f
break out state initializers to handle reorder
Jan 21, 2026
b7dc74c
break out state initializers to handle reorder
Jan 21, 2026
b09c019
do not enclose in parens does this help testing?
Jan 21, 2026
205c8ee
restore parens
Jan 21, 2026
96ca575
Merge branch 'update_uci' of github.com:HARPgroup/HSPsquared into dev…
Jan 21, 2026
bff8291
merged adjacent branches to facilitate synch with develop
Jan 21, 2026
4efdafe
develop-state-class
Jan 21, 2026
29ef8b6
develop-state-class
Jan 21, 2026
6b93735
info
Jan 21, 2026
38adfee
allow tests_root_dir to be passed in instead of guessing
Jan 21, 2026
c70a343
test directory handling
Jan 22, 2026
23b5db6
get fixed tests
Jan 22, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 28 additions & 11 deletions examples/state_specl_ops/compare_eq_to_specl.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from src.hsp2.hsp2tools.commands import import_uci, run
from src.hsp2.hsp2tools.HDF5 import HDF5
from src.hsp2.hsp2tools.HBNOutput import HBNOutput
import tabulate

def test_h5_file_exists():
assert os.path.exists('test10.h5')
Expand All @@ -24,15 +25,15 @@ def test_h5_file_exists():
# get RCHRES 5 sedtrn silt
ts_silt_hspf = hspf_data.get_time_series('RCHRES', 5, 'RSEDTOTSILT', 'SEDTRN', 'full')
total_silt_hspf = ts_silt_hspf.mean()
quantile_silt_hspf = np.quantile(ts_silt_hspf,[0.0,0.10,0.5,0.5,0.75,0.9,0.95,1.0])
quantile_silt_hspf = np.quantile(ts_silt_hspf,[0.0,0.25,0.5,0.75,1.0])

############# HSPF NO SPECL
hspf_nospecl_root = Path("tests/test10/HSPFresults")
hspf_nospecl_data = HBNOutput(os.path.join(hspf_nospecl_root, 'test10R.hbn'))
hspf_nospecl_data.read_data()
ts_silt_nospecl_hspf = hspf_nospecl_data.get_time_series('RCHRES', 5, 'RSEDTOTSILT', 'SEDTRN', 'full')
total_silt_nospecl_hspf = ts_silt_nospecl_hspf.mean()
quantile_silt_nospecl_hspf = np.quantile(ts_silt_nospecl_hspf,[0.0,0.10,0.5,0.5,0.75,0.9,0.95,1.0])
quantile_silt_nospecl_hspf = np.quantile(ts_silt_nospecl_hspf,[0.0,0.25,0.5,0.75,1.0])

############# hsp2 SPECL
# Run and Analyze hsp2 WITH SPECL actions
Expand All @@ -54,19 +55,19 @@ def test_h5_file_exists():
hsp2_specl_hydr5 = read_hdf(dstore_specl, '/RESULTS/RCHRES_R005/HYDR')
hsp2_specl_sedtrn5 = read_hdf(dstore_specl, '/RESULTS/RCHRES_R005/SEDTRN')
hsp2_specl_rsed5 = hsp2_specl_sedtrn5['RSED5']
quantile_silt_hsp2 = np.quantile(hsp2_specl_rsed5,[0.0,0.10,0.5,0.5,0.75,0.9,0.95,1.0])
quantile_ro_hsp2 = np.quantile(hsp2_specl_hydr5['RO'],[0.0,0.10,0.5,0.5,0.75,0.9,0.95,1.0])
quantile_silt_hsp2 = np.quantile(hsp2_specl_rsed5,[0.0,0.25,0.5,0.75,1.0])
quantile_ro_hsp2 = np.quantile(hsp2_specl_hydr5['RO'],[0.0,0.25,0.5,0.75,1.0])
total_silt_hsp2 = hsp2_specl_rsed5.mean()
dstore_specl.close()

############# hsp2 w/out SPECL
# Run and Analyze hsp2 without SPECL actions
nospecl_root = Path("tests/test10")
nospecl_root.exists()
nospecl_root_hspf = Path(nospecl_root) / "HSPFresults"
hsp2_nospecl_uci = nospecl_root_hspf.resolve() / "test10.uci"
nospecl_root_hsp2 = Path(nospecl_root) / "HSP2results"
hsp2_nospecl_uci = nospecl_root_hsp2.resolve() / "test10.uci"
hsp2_nospecl_uci.exists()
temp_nospecl_h5file = nospecl_root_hspf / "nospecl_case.h5"
temp_nospecl_h5file = nospecl_root_hsp2 / "test10.h5"

# IF we want to run it from python, do this:
#if temp_nospecl_h5file.exists():
Expand All @@ -79,8 +80,8 @@ def test_h5_file_exists():
hsp2_nospecl_hydr5 = read_hdf(dstore_nospecl, '/RESULTS/RCHRES_R005/HYDR')
hsp2_nospecl_sedtrn5 = read_hdf(dstore_nospecl, '/RESULTS/RCHRES_R005/SEDTRN')
hsp2_nospecl_rsed5 = hsp2_nospecl_sedtrn5['RSED5']
np.quantile(hsp2_nospecl_rsed5,[0.0,0.10,0.5,0.5,0.75,0.9,0.95,1.0])
np.quantile(hsp2_nospecl_hydr5['RO'],[0.0,0.10,0.5,0.5,0.75,0.9,0.95,1.0])
quantile_silt_nospecl_hsp2 = np.quantile(hsp2_nospecl_rsed5,[0.0,0.25,0.5,0.75,1.0])
np.quantile(hsp2_nospecl_hydr5['RO'],[0.0,0.25,0.5,0.75,1.0])
total_silt_nospecl_hsp2 = hsp2_nospecl_rsed5.mean()
dstore_nospecl.close()

Expand All @@ -105,8 +106,8 @@ def test_h5_file_exists():
hsp2_eq_hydr5 = read_hdf(dstore_eq_specl, '/RESULTS/RCHRES_R005/HYDR')
hsp2_eq_sedtrn5 = read_hdf(dstore_eq_specl, '/RESULTS/RCHRES_R005/SEDTRN')
hsp2_eq_rsed5 = hsp2_eq_sedtrn5['RSED5']
quantile_silt_eq_hsp2 = np.quantile(hsp2_eq_rsed5,[0.0,0.10,0.5,0.5,0.75,0.9,0.95,1.0])
quantile_ro_eq_hsp2 = np.quantile(hsp2_eq_hydr5['RO'],[0.0,0.10,0.5,0.5,0.75,0.9,0.95,1.0])
quantile_silt_eq_hsp2 = np.quantile(hsp2_eq_rsed5,[0.0,0.25,0.5,0.75,1.0])
quantile_ro_eq_hsp2 = np.quantile(hsp2_eq_hydr5['RO'],[0.0,0.25,0.5,0.75,1.0])
total_silt_eq_hsp2 = hsp2_eq_rsed5.mean()
dstore_eq_specl.close()

Expand All @@ -133,3 +134,19 @@ def test_h5_file_exists():
print("Total SiltHSP2 vs. HSPF, % difference = ", pct_dif_specl, "%")
print("No SPECL: Total SiltHSP2 vs. HSPF, % difference = ", pct_dif_nospecl, "%")


a = pd.DataFrame(
{
'HSP2 no specl':quantile_silt_nospecl_hsp2,
'HSPF no specl':quantile_silt_nospecl_hspf,
'HSPF w/specl':quantile_silt_hspf,
'HSP2 w/specl':quantile_silt_hsp2,
'HSP2 w/EQ':quantile_silt_eq_hsp2
}
)


tabulate(a, headers='keys', tablefmt='markdown')
tabulate(a, headers='keys', tablefmt='psql')
# Thi is better, it USES the tabulate lib but has usable format
a.to_markdown(index=False)
77 changes: 77 additions & 0 deletions examples/state_specl_ops/debug_pyt_est.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
from pathlib import Path

import pytest
from hsp2.hsp2tools.commands import import_uci, run
from hsp2.hsp2tools.HDF5 import HDF5

from convert.regression_base import RegressTest as RegressTestBase


class RegressTest(RegressTestBase):
def _get_hsp2_data(self, test_root) -> None:
test_root_hspf = Path(test_root) / "HSPFresults"
hspf_uci = test_root_hspf.resolve() / f"{self.compare_case}.uci"
assert hspf_uci.exists()

temp_h5file = test_root_hspf / f"{self.compare_case}.h5"
if temp_h5file.exists():
temp_h5file.unlink()

self.temp_h5file = temp_h5file

import_uci(str(hspf_uci), str(self.temp_h5file))
run(self.temp_h5file, saveall=True, compress=False)
self.hsp2_data = HDF5(str(self.temp_h5file))

def _init_files(self):
test_dir = Path(__file__).resolve().parent
assert test_dir.name == "tests"

test_root = test_dir / self.compare_case
assert test_root.exists()

self._get_hbn_data(str(test_root))
self._get_hsp2_data(str(test_root))


@pytest.mark.parametrize(
"case",
[
# "test05",
# "test09",
"test10",
"test10specl",
# "test10b",
],
)
def test_case(case):
test = RegressTest(case, threads=1)
results = test.run_test()
test.temp_h5file.unlink()

found = False
mismatches = []
for key, results in results.items():
no_data_hsp2, no_data_hspf, match, diff = results
if any([no_data_hsp2, no_data_hspf]):
continue
if not match:
mismatches.append((case, key, results))
found = True
assert found

if mismatches:
for case, key, results in mismatches:
_, _, _, diff = results
print(case, key, f"{diff:0.00%}")
raise ValueError("results don't match hspf output")


# demo the code in regression_base.py with this:
# creates a shell object namd "self" that can have attributes just added
self = type('', (), {})()
self.compare_case='test10'
self.html_file = os.path.join(
tests_root_dir, f"HSPF_HSP2_{self.compare_case}.html"
)
self.html_file
38 changes: 38 additions & 0 deletions examples/state_specl_ops/demo_land_specl.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Must be run from the HSPsquared source directory, the h5 file has already been setup with hsp import_uci test10.uci
# bare bones tester - must be run from the HSPsquared source directory

from hsp2.hsp2.main import *
from hsp2.hsp2.om import *
from hsp2.hsp2.SPECL import *
from hsp2.hsp2io.hdf import HDF5
from hsp2.hsp2io.io import IOManager
from hsp2.hsp2tools.readUCI import *

from hsp2.state.state import *

fpath = "./tests/land_spec/HSP2Results/hwmA51800.h5"
# try also:
# fpath = './tests/testcbp/HSP2results/JL1_6562_6560.h5'

# sometimes when testing you may need to close the file, so try:
# f = h5py.File(fpath,'a') # use mode 'a' which allows read, write, modify
# # f.close()
hdf5_instance = HDF5(fpath)
io_manager = IOManager(hdf5_instance)

parameter_obj = io_manager.read_parameters()
opseq = parameter_obj.opseq
ddlinks = parameter_obj.ddlinks
ddmasslinks = parameter_obj.ddmasslinks
ddext_sources = parameter_obj.ddext_sources
ddgener = parameter_obj.ddgener
model = parameter_obj.model
siminfo = parameter_obj.siminfo
ftables = parameter_obj.ftables
specactions = parameter_obj.specactions
monthdata = parameter_obj.monthdata
conditions = specactions["conditions"]
actions = specactions["ACTIONS"]

start, stop = siminfo["start"], siminfo["stop"]
hdf5_instance._store.close()
104 changes: 79 additions & 25 deletions examples/state_specl_ops/demo_specl_initialize.py
Original file line number Diff line number Diff line change
@@ -1,36 +1,90 @@
# Must be run from the HSPsquared source directory, the h5 file has already been setup with hsp import_uci test10.uci
# bare bones tester - must be run from the HSPsquared source directory

##########################################################################################
# LOAD HSP2 RUNTIME CODE AND UCI FILE
##########################################################################################
import os, numpy
import os
import numpy
from hsp2.hsp2.main import *
from hsp2.state.state import *
from hsp2.hsp2.om import *
from hsp2.hsp2.state import *
from hsp2.hsp2.SPECL import *
from hsp2.hsp2io.hdf import HDF5
from hsp2.hsp2io.io import IOManager
hdf5_instance = HDF5("./tests/test10specl/HSP2results/test10specl.demo.h5")
from hsp2.state.state import *
from hsp2.hsp2.om_timer import timer_class

fpath = "./tests/test10specl/HSP2results/test10specl.h5"
timer = timer_class()
# try also:
# fpath = './tests/testcbp/HSP2results/JL1_6562_6560.h5'

iomanager = IOManager(hdf5_instance)
uci_obj = iomanager.read_uci()
siminfo = uci_obj.siminfo
opseq = uci_obj.opseq
state = init_state_dicts()
state_siminfo_hsp2(uci_obj, siminfo, iomanager, state)
# sometimes when testing you may need to close the file, so try:
# f = h5py.File(fpath,'a') # use mode 'a' which allows read, write, modify
# # f.close()
hdf5_instance = HDF5(fpath)
io_manager = IOManager(hdf5_instance)

parameter_obj = io_manager.read_parameters()
opseq = parameter_obj.opseq
ddlinks = parameter_obj.ddlinks
ddmasslinks = parameter_obj.ddmasslinks
ddext_sources = parameter_obj.ddext_sources
ddgener = parameter_obj.ddgener
model = parameter_obj.model
siminfo = parameter_obj.siminfo
ftables = parameter_obj.ftables
specactions = parameter_obj.specactions
monthdata = parameter_obj.monthdata

# Add support for dynamic functions to operate on STATE
state_load_dynamics_hsp2(state, iomanager, siminfo)
state_init_hsp2(state, opseq, activities)
state["specactions"] = uci_obj.specactions # stash the specaction dict in state
om_init_state(state) # set up operational model specific state entries
specl_load_state(state, iomanager, siminfo) # traditional special actions
state_load_dynamics_om(state, iomanager, siminfo)
state_om_model_run_prep(state, iomanager, siminfo)
state_context_hsp2(state, "RCHRES", "R005", "SEDTRN")

domain, state_paths, state_ix, dict_ix, ts_ix, op_tokens = state["domain"], state["state_paths"], state["state_ix"], state["dict_ix"], state["ts_ix"], state["op_tokens"]
ep_list = np.asarray(["RSED1", "RSED2", "RSED3", "RSED4", "RSED5", "RSED6"], dtype='U')
model_exec_list = model_domain_dependencies(state, domain, ep_list, True)
get_domain_state(state_paths, state_ix, domain, ep_list)
# read user control, parameters, states, and flags parameters and map to local variables
parameter_obj = io_manager.read_parameters()
opseq = parameter_obj.opseq
ddlinks = parameter_obj.ddlinks
ddmasslinks = parameter_obj.ddmasslinks
ddext_sources = parameter_obj.ddext_sources
ddgener = parameter_obj.ddgener
model = parameter_obj.model
siminfo = parameter_obj.siminfo
ftables = parameter_obj.ftables
specactions = parameter_obj.specactions
monthdata = parameter_obj.monthdata

start, stop = siminfo["start"], siminfo["stop"]

copy_instances = {}
gener_instances = {}
section_timing = {}

section_timing["io_manager.read_parameters() call and config"] = str(timer.split()) + "seconds"
#######################################################################################
# initialize STATE dicts
#######################################################################################
# Set up Things in state that will be used in all modular activities like SPECL
state = state_class(
state_empty["state_ix"], state_empty["op_tokens"], state_empty["state_paths"],
state_empty["op_exec_lists"], state_empty["model_exec_list"], state_empty["dict_ix"],
state_empty["ts_ix"], state_empty["hsp_segments"]
)
om_operations = om_init_state() # set up operational model specific containers
state_siminfo_hsp2(state, parameter_obj, siminfo, io_manager)
state_om_model_root_object(state, om_operations, siminfo)
# Iterate through all segments and add crucial paths to state
# before loading dynamic components that may reference them
state_init_hsp2(state, opseq, activities, timer)
om_init_hsp2_segments(state, om_operations)
# now initialize all state variables for mutable variables
hsp2_domain_dependencies(state, opseq, activities, om_operations, False)
# Add support for dynamic functions to operate on STATE
# - Load any dynamic components if present, and store variables on objects
state_load_dynamics_hsp2(state, io_manager, siminfo)
# - finally stash specactions in state, not domain (segment) dependent so do it once
specl_load_om(om_operations, specactions) # load traditional special actions
state_load_dynamics_om(
state, io_manager, siminfo, om_operations
) # operational model for custom python
# finalize all dynamically loaded components and prepare to run the model
state_om_model_run_prep(opseq, activities, state, om_operations, siminfo)
section_timing["state om initialization()"] = str(timer.split()) + "seconds"
statenb = state_class_lite(0)
state_copy(state, statenb)
#######################################################################################
Loading
Loading