-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #227 from dapomeroy/file_upload
Add support to import & upload experiment results
- Loading branch information
Showing
9 changed files
with
275 additions
and
34 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
# Copyright 2022-2023 Google LLC | ||
# | ||
# Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or | ||
# https://www.apache.org/licenses/LICENSE-2.0> or the MIT license | ||
# <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your | ||
# option. This file may not be copied, modified, or distributed | ||
# except according to those terms. | ||
|
||
import llnl.util.tty as tty | ||
import json | ||
|
||
import ramble.experimental.uploader | ||
|
||
description = "take actions on experiment results" | ||
section = "results" | ||
level = "short" | ||
|
||
|
||
def setup_parser(subparser): | ||
sp = subparser.add_subparsers(metavar='SUBCOMMAND', | ||
dest='results_command') | ||
|
||
# Upload | ||
upload_parser = sp.add_parser('upload', help=results_upload.__doc__) | ||
upload_parser.add_argument( | ||
'filename', help='path of file to upload') | ||
|
||
|
||
def results_upload(args): | ||
"""Imports Ramble experiment results from JSON file and uploads them as | ||
specified in the upload block of Ramble's config file.""" | ||
imported_results = import_results_file(args.filename) | ||
|
||
ramble.experimental.uploader.upload_results(imported_results) | ||
|
||
|
||
def import_results_file(filename): | ||
""" | ||
Import Ramble experiment results from a JSON file. | ||
""" | ||
tty.debug("File to import:") | ||
tty.debug(filename) | ||
|
||
imported_file = open(filename) | ||
|
||
try: | ||
tty.msg("Import file...") | ||
parsed_json_file = json.load(imported_file) | ||
# Check if data contains an experiment | ||
if parsed_json_file.get('experiments'): | ||
return parsed_json_file | ||
else: | ||
tty.die("Error parsing file: Does not contain valid data to upload.") | ||
except ValueError: | ||
tty.die("Error parsing file: Invalid JSON formatting.") | ||
|
||
|
||
def results(parser, args): | ||
action = {'upload': results_upload} | ||
action[args.results_command](args) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# Copyright 2022-2023 Google LLC | ||
# | ||
# Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or | ||
# https://www.apache.org/licenses/LICENSE-2.0> or the MIT license | ||
# <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your | ||
# option. This file may not be copied, modified, or distributed | ||
# except according to those terms. | ||
|
||
import py | ||
import pytest | ||
|
||
import ramble.paths | ||
import ramble.cmd.results | ||
|
||
INPUT_DATA = py.path.local(ramble.paths.test_path).join('data', 'results_upload') | ||
|
||
|
||
@pytest.mark.parametrize( | ||
'filename,expected_output', | ||
[ | ||
( | ||
py.path.local(INPUT_DATA).join('test1_empty_experiments.json'), | ||
'Error parsing file: Does not contain valid data to upload.', | ||
), | ||
( | ||
py.path.local(INPUT_DATA).join('test2_not_json.txt.json'), | ||
'Error parsing file: Invalid JSON formatting.', | ||
), | ||
( | ||
py.path.local(INPUT_DATA).join('test3_malformed_json.json'), | ||
'Error parsing file: Invalid JSON formatting', | ||
), | ||
], | ||
) | ||
def test_file_import_rejects_invalid_files(filename, expected_output, capsys): | ||
with pytest.raises(SystemExit): | ||
ramble.cmd.results.import_results_file(filename) | ||
captured = capsys.readouterr() | ||
assert expected_output in captured |
4 changes: 4 additions & 0 deletions
4
lib/ramble/ramble/test/data/results_upload/test1_empty_experiments.json
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,4 @@ | ||
{ | ||
"experiments": [ | ||
] | ||
} |
1 change: 1 addition & 0 deletions
1
lib/ramble/ramble/test/data/results_upload/test2_not_json.txt.json
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 @@ | ||
This is not a JSON file. |
113 changes: 113 additions & 0 deletions
113
lib/ramble/ramble/test/data/results_upload/test3_malformed_json.json
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,113 @@ | ||
|
||
experiments": [ | ||
{ | ||
"name": "gromacs.water_gmx50.pme_single_rank", | ||
"EXPERIMENT_CHAIN": [], | ||
"RAMBLE_STATUS": "SUCCESS", | ||
"RAMBLE_VARIABLES": { | ||
"log_dir": "/home/user/gromacs_example/logs", | ||
"env_name": "gromacs", | ||
"experiments_file": "/home/user/gromacs_example/all_experiments", | ||
"processes_per_node": "16", | ||
"mpi_command": "mpirun -n 1 -ppn 16", | ||
"batch_submit": "/home/user/gromacs_example/experiments/gromacs/water_gmx50/pme_single_rank/execute_experiment", | ||
"n_ranks": "1", | ||
"n_threads": "1", | ||
"size": "0003", | ||
"type": "pme", | ||
"global_conf_name": "global_conf", | ||
"base_name": "None", | ||
"workspace_name": "gromacs_example", | ||
"application_name": "gromacs", | ||
"workload_name": "water_gmx50", | ||
"experiment_name": "pme_single_rank", | ||
"required_name": "None", | ||
"application_namespace": "gromacs", | ||
"workload_namespace": "gromacs.water_gmx50", | ||
"experiment_namespace": "gromacs.water_gmx50.pme_single_rank", | ||
"application_run_dir": "/home/user/gromacs_example/experiments/gromacs", | ||
"application_input_dir": "/home/user/gromacs_example/inputs/gromacs", | ||
"workload_run_dir": "/home/user/gromacs_example/experiments/gromacs/water_gmx50", | ||
"workload_input_dir": "/home/user/gromacs_example/inputs/gromacs/water_gmx50", | ||
"experiment_run_dir": "/home/user/gromacs_example/experiments/gromacs/water_gmx50/pme_single_rank", | ||
"spack_env": "/home/user/gromacs_example/software/gromacs.water_gmx50", | ||
"n_nodes": "1", | ||
"experiment_template_name": "pme_single_rank", | ||
"log_file": "/home/user/gromacs_example/experiments/gromacs/water_gmx50/pme_single_rank/pme_single_rank.out", | ||
"input_path": "/home/user/gromacs_example/inputs/gromacs/water_gmx50/water_gmx50_bare/0003", | ||
"water_gmx50_bare": "/home/user/gromacs_example/inputs/gromacs/water_gmx50/water_gmx50_bare", | ||
"command": "rm -f \"/home/user/gromacs_example/experiments/gromacs/water_gmx50/pme_single_rank/pme_single_rank.out\"\ntouch \"/home/user/gromacs_example/experiments/gromacs/water_gmx50/pme_single_rank/pme_single_rank.out\"\n. /opt/apps/spack/share/spack/setup-env.sh\nspack env activate /home/user/gromacs_example/software/gromacs.water_gmx50\ngmx_mpi grompp -f /home/user/gromacs_example/inputs/gromacs/water_gmx50/water_gmx50_bare/0003/pme.mdp -c /home/user/gromacs_example/inputs/gromacs/water_gmx50/water_gmx50_bare/0003/conf.gro -p /home/user/gromacs_example/inputs/gromacs/water_gmx50/water_gmx50_bare/0003/topol.top -o exp_input.tpr >> \"/home/user/gromacs_example/experiments/gromacs/water_gmx50/pme_single_rank/pme_single_rank.out\"\nmpirun -n 1 -ppn 16 gmx_mpi mdrun -notunepme -dlb yes -v -resethway -noconfout -nsteps 4000 -s exp_input.tpr >> \"/home/user/gromacs_example/experiments/gromacs/water_gmx50/pme_single_rank/pme_single_rank.out\"", | ||
"spack_setup": "", | ||
"execute_experiment": "/home/user/gromacs_example/experiments/gromacs/water_gmx50/pme_single_rank/execute_experiment" | ||
}, | ||
"RAMBLE_RAW_VARIABLES": { | ||
"log_dir": "/home/user/gromacs_example/logs", | ||
"env_name": "{application_name}", | ||
"experiments_file": "/home/user/gromacs_example/all_experiments", | ||
"processes_per_node": 16, | ||
"mpi_command": "mpirun -n {n_ranks} -ppn {processes_per_node}", | ||
"batch_submit": "{execute_experiment}", | ||
"n_ranks": "1", | ||
"n_threads": "1", | ||
"size": "0003", | ||
"type": "pme", | ||
"global_conf_name": "global_conf", | ||
"base_name": null, | ||
"workspace_name": "gromacs_example", | ||
"application_name": "gromacs", | ||
"workload_name": "water_gmx50", | ||
"experiment_name": "pme_single_rank", | ||
"required_name": null, | ||
"application_namespace": "gromacs", | ||
"workload_namespace": "gromacs.water_gmx50", | ||
"experiment_namespace": "gromacs.water_gmx50.pme_single_rank", | ||
"application_run_dir": "/home/user/gromacs_example/experiments/{application_name}", | ||
"application_input_dir": "/home/user/gromacs_example/inputs/{application_name}", | ||
"workload_run_dir": "{application_run_dir}/{workload_name}", | ||
"workload_input_dir": "{application_input_dir}/{workload_name}", | ||
"experiment_run_dir": "{workload_run_dir}/{experiment_name}", | ||
"spack_env": "/home/user/gromacs_example/software/{env_name}.{workload_name}", | ||
"n_nodes": 1, | ||
"experiment_template_name": "pme_single_rank", | ||
"log_file": "{experiment_run_dir}/{experiment_name}.out", | ||
"input_path": "{water_gmx50_bare}/{size}", | ||
"water_gmx50_bare": "/home/user/gromacs_example/inputs/gromacs/water_gmx50/water_gmx50_bare", | ||
"command": "rm -f \"{log_file}\"\ntouch \"{log_file}\"\n. /opt/apps/spack/share/spack/setup-env.sh\nspack env activate /home/user/gromacs_example/software/gromacs.water_gmx50\ngmx_mpi grompp -f /home/user/gromacs_example/inputs/gromacs/water_gmx50/water_gmx50_bare/0003/pme.mdp -c /home/user/gromacs_example/inputs/gromacs/water_gmx50/water_gmx50_bare/0003/conf.gro -p /home/user/gromacs_example/inputs/gromacs/water_gmx50/water_gmx50_bare/0003/topol.top -o exp_input.tpr >> \"/home/user/gromacs_example/experiments/gromacs/water_gmx50/pme_single_rank/pme_single_rank.out\"\nmpirun -n 1 -ppn 16 gmx_mpi mdrun -notunepme -dlb yes -v -resethway -noconfout -nsteps 4000 -s exp_input.tpr >> \"/home/user/gromacs_example/experiments/gromacs/water_gmx50/pme_single_rank/pme_single_rank.out\"", | ||
"spack_setup": "", | ||
"execute_experiment": "/home/user/gromacs_example/experiments/gromacs/water_gmx50/pme_single_rank/execute_experiment" | ||
}, | ||
"CONTEXTS": [ | ||
{ | ||
"name": "null", | ||
"foms": [ | ||
{ | ||
"value": "42.556", | ||
"units": "s", | ||
"name": "Core Time" | ||
}, | ||
{ | ||
"value": "21.280", | ||
"units": "s", | ||
"name": "Wall Time" | ||
}, | ||
{ | ||
"value": "200.0", | ||
"units": "%", | ||
"name": "Percent Core Time" | ||
}, | ||
{ | ||
"value": "16.249", | ||
"units": "ns/day", | ||
"name": "Nanosecs per day" | ||
}, | ||
{ | ||
"value": "1.477", | ||
"units": "hours/ns", | ||
"name": "Hours per nanosec" | ||
} | ||
] | ||
} | ||
] | ||
} | ||
] | ||
} |
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
Oops, something went wrong.