Skip to content

Commit 9e99841

Browse files
authored
Enhancement: Automatically insert technology names in control strategy definitions (#558)
* add tech name to control parameters in setup * remove obselete test and associate files * handle no keys in control parameters and update testing
1 parent b9db880 commit 9e99841

5 files changed

Lines changed: 30 additions & 83 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
- Partial testing suite refactor to parameterize many of the common fixtures and test routines.
2121
- `unittest` style tests are refactored to be `pytest` style tests for test consistency.
2222
- Added a pre-commit hook for `yamlfix` to auto-format YAML files and `yamlfix`'d all YAML files for consistent formatting
23+
- Insert model names for technologies with control strategies to simplify Pyomo workflows.
2324

2425
## 0.6 [February 10, 2026]
2526

examples/18_pyomo_heuristic_dispatch/pyomo_heuristic_dispatch_error_for_testing.yaml

Lines changed: 0 additions & 6 deletions
This file was deleted.

examples/18_pyomo_heuristic_dispatch/tech_config_error_for_testing.yaml

Lines changed: 0 additions & 69 deletions
This file was deleted.

examples/test/test_all_examples.py

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1276,14 +1276,20 @@ def test_pyomo_heuristic_dispatch_example(subtests, temp_copy_of_example):
12761276
)
12771277
assert electricity_unmet_demand == pytest.approx(711.1997294551337, rel=1e-6)
12781278

1279-
# check that error is raised when incorrect tech_name is given
1280-
with subtests.test("Check incorrect tech_name error"):
1281-
expected_error = (
1282-
r"tech_name in control_parameters \(wrong_tech_name\) must match "
1283-
r"the top-level name of the tech group \(battery\)"
1284-
)
1285-
with pytest.raises(ValueError, match=expected_error):
1286-
H2IntegrateModel(example_folder / "pyomo_heuristic_dispatch_error_for_testing.yaml")
1279+
# Check that incorrect and no tech name provided will be replaced and validate
1280+
model_config = load_yaml(example_folder / "pyomo_heuristic_dispatch.yaml")
1281+
tech = load_yaml(example_folder / "tech_config.yaml")
1282+
with subtests.test("Ensure no-tech name validates"):
1283+
tech["technologies"]["battery"]["model_inputs"]["control_parameters"] = None
1284+
model_config["technology_config"] = tech
1285+
model = H2IntegrateModel(model_config)
1286+
1287+
with subtests.test("Ensure incorrect name is corrected"):
1288+
tech["technologies"]["battery"]["model_inputs"]["control_parameters"] = {
1289+
"tech_name": "goose"
1290+
}
1291+
model_config["technology_config"] = tech
1292+
model = H2IntegrateModel(model_config)
12871293

12881294

12891295
@pytest.mark.integration

h2integrate/core/h2integrate_model.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,21 @@ def load_config(self, config_input):
188188
)
189189
)
190190

191+
for name, vals in self.technology_config["technologies"].items():
192+
if "control_parameters" in vals["model_inputs"]:
193+
val = self.technology_config["technologies"][name]["model_inputs"][
194+
"control_parameters"
195+
]
196+
updated = {"tech_name": name}
197+
if val is not None:
198+
self.technology_config["technologies"][name]["model_inputs"][
199+
"control_parameters"
200+
].update(updated)
201+
else:
202+
self.technology_config["technologies"][name]["model_inputs"][
203+
"control_parameters"
204+
] = updated
205+
191206
def create_custom_models(self, model_config, config_parent_path, model_types, prefix=""):
192207
"""This method loads custom models from the specified directory and adds them to the
193208
supported models dictionary.

0 commit comments

Comments
 (0)