Skip to main content

Python API

The package exports these names. Anything else in the package is internal and can change.

from nornir_ray import (
RayRunner,
RunLocation,
NornirRayError,
NoWorkerNodeError,
OperationTaskNotOnWorkerError,
RayClusterUnreachableError,
RemoteTaskError,
RunnerSettingsError,
TaskNotSerializableError,
WorkerDiedError,
__version__,
)

Entry point​

The package registers the runner under the name ray in the entry point group nornir.plugins.runners. That name is the value of runner.plugin in the Nornir configuration.

RayRunner​

RayRunner(
address: str | None = None,
role: Literal["both", "server", "worker"] | None = None,
workers_per_node: int | None = None,
hosts_per_worker: int | None = None,
max_abandoned_calls: int | None = None,
per_host_timeout: float | None = None,
timeout: float | None = None,
connect_timeout: float | None = None,
worker_start_timeout: float | None = None,
site_key: str | None = None,
)

The arguments are the runner options. An argument left at None is read from the next source.

Nornir methods that work with the runner​

nr.run, nr.arun, nr.submit, nr.asubmit, nr.stream, nr.astream, nr.run_operation and nr.arun_operation.

What each call does​

CallBehaviour
RayRunner(...)Checks the options given. Raises RunnerSettingsError for an unknown or invalid option. Does not connect to Ray
The first runReads the configuration, checks the role against the address, connects to Ray and starts the workers. Fails before any host starts with RunnerSettingsError, RayClusterUnreachableError, NoWorkerNodeError or TaskNotSerializableError
Each runRecords every host exactly once. One host's failure does not change the result of another host. No host is run again after a failure
A run with no hostsReturns an empty result and starts no workers
close()Stops the workers of the runner's pool when no other open runner shares it. Stops Ray when the runner started it and no other open runner uses it. Calling it again does nothing

Cancellation​

The runner's cancellation_depth is "checkpoint": a cancelled sync task stops at its next checkpoint. An async task stops at the call it awaits, as with AsyncioRunner.

RunLocation​

@dataclass(frozen=True)
class RunLocation:
node_id: str
node_name: str
site: str | None
worker_id: str

The runner sets a RunLocation as the attribute ray of each host's top-level result that a worker produced:

location = getattr(nr.run(task=my_task)["r1"][0], "ray", None)
FieldValue
node_idThe Ray node ID
node_nameThe node's name
siteThe host's site, or None
worker_idThe worker, in the form <node_id>/<n>

Results that Nornir records without a result from a worker have no ray attribute. See Find where each host ran.