Skip to content

Commit 1ae0992

Browse files
author
Rolf Johan Lorentzen
committed
Fix use of eCalc to handle ecalc version 8.23.1. This version is now pinned in the setup.py to avoid frequent updates.
1 parent 0e5e631 commit 1ae0992

File tree

3 files changed

+30
-7
lines changed

3 files changed

+30
-7
lines changed

popt/cost_functions/ecalc_npv.py

+14-3
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ def ecalc_npv(pred_data, **kwargs):
3535

3636
from libecalc.application.energy_calculator import EnergyCalculator
3737
from libecalc.common.time_utils import Frequency
38+
from ecalc_cli.infrastructure.file_resource_service import FileResourceService
39+
from libecalc.presentation.yaml.file_configuration_service import FileConfigurationService
3840
from libecalc.presentation.yaml.model import YamlModel
3941

4042
# Get the necessary input
@@ -89,11 +91,20 @@ def ecalc_npv(pred_data, **kwargs):
8991

9092
# Config
9193
model_path = HERE / "ecalc_config.yaml" # "drogn.yaml"
92-
yaml_model = YamlModel(path=model_path, output_frequency=Frequency.NONE)
94+
configuration_service = FileConfigurationService(configuration_path=model_path)
95+
resource_service = FileResourceService(working_directory=model_path.parent)
96+
yaml_model = YamlModel(
97+
configuration_service=configuration_service,
98+
resource_service=resource_service,
99+
output_frequency=Frequency.NONE,
100+
)
93101
# comps = {c.name: id_hash for (id_hash, c) in yaml_model.graph.components.items()}
94102

95103
# Compute energy, emissions
96-
model = EnergyCalculator(graph=yaml_model.graph)
104+
#model = EnergyCalculator(energy_model=yaml_model, expression_evaluator=yaml_model.variables)
105+
#consumer_results = model.evaluate_energy_usage()
106+
#emission_results = model.evaluate_emissions()
107+
model = EnergyCalculator(graph=yaml_model.get_graph())
97108
consumer_results = model.evaluate_energy_usage(yaml_model.variables)
98109
emission_results = model.evaluate_emissions(yaml_model.variables, consumer_results)
99110

@@ -127,7 +138,7 @@ def results_as_df(yaml_model, results, getter) -> pd.DataFrame:
127138
for id_hash in results:
128139
res = results[id_hash]
129140
res = getter(res)
130-
component = yaml_model.graph.get_node(id_hash)
141+
component = yaml_model.get_graph().get_node(id_hash)
131142
df[component.name] = res.values
132143
attrs[component.name] = {'id_hash': id_hash,
133144
'kind': type(component).__name__,

popt/cost_functions/ecalc_pareto_npv.py

+15-3
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ def ecalc_pareto_npv(pred_data, kwargs):
3737

3838
from libecalc.application.energy_calculator import EnergyCalculator
3939
from libecalc.common.time_utils import Frequency
40+
from ecalc_cli.infrastructure.file_resource_service import FileResourceService
41+
from libecalc.presentation.yaml.file_configuration_service import FileConfigurationService
4042
from libecalc.presentation.yaml.model import YamlModel
4143

4244
# Get the necessary input
@@ -91,11 +93,21 @@ def ecalc_pareto_npv(pred_data, kwargs):
9193

9294
# Config
9395
model_path = HERE / "ecalc_config.yaml" # "drogn.yaml"
94-
yaml_model = YamlModel(path=model_path, output_frequency=Frequency.NONE)
96+
configuration_service = FileConfigurationService(configuration_path=model_path)
97+
resource_service = FileResourceService(working_directory=model_path.parent)
98+
yaml_model = YamlModel(
99+
configuration_service=configuration_service,
100+
resource_service=resource_service,
101+
output_frequency=Frequency.NONE,
102+
)
103+
#yaml_model = YamlModel(path=model_path, output_frequency=Frequency.NONE)
95104
# comps = {c.name: id_hash for (id_hash, c) in yaml_model.graph.components.items()}
96105

97106
# Compute energy, emissions
98-
model = EnergyCalculator(graph=yaml_model.graph)
107+
# model = EnergyCalculator(energy_model=yaml_model, expression_evaluator=yaml_model.variables)
108+
# consumer_results = model.evaluate_energy_usage()
109+
# emission_results = model.evaluate_emissions()
110+
model = EnergyCalculator(graph=yaml_model.get_graph())
99111
consumer_results = model.evaluate_energy_usage(yaml_model.variables)
100112
emission_results = model.evaluate_emissions(yaml_model.variables, consumer_results)
101113

@@ -151,7 +163,7 @@ def results_as_df(yaml_model, results, getter) -> pd.DataFrame:
151163
for id_hash in results:
152164
res = results[id_hash]
153165
res = getter(res)
154-
component = yaml_model.graph.get_node(id_hash)
166+
component = yaml_model.get_graph().get_node(id_hash)
155167
df[component.name] = res.values
156168
attrs[component.name] = {'id_hash': id_hash,
157169
'kind': type(component).__name__,

setup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
'tomli',
4343
'tomli-w',
4444
'pyyaml',
45-
'libecalc',
45+
'libecalc==8.23.1', # pin version to avoid frequent modifications
4646
'scikit-learn'
4747
] + EXTRAS['doc'],
4848
)

0 commit comments

Comments
 (0)