forked from Urban-Meteorology-Reading/SUEWS
-
Notifications
You must be signed in to change notification settings - Fork 10
Add physics method dependency description in docs #865
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
Draft
sunt05
wants to merge
4
commits into
master
Choose a base branch
from
sunt05/davao
base: master
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.
Draft
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
75f9419
Feat: Add physics method dependency validation with improved error ha…
sunt05 771e51b
Fix: Display depends_on and provides_to on separate rows in docs
sunt05 4632c0d
style: auto-format code with ruff and fprettify
github-actions[bot] 94317ca
Refactor: Remove unnecessary path setup boilerplate from test
sunt05 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
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,79 @@ | ||
| import pytest | ||
|
|
||
| from supy.data_model.core.model import ( | ||
| ModelPhysics, | ||
| NetRadiationMethod, | ||
| OhmIncQf, | ||
| RCMethod, | ||
| StebbsMethod, | ||
| StorageHeatMethod, | ||
| ) | ||
|
|
||
|
|
||
| def test_ehc_requires_spartacus_netrad(): | ||
| """EHC storage heat must use a SPARTACUS net radiation option.""" | ||
|
|
||
| with pytest.raises(ValueError, match="requires NetRadiationMethod >= 1000"): | ||
| ModelPhysics( | ||
| storageheatmethod=StorageHeatMethod.EHC, | ||
| netradiationmethod=NetRadiationMethod.LDOWN_AIR, | ||
| ) | ||
|
|
||
|
|
||
| def test_spartacus_requires_ehc_storage(): | ||
| """SPARTACUS radiation options should only be paired with EHC storage heat.""" | ||
|
|
||
| # Verify that the test uses a valid SPARTACUS option (>= 1000) | ||
| assert NetRadiationMethod.LDOWN_SS_OBSERVED.value >= 1000, ( | ||
| f"NetRadiationMethod.LDOWN_SS_OBSERVED should be >= 1000, got {NetRadiationMethod.LDOWN_SS_OBSERVED.value}" | ||
| ) | ||
|
|
||
| with pytest.raises(ValueError, match="must be coupled with StorageHeatMethod=5"): | ||
| ModelPhysics( | ||
| storageheatmethod=StorageHeatMethod.OHM_WITHOUT_QF, | ||
| netradiationmethod=NetRadiationMethod.LDOWN_SS_OBSERVED, | ||
| ) | ||
|
|
||
|
|
||
| def test_stebbs_storage_requires_stebbs_method(): | ||
| with pytest.raises(ValueError, match="requires stebbsmethod"): | ||
| ModelPhysics( | ||
| storageheatmethod=StorageHeatMethod.STEBBS, | ||
| stebbsmethod=StebbsMethod.NONE, | ||
| ) | ||
|
|
||
|
|
||
| def test_rcmethod_requires_active_stebbs(): | ||
| with pytest.raises(ValueError, match="RCMethod>0 requires stebbsmethod"): | ||
| ModelPhysics( | ||
| rcmethod=RCMethod.PROVIDED, | ||
| stebbsmethod=StebbsMethod.NONE, | ||
| ) | ||
|
|
||
|
|
||
| def test_ohmincqf_include_only_for_ohm_methods(): | ||
| with pytest.raises(ValueError, match="ohmIncQf=1"): | ||
| ModelPhysics( | ||
| storageheatmethod=StorageHeatMethod.OBSERVED, | ||
| ohmincqf=OhmIncQf.INCLUDE, | ||
| ) | ||
|
|
||
|
|
||
| def test_valid_combinations_pass(): | ||
| """A configuration satisfying all constraints should instantiate cleanly.""" | ||
|
|
||
| # Verify that the test uses a valid SPARTACUS option (>= 1000) for EHC | ||
| assert NetRadiationMethod.LDOWN_SS_CLOUD.value >= 1000, ( | ||
| f"NetRadiationMethod.LDOWN_SS_CLOUD should be >= 1000, got {NetRadiationMethod.LDOWN_SS_CLOUD.value}" | ||
| ) | ||
|
|
||
| config = ModelPhysics( | ||
| storageheatmethod=StorageHeatMethod.EHC, | ||
| netradiationmethod=NetRadiationMethod.LDOWN_SS_CLOUD, | ||
| stebbsmethod=StebbsMethod.DEFAULT, | ||
| rcmethod=RCMethod.NONE, | ||
| ohmincqf=OhmIncQf.EXCLUDE, | ||
| ) | ||
|
|
||
| assert config.storageheatmethod == StorageHeatMethod.EHC | ||
| assert config.netradiationmethod == NetRadiationMethod.LDOWN_SS_CLOUD |
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.
Hi @dayantur - this shows the idea I mentioned about using data structure to illustrate the module dependency.
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.
Hi @sunt05, I had a quick look and it seems like a good improvement.. definitely a faster way to implement this kind of rule. I think we just need to make sure we clean up the existing dependency rules in phase_b.py (there are already a couple or so in there), and that we place this new model validator in SUEWSConfig (since we've moved all validators into config.py - unless you think this specific case requires otherwise?).
I’m about to push a couple of updated CSV files in PR #851, where I’ve collected all the rules currently in the pipeline. That should give us a clearer picture of what would need to be deduplicated if we move forward with this approach.
P.S.: I think we can agree - though correct me if you think I'm wrong! - that we'll still need some rules in phase_b.py for physics-option dependencies when a particular combination of model physics settings imposes checks or constraints on other parameters, rather than just encoding the basic physics-option dependency itself.