Skip to content

Commit a1f9b8f

Browse files
Bugfix: Connecting resource to multiple techs (#655)
* bugfix and added test for connecting one resource model to multiple techs * updated changelog * Updated test to call setup to trigger connection error --------- Co-authored-by: John Jasa <johnjasa11@gmail.com>
1 parent 1570ea0 commit a1f9b8f

4 files changed

Lines changed: 30 additions & 2 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
- Added a storage performance baseclass model `StoragePerformanceBase` and updated the other storage performance models to inherit it [PR 624](https://github.com/NatLabRockies/H2Integrate/pull/624)
3434
- Modified the calc tilt angle function for pysam solar to support latitudes in the southern hemisphere [PR 646](https://github.com/NatLabRockies/H2Integrate/pull/646)
3535
- Added oxygen production metrics and as outputs to `ECOElectrolyzerPerformanceModel` [PR 642](https://github.com/NatLabRockies/H2Integrate/pull/642)
36+
- Bugfix to allow for one resource to be connected to multiple technologies [PR 655](https://github.com/NatLabRockies/H2Integrate/pull/655)
3637
- Removed the last of the logic that was based on technology names rather than model classes [PR 654](https://github.com/NatLabRockies/H2Integrate/pull/654)
3738

3839
## 0.7.1 [March 13, 2026]

h2integrate/core/file_utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ def find_file(filename: str | Path, root_folder: str | Path | None = None):
143143
f"the root directory {root_folder}."
144144
)
145145
raise ValueError(
146-
f"Cannot find unique file: found {len(files_cwd)} files relative to cwd, "
146+
f"Cannot find unique file for {filename}: found {len(files_cwd)} files relative to cwd, "
147147
f"{len(files_h2i)} files relative to H2Integrate root directory, "
148148
f"{len(files)} files relative to the root folder."
149149
)

h2integrate/core/h2integrate_model.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1167,7 +1167,7 @@ def connect_technologies(self):
11671167
resource_models = {}
11681168
for site_grp, site_grp_inputs in self.plant_config["sites"].items():
11691169
for resource_key, resource_params in site_grp_inputs.get("resources", {}).items():
1170-
resource_models[f"{site_grp}-{resource_key}"] = resource_params
1170+
resource_models[f"{site_grp}.{resource_key}"] = resource_params
11711171

11721172
resource_source_connections = [c[0] for c in resource_to_tech_connections]
11731173
# Check if there is a missing resource to tech connection or missing resource model

h2integrate/core/test/test_framework.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,33 @@ def test_resource_connection_error_missing_resource(temp_dir):
324324
temp_highlevel_yaml.unlink(missing_ok=True)
325325

326326

327+
@pytest.mark.unit
328+
def test_no_resource_connection_error_resource_to_multiple_techs(temp_dir):
329+
# Path to the original plant_config.yaml and high-level yaml in the example directory
330+
331+
driver_config = load_driver_yaml(EXAMPLE_DIR / "08_wind_electrolyzer" / "driver_config.yaml")
332+
tech_config = load_tech_yaml(EXAMPLE_DIR / "08_wind_electrolyzer" / "tech_config.yaml")
333+
plant_config = load_plant_yaml(EXAMPLE_DIR / "08_wind_electrolyzer" / "plant_config.yaml")
334+
# Add a second wind technology
335+
wind_tech = tech_config["technologies"]["wind"]
336+
tech_config["technologies"].update({"wind_plant2": wind_tech})
337+
resource_to_tech_connections = [
338+
["site.wind_resource", "wind", "wind_resource_data"],
339+
["site.wind_resource", "wind_plant2", "wind_resource_data"],
340+
]
341+
plant_config["resource_to_tech_connections"] = resource_to_tech_connections
342+
input_config = {
343+
"plant_config": plant_config,
344+
"technology_config": tech_config,
345+
"driver_config": driver_config,
346+
}
347+
h2i_model = H2IntegrateModel(input_config)
348+
h2i_model.setup()
349+
# Need to call final_setup to trigger the potential error related to the resource connections
350+
h2i_model.prob.final_setup()
351+
assert True
352+
353+
327354
@pytest.mark.unit
328355
def test_reports_turned_off(temp_dir):
329356
# Path to the original config files in the example directory

0 commit comments

Comments
 (0)