concepts.dm.pdsketch.simulator_interface.PDSketchSimulatorInterface#

class PDSketchSimulatorInterface[source]#

Bases: object

The base class for interaction with a (physical simulator). This class serves two purposes:

  1. perform simulation for planners. Therefore, it requires actions to support restore operations.

  2. perform simulation when executing a given plan. In this case, restore operations are not required.

Methods

get_latest_pd_state()

Get the latest PDSketch state.

get_pd_state(action_index)

Get the PDSketch state at a given action index.

get_restore_function(action_index)

Get the restore function for a given action index.

register_action_controller(name, ...)

Register a controller function for a controller name.

restore(target_action_index[, verbose])

Restore the simulator to a given action index.

restore_context([verbose])

A context manager for restoring the simulator to the current action index.

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.

restore_functions

Mappings from action indices to controller states.

__init__(executor)[source]#

Initialize the simulator 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

get_restore_function(action_index)[source]#

Get the restore function for a given action index.

Parameters:

action_index (int) – the action index.

Return type:

Any

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, restore function).

restore(target_action_index, verbose=False)[source]#

Restore the simulator to a given action index.

Parameters:
  • target_action_index (int) – the target action index.

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

Returns:

whether the restore operation is successful.

Return type:

bool

restore_context(verbose=False)[source]#

A context manager for restoring the simulator to the current action index.

Parameters:

verbose (bool)

Return type:

Iterable[int]

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.

restore_functions: Dict[int, Any]#

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