concepts.dm.pdsketch.simulator_interface.PDSketchExecutionInterface#

class PDSketchExecutionInterface[source]#

Bases: object

The base class for interaction with the actual executor.

Methods

get_latest_pd_state()

Get the latest PDSketch state.

get_pd_state(action_index)

Get the PDSketch state at a given action index.

register_action_controller(name, ...)

Register a controller function for a controller name.

run(action_index, action_name, action_args)

Run an action, and return the success flag and the new PDSketch state.

run_operator_applier(action_index, action)

Execute an action, and return the success flag and the new PDSketch state.

set_init_state(state)

Set the initial PDSketch state of the simulator.

Attributes

last_action_index

The last action index.

controllers

Registered controllers.

pd_states

Mappings from action indices to PDSketch states.

__init__(executor)[source]#

Initialize the executor interface.

Parameters:

executor (PDSketchExecutor) – the PDSketchExecutor instance for grounding action parameters.

__new__(**kwargs)#
get_latest_pd_state()[source]#

Get the latest PDSketch state.

Return type:

State

get_pd_state(action_index)[source]#

Get the PDSketch state at a given action index. -1 is the initial state.

Parameters:

action_index (int) – the action index.

Return type:

State

register_action_controller(name, controller_function)[source]#

Register a controller function for a controller name.

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

  • controller_function (Callable) – the controller function. It should take a PDSketch state as the first argument, together with other action arguments, and return a tuple of (success, new PDSketch state).

run(action_index, action_name, action_args, verbose=False)[source]#

Run an action, and return the success flag and the new PDSketch state. This function will also store the restore function corresponding to the action.

Parameters:
  • action_index (int) – the action index.

  • action_name (str) – the name of the action (the controller).

  • action_args (Tuple[Any, ...]) – the arguments to the controller.

  • verbose (bool) – whether to print verbose information.

Returns:

a tuple of (success, new PDSketch state).

Return type:

Tuple[bool, State]

run_operator_applier(action_index, action)[source]#

Execute an action, and return the success flag and the new PDSketch state. This function will not store the restore function corresponding to the action.

Parameters:
  • action_index (int) – the action index.

  • action (OperatorApplier) – the action to execute.

Returns:

a tuple of (success, new PDSketch state).

Return type:

Tuple[bool, State]

set_init_state(state)[source]#

Set the initial PDSketch state of the simulator.

Parameters:

state (State)

controllers: Dict[str, Callable]#

Registered controllers.

property last_action_index#

The last action index.

pd_states: Dict[int, State]#

Mappings from action indices to PDSketch states. -1 is the initial state.