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
The internal implementation of the function.
The quantized version of the function (can be None).
The return type of the function.
Whether the function supports batched inputs.
Whether the executor should automatically broadcast the arguments before calling the function.
Whether the executor should use the object names in the state (instead of the index).
Whether the executor should unwrap the tensor values before calling the function.
Whether the caller should include the executor as the first argument.
Whether the function is an iterator.
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 (TensorValueTypeBase | PyObjValueType | None)
auto_broadcast (bool)
wrap_rv (bool)
- 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:
argument_values (Sequence[TensorValue | slice | StateObjectReference | ListValue | None | Tuple[TensorValue | slice | StateObjectReference | ListValue | None, ...]]) – the arguments to the function.
return_type (TensorValueTypeBase | PyObjValueType | None) – the type of the return value.
additional_parameters (Sequence[Any] | None) – the additional parameters to the function.
auto_broadcast (bool) – whether the executor should automatically broadcast the arguments before calling the function.
wrap_rv (bool) – whether the executor should wrap the return value.
function_def (Function | None) – the function definition.
batch_variable_names (Dict[int, str] | None) – the batch variable names.
- 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:
argument_values (Sequence[TensorValue | slice | StateObjectReference | ListValue | None | Tuple[TensorValue | slice | StateObjectReference | ListValue | None, ...]]) – the arguments to the function.
return_type (TensorValueTypeBase | PyObjValueType | None) – the type of the return value.
auto_broadcast (bool) – whether the executor should automatically broadcast the arguments before calling the function.
wrap_rv (bool) – whether the executor should wrap the
- 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:
state (State) – the current state.
goal (Expression) – the goal expression.
constraints (Sequence[Expression]) – the constraints, as a list of expressions.
additional_arguments (Sequence[TensorValue | slice | StateObjectReference | ListValue | None | Tuple[TensorValue | slice | StateObjectReference | ListValue | None, ...]]) – the additional arguments.
return_type (TensorValueTypeBase | PyObjValueType | None) – the type of the return value.
auto_broadcast (bool) – whether the executor should automatically broadcast the arguments before calling the function.
wrap_rv (bool) – whether the executor should wrap the return value.
- iter_from(*args, return_type=None, auto_broadcast=True, wrap_rv=True)[source]#
- Parameters:
return_type (TensorValueTypeBase | PyObjValueType | None)
auto_broadcast (bool)
wrap_rv (bool)
- 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:
- auto_broadcast: bool#
Whether the executor should automatically broadcast the arguments before calling the function.
- return_type: TensorValueTypeBase | PyObjValueType | Tuple[TensorValueTypeBase | PyObjValueType, ...] | None#
The return type of the function.