Skip to content

Commit

Permalink
Add account to init.
Browse files Browse the repository at this point in the history
  • Loading branch information
joaander committed Aug 22, 2024
1 parent 4e2b16b commit 26bbb2e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
3 changes: 0 additions & 3 deletions hoomd_validation/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,6 @@ def init(args):

project = signac.init_project(path=config.project_root)

# TODO: Add command line arguments to limit which projects are initialized.
# Will need to selectively remove actions from the other projects from the workflow.

# initialize jobs for validation test projects
for subproject in all_subprojects:
# add all the jobs to the project
Expand Down
18 changes: 16 additions & 2 deletions hoomd_validation/workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,19 @@

import argparse
from pathlib import Path
import subprocess

import rtoml
import signac


def _get_cluster_name():
"""Get the current cluster name."""
result = subprocess.run(
['row', 'show', 'cluster', '--name'], capture_output=True, check=True, text=True
)
return result.stdout.strip()

class Action:
"""Represent a row action.
Expand Down Expand Up @@ -68,7 +76,7 @@ def add_action(cls, name, action):
cls._actions[name] = action

@classmethod
def write_workflow(cls, entrypoint, path=None, default=None):
def write_workflow(cls, entrypoint, path=None, default=None, account=None):
"""Write the file ``workflow.toml``.
``workflow.toml`` will include the signac workspace definition, the given
Expand All @@ -82,6 +90,7 @@ def write_workflow(cls, entrypoint, path=None, default=None):
entrypoint(str): Name of the python file that calls the `main` entrypoint.
path(Path): Path to write ``workflow.toml``.
default(dict): The ``[default]`` mapping.
account(str): Name of the cluster account to use.
"""
workflow = {
'workspace': {'path': 'workspace', 'value_file': 'signac_statepoint.json'}
Expand All @@ -92,6 +101,9 @@ def write_workflow(cls, entrypoint, path=None, default=None):
'command': f'python -u {entrypoint} action $ACTION_NAME {{directories}}'
}
}
if account is not None:
print(account)
workflow['default']['action'].update({'submit_options': {_get_cluster_name(): {'account': account}}})

if default is not None:
workflow['default'].update(default)
Expand Down Expand Up @@ -129,6 +141,7 @@ def main(cls, init=None, init_args=None, **kwargs):
parser = argparse.ArgumentParser()
command = parser.add_subparsers(dest='command', required=True)
init_parser = command.add_parser('init')
init_parser.add_argument('--account')
if init_args is not None:
for arg in init_args:
init_parser.add_argument(arg)
Expand All @@ -138,12 +151,13 @@ def main(cls, init=None, init_args=None, **kwargs):
action_parser.add_argument('directories', nargs='+')

args = parser.parse_args()
print(args)

if args.command == 'init':
if init is not None:
init(args)

cls.write_workflow(**kwargs)
cls.write_workflow(account=args.account, **kwargs)
elif args.command == 'action':
project = signac.get_project()
jobs = [project.open_job(id=directory) for directory in args.directories]
Expand Down

0 comments on commit 26bbb2e

Please sign in to comment.