.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/example_scheduling_engine.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_examples_example_scheduling_engine.py: Use a scheduling engine ======================= .. GENERATED FROM PYTHON SOURCE LINES 5-18 .. code-block:: Python from pathlib import Path import time from remote_run.run import ( ExecutionContext, SlurmSchedulingEngine, GuixRunner, GitProject, remote, is_finished, SshExecution, ) .. GENERATED FROM PYTHON SOURCE LINES 19-21 Define an execution context with a scheduling engine. For slurm you can pass slurm parameters directly here. .. GENERATED FROM PYTHON SOURCE LINES 21-36 .. code-block:: Python execution_context = ExecutionContext( execution=SshExecution( machine="shpc0003.ost.ch", working_directory=Path("/cluster/raid/home/reza.housseini"), ), project=GitProject(), runner=GuixRunner(channels=Path("channels.scm").read_text()), scheduling_engine=SlurmSchedulingEngine( job_name="test_remote_run", mail_type="ALL", mail_user="reza.housseini@ost.ch", ), ) .. GENERATED FROM PYTHON SOURCE LINES 37-39 decorate your functions you want to run in the specified execution context .. GENERATED FROM PYTHON SOURCE LINES 39-44 .. code-block:: Python @remote(execution_context) def add(a, b): return a + b .. GENERATED FROM PYTHON SOURCE LINES 45-49 this call will run on the remote machine specified in execution_context but due to the asynchronous nature of scheduling engines this will not return the result, instead you get the job id and a function to retrieve the result later. .. GENERATED FROM PYTHON SOURCE LINES 49-51 .. code-block:: Python job_id, result_func = add(1, 2) .. GENERATED FROM PYTHON SOURCE LINES 52-53 now we wait for the remote execution to finish before retrieving the result .. GENERATED FROM PYTHON SOURCE LINES 53-55 .. code-block:: Python time.sleep(20) .. GENERATED FROM PYTHON SOURCE LINES 56-57 we should check if the job id has finished before retrieving the result .. GENERATED FROM PYTHON SOURCE LINES 57-59 .. code-block:: Python if is_finished(execution_context, job_id): assert result_func() == 3 .. _sphx_glr_download_auto_examples_example_scheduling_engine.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: example_scheduling_engine.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: example_scheduling_engine.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: example_scheduling_engine.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_