Use a bash script

from pathlib import Path
import subprocess
from remote_run import (
    Executor,
    SlurmSchedulingEngine,
    GuixEnvironment,
    remote,
    SshMachine,
)

Define an execution context with a scheduling engine. For slurm you can pass slurm parameters directly here.

executor = Executor(
    machine=SshMachine(
        host="shpc0003.ost.ch",
        working_directory=Path("/cluster/raid/home/reza.housseini"),
    ),
    environment=[GuixEnvironment(channels=Path("channels.scm").read_text())],
    scheduling_engine=SlurmSchedulingEngine(
        job_name="run_bash_script",
        mail_type="ALL",
        mail_user="reza.housseini@ost.ch",
    ),
)

decorate your functions you want to run in an executor

@remote
def execute_bash_commands(message):
    return subprocess.check_output(["echo", message, ";", "hostname"], text=True)

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.

job = execute_bash_commands("hello", executor=executor)

now we wait for the remote execution to finish before retrieving the result

assert job.result(timeout=20) == "hello\nshpc0003"

Gallery generated by Sphinx-Gallery