Skip to content

Commit

Permalink
parse args in run_tracking_inputs and call script in ci
Browse files Browse the repository at this point in the history
  • Loading branch information
clmould committed Nov 12, 2024
1 parent 085463a commit 02d557b
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 62 deletions.
15 changes: 2 additions & 13 deletions .github/workflows/process.yml
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ jobs:
- name: Install PROCESS
run: pip install -e .
- name: Run regression input files
run: python tracking/run_tracking_inputs.py
run: python tracking/run_tracking_inputs.py run tests/regression/input_files
- name: Archive tracked MFILEs
uses: actions/upload-artifact@v3
with:
Expand Down Expand Up @@ -203,18 +203,7 @@ jobs:
run: |
MSG=$(printf "%q " $COMMIT_MESSAGE)
git config --global --add safe.directory '*'
python tracking/tracking_data.py track process-tracking-data --mfile tracking/large_tokamak_MFILE.DAT --hash ${{ github.sha }} --commit "${MSG}"
cp tracking/large_tokamak_MFILE.DAT process-tracking-data/large_tokamak_MFILE_$(git rev-parse HEAD).DAT
python tracking/tracking_data.py track process-tracking-data --mfile tracking/st_regression_MFILE.DAT --hash ${{ github.sha }} --commit "${MSG}"
cp tracking/st_regression_MFILE.DAT process-tracking-data/st_regression_MFILE_$(git rev-parse HEAD).DAT
python tracking/tracking_data.py track process-tracking-data --mfile tracking/large_tokamak_nof_MFILE.DAT --hash ${{ github.sha }} --commit "${MSG}"
cp tracking/large_tokamak_nof_MFILE.DAT process-tracking-data/large_tokamak_nof_MFILE_$(git rev-parse HEAD).DAT
python tracking/tracking_data.py track process-tracking-data --mfile tracking/large_tokamak_once_through_MFILE.DAT --hash ${{ github.sha }} --commit "${MSG}"
cp tracking/large_tokamak_once_through_MFILE.DAT process-tracking-data/large_tokamak_once_through_MFILE_$(git rev-parse HEAD).DAT
python tracking/tracking_data.py track process-tracking-data --mfile tracking/stellarator_MFILE.DAT --hash ${{ github.sha }} --commit "${MSG}"
cp tracking/stellarator_MFILE.DAT process-tracking-data/stellarator_MFILE_$(git rev-parse HEAD).DAT
python tracking/tracking_data.py track process-tracking-data --mfile tracking/IFE_MFILE.DAT --hash ${{ github.sha }} --commit "${MSG}"
cp tracking/IFE_MFILE.DAT process-tracking-data/IFE_MFILE_$(git rev-parse HEAD).DAT
python tracking/run_tracking_inputs.py track process-tracking-data "${MSG}" ${{ github.sha }}
- name: Create the tracking dashboard
run: python tracking/tracking_data.py plot process-tracking-data --out tracking.html
- name: Archive tracking dashboard
Expand Down
99 changes: 50 additions & 49 deletions tracking/run_tracking_inputs.py
Original file line number Diff line number Diff line change
@@ -1,64 +1,65 @@
"""Run the tracked files and move into tracking/ directory."""
"""Run the tracked files and move into tracking directory."""

import argparse
from pathlib import Path
import subprocess
import shutil

from tracking_data import ProcessTracker

def run_and_move_tracked_files():
# Stellarator doesn't converge so don't want to track it
exclusions = ["stellarator"]

path_to_tracking_files = Path("tests/regression/input_files")
all_files = path_to_tracking_files.iterdir()
def run_and_move_tracked_files(arguments):
"""
Run PROCESS on the tracked files and move the MFiles to the tracking directory.
"""
path_to_tracking_files = Path(arguments.input_locs)

all_files = []
for file in list(path_to_tracking_files.iterdir()):
if file.is_file():
all_files.append(file.name)
input_files = path_to_tracking_files.glob("*.IN.DAT")
tracking_dir = Path(__file__).parent
for file_path in input_files:
try:
subprocess.run(f"process -i {file_path}", shell=True, check=True)
except subprocess.CalledProcessError:
continue
created_mfile = file_path.with_name(
file_path.name.replace(".IN.DAT", ".MFILE.DAT")
)
moved_mfile = created_mfile.with_name(
created_mfile.name.replace(".MFILE.DAT", "_MFILE.DAT")
)
created_mfile.rename(tracking_dir / moved_mfile.name)

input_files = []
for file in all_files:
for excl in exclusions:
if excl not in file and file.endswith("IN.DAT"):
input_files.append(file)

mfile_names = []
for in_dat in input_files:
file_prefix = in_dat.removesuffix("IN.DAT")
mfile_name = file_prefix + "MFILE.DAT"
mfile_names.append(mfile_name)
def tracking(arguments):
"""
Call the ProcessTracker, move the MFiles to the database and rename.
"""
db = arguments.db
commit = arguments.commit
hash = arguments.hash
path_to_tracking_mfiles = Path(__file__).parent
mfiles = path_to_tracking_mfiles.glob("*_MFILE.DAT")
for mfile_path in mfiles:
ProcessTracker(mfile=mfile_path, database=db, message=commit, hashid=hash)
moved_mfile_name = mfile_path.with_name(
mfile_path.name.replace("_MFILE.DAT", f"_MFILE_{hash}.DAT")
)
copied_mfile_destination = Path(db) / moved_mfile_name.name
copied_mfile_destination.write_bytes(mfile_path.read_bytes())

new_location_mfile_names = []
for current_name in mfile_names:
prefix = current_name.removesuffix(".MFILE.DAT")
new_name = prefix + "_MFILE.DAT"
new_location_mfile_names.append(new_name)

process_dir = Path(__file__).resolve().parent.parent
input_file_dir = process_dir / "tests/regression/input_files"

for count, file in enumerate(input_files):
input_file_path = input_file_dir / file
output_file_path = input_file_dir / mfile_names[count]
subprocess.run(f"process -i {input_file_path}", shell=True)
new_mfile_location = process_dir / "tracking" / new_location_mfile_names[count]
shutil.move(output_file_path, new_mfile_location)


# def tracking():
# ^ will use the parsed args of track hash etc
# set up parse, parse args, then if sub parser is run call run_and_move_tracked_files, if other args then do
# the other fn which will be in here
if __name__ == "__main__":
run_and_move_tracked_files()
parser = argparse.ArgumentParser()
subparsers = parser.add_subparsers(help="Choose the usage mode", dest="command")
subparser_run = subparsers.add_parser("run")
subparser_trk = subparsers.add_parser("track")
subparser_run.add_argument("input_locs", type=str)
subparser_trk.add_argument("db", type=str)
subparser_trk.add_argument("commit", type=str)
subparser_trk.add_argument("hash", type=str)

arguments = parser.parse_args()

# def main(args=None):
# parser = argparse.ArgumentParser()
# parser.add_argument("-r", "--run")
# parser.add_argument(
# "-t",
# "--track",
# )
if arguments.command == "run":
run_and_move_tracked_files(arguments)
else:
tracking(arguments)

0 comments on commit 02d557b

Please sign in to comment.