Skip to content
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

Adding loopTool to analysis tools #1098

Merged
merged 53 commits into from
Sep 13, 2023
Merged
Show file tree
Hide file tree
Changes from 52 commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
6c2880b
merged LoopTool from Analysis
avdudchenko Aug 7, 2023
379bf9a
updated diff test
avdudchenko Aug 8, 2023
7fa857e
add_diff_fixed_names
avdudchenko Aug 8, 2023
9499d8a
Update loopTool.rst
avdudchenko Aug 8, 2023
60cbd2c
Update index.rst
avdudchenko Aug 8, 2023
5569f71
fixed tests
avdudchenko Aug 8, 2023
05d6426
Fixing file pathing, using abspath(__file__)
avdudchenko Aug 8, 2023
500cce3
Merge branch 'main' into loopTool
k1nshuk Aug 9, 2023
22c9f1e
fixed covecod for diff_spec, and pathing in test files
avdudchenko Aug 10, 2023
2666df9
switched to useing parallel manager to get mpi config
avdudchenko Aug 14, 2023
dbcb1e0
simplify mpi check
avdudchenko Aug 14, 2023
8720a9c
Remove setup_multi_processing
avdudchenko Aug 14, 2023
943c57e
Merge branch 'main' into loopTool
bknueven Aug 15, 2023
f85fbb3
Merge branch 'main' into loopTool
avdudchenko Aug 24, 2023
0af609f
Update docs/technical_reference/tools/loopTool.rst
avdudchenko Aug 24, 2023
526404e
Update docs/technical_reference/tools/loopTool.rst
avdudchenko Aug 24, 2023
36ce3f2
Update docs/technical_reference/tools/loopTool.rst
avdudchenko Aug 24, 2023
c72c2f2
Update docs/technical_reference/tools/loopTool.rst
avdudchenko Aug 24, 2023
404582d
Update docs/technical_reference/tools/loopTool.rst
avdudchenko Aug 24, 2023
e4b285d
Update docs/technical_reference/tools/loopTool.rst
avdudchenko Aug 24, 2023
7e1651c
Update docs/technical_reference/tools/loopTool.rst
avdudchenko Aug 24, 2023
36ccbf0
update #1 to match new async setup
avdudchenko Aug 24, 2023
f087d44
updarted tests to reader and small fixes throughout
avdudchenko Aug 25, 2023
ebabdc9
added additonal tests
avdudchenko Aug 26, 2023
14ecd5d
Update test_data_merging_tool.py
avdudchenko Aug 26, 2023
014af77
moved doc to howto as it seems better place for it
avdudchenko Aug 26, 2023
75f46c6
Update index.rst
avdudchenko Aug 26, 2023
cb2a931
Removed legacy code, added additional tests, added MPI test
avdudchenko Aug 27, 2023
5e1485c
Merge branch 'main' into loopTool
avdudchenko Aug 27, 2023
40b0a88
Update mpi4py-test.yml
avdudchenko Aug 27, 2023
4292805
mpi fix try #1
avdudchenko Aug 27, 2023
81f93f3
Fixing MPI test
avdudchenko Aug 27, 2023
bb3fb11
Fixed MPI rank
avdudchenko Aug 27, 2023
649a352
Clean up and changes to MPI rank
avdudchenko Aug 27, 2023
1b9aca9
update doc and added outputs and tests
avdudchenko Aug 27, 2023
284c07c
cleaned up sim_csaes and added key tests for yaml config file
avdudchenko Aug 28, 2023
9b973ce
Update mpi4py-test.yml
avdudchenko Aug 28, 2023
28c29f4
Merge branch 'main' into loopTool
k1nshuk Sep 5, 2023
58b9ad1
Update docs/how_to_guides/how_to_use_loopTool_to_explore_flowsheets.rst
avdudchenko Sep 6, 2023
d65d160
Update watertap/tools/analysis_tools/loop_tool/loop_tool.py
avdudchenko Sep 6, 2023
0229611
Update watertap/tools/analysis_tools/loop_tool/loop_tool.py
avdudchenko Sep 6, 2023
a25ed6c
Update docs/how_to_guides/how_to_use_loopTool_to_explore_flowsheets.rst
avdudchenko Sep 6, 2023
918ee55
Update watertap/tools/analysis_tools/loop_tool/loop_tool.py
avdudchenko Sep 6, 2023
9847204
Update watertap/tools/analysis_tools/loop_tool/loop_tool.py
avdudchenko Sep 6, 2023
83fadc8
Update watertap/tools/analysis_tools/loop_tool/loop_tool.py
avdudchenko Sep 6, 2023
bf51ab5
Update watertap/tools/analysis_tools/loop_tool/tests/test_loop_tool.py
avdudchenko Sep 6, 2023
d289c45
updates to loopt tool
avdudchenko Sep 6, 2023
234ff05
Merge branch 'loopTool' of https://github.com/avdudchenko/watertap in…
avdudchenko Sep 6, 2023
077abf2
Update test_loop_tool.py
avdudchenko Sep 6, 2023
c9e1fd4
Update test_loop_tool.py
avdudchenko Sep 6, 2023
66574b5
Merge branch 'main' into loopTool
k1nshuk Sep 7, 2023
139ecf5
Merge branch 'main' into loopTool
k1nshuk Sep 8, 2023
dff496f
Update loop_tool.py
avdudchenko Sep 9, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/mpi4py-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ jobs:
run: conda info
- name: Test parallel pytest w/ MPI
run: |
mpiexec -n 2 coverage run --parallel-mode -m mpi4py -m pytest watertap/tools/parameter_sweep/tests/test*parameter_sweep.py --no-cov
mpiexec -n 2 coverage run --parallel-mode -m mpi4py -m pytest watertap/tools/parameter_sweep/tests/test*parameter_sweep.py watertap/tools/analysis_tools/loop_tool/tests/test*loop_tool.py --no-cov
# single report
coverage combine
# convert to XML
Expand Down
502 changes: 502 additions & 0 deletions docs/how_to_guides/how_to_use_loopTool_to_explore_flowsheets.rst

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions docs/how_to_guides/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ How To Guides
how_to_use_parameter_sweep
how_to_use_parameter_sweep_monte_carlo
how_to_run_differential_parameter_sweep
how_to_use_loopTool_to_explore_flowsheets
how_to_install_electrolyte_database
how_to_use_EDB
how_to_use_ui_api
Expand Down
1 change: 1 addition & 0 deletions docs/technical_reference/tools/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ Tools for Flowsheet Analysis
:maxdepth: 2

parameter_sweep

128 changes: 128 additions & 0 deletions watertap/tools/analysis_tools/loop_tool/data_merging_tool.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
#################################################################################
# WaterTAP Copyright (c) 2020-2023, The Regents of the University of California,
# through Lawrence Berkeley National Laboratory, Oak Ridge National Laboratory,
# National Renewable Energy Laboratory, and National Energy Technology
# Laboratory (subject to receipt of any required approvals from the U.S. Dept.
# of Energy). All rights reserved.
#
# Please see the files COPYRIGHT.md and LICENSE.md for full copyright and license
# information, respectively. These files are also available online at the URL
# "https://github.com/watertap-org/watertap/"
#################################################################################


import h5py
import numpy as np
import time
import os
import datetime
from datetime import datetime

import logging

__author__ = "Alexander V. Dudchenko (SLAC)"


_log = logging.getLogger(__name__)


def merge_data_into_file(
file_name,
backup_file_name,
directory,
expected_solved_values=None,
min_solve_values=None,
force_rerun=None,
):
"""
This function checks if there is a sim file, and a back up file.
if there is a sim file, it backs it up, and checks if full solution set already exsts and copies it over,
other wise it creates a new group in actual file, and adds new solved data set to it
"""
run_sweep = True
if os.path.isfile(file_name) == False:
create_h5_file(file_name)
h5file = h5py.File(file_name, "a")

# check if there is a back up
if isinstance(backup_file_name, str):
f_old_solutions = h5py.File(backup_file_name, "r")
solved_values = sum(
np.array(
f_old_solutions[directory]["solve_successful"]["solve_successful"][()]
)
)
else:
solved_values = None
if force_rerun:
_log.info("Forcing a rerun")
run_sweep = False
elif force_rerun == False:
_log.info("Forced to not rerun")
run_sweep = False
elif force_rerun == None and solved_values is not None:
if min_solve_values is not None:
if min_solve_values <= solved_values:
run_sweep = False
elif expected_solved_values == solved_values:
run_sweep = False
_log.info(
"Found {} solved values, expected {} solved values , min {} solved values, re-running == {}".format(
solved_values, expected_solved_values, min_solve_values, run_sweep
)
)
if run_sweep:
if directory not in h5file:
h5file.create_group(directory)
elif backup_file_name is not None and os.path.isfile(backup_file_name):
if directory not in h5file:
h5file.copy(f_old_solutions[directory], directory)
else:
_log.warning(
"Solution already {} exist in file, not copying over back up data".format(
directory
)
)
f_old_solutions.close()
h5file.close()
return run_sweep


def create_backup_file(file_name, backup_name, h5_dir):
"""used to created file and back up file
file_name - orignal h5 file
backup_name - backup name for h5 file if exists
h5_dir - directory to check in h5 file, if not there creates fresh file, otherwise
renames existing file"""

if backup_name is None and os.path.isfile(file_name):
h5file = h5py.File(file_name, "r")

if h5_dir in h5file:
# need to close file before renaming it
h5file.close()
date = datetime.now().strftime("%d_%m-%H_%M_%S")
backup_name = file_name + "_{}_{}".format(date, ".bak")
if os.path.isfile(backup_name) == False:
os.rename(file_name, backup_name)
else:
# close it in case we did not rename
h5file.close()
return backup_name


def create_h5_file(file_name):
"""used to created h5file, retry in case disk is busy"""
if os.path.isfile(file_name) == False:
file_created = False
for i in range(60):
try:
f = h5py.File(file_name, "w")
f.close()
file_created = True
break
except:
_log.warning("Could note create h5 file {}".format(file_name))
time.sleep(0.01) # Waiting to see if file is free to create again
if file_created == False:
raise OSError("Could not create file {}".format(file_name))
Loading
Loading