concepts.pdsketch.executor.PythonFunctionRef#

class PythonFunctionRef[source]#

Bases: object

A reference to a Python function.

This class is used to wrap external function implementations in domains.

Methods

forward(argument_values[, return_type, ...])

Call the function.

forward_generator(argument_values[, ...])

Call the function and return a generator.

forward_internal_autobatch(function_def, ...)

forward_sgc_function(state, goal, ...[, ...])

Call an SGC function (state-goal-constraints) function.

iter_from(*args[, return_type, ...])

set_executor(executor)

Set the executor that is using this function reference.

Attributes

flags

function

The internal implementation of the function.

function_quantized

The quantized version of the function (can be None).

return_type

The return type of the function.

support_batch

Whether the function supports batched inputs.

auto_broadcast

Whether the executor should automatically broadcast the arguments before calling the function.

use_object_names

Whether the executor should use the object names in the state (instead of the index).

unwrap_values

Whether the executor should unwrap the tensor values before calling the function.

include_executor_args

Whether the caller should include the executor as the first argument.

is_iterator

Whether the function is an iterator.

is_sgc_function

Whether the function is an SGC function (state-goal-constraints).

__call__(*args, return_type=None, auto_broadcast=True, wrap_rv=True)[source]#

Call self as a function.

Parameters:
Return type:

TensorValue | Tuple[TensorValue, …]

__init__(function, function_quantized=None, *, return_type=None, support_batch=False, auto_broadcast=False, use_object_names=True, unwrap_values=None, include_executor_args=False, is_iterator=False, is_sgc_function=False, executor=None)[source]#

Initialize a Python function reference.

Parameters:
  • function (Callable) – the function to be wrapped.

  • function_quantized (Callable | None) – the quantized version of the function (can be None).

  • support_batch (bool) – whether the function supports batched inputs.

  • auto_broadcast (bool) – whether the executor should automatically broadcast the arguments before calling the function.

  • use_object_names (bool) – whether the executor should use the object names in the state (instead of the index).

  • unwrap_values (bool | None) – whether the executor should unwrap the tensor values before calling the function.

  • include_executor_args (bool) – whether the caller should include the executor as the first argument.

  • is_iterator (bool) – whether the function is an iterator.

  • is_sgc_function (bool) – whether the function is an SGC function (state-goal-constraints).

  • executor (PDSketchExecutor | None) – the executor that is using this function reference.

  • return_type (TensorValueTypeBase | PyObjValueType | Tuple[TensorValueTypeBase | PyObjValueType, ...] | None)

__new__(**kwargs)#
forward(argument_values, return_type=None, additional_parameters=None, auto_broadcast=True, wrap_rv=True, function_def=None, batch_variable_names=None)[source]#

Call the function.

Parameters:
Returns:

the result of the function.

Return type:

TensorValue | Tuple[TensorValue, …]

forward_generator(argument_values, return_type=None, auto_broadcast=True, wrap_rv=True)[source]#

Call the function and return a generator.

Parameters:
Return type:

Iterator[TensorValue] | Iterator[Tuple[TensorValue, …]]

forward_internal_autobatch(function_def, function, argument_values_flat, batch_variable_names)[source]#
forward_sgc_function(state, goal, constraints, additional_arguments, return_type=None, auto_broadcast=True, wrap_rv=True)[source]#

Call an SGC function (state-goal-constraints) function.

Parameters:
iter_from(*args, return_type=None, auto_broadcast=True, wrap_rv=True)[source]#
Parameters:
Return type:

Iterator[TensorValue] | Iterator[Tuple[TensorValue, …]]

set_executor(executor)[source]#

Set the executor that is using this function reference.

Parameters:

executor (PDSketchExecutor) – the executor that is using this function reference.

Returns:

the function reference itself.

Return type:

PythonFunctionRef

auto_broadcast: bool#

Whether the executor should automatically broadcast the arguments before calling the function.

property flags: Dict[str, bool]#
function: Callable#

The internal implementation of the function.

function_quantized: Callable | None#

The quantized version of the function (can be None).

include_executor_args: bool#

Whether the caller should include the executor as the first argument.

is_iterator: bool#

Whether the function is an iterator.

is_sgc_function: bool#

Whether the function is an SGC function (state-goal-constraints).

return_type: TensorValueTypeBase | PyObjValueType | Tuple[TensorValueTypeBase | PyObjValueType, ...] | None#

The return type of the function.

support_batch: bool#

Whether the function supports batched inputs.

unwrap_values: bool#

Whether the executor should unwrap the tensor values before calling the function.

use_object_names: bool#

Whether the executor should use the object names in the state (instead of the index).