yr.FunctionProxy.invoke

yr.FunctionProxy.invoke#

FunctionProxy.invoke(*args, **kwargs)[source]#

Execute the decorated function remotely.

This method triggers the execution of the decorated function on remote workers. The function is executed with the provided arguments and returns an ObjectRef that can be used to retrieve the result.

Parameters:
  • *args – Variable arguments to pass to the decorated function.

  • **kwargs – Keyword arguments to pass to the decorated function.

Returns:

A reference to the result object(s). For functions with return_nums=1, returns a single ObjectRef. For functions with return_nums>1, returns a list of ObjectRefs. For generator functions, returns an ObjectRefGenerator. For functions with return_nums=0, returns None.

Return type:

ObjectRef or List[ObjectRef]

Raises:
  • TypeError – If the provided arguments don’t match the function signature.

  • RuntimeError – If the function execution fails or runtime is not initialized.

Examples

>>> import yr
>>>
>>> yr.init()
>>>
>>> @yr.invoke
... def add(a, b):
...     return a + b
>>>
>>> result_ref = add.invoke(1, 2)
>>> result = yr.get(result_ref)
>>> print(result)  # Output: 3
>>>
>>> # For functions with multiple return values
>>> @yr.invoke(return_nums=2)
... def divmod_func(a, b):
...     return divmod(a, b)
>>>
>>> quotient_ref, remainder_ref = divmod_func.invoke(10, 3)
>>> print(yr.get(quotient_ref))  # Output: 3
>>> print(yr.get(remainder_ref))  # Output: 1
>>>
>>> yr.finalize()