Note
Go to the end to download the full example code.
Decorate your function
from pathlib import Path
from remote_run import (
Executor,
GuixEnvironment,
remote,
SshMachine,
LocalMachine,
)
Define an executor
executor = Executor(
machine=SshMachine(
host="shpc0003.ost.ch",
working_directory=Path("/cluster/raid/home/reza.housseini"),
),
environments=[
GuixEnvironment(
channels=Path("channels.scm").read_text(),
manifest=Path("manifest.scm").read_text(),
)
],
)
decorate your function you want to run with an executor with the remote decorator
@remote
def add(a, b, some_file):
assert some_file.exists(), f"File {some_file} does not exist"
return a + b
Let’s create a file locally
some_file = Path("some_file").write_text("hello")
this call will run on the machine specified in the executor. When passing an argument of type Path, the file will be transferred to the machine and the arguments path will be patched to point to this new location.
job = add(1, 2, some_file=some_file, executor=executor)
assert job.result() == 5
you can also call the function with a different executor
executor = Executor(
machine=LocalMachine(),
environment=[
GuixEnvironment(
channels=Path("channels.lock.scm").read_text(),
manifest=Path("manifest.scm").read_text(),
)
],
)
job = add(1, 2, executor=executor)
assert job.result() == 5
you can even run the function like any normal function
assert add(1, 2) == 3