-
Notifications
You must be signed in to change notification settings - Fork 20
Develop state class #202
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
Open
rburghol
wants to merge
362
commits into
respec:develop
Choose a base branch
from
HARPgroup:develop-state-class
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Develop state class #202
Changes from all commits
Commits
Show all changes
362 commits
Select commit
Hold shift + click to select a range
be1e938
debug
fc78f4a
debug
8881a27
debug
0097594
Move get_ix_path to state object and use numpy array tuple handler to…
953376c
items are a dictionary must refer to state also
4050a29
use correct method syntac
2e27c2d
can we return unicode or None?
704e6fb
more debug
d816181
provide OVOL to state for use in specl
7cd18af
ref ovol3 in equation for withdrawal
e0a07b0
corrected bad overwrite of demand o1,... and set test flow to ivol
08ca68e
debug
5d5891d
debug
167a62a
debug
37c5b0f
debug
1fb6e64
do not convert ivol in state transactions, if ops need conversions th…
2ae811a
added an extra equation
rburghol 21cef61
removed deprecated column
003ddea
Merge branch 'develop-state-class' of github.com:HARPgroup/HSPsquared…
a3ce2fc
madapt sedtrn to new state object
92b7fca
io_manager was no longer used
0be33d4
io_manager was no longer used
d499de3
one more state migration fix
89c003f
migrate RQUAL to new format
c7ccff7
debug off
7916fec
debug off
f59f92c
debug off
705f355
test no om
5702caf
reenable om
95b5f70
debug off
9cd4d7c
debug off
d034b05
added refresh for uci only command
53b077a
added a long running version of UCI
rburghol c4c0959
Merge branch 'develop-state-class' of github.com:HARPgroup/HSPsquared…
f891529
dont remove existing h5
1760357
add info
70ba943
add info
f1103a9
update uci test
rburghol 5f8a6d6
replace Dict to make explicit reference that hopefully numba will run…
7ea20fe
test different declaration style
42826d8
test different declaration style - fixe
ed13ec7
new declarations ready for model run testin
aa787de
removed extraneous package indicator since it is aliased
2b2bd27
add state_ix initialization
2225002
go to all numba types for number arrays
550874e
muste use numpy types when casting to numba arrays?
39ce8f7
use numpy types during resize too
0d50083
change all OM indices to 64 bit
a039364
timer debugging added
17dde1d
remove unused import
5670b61
detailed state tracking 1
372431a
detailed state tracking 2
7b26504
test caching objecdt in function
fa645cc
different reference will work?
3adaad0
set initial values externally
9468566
test simpler implementation
7e44c77
test simpler implementation
f019206
add num_ops
7f2042c
simpler spec
61ac913
simpler spec
fb71314
no complex setting in init
ffddc64
no complex setting in init
33ac79e
no complex setting in init
d9001b7
no complex setting in init
e728ae7
what happens if we dont return it?
fb36864
numba as source not types
175aed4
numba as source not types
ea92501
return nothing
9d6e7da
pass atts
a6cdeb1
pass atts
75e31f9
pass atts and return
8bad920
pass atts and return
9361030
try to use cache=true cause the google AI said it should work even th…
075d8b3
this is why you dont trust the silly AI
92e9abf
can compile state_init_true?
b60d263
can compile state_init_true?
aeb3c7e
can compile state_init_true?
1a87893
can compile state_context_hsp2
e6b4662
more info
f31ef35
no njit
01b4da9
remove redundant path creation
b4f8293
info
c414585
info
c40c0aa
eval prep with state as non jit
a2db292
eval prep with state as non jit
10da314
state class lite compiled and returned what is time impact?
fb22f75
also must compile state_class
2b09ca8
add field to lite
f3176c2
add field to lite
cfe0b7b
add field to lite
0a8f3d8
add field to lite
19d01b5
add field to lite
abd0bbe
add remaining needed fields to lite
5674ce0
add contextual fields to lite
4f0fc2f
where is lite
2ac85a9
now use lite with copier at start
500933a
typo
e27a153
typo
4ce465c
use non method function
6cf1552
dont forget to copy all needed
efc3f1b
de ubg and copy hsp active or not
162725e
jit off
923f9b3
debug
bf5bbe5
jit on, removed context call since that is a double function that is …
fc112df
info
3323804
info
7016e7e
add actual defaults
84d10b2
add model_root_name!
75131dc
use old function
eed2c12
copy root name
f365fcd
numbaize old support function
cb32862
no jit on base state class to speed up
17e21cc
use correct term
97baab9
cleaned up imports
1203557
better memory handling
1170c64
missing import
1dc0001
missing import
ea180cd
timer
a8f0103
need to pass state
70fdba5
nreposition
9205c57
oops overwrote state
4eebe6a
dont pass timer
480fa09
restore main.py and add timing alerts
1c6ab62
create timer
9f9ab0f
import def
c4d976b
fix args
dbb51d4
add numba compatible small state
2a1844b
add segments
8f5d9b4
reduce args for this empty function
8c37013
isable jit for debug
74c2ec4
isable jit for debug
563c858
debug
a92d57d
debug
005aa9b
need to include other pointer
b7c6942
need to include other pointer
57640e9
debug off
9008810
njiton
c826e9f
debug
251761b
jit on
0afb066
debug less
8a87929
debug less
42fdb4c
debug
77e6a74
debug
fe0b1bd
debug
6dd19b6
debug
417cfd8
handle other dict append too
f6680f8
oops missing arg
9dfaa64
oops missing arg
cffa44e
wrong target
39b9df9
wrong target
e101c8d
less debug
bb3eebd
jit fn to see if key exists in state
4eef404
jit part of fn to measure speed
54d1b4a
jit part of fn to measure speed
a401615
jit part of fn to measure speed
6c9806a
jit set value
b6c67a7
jit set value not append
ffc4bba
jit set value not append
5859220
return not set in ref
0911864
use np array
16cd73f
use DataFrame to as_nparray
66962c4
must call as function
1cde96a
make all ixs as df then convert
30502e9
import df
278de38
convert all to df
4f311c2
add a timer to single section
15d32e2
make timer a separate function file
667d7fa
missing import
d3cc126
debug
c575a78
debug timing
dfe6b31
debug timing
1df85cd
disambiguate
d11cd06
use faster state path check
321a917
include fn
469343f
debug less
46150bf
use fn in sim timer
2633f71
debugless
dafe319
less verbose
639b6e6
less verbose
b37f90d
less verbose
15f5dc8
less verbose
6f7bfd4
ad big test data set
fc0b362
debug
d868f28
replace nuneeded link
f0d49a5
debug
d5784b7
good WD test
b851d5b
good WD test
e8134bb
info
8158666
info
8fd53a0
debug
d791160
debug
f89c64a
do not conert ep_list to numpy cuz it is text!
ea37f23
debug
1675434
debug
e5194a8
debug
82d4a39
debug
89b9d33
copy domain too!
4eb1707
debug off
9b996dd
debug off
189b77f
debug off
4d57370
return on zero op type
74701bd
return on -1 initialize op_lists as such
46fb0af
debug
df32f75
multi dim not scalar
35adb5f
multi dim not scalar
058937f
check comparator efficiency
10254be
tiny withdrawal
459c1c6
Merge branch 'develop' into develop-state-class
rburghol 9b636ca
rename import
4194fd9
Merge branch 'develop-state-class' of github.com:HARPgroup/HSPsquared…
aba5236
add import
aa601af
use non obj function version
a87371a
use non obj function version
c35d974
make sure all are jitted
a4549e5
dont jit stuff that shouldnt be!
369f341
parsing help
d8d2f2e
annotate and better handking
dd7eb61
initialize HSP2 rchres etc earlier in the process
e8fd513
use direct dictionary referecnes instead of copies (which should pass…
edc451f
break out state initializers to handle reorder
b7dc74c
break out state initializers to handle reorder
b09c019
do not enclose in parens does this help testing?
205c8ee
restore parens
96ca575
Merge branch 'update_uci' of github.com:HARPgroup/HSPsquared into dev…
bff8291
merged adjacent branches to facilitate synch with develop
4efdafe
develop-state-class
29ef8b6
develop-state-class
6b93735
info
38adfee
allow tests_root_dir to be passed in instead of guessing
c70a343
test directory handling
23b5db6
get fixed tests
8541f47
pass objects to clean up routine
7829bf7
merged changes from utilities.py into this branch
rburghol 15f5020
integrated the changes to main.py get_flows for pandas > 3.0
c9c3c5f
Merge branch 'develop-state-class' of github.com:HARPgroup/HSPsquared…
e7c5fe7
use root class object getter
rburghol aa31b7e
fix args
rburghol de6db7a
create new HDF5 close() method and call at the end of run().
rburghol 8bbedea
changes to main and utilities to adapt to pandas 3 deprecations
e7331cc
code for cmd prmpt test regression
rburghol eee6959
removed seemingly inactive file that causes compile problems at times
rburghol acc1e36
trigger test bot with pre pandas 3 for testing
rburghol 6c92311
used freq + convert to_timedelta to insure valid comparisons in all t…
rburghol fcacfd4
check if these changes are robust into pandas 3
rburghol 193c4bb
use pandas to_timedelta function to future proof
8df5ad0
use freq own delta property for properly formatted
389a3cb
pandas < 3
3b3e56d
pandas 3.0.0 safe code for model execution but NOT RegressTest. QUant…
a3a68d4
Merge branch 'develop-state-class' into develop-hdf5
rburghol 9c23bd6
Merge pull request #121 from HARPgroup/develop-hdf5
rburghol File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) | ||
| ####################################################################################### |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks like it has been added to the examples by mistake.