Skip to content

Commit 351c671

Browse files
committed
Engine: Improve error message when submitting without broker
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.
1 parent 1b4a19a commit 351c671

File tree

2 files changed

+34
-8
lines changed

2 files changed

+34
-8
lines changed

Diff for: src/aiida/engine/launch.py

+7-1
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,14 @@ def submit(
111111
raise InvalidOperation('Cannot use top-level `submit` from within another process, use `self.submit` instead')
112112

113113
runner = manager.get_manager().get_runner()
114+
115+
if runner.controller is None:
116+
raise InvalidOperation(
117+
'Cannot submit because the runner does not have a process controller. Does the current profile define a '
118+
'broker? Submitting processes requires a broker like RabbitMQ.'
119+
)
120+
114121
assert runner.persister is not None, 'runner does not have a persister'
115-
assert runner.controller is not None, 'runner does not have a controller'
116122

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

Diff for: tests/engine/test_launch.py

+27-7
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,16 @@
2020
ArithmeticAddCalculation = CalculationFactory('core.arithmetic.add')
2121

2222

23+
@pytest.fixture
24+
def arithmetic_add_builder(aiida_code_installed):
25+
builder = ArithmeticAddCalculation.get_builder()
26+
builder.code = aiida_code_installed(default_calc_job_plugin='core.arithmetic.add', filepath_executable='/bin/bash')
27+
builder.x = orm.Int(1)
28+
builder.y = orm.Int(1)
29+
builder.metadata = {'options': {'resources': {'num_machines': 1, 'num_mpiprocs_per_machine': 1}}}
30+
return builder
31+
32+
2333
@calcfunction
2434
def add(term_a, term_b):
2535
return term_a + term_b
@@ -69,18 +79,28 @@ def add(self):
6979

7080

7181
@pytest.mark.usefixtures('started_daemon_client')
72-
def test_submit_wait(aiida_code_installed):
82+
def test_submit_wait(arithmetic_add_builder):
7383
"""Test the ``wait`` argument of :meth:`aiida.engine.launch.submit`."""
74-
builder = ArithmeticAddCalculation.get_builder()
75-
builder.code = aiida_code_installed(default_calc_job_plugin='core.arithmetic.add', filepath_executable='/bin/bash')
76-
builder.x = orm.Int(1)
77-
builder.y = orm.Int(1)
78-
builder.metadata = {'options': {'resources': {'num_machines': 1, 'num_mpiprocs_per_machine': 1}}}
79-
node = launch.submit(builder, wait=True, wait_interval=0.1)
84+
node = launch.submit(arithmetic_add_builder, wait=True, wait_interval=0.1)
8085
assert node.is_finished, node.process_state
8186
assert node.is_finished_ok, node.exit_code
8287

8388

89+
def test_submit_no_broker(arithmetic_add_builder, monkeypatch, manager):
90+
"""Test that ``submit`` raises ``InvalidOperation`` if the runner does not have a controller.
91+
92+
The runner does not have a controller if the runner was not provided a communicator which is the case for profiles
93+
that do not define a broker.
94+
"""
95+
runner = manager.get_runner()
96+
monkeypatch.setattr(runner, '_controller', None)
97+
98+
with pytest.raises(
99+
exceptions.InvalidOperation, match=r'Cannot submit because the runner does not have a process controller.*'
100+
):
101+
launch.submit(arithmetic_add_builder)
102+
103+
84104
def test_await_processes_invalid():
85105
"""Test :func:`aiida.engine.launch.await_processes` for invalid inputs."""
86106
with pytest.raises(TypeError):

0 commit comments

Comments
 (0)