-
Notifications
You must be signed in to change notification settings - Fork 37
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Optimized dispatches from HERON to HYBRID #202
Merged
Merged
Changes from 12 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
a77478a
tests/integration_tests/mechanics/hybrid_heron_integration/
BotrosHanna-INL a108833
Merge branch 'idaholab:devel' into devel
BotrosHanna-INL f0f0638
Merge branch 'idaholab:devel' into devel
BotrosHanna-INL 8b3b17b
Merge branch 'idaholab:devel' into devel
BotrosHanna-INL 7f07e81
optimized dispatches from HERON to HYBRID
BotrosHanna-INL 6e09018
deleting extra folder
BotrosHanna-INL 01a37b9
tests file
BotrosHanna-INL b61be3f
remove extra file
BotrosHanna-INL ea0c4b3
reviewers' comments
BotrosHanna-INL f977ba4
fixing the tests
BotrosHanna-INL ecd798d
user manual section
BotrosHanna-INL e56e316
fixing typos
BotrosHanna-INL d60bde1
fixing more typos
BotrosHanna-INL 32a6748
fixing more typos
BotrosHanna-INL File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
43 changes: 43 additions & 0 deletions
43
tests/integration_tests/mechanics/optimizedDispatch2Hybrid/ReadMe.txt
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,43 @@ | ||
This test demonstrates converting the HERON optimized components' variables (optimized dispatch) to a text file that is compatible with HYBRID via two steps: | ||
|
||
|
||
|
||
Step #0: Producing the HERON optimized dispatches | ||
In this step, the HERON optimized dispatches are created like creating the dispatches CSV file in the folder: /HERON/tests/integration_tests/mechanics/debug_mode. You can create the dispatches CSV file running the commands such as: | ||
~/projects/HERON/heron heron_input.xml | ||
~/projects/raven/raven_framework outer.xml | ||
|
||
|
||
|
||
Step #1: "create_user_input.py" | ||
This script is run to create a user-input file for the HYBRID user. | ||
It is an initial step that the HYBRID user needs to rename, if necessary, the optimized dispatch outputs and the components' capacities. | ||
This script extracts the optimized dispatch outputs from the dispatch prints CSV file and the list of components' capacities from the HERON input XML file. | ||
|
||
This script takes the following arguments: | ||
1- The HERON input XML file | ||
2- The optimized dispatch outputs CSV file. | ||
For example, to run the script, use the following command: | ||
python create_user_input.py heron_input.xml Debug_Run_o/dispatch_print.csv | ||
The output will be a user input file: "user_input.txt" | ||
The user needs to review the user input file and change/review the HYBRID variables and capacities there. | ||
|
||
Next, the user can run the "export2Hybrid.py" which loads the dispatch outputs from HERON to a new file that HYBRID can use. The variables' names in the autoloaded HYBRID file are borrowed from "user_input.txt" | ||
|
||
|
||
|
||
Step #2: "export2Hybrid.py" | ||
A script to convert the HERON optimized components' variables (optimized dispatch) to a text file compatible with HYBRID. | ||
|
||
The user-input file "user_input.txt" must be in the same folder. | ||
The user must review/modify the "user_input.txt" before running this script. | ||
|
||
This script is run with the following arguments: | ||
1- The HERON input XML file. | ||
2- The optimized dispatch outputs CSV file. | ||
For example, to run this script, use the following command: | ||
python export2Hybrid.py heron_input.xml Debug_Run_o/dispatch_print.csv | ||
The output will be a text file compatible with HYBRID: "hybrid_compatible_dispatch.txt | ||
|
||
|
||
For more details, the HERON User Manual, Sec. 7.2: Auto-loading the optimized dispatches from HERON to HYBRID |
161 changes: 161 additions & 0 deletions
161
tests/integration_tests/mechanics/optimizedDispatch2Hybrid/create_user_input.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,161 @@ | ||
# Copyright 2022, Battelle Energy Alliance, LLC | ||
# ALL RIGHTS RESERVED | ||
""" | ||
A script to create a user-input file for the HYBRID user. | ||
|
||
This script is an initial step that the HYBRID user needs to create new names, if necessary, to: 1- The optimized dispatch outputs, 2- The components' capacities. | ||
This script extracts the optimized dispatch outputs from the dispatch prints csv file and the list of components (and their capacities) from the HERON input XML file. | ||
|
||
It takes the following arguments: | ||
1- The HERON input XML file | ||
2- The optimized dispatch outputs csv file. | ||
For example, To run the script, use the following command: | ||
python create_user_input.py heron_input.xml Debug_Run_o/dispatch_print.csv | ||
The output will be a user input file: "user_input.txt". | ||
The user needs to review the user input file and change/review the HYRBID variables and capacities there. | ||
|
||
Next, the user can run the "export2Hybrid.py" which loads the dispatch outpus from HERON to a new file that HYBRID can use. The variables names in the autoloaded HYBRID file are borrowd from "user_input.txt" | ||
""" | ||
|
||
##### | ||
# Section 0 | ||
# Importing libraries and modules | ||
|
||
import os.path | ||
import argparse | ||
from xml.etree import ElementTree as ET | ||
import pandas as pd | ||
|
||
|
||
|
||
##### | ||
# Section 1: Extracting components' capacities Function | ||
def extract_capacities_heron_hybrid(heron_input, output_file): | ||
""" | ||
Creates a list of components' capacities from the HERON inpue file plus creating placeholders for the components' capacities in HYRBID | ||
@ In, heron input, str, the HERON input XML file | ||
@ In, output_file, str, the text file where the list of components capacities should be printed. | ||
@ Out, None | ||
""" | ||
|
||
# Creating the HERON XML file tree | ||
HERON_inp_tree = ET.parse(heron_input) | ||
# Searching for the "components" node | ||
components_list = HERON_inp_tree.findall("Components") | ||
if not components_list: | ||
print("The 'Components' node is not found in the HERON input xml file") | ||
# Searching for the node "Component" | ||
for components in components_list: | ||
component = components.findall("Component") | ||
comp_list = [] # The list of compoenents | ||
|
||
# Printing the components' capacities in the output file | ||
with open(output_file, "a+") as u: | ||
u.write( | ||
"\n\n\n" + "# Below is a list of the components' capacities." | ||
+ "\n" + "# Components' list is extracted from HERON input file: " + '"' + args.HERON_input_file + '"' | ||
+ "\n" + "# The capacities are listed in the form:" | ||
+ "\n" + "#" + "\t\t\t\t " + "HERON_component_capacity_1 = HYBRID_component_capacity_1" + "\n" | ||
+ "# The user is expected to change/review the HYRBID components' capacities." + "\n" | ||
) | ||
# Components' capacities for HYBRID are also printed as placeholders until the user change them | ||
for comp in component: | ||
comp_list.append(comp.attrib["name"]) | ||
u.write( | ||
comp.attrib["name"] | ||
+ "_capacity = HYBRID_" | ||
+ comp.attrib["name"] | ||
+ "_capacity" | ||
+ "\n" | ||
) | ||
print("\n") | ||
print(len(comp_list), "components are found in:", heron_input) | ||
print( | ||
"The capacities of", | ||
len(comp_list), | ||
"components are printed at the", | ||
output_file | ||
) | ||
|
||
if not comp_list: | ||
print("No components found in the HERON input xml file") | ||
|
||
|
||
##### | ||
# Section 2: Extracting dispatch outputs Function | ||
def extract_dispatches_heron_hybrid(dispatch_print, output_file): | ||
""" | ||
Creates a list of dispatches (components' optimized variables) from the HERON inpue file plus creating placeholders for the dispatches in HYRBID | ||
@ In, dispatch_print, str, the distpach csv file with a list of optimized variables | ||
@ In, output_file, str, the text file where the list of optimized dispatches should be printed. | ||
@ Out, None | ||
""" | ||
input_dataset = pd.read_csv(dispatch_print) | ||
# Extracting the HERON csv dispatches | ||
colNames = input_dataset.columns[ | ||
input_dataset.columns.str.contains(pat="Dispatch", case=False) | ||
] | ||
# Printing the dispatches in the output file | ||
with open(user_input_file, "a+") as u: | ||
u.write( | ||
"\n\n" | ||
+ "# Below are the HERON variables and their corresponding HYBRID variables" + "\n" | ||
+ "# HERON variables are extracted from the HERON dispatch outputs file" | ||
+ "\n" + "# HERON dispatch outputs file is: " | ||
+ '"' + args.HERON_dipatch_csv_file | ||
+ '"' + "\n" + "# The variables are listed in the form:" | ||
+ "\n" + "#" + "\t\t\t\t" + "HERON_variable_1 = HYBRID_variable_1" | ||
+ "\n" + "# The user is expected to change/review the HYRBID variables" | ||
+ "\n" | ||
) | ||
|
||
for col in colNames: | ||
u.write(col + " = HYBRID_" + col) | ||
u.write("\n") | ||
print( | ||
len(list(colNames)), | ||
" optimized dispatches are found in:", | ||
dispatch_print, | ||
"and printed at the", | ||
output_file | ||
) | ||
|
||
|
||
##### | ||
# Section 3: Specifying terminal command arguments & HYBRID user-input filename | ||
if __name__ == "__main__": | ||
parser = argparse.ArgumentParser( | ||
description="Create a user-input file for the HYBRID user" | ||
) | ||
# Inputs from the user | ||
parser.add_argument("HERON_input_file", help="HERON XML input file path") | ||
parser.add_argument( | ||
"HERON_dipatch_csv_file", help="HERON optimized dispatch output csv file" | ||
) | ||
args = parser.parse_args() | ||
|
||
# Output file: the user input | ||
user_input_file = "user_input.txt" | ||
# remove old user input if exists | ||
file_exists = os.path.exists(user_input_file) | ||
if file_exists: | ||
os.remove(user_input_file) | ||
|
||
##### | ||
# Section 4: Creating the HYBRID user-input file | ||
with open(user_input_file, "a+") as u: | ||
u.write( | ||
"# The file that includes all the HYBRID variables." + "\n" | ||
"# All the capacities and dispatches should be a subset of this file's variables." "\n" + "# The user is expected to change/review the filename" | ||
+ "\n" + "all_variables_file = " | ||
+ '"' + "dsfinal.txt"+ '"' | ||
) | ||
|
||
extract_capacities_heron_hybrid(args.HERON_input_file, user_input_file) | ||
extract_dispatches_heron_hybrid(args.HERON_dipatch_csv_file, user_input_file) | ||
|
||
print('\033[94m', | ||
f"The {user_input_file} file is created for the HYBRID user to change/review it", | ||
"\n", | ||
'\033[0m' | ||
) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is fine for now, but we may not always use XML and we should use the RAVEN tree reader instead. We can fix that if and when we ever get that far.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Noted