Skip to content

nodus.functions

View Markdown

Functions, FunctionCalls and @app.cls classes (resources.md §3.10, §3.11, ADR-047, ADR-110).

.remote(), .spawn() and .map() all create FunctionCall objects, the one fan-out mechanism of R3. Arguments are cloudpickled (nodus._serialize), results come back through a watch on the call, and a remote exception is re-raised as its own type when that type is importable here.

class Cls(fn: _Function) -> None

An @app.cls class: Embedder() gives an object whose @nodus.method()s have .remote, .map, .spawn.

from_name(app: str, name: str, project: str | None = None) -> _Cls
class ClsObject(fn: _Function) -> None
class Function(*, raw: Callable[..., Any] | None = None, app: _App | None = None, options: FunctionOptions | None = None, user_cls: type | None = None, method: str | None = None, deployed: str | None = None, deployed_app: str | None = None, project: str | None = None, instance: _Obj | None = None) -> None

A Function defined with @app.function, a method of an @app.cls class, or a deployed one by name.

estimate(*args: Any, **kwargs: Any) -> View

Dry-run one call: cold and warm start ETAs and the rate; .etag binds a reviewed launch.

for_each(*iterables: Iterable[Any], ignore_exceptions: bool = False) -> None

Run the function over the inputs and discard the results.

from_name(app: str, name: str, project: str | None = None) -> _Function

A deployed Function: <app>-<name> in the project (Function.lookup is an alias).

get_raw_f() -> Callable[..., Any]

The undecorated function (for a class method, the class).

local(*args: Any, **kwargs: Any) -> Any

Run in this process, without Nodus.

map(*iterables: Iterable[Any], kwargs: dict[str, Any] | None = None, order_outputs: bool = True, return_exceptions: bool = False) -> AsyncIterator[Any]

One FunctionCall per input, created in batches (≤1,000 calls, ≤8 MiB); results stream back as they finish.

remote(*args: Any, **kwargs: Any) -> Any

One FunctionCall: block until it finishes and return its result, or raise its exception.

spawn(*args: Any, **kwargs: Any) -> _FunctionCall

Start one FunctionCall and return its handle without waiting.

starmap(iterable: Iterable[Iterable[Any]], order_outputs: bool = True, return_exceptions: bool = False) -> AsyncIterator[Any]
class FunctionCall(name: str, function: str | None = None, project: str | None = None) -> None

A handle on one FunctionCall: .get(timeout=None), .cancel(), .status(), .logs().

cancel() -> None
from_name(name: str, project: str | None = None) -> _FunctionCall

Type: str | None

get(timeout: float | None = None) -> Any

Wait for the result; raises the remote exception, or TimeoutError after timeout seconds.

logs(follow: bool = False) -> AsyncIterator[str]

Log lines of the Function’s workers.

Type: str

status() -> str | None

The call’s phase: Queued, Running, Recovering, Succeeded, Failed, Cancelling or Cancelled.

class FunctionOptions(name: str | None = None, gpu: Any = None, cpu: Any = None, memory: Any = None, ephemeral_disk: Any = None, image: Any = None, secrets: list[Any] = list(), volumes: dict[str, Any] = dict(), env: dict[str, str] | None = None, network: Any = None, timeout: Any = None, retries: Any = None, checkpoint: Any = None, interruptible: Any = None, region: Any = None, profile: Any = None, max_cost: Any = None, min_workers: int | None = None, max_workers: int | None = None, scaledown_window: Any = None, target_concurrency: int | None = None) -> None

The @app.function / @app.cls arguments, mapped to Function spec fields by spec().

Type: Any

Type: Any

Type: dict[str, str] | None

Type: Any

Type: Any

Type: Any

Type: Any

Type: Any

Type: int | None

Type: Any

Type: int | None

Type: str | None

Type: Any

Type: Any

Type: Any

Type: Any

Type: Any

Type: list[Any]

Type: int | None

Type: Any

Type: dict[str, Any]

clustered(size: int, launcher: str = 'Plain', network: str = 'Colocated', transport: str = 'Direct') -> Callable[[Callable[..., Any]], Callable[..., Any]]

Run each .remote() or .spawn() as one gang of size nodes; rank 0’s return value is the result (Beta).

Apply it below @app.function. nodus.cluster.info() gives each member its rank and the gang’s addresses.