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

launch_shell_job: Move computer to top-level of metadata #98

Merged
merged 1 commit into from
Jul 22, 2024
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
4 changes: 2 additions & 2 deletions docs/source/howto.rst
Original file line number Diff line number Diff line change
Expand Up @@ -444,15 +444,15 @@ Defining a specific computer
By default the shell command ran by ``launch_shell_job`` will be executed on the localhost, i.e., the computer where AiiDA is running.
However, AiiDA also supports running commands on remote computers.
See the `AiiDA's documentation <https://aiida.readthedocs.io/projects/aiida-core/en/latest/howto/run_codes.html#how-to-set-up-a-computer>`__ for instructions to setting up and configuring a remote computer.
To specify what computer to use for a shell command, pass it as an option to the ``metadata`` keyword:
To specify what computer to use for a shell command, pass it as a key to the ``metadata`` argument:

.. code-block:: python

from aiida.orm import load_computer
from aiida_shell import launch_shell_job
results, node = launch_shell_job(
'date',
metadata={'options': {'computer': load_computer('some-computer')}}
metadata={'computer': load_computer('some-computer')}
)
print(results['stdout'].get_content())

Expand Down
15 changes: 14 additions & 1 deletion src/aiida_shell/launch.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@
import shlex
import tempfile
import typing as t
import warnings

from aiida.common import exceptions, lang
from aiida.common.warnings import AiidaDeprecationWarning
from aiida.engine import Process, WorkChain, launch
from aiida.orm import AbstractCode, Computer, Data, ProcessNode, SinglefileData, load_code, load_computer

Expand Down Expand Up @@ -58,7 +60,18 @@ def launch_shell_job( # noqa: PLR0913
generated for each ``CalcJob`` and typically are not of interest to a user running ``launch_shell_job``. In
order to not confuse them, these nodes are omitted, but they can always be accessed through the node.
"""
computer = (metadata or {}).get('options', {}).pop('computer', None)
metadata = metadata or {}
computer = metadata.get('options', {}).pop('computer', None)

if computer:
warnings.warn(
'Specifying a computer through `metadata.options.computer` in `launch_shell_job` is deprecated. Please use '
'`metadata.computer` instead.',
AiidaDeprecationWarning,
stacklevel=2,
)
else:
computer = metadata.pop('computer', None)

if isinstance(command, str):
code = prepare_code(command, computer, resolve_command)
Expand Down
11 changes: 11 additions & 0 deletions tests/test_launch.py
Original file line number Diff line number Diff line change
Expand Up @@ -337,3 +337,14 @@ def test_preexisting_localhost_no_default_mpiprocs_per_machine(
assert computer.get_default_mpiprocs_per_machine() is None

Computer.collection.delete(computer.pk)


def test_metadata_computer(generate_computer):
"""Test the ``metadata.computer`` input."""
label = 'custom-computer'
computer = generate_computer(label=label)
assert computer.label == label

_, node = launch_shell_job('date', metadata={'computer': computer})
assert node.is_finished_ok
assert node.inputs.code.computer.uuid == computer.uuid
Loading