Skip to content

Commit

Permalink
Engine: Improve error message when submitting without broker (aiidate…
Browse files Browse the repository at this point in the history
…am#6465)

The `aiida.engine.launch.submit` method was just raising a vague
`AssertionError` in case the runner did not have a communicator, which
is the case if it was constructed without a communicator which in turn
happens for profiles that do not configure a broker.

Since profiles without brokers are now supported and users are bound to
try to submit anyway, the error message should be clearer.
  • Loading branch information
sphuber authored and mikibonacci committed Sep 3, 2024
1 parent 12cba28 commit 279ac5b
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 8 deletions.
10 changes: 9 additions & 1 deletion src/aiida/engine/launch.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,16 @@ def submit(
raise InvalidOperation('Cannot use top-level `submit` from within another process, use `self.submit` instead')

runner = manager.get_manager().get_runner()

if runner.controller is None:
raise InvalidOperation(
'Cannot submit because the runner does not have a process controller, probably because the profile does '
'not define a broker like RabbitMQ. If a RabbitMQ server is available, the profile can be configured to '
'use it with `verdi profile configure-rabbitmq`. Otherwise, use :meth:`aiida.engine.launch.run` instead to '
'run the process in the local Python interpreter instead of submitting it to the daemon.'
)

assert runner.persister is not None, 'runner does not have a persister'
assert runner.controller is not None, 'runner does not have a controller'

process_inited = instantiate_process(runner, process, **inputs)

Expand Down
34 changes: 27 additions & 7 deletions tests/engine/test_launch.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,16 @@
ArithmeticAddCalculation = CalculationFactory('core.arithmetic.add')


@pytest.fixture
def arithmetic_add_builder(aiida_code_installed):
builder = ArithmeticAddCalculation.get_builder()
builder.code = aiida_code_installed(default_calc_job_plugin='core.arithmetic.add', filepath_executable='/bin/bash')
builder.x = orm.Int(1)
builder.y = orm.Int(1)
builder.metadata = {'options': {'resources': {'num_machines': 1, 'num_mpiprocs_per_machine': 1}}}
return builder


@calcfunction
def add(term_a, term_b):
return term_a + term_b
Expand Down Expand Up @@ -69,18 +79,28 @@ def add(self):


@pytest.mark.usefixtures('started_daemon_client')
def test_submit_wait(aiida_code_installed):
def test_submit_wait(arithmetic_add_builder):
"""Test the ``wait`` argument of :meth:`aiida.engine.launch.submit`."""
builder = ArithmeticAddCalculation.get_builder()
builder.code = aiida_code_installed(default_calc_job_plugin='core.arithmetic.add', filepath_executable='/bin/bash')
builder.x = orm.Int(1)
builder.y = orm.Int(1)
builder.metadata = {'options': {'resources': {'num_machines': 1, 'num_mpiprocs_per_machine': 1}}}
node = launch.submit(builder, wait=True, wait_interval=0.1)
node = launch.submit(arithmetic_add_builder, wait=True, wait_interval=0.1)
assert node.is_finished, node.process_state
assert node.is_finished_ok, node.exit_code


def test_submit_no_broker(arithmetic_add_builder, monkeypatch, manager):
"""Test that ``submit`` raises ``InvalidOperation`` if the runner does not have a controller.
The runner does not have a controller if the runner was not provided a communicator which is the case for profiles
that do not define a broker.
"""
runner = manager.get_runner()
monkeypatch.setattr(runner, '_controller', None)

with pytest.raises(
exceptions.InvalidOperation, match=r'Cannot submit because the runner does not have a process controller.*'
):
launch.submit(arithmetic_add_builder)


def test_await_processes_invalid():
"""Test :func:`aiida.engine.launch.await_processes` for invalid inputs."""
with pytest.raises(TypeError):
Expand Down

0 comments on commit 279ac5b

Please sign in to comment.