concepts.dsl.executors.tensor_value_executor.FunctionDomainTensorValueExecutor#

class FunctionDomainTensorValueExecutor[source]#

Bases: TensorValueExecutorBase

Similar to FunctionDomainExecutor, but works for TensorValue. The two of the main differences are:

  1. The execute() method returns a TensorValue object instead of a Value object.

  2. The class supports binding variables to values during execution. See the documentation for this file and tutorials for details.

Methods

checkpoint_storage()

Checkpoint the storages of the executor, including the value quantizer and the Python object store.

execute(expression[, state, bounded_variables])

Execute an expression.

get_bounded_variable(variable)

Get the value of a bounded variable.

get_function_implementation(name)

Get the implementation of a function.

has_function_implementation(name)

Check whether the executor has an implementation for a function.

new_bounded_variables(bvdict)

A context manager to add additional bounded variables to the executor.

parse(expression)

Parse an expression.

register_function(name, func)

Register an implementation for a function to the executor.

register_function_implementation(name, func)

Register an implementation for a function.

reset_pyobj_store()

Reset the Python object store.

reset_value_quantizer()

Reset the value quantizer to the default value quantizer.

set_parser(parser)

Set the parser for the executor.

set_pyobj_store(pyobj_store)

Set the Python object store for the executor.

set_value_quantizer(value_quantizer)

Set the value quantizer for the executor.

with_bounded_variables(bvdict)

A context manager to set the bounded variables for the executor.

with_state([state])

A context manager to temporarily set the state of the executor.

Attributes

bounded_variables

The bounded variables for the execution.

domain

The function domain of the executor.

function_implementations

The implementations of functions, which is a mapping from function names to implementations.

parser

The parser for the domain.

pyobj_store

The Python object store.

state

The current state of the environment.

value_quantizer

The value quantizer.

__init__(domain, parser=None)[source]#

Initialize a tensor value executor for a function domain.

Parameters:
  • domain (FunctionDomain) – the domain of the executor.

  • parser (ParserBase | None) – the parser to use. If not specified, no parser will be used.

__new__(**kwargs)#
checkpoint_storage()#

Checkpoint the storages of the executor, including the value quantizer and the Python object store.

execute(expression, state=None, bounded_variables=None)#

Execute an expression.

Parameters:
Returns:

the TensorValue object.

Return type:

TensorValue | slice | StateObjectReference | ListValue | None | Tuple[TensorValue | slice | StateObjectReference | ListValue | None, …]

get_bounded_variable(variable)#

Get the value of a bounded variable.

Parameters:

variable (Variable) – the variable.

Returns:

the value of the variable.

Return type:

TensorValue | slice | StateObjectReference

get_function_implementation(name)#

Get the implementation of a function. When the executor does not have an implementation for the function, the implementation of the function in the domain will be returned. If that is also None, a KeyError will be raised.

Parameters:

name (str) – the name of the function.

Returns:

the implementation of the function.

Return type:

Callable

has_function_implementation(name)#

Check whether the executor has an implementation for a function.

Parameters:

name (str) – the name of the function.

Returns:

whether the executor has an implementation for the function.

Return type:

bool

new_bounded_variables(bvdict)#

A context manager to add additional bounded variables to the executor.

Parameters:

bvdict (None | Sequence[Variable] | Dict[str | Variable, str | int | slice | bool | float | Tensor | TensorValue | ObjectConstant | StateObjectReference] | Dict[str, Dict[str, StateObjectReference | slice | TensorValue]]) – the new bounded variables.

parse(expression)#

Parse an expression.

Parameters:

expression (Expression | str) – the expression to parse. When the input is already an expression, it will be returned directly.

Returns:

the parsed expression.

register_function(name, func)#

Register an implementation for a function to the executor. Alias for register_function_implementation().

Parameters:
  • name (str) – the name of the function.

  • func (Callable) – the implementation of the function.

register_function_implementation(name, func)#

Register an implementation for a function.

Parameters:
  • name (str) – the name of the function.

  • func (Callable) – the implementation of the function.

reset_pyobj_store()#

Reset the Python object store.

reset_value_quantizer()#

Reset the value quantizer to the default value quantizer.

set_parser(parser)#

Set the parser for the executor.

Parameters:

parser (ParserBase) – the parser.

set_pyobj_store(pyobj_store)#

Set the Python object store for the executor.

Parameters:

pyobj_store (PyObjectStore) – the Python object store.

set_value_quantizer(value_quantizer)#

Set the value quantizer for the executor.

Parameters:

value_quantizer (ValueQuantizer) – the value quantizer.

with_bounded_variables(bvdict)#

A context manager to set the bounded variables for the executor.

Parameters:

bvdict (None | Sequence[Variable] | Dict[str | Variable, str | int | slice | bool | float | Tensor | TensorValue | ObjectConstant | StateObjectReference] | Dict[str, Dict[str, StateObjectReference | slice | TensorValue]]) – the bounded variables.

with_state(state=None)#

A context manager to temporarily set the state of the executor.

Parameters:

state (TensorState | None) –

property bounded_variables: Dict[str, Dict[str, StateObjectReference | slice | TensorValue]]#

The bounded variables for the execution. Note that most of the time you should use the get_bounded_variable() method to get values for the bounded variable.

property domain: FunctionDomain#

The function domain of the executor.

property function_implementations: Dict[str, Callable]#

The implementations of functions, which is a mapping from function names to implementations.

property parser: ParserBase | None#

The parser for the domain.

property pyobj_store: PyObjectStore#

The Python object store.

property state: TensorState | None#

The current state of the environment.

property value_quantizer: ValueQuantizer#

The value quantizer.