From d7b2d1e41120dd320b076a1c8878f48e3b64ed7f Mon Sep 17 00:00:00 2001 From: masseramatteo Date: Fri, 10 Jan 2025 15:27:50 +0100 Subject: [PATCH 1/2] "Changed structure to full_model_flow tests" --- adopt_net0/modelhub.py | 5 +++-- conftest.py | 2 +- tests/test_full_model_flow.py | 35 +++++++++++++++++++++++------------ 3 files changed, 27 insertions(+), 15 deletions(-) diff --git a/adopt_net0/modelhub.py b/adopt_net0/modelhub.py index e6da932a4..4d035ba4b 100644 --- a/adopt_net0/modelhub.py +++ b/adopt_net0/modelhub.py @@ -77,7 +77,6 @@ def read_data( log.info(log_msg) self.data.set_settings(data_path, start_period, end_period) self.data.read_data() - self._perform_preprocessing_checks() log_msg = "--- Reading in data complete ---" log.info(log_msg) @@ -231,6 +230,8 @@ def construct_model(self): log.info(log_msg) start = time.time() + self._perform_preprocessing_checks() + # Determine aggregation config = self.data.model_config @@ -473,7 +474,7 @@ def add_technology(self, investment_period: str, node: str, technologies: list): } for technology in technologies: # read in technology data - tec_data = read_tec_data( + tec_data = create_technology_class( technology, self.data.data_path / investment_period diff --git a/conftest.py b/conftest.py index 56627fdfa..8f9822baa 100644 --- a/conftest.py +++ b/conftest.py @@ -32,7 +32,7 @@ def pytest_configure(config): config.docu_notebook_folder_path = Path("tests") config.docu_notebook_data_path = Path("tests/notebook_data") config.root_folder_path = Path(".") - config.solver = "glpk" + config.solver = "gurobi" @pytest.fixture(autouse=True) diff --git a/tests/test_full_model_flow.py b/tests/test_full_model_flow.py index fd0938ddf..b007eadc7 100644 --- a/tests/test_full_model_flow.py +++ b/tests/test_full_model_flow.py @@ -40,8 +40,6 @@ def test_full_model_flow(request): pyhub = ModelHub() pyhub.read_data(path, start_period=0, end_period=1) - pyhub.construct_model() - pyhub.construct_balances() pyhub.data.model_config["solveroptions"]["solver"]["value"] = request.config.solver pyhub.data.model_config["reporting"]["save_summary_path"][ "value" @@ -49,6 +47,8 @@ def test_full_model_flow(request): pyhub.data.model_config["reporting"]["save_path"][ "value" ] = request.config.result_folder_path + pyhub.construct_model() + pyhub.construct_balances() pyhub.solve() m = pyhub.model["full"] @@ -105,8 +105,6 @@ def test_clustering_algo(request): pyhub = ModelHub() pyhub.read_data(path, start_period=0, end_period=2 * 24) - pyhub.construct_model() - pyhub.construct_balances() pyhub.data.model_config["solveroptions"]["solver"]["value"] = request.config.solver pyhub.data.model_config["reporting"]["save_summary_path"][ "value" @@ -114,6 +112,9 @@ def test_clustering_algo(request): pyhub.data.model_config["reporting"]["save_path"][ "value" ] = request.config.result_folder_path + + pyhub.construct_model() + pyhub.construct_balances() pyhub.solve() m = pyhub.model["full"] @@ -131,6 +132,7 @@ def test_clustering_algo(request): pyhub.data.model_config["reporting"]["save_path"][ "value" ] = request.config.result_folder_path + pyhub.data.model_config["solveroptions"]["solver"]["value"] = request.config.solver for method in methods: for n in N: pyhub.data.model_config["optimization"]["typicaldays"]["N"]["value"] = n @@ -174,8 +176,6 @@ def test_average_algo(request): pyhub = ModelHub() pyhub.read_data(path, start_period=0, end_period=2 * 24) - pyhub.construct_model() - pyhub.construct_balances() pyhub.data.model_config["solveroptions"]["solver"]["value"] = request.config.solver pyhub.data.model_config["reporting"]["save_summary_path"][ "value" @@ -183,6 +183,9 @@ def test_average_algo(request): pyhub.data.model_config["reporting"]["save_path"][ "value" ] = request.config.result_folder_path + + pyhub.construct_model() + pyhub.construct_balances() pyhub.solve() m = pyhub.model["full"] @@ -200,6 +203,7 @@ def test_average_algo(request): pyhub.data.model_config["reporting"]["save_path"][ "value" ] = request.config.result_folder_path + pyhub.data.model_config["solveroptions"]["solver"]["value"] = request.config.solver pyhub.data._read_time_series() pyhub.data._read_node_locations() @@ -236,8 +240,7 @@ def test_objective_functions(request): pyhub = ModelHub() pyhub.read_data(path, start_period=0, end_period=1) - pyhub.construct_model() - pyhub.construct_balances() + pyhub.data.model_config["solveroptions"]["solver"]["value"] = request.config.solver pyhub.data.model_config["reporting"]["save_summary_path"][ "value" @@ -245,11 +248,15 @@ def test_objective_functions(request): pyhub.data.model_config["reporting"]["save_path"][ "value" ] = request.config.result_folder_path + + pyhub.construct_model() + pyhub.construct_balances() pyhub._define_solver_settings() pyhub._optimize_emissions_net() pyhub._optimize_costs_minE() pyhub._optimize_costs_emissionslimit() + pyhub._solve_pareto() @@ -266,8 +273,6 @@ def test_monte_carlo(request): # Monte Carlo type normal pyhub.data.model_config["optimization"]["monte_carlo"]["N"]["value"] = 2 - pyhub.construct_model() - pyhub.construct_balances() pyhub.data.model_config["solveroptions"]["solver"]["value"] = request.config.solver pyhub.data.model_config["reporting"]["save_summary_path"][ "value" @@ -275,6 +280,9 @@ def test_monte_carlo(request): pyhub.data.model_config["reporting"]["save_path"][ "value" ] = request.config.result_folder_path + + pyhub.construct_model() + pyhub.construct_balances() pyhub.solve() termination = pyhub.solution.solver.termination_condition @@ -300,8 +308,7 @@ def test_scaling(request): pyhub = ModelHub() pyhub.read_data(path, start_period=0, end_period=1) - pyhub.construct_model() - pyhub.construct_balances() + pyhub.data.model_config["scaling"]["scaling_on"]["value"] = 1 pyhub.data.model_config["reporting"]["save_summary_path"][ "value" @@ -309,4 +316,8 @@ def test_scaling(request): pyhub.data.model_config["reporting"]["save_path"][ "value" ] = request.config.result_folder_path + pyhub.data.model_config["solveroptions"]["solver"]["value"] = request.config.solver + + pyhub.construct_model() + pyhub.construct_balances() pyhub.solve() From 8c35dccc124305f11156257837dd5f712e14a483 Mon Sep 17 00:00:00 2001 From: masseramatteo Date: Fri, 10 Jan 2025 15:31:10 +0100 Subject: [PATCH 2/2] "read_tech_data back where it changed" --- adopt_net0/modelhub.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/adopt_net0/modelhub.py b/adopt_net0/modelhub.py index 4d035ba4b..bd3bbae39 100644 --- a/adopt_net0/modelhub.py +++ b/adopt_net0/modelhub.py @@ -474,7 +474,7 @@ def add_technology(self, investment_period: str, node: str, technologies: list): } for technology in technologies: # read in technology data - tec_data = create_technology_class( + tec_data = read_tec_data( technology, self.data.data_path / investment_period