Skip to content

Commit

Permalink
ShellJob: Customize the _build_process_label method (#17)
Browse files Browse the repository at this point in the history
This method returns the string that is set as the `process_label`
attribute on the nodes representing executions of the process class. By
default this is the name of the process class, i.e., `ShellJob` in this
case. This is not very informative as all `ShellJob` runs, regardless of
the shell command it ran, will get the same label.

Here we override the `_build_process_label` to include the full label of
the code, which in turn will include the label (typically the name of
the shell command) and the name of the computer on which is was run.
An example is `ShellJob<echo@localhost>`.
  • Loading branch information
sphuber authored Nov 6, 2022
1 parent bde79f3 commit 506fe91
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
12 changes: 12 additions & 0 deletions src/aiida_shell/calculations/shell.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,18 @@ def validate_outputs(cls, value: List, _) -> str | None:

return None

def _build_process_label(self) -> str:
"""Construct the process label that should be set on ``ProcessNode`` instances for this process class.
Override the base implementation to include the full label of the ``Code`` which provides more useful info to
the user, for example when looking at an overview of submitted processes.
:returns: The process label to use for ``ProcessNode`` instances.
"""
if self.inputs:
return f'ShellJob<{self.inputs.code.full_label}>'
return super()._build_process_label()

def prepare_for_submission(self, folder: Folder) -> CalcInfo:
"""Prepare the calculation for submission.
Expand Down
9 changes: 9 additions & 0 deletions tests/calculations/test_shell.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,15 @@ def value_raises(self):
generate_calc_job('core.shell', {'code': generate_code(), 'nodes': nodes})


def test_build_process_label(generate_calc_job, generate_code):
"""Test the :meth:`~aiida_shell.calculations.shell_job.ShellJob.build_process_label` method."""
computer = 'localhost'
executable = '/bin/echo'
code = generate_code(executable, computer_label=computer, label='echo')
process = generate_calc_job('core.shell', {'code': code}, return_process=True)
assert process._build_process_label() == f'ShellJob<{code.full_label}>' # pylint: disable=protected-access


def test_submit_to_daemon(generate_code, submit_and_await):
"""Test submitting a ``ShellJob`` to the daemon."""
builder = generate_code('echo').get_builder()
Expand Down
6 changes: 5 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def generate_calc_job(tmp_path):
as well as the ``CalcInfo`` instance that it returned.
"""

def factory(entry_point_name, inputs=None):
def factory(entry_point_name, inputs=None, return_process=False):
"""Create a :class:`aiida.engine.CalcJob` instance with the given inputs."""
manager = get_manager()
runner = manager.get_runner()
Expand All @@ -59,6 +59,10 @@ def factory(entry_point_name, inputs=None):
process = instantiate_process(runner, process_class, **inputs or {})

calc_info = process.prepare_for_submission(Folder(tmp_path))

if return_process:
return process

return tmp_path, calc_info

return factory
Expand Down

0 comments on commit 506fe91

Please sign in to comment.