-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
start work on post-analysis multirun API, add tarball capabilities
Signed-off-by: Lance-Drane <[email protected]>
- Loading branch information
1 parent
655766e
commit f915e44
Showing
5 changed files
with
109 additions
and
53 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
"""Internal logic for interacting with the Jupyter API. | ||
Users should not need to access anything in this module directoy, please use the corresponding services functions instead. | ||
The APIs should only be accessed outside of the IPS Framework, when performing bulk operations with multiple runids. | ||
""" |
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,62 @@ | ||
"""This file is meant to be directly imported and utilized in the Jupyter analysis stage when comparing multiple runs.""" | ||
|
||
import datetime | ||
import importlib.util | ||
import os | ||
import tarfile | ||
from pathlib import Path | ||
from typing import Dict, Iterable, Union | ||
|
||
THIS_DIR = Path(__file__).resolve().parent | ||
|
||
|
||
def get_data_from_runid(runid: int) -> Dict[float, str]: | ||
"""Load all data associated with a single runid into a dictionary. | ||
Params: | ||
- runid: the run id we're working with | ||
Returns: | ||
- a dictionary mapping timesteps to associated data file paths. | ||
""" | ||
spec = importlib.util.spec_from_file_location('', f'{os.path.join(THIS_DIR, str(runid), "data_listing.py")}') | ||
module = importlib.util.module_from_spec(spec) | ||
spec.loader.exec_module(module) | ||
return module.DATA_FILES | ||
|
||
|
||
def get_data_from_runids(runids: Iterable[int]) -> Dict[int, Dict[float, str]]: | ||
"""Load all data associated with multiple runids into a common data structure. | ||
Params: | ||
- runids: iterable of existing runids (note that it is the caller's responsibility to verify uniqueness) | ||
Returns: | ||
- a dictionary of runids to the common runid data structure. This data structure is a mapping of timesteps to associated data file paths. | ||
""" | ||
return {runid: get_data_from_runid(runid) for runid in runids} | ||
|
||
|
||
def generate_tar_from_runids(runids: Union[Iterable[int], int]) -> str: | ||
""" | ||
Generate a tarball containing all data from the provided runs | ||
Params: | ||
- runids: list of runids where we want to include the data | ||
Returns: | ||
- the absolute path of the tarball generated | ||
""" | ||
tarball_name = f'{datetime.datetime.now(datetime.timezone.utc).isoformat().replace(":", "-").replace("+", "_")}__ips_runs' | ||
tarball = THIS_DIR / f'{tarball_name}.tar.gz' | ||
archive = tarfile.open(tarball, 'w:gz') | ||
|
||
if isinstance(runids, int): | ||
runids = [runids] | ||
|
||
for runid in runids: | ||
arcname = os.path.join(tarball_name, str(runid), 'data') | ||
archive.add(os.path.join(THIS_DIR, str(runid), 'data'), arcname=arcname) | ||
|
||
archive.close() | ||
return str(tarball) |
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