Skip to content

Commit

Permalink
Add explicit test for CalcJob submission script using Docker
Browse files Browse the repository at this point in the history
Realized also that the `Computer` should define
`use_double_quotes=False` which is now added to the docs.
  • Loading branch information
sphuber committed Jan 30, 2023
1 parent 450da7f commit 85f776d
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 6 deletions.
4 changes: 3 additions & 1 deletion docs/source/topics/data_types.rst
Original file line number Diff line number Diff line change
Expand Up @@ -609,14 +609,16 @@ The ``ContainerizedCode`` is compatible with a variety of containerization techn

.. tab-item:: Docker

To use `Docker <https://www.docker.com/>`_ ``aiida-core==2.2.0`` or higher is required in order to be able to set ``wrap_cmdline_params = True``.
To use `Docker <https://www.docker.com/>`_ ``aiida-core==2.3.0`` or higher is required in order to be able to set ``wrap_cmdline_params = True``.
When setting up a code for a Docker container, use the following ``engine_command`` when setting up the code:

.. code-block:: console
docker run -i -v $PWD:/workdir:rw -w /workdir {image_name} sh -c
.. note:: Currently running with MPI is not yet supported, as it needs to be called inside of the container which is currently not possible.
The associated computer should also be configured to have the setting ``use_double_quotes = False``.
This can be set from the Python API using ``load_computer('idenfitier').set_use_double_quotes(False)``.

The following configuration provides an example to setup Quantum ESPRESSO's ``pw.x`` to be run by Docker on the local host

Expand Down
47 changes: 42 additions & 5 deletions tests/engine/processes/calcjobs/test_calc_job.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,44 @@ def test_containerized_code(file_regression, aiida_localhost):
_, node = launch.run_get_node(DummyCalcJob, **inputs)
folder_name = node.dry_run_info['folder']
submit_script_filename = node.get_option('submit_script_filename')
content = (pathlib.Path(folder_name) / submit_script_filename).read_bytes().decode('utf-8')
content = (pathlib.Path(folder_name) / submit_script_filename).read_text()

file_regression.check(content, extension='.sh')


@pytest.mark.requires_rmq
@pytest.mark.usefixtures('chdir_tmp_path')
def test_containerized_code_wrap_cmdline_params(file_regression, aiida_localhost):
"""Test :class:`~aiida.orm.nodes.data.code.containerized.ContainerizedCode` with ``wrap_cmdline_params = True``."""
aiida_localhost.set_use_double_quotes(False)
engine_command = """docker run -i -v $PWD:/workdir:rw -w /workdir {image_name} sh -c"""
containerized_code = orm.ContainerizedCode(
default_calc_job_plugin='core.arithmetic.add',
filepath_executable='/bin/bash',
engine_command=engine_command,
image_name='ubuntu',
computer=aiida_localhost,
wrap_cmdline_params=True,
).store()

inputs = {
'code': containerized_code,
'metadata': {
'dry_run': True,
'options': {
'resources': {
'num_machines': 1,
'num_mpiprocs_per_machine': 1
},
'withmpi': False,
}
}
}

_, node = launch.run_get_node(DummyCalcJob, **inputs)
folder_name = node.dry_run_info['folder']
submit_script_filename = node.get_option('submit_script_filename')
content = (pathlib.Path(folder_name) / submit_script_filename).read_text()

file_regression.check(content, extension='.sh')

Expand Down Expand Up @@ -305,7 +342,7 @@ def test_containerized_code_withmpi_true(file_regression, aiida_localhost):
_, node = launch.run_get_node(DummyCalcJob, **inputs)
folder_name = node.dry_run_info['folder']
submit_script_filename = node.get_option('submit_script_filename')
content = (pathlib.Path(folder_name) / submit_script_filename).read_bytes().decode('utf-8')
content = (pathlib.Path(folder_name) / submit_script_filename).read_text()

file_regression.check(content, extension='.sh')

Expand Down Expand Up @@ -379,9 +416,9 @@ def test_portable_code(tmp_path, aiida_localhost):
for filename in code.base.repository.list_object_names():
assert filename in uploaded_files

content = (pathlib.Path(folder_name) / code.filepath_executable).read_bytes().decode('utf-8')
subcontent = (pathlib.Path(folder_name) / 'sub' / 'dummy').read_bytes().decode('utf-8')
subsubcontent = (pathlib.Path(folder_name) / 'sub' / 'sub' / 'sub-dummy').read_bytes().decode('utf-8')
content = (pathlib.Path(folder_name) / code.filepath_executable).read_text()
subcontent = (pathlib.Path(folder_name) / 'sub' / 'dummy').read_text()
subsubcontent = (pathlib.Path(folder_name) / 'sub' / 'sub' / 'sub-dummy').read_text()

assert content == 'bash implementation'
assert subcontent == 'dummy'
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash
exec > _scheduler-stdout.txt
exec 2> _scheduler-stderr.txt


'docker' 'run' '-i' '-v' '$PWD:/workdir:rw' '-w' '/workdir' 'ubuntu' 'sh' '-c' "'/bin/bash' '--version' '-c' < 'aiida.in' > 'aiida.out' 2> 'aiida.err'"

0 comments on commit 85f776d

Please sign in to comment.