-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add modeler non-regression tests (#2617)
Signed-off-by: Peter Mitri <[email protected]>
- Loading branch information
Showing
20 changed files
with
465 additions
and
26 deletions.
There are no files selected for viewing
This file contains 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 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 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 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
36 changes: 36 additions & 0 deletions
36
src/tests/cucumber/features/modeler-features/epic2/us2.5.feature
This file contains 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,36 @@ | ||
Feature: 2.5 - Pure modeler simple studies, with no ports and no timeseries | ||
|
||
Scenario: 2.5.1: One model with one load and two generators, one timestamp | ||
Given the study path is "modeler/epic2/us2.5/study_2.5.1" | ||
When I run antares modeler | ||
Then the simulation succeeds | ||
And the optimal value of variable node1.gen1_p_0 is 80 | ||
And the optimal value of variable node1.gen2_p_0 is 20 | ||
|
||
Scenario: 2.5.2: One model with one load and two generators (minP), three timestamps | ||
Given the study path is "modeler/epic2/us2.5/study_2.5.2" | ||
When I run antares modeler | ||
Then the simulation succeeds | ||
And the optimal value of variable node1.gen1_up_0 is 1 | ||
And the optimal value of variable node1.gen1_up_1 is 1 | ||
And the optimal value of variable node1.gen1_up_2 is 1 | ||
And the optimal value of variable node1.gen1_p_0 is 60 | ||
And the optimal value of variable node1.gen1_p_1 is 60 | ||
And the optimal value of variable node1.gen1_p_2 is 60 | ||
And the optimal value of variable node1.gen2_up_0 is 1 | ||
And the optimal value of variable node1.gen2_up_1 is 1 | ||
And the optimal value of variable node1.gen2_up_2 is 1 | ||
And the optimal value of variable node1.gen2_p_0 is 40 | ||
And the optimal value of variable node1.gen2_p_1 is 40 | ||
And the optimal value of variable node1.gen2_p_2 is 40 | ||
|
||
Scenario: 2.5.3: Two libs, one timestamp | ||
Given the study path is "modeler/epic2/us2.5/study_2.5.3" | ||
When I run antares modeler | ||
Then the simulation succeeds | ||
And the optimal value of variable node1.gen1_p_0 is 0 | ||
And the optimal value of variable node1.gen2_p_0 is 100 | ||
And the optimal value of variable node2.gen1_p_0 is 500 | ||
And the optimal value of variable node2.gen1_up_0 is 1 | ||
And the optimal value of variable node2.gen2_p_0 is 500 | ||
And the optimal value of variable node2.gen2_up_0 is 1 |
This file contains 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 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
24 changes: 24 additions & 0 deletions
24
src/tests/cucumber/features/steps/common_steps/modeler_output_handler.py
This file contains 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,24 @@ | ||
# Antares modeler outputs parsing | ||
|
||
import os | ||
import pandas as pd | ||
import configparser | ||
from enum import Enum | ||
|
||
|
||
class modeler_output_handler: | ||
|
||
def __init__(self, study_output_path): | ||
self.study_output_path = study_output_path | ||
self.results = self.__read_csv("solution.csv") | ||
|
||
|
||
def __read_csv(self, file_name) -> pd.DataFrame: | ||
absolute_path = os.path.join(self.study_output_path, file_name.replace("/", os.sep)) | ||
return pd.read_csv(absolute_path, header=None, sep=' ', low_memory=False) | ||
|
||
def get_optimal_value(self, var : str) -> float: | ||
for row in self.results.iterrows(): | ||
if row[1][0] == var: | ||
return row[1][1] | ||
raise ValueError("Variable not found") |
28 changes: 28 additions & 0 deletions
28
src/tests/cucumber/features/steps/common_steps/modeler_utils.py
This file contains 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,28 @@ | ||
# Methods to run Antares modeler | ||
|
||
import subprocess | ||
import os | ||
|
||
from common_steps.modeler_output_handler import modeler_output_handler | ||
|
||
|
||
def run_modeler(context): | ||
command = build_antares_modeler_command(context) | ||
print(f"Running command: {command}") | ||
process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.DEVNULL) | ||
out, err = process.communicate() | ||
context.output_path = os.path.join( context.study_path , "output") # TODO : fixme parse_output_folder_from_logs(out) | ||
context.return_code = process.returncode | ||
context.moh = modeler_output_handler(context.output_path) | ||
|
||
|
||
def build_antares_modeler_command(context): | ||
command = [context.config.userdata["antares-modeler"], str(context.study_path)] | ||
return command | ||
|
||
|
||
def parse_output_folder_from_logs(logs: bytes) -> str: | ||
for line in logs.splitlines(): | ||
if b'Output folder : ' in line: | ||
return line.split(b'Output folder : ')[1].decode('ascii') | ||
raise LookupError("Could not parse output folder in output logs") |
This file contains 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
36 changes: 36 additions & 0 deletions
36
src/tests/resources/modeler/epic2/us2.5/study_2.5.1/input/model-libraries/lib_example1.yml
This file contains 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,36 @@ | ||
library: | ||
id: lib_example1 | ||
description: test model library | ||
|
||
models: | ||
- id: node_2gen_1load | ||
description: A simple node with two generators and one load | ||
parameters: | ||
- id: load | ||
time-dependent: false | ||
scenario-dependent: false | ||
- id: gen1_max_p | ||
time-dependent: false | ||
scenario-dependent: false | ||
- id: gen1_prop_cost | ||
time-dependent: false | ||
scenario-dependent: false | ||
- id: gen2_max_p | ||
time-dependent: false | ||
scenario-dependent: false | ||
- id: gen2_prop_cost | ||
time-dependent: false | ||
scenario-dependent: false | ||
variables: | ||
- id: gen1_p | ||
lower-bound: 0 | ||
upper-bound: gen1_max_p | ||
variable-type: continuous | ||
- id: gen2_p | ||
lower-bound: 0 | ||
upper-bound: gen2_max_p | ||
variable-type: continuous | ||
constraints: | ||
- id: balance | ||
expression: gen1_p + gen2_p - load = 0 | ||
objective: gen1_p * gen1_prop_cost + gen2_p * gen2_prop_cost |
Oops, something went wrong.