concepts.dm.crow.executors.crow_executor.CrowExecutor#

class CrowExecutor[source]#

Bases: TensorValueExecutorBase

Methods

check_constraint(constraint[, state])

check_eq_constraint(dtype, x, y, target[, state])

execute(expression[, state, ...])

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.

load_external_function_implementations_from_file(...)

new_bounded_variables(bvdict)

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

parse(string, *[, state, variables])

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.

retrieve_bounded_variable_by_name(name)

Retrieve a bounded variable by its name.

set_parser(parser)

Set the parser for the executor.

update_effect_mode(evaluation_mode[, ...])

with_bounded_variables(bvdict[, ...])

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

with_csp(csp)

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

with_sgc(sgc)

A context manager to temporarily set the SGC of 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.

csp

The CSP that describes the constraints in past executions.

domain

The domain of the executor.

effect_action_index

effect_update_from_execution

A context variable indicating whether the current effect should be updated from the execution of the operator.

effect_update_from_simulation

A context variable indicating whether the current effect should be updated from simulation, instead of the evaluation of expressions.

function_implementations

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

optimistic_execution

Whether to execute the expression optimistically (i.e., treat all CSP constraints True).

parser

The parser for the domain.

pyobj_store

The Python object store.

sgc

The SGC (state-goal-constraints) context.

state

The state of the executor.

value_quantizer

The value quantizer.

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

Initialize a Crow expression executor.

Parameters:
  • domain (CrowDomain) – the domain of this executor.

  • parser (ParserBase | None) – the parser to be used. This argument is optional. If provided, the execute function can take strings as input.

  • load_external_function_implementations (bool) – whether to load the external function implementations defined in the domain file.

__new__(**kwargs)#
check_constraint(constraint, state=None)#
Parameters:
check_eq_constraint(dtype, x, y, target, state=None)#
Parameters:
Return type:

bool

execute(expression, state=None, bounded_variables=None, csp=None, sgc=None, bypass_bounded_variable_check=False, optimistic_execution=False)[source]#

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)[source]#

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:

CrowPythonFunctionRef

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

load_external_function_implementations_from_file(filepath)[source]#
Parameters:

filepath (str)

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(string, *, state=None, variables=None)[source]#

Parse an expression.

Parameters:
  • expression – the expression to parse. When the input is already an expression, it will be returned directly.

  • string (str | Expression)

  • state (CrowState | None)

  • variables (Sequence[Variable] | None)

Returns:

the parsed expression.

Return type:

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)[source]#

Register an implementation for a function.

Parameters:
retrieve_bounded_variable_by_name(name)#

Retrieve a bounded variable by its name.

Parameters:

name (str) – the name of the variable.

Returns:

the value of the variable.

Return type:

TensorValue | slice | StateObjectReference

set_parser(parser)#

Set the parser for the executor.

Parameters:

parser (ParserBase) – the parser.

update_effect_mode(evaluation_mode, action_index=None)[source]#
Parameters:
with_bounded_variables(bvdict, bypass_bounded_variable_check=False)#

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

Parameters:
with_csp(csp)[source]#

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

Parameters:

csp (ConstraintSatisfactionProblem | None)

with_sgc(sgc)[source]#

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

Parameters:

sgc (CrowSGC | None)

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 csp: ConstraintSatisfactionProblem | None#

The CSP that describes the constraints in past executions.

property domain: CrowDomain#

The domain of the executor.

property effect_action_index: int | None#
property effect_update_from_execution: bool#

A context variable indicating whether the current effect should be updated from the execution of the operator.

property effect_update_from_simulation: bool#

A context variable indicating whether the current effect should be updated from simulation, instead of the evaluation of expressions.

property function_implementations: Dict[str, CrowPythonFunctionRef | CrowPythonFunctionCrossRef]#

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

property optimistic_execution: bool#

Whether to execute the expression optimistically (i.e., treat all CSP constraints True).

property parser: ParserBase | None#

The parser for the domain.

property pyobj_store: PyObjectStore#

The Python object store.

property sgc: CrowSGC | None#

The SGC (state-goal-constraints) context.

property state: CrowState#

The state of the executor.

property value_quantizer: ValueQuantizer#

The value quantizer.