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

Allow modifiers to add attributes into experiment inventories #705

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
11 changes: 11 additions & 0 deletions lib/ramble/ramble/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ def __init__(self, file_path):
"software": [],
"templates": [],
"package_manager": [],
"modifier_artifacts": [],
}
self.experiment_hash = None

Expand Down Expand Up @@ -1492,6 +1493,16 @@ def _write_inventory(self, workspace, app_inst=None):
experiment_run_dir = self.expander.experiment_run_dir
inventory_file = os.path.join(experiment_run_dir, self._inventory_file_name)

# Populate modifier artifacts portion of inventory
# This happens here to allow modifiers to hash files
# that are downloaded within phases earlier than this.
for mod_inst in self._modifier_instances:
inventory = mod_inst.artifact_inventory(workspace, app_inst)
if inventory:
self.hash_inventory["modifier_artifacts"].append(
{"name": mod_inst.name, "mode": mod_inst._usage_mode, "artifacts": inventory}
)

with lk.WriteTransaction(self.experiment_lock()):
with open(inventory_file, "w+") as f:
spack.util.spack_json.dump(self.hash_inventory, f)
Expand Down
14 changes: 14 additions & 0 deletions lib/ramble/ramble/modifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,20 @@ def run_phase_hook(self, workspace, pipeline, hook_name):

phase_func(workspace)

def artifact_inventory(self, workspace, app_inst=None):
"""Return an inventory of modifier artifacts

Artifact inventories are up to the individual modifier to define the
format of.

This will then show up in an experiment inventory.

Returns:
(Any) Artifact inventory for this modifier
"""

return None

def _prepare_analysis(self, workspace):
"""Hook to perform analysis that a modifier defines.

Expand Down
36 changes: 36 additions & 0 deletions var/ramble/repos/builtin/modifiers/pyxis-enroot/modifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import os

from ramble.modkit import *
from ramble.util.hashing import hash_file, hash_string

import llnl.util.filesystem as fs

Expand Down Expand Up @@ -270,6 +271,41 @@ def _extract_from_sqsh(self, workspace, app_inst=None):
unsquash_args + [expanded_path],
)

def artifact_inventory(self, workspace, app_inst=None):
"""Return hash of container uri and sqsh file if they exist

Args:
workspace (Workspace): Reference to workspace
app_inst (ApplicationBase): Reference to application instance

Returns:
(dict): Artifact inventory for container attributes
"""
container_name = self.expander.expand_var_name("container_name")
container_path = self.expander.expand_var_name("container_path")
container_uri = self.expander.expand_var_name("container_uri")
inventory = []

if self._usage_mode == "disabled":
return inventory

inventory.append(
{
"container_uri": container_uri,
"digest": hash_string(container_uri),
}
)

if os.path.isfile(container_path):
inventory.append(
{
"container_name": container_name,
"digest": hash_file(container_path),
}
)

return inventory

# TODO: Decide on backing up sqsh files.
# The following code works. But there's not a nice way to auto-extract the sqsh file out of the mirror
# This is because the import functionality uses `enroot` directly, which bypasses
Expand Down