concepts.dm.pdsketch.executor.StateDefinitionHelper#

class StateDefinitionHelper[source]#

Bases: object

A helper class to define the planning domain state (State). Typically you should use new_state() to create an instance of this helper class.

The most important feature of this class is that it supports a human-friendly definition of Boolean predicates. For example, you can define the grounding values for a predicate p as follows:

state, ctx = executor.new_state({'a': ObjectType('person'), 'b': ObjectType('person')})
state.define_predicates([
    ctx.p('a', 'b')
])  # define the predicate p(a, b) as True. All other values are False by convention.

Methods

define_feature(feature_name, tensor_or_mapping)

Define a relational feature directly with torch.Tensor objects.

define_predicates(predicates)

Define a list of grounding values of predicates.

define_pyobj_feature(feature_name, pyobj_list)

Define a feature with a list of Python objects.

get_predicate(name)

Get a predicate definition helper by name.

init_feature(feature_name)

Initialize a feature tensor with all zeros.

set_value(feature_name, arguments, value)

Set a single entry in the feature representation.

__init__(domain_or_executor, state)[source]#

Initialize a new instance of the state definition helper.

Parameters:
  • domain_or_executor (PDSketchExecutor | Domain) – the domain or an executor.

  • state (State) – a (possibly empty) state to be modified.

__new__(**kwargs)#
define_feature(feature_name, tensor_or_mapping)[source]#

Define a relational feature directly with torch.Tensor objects. For example,

state, ctx = executor.new_state({'a': ObjectType('person'), 'b': ObjectType('person')})
# assume p is a Boolean predicate with the signature person x person -> bool
state.define_feature('p', torch.tensor([[1, 0], [0, 1]]), quantized=True)
Parameters:
  • feature_name (str) – the name of the feature.

  • tensor_or_mapping (Tensor | TensorizedPyObjValues | Mapping[str | Tuple[str, ...], bool | int | float | Tensor | TensorizedPyObjValues]) – a tensor or a mapping from argument values to tensors. If a tensor is given, it is assumed that the tensor has exactly the same shape as the tensor of the feature. If the input is a mapping, the keys of the mapping are tuples (entry indices), and the values are tensors. The tensors will be filled into an all-zero tensor of the same shape as the feature tensor.

define_predicates(predicates)[source]#

Define a list of grounding values of predicates. See the example in StateDefinitionHelper.

Parameters:

predicates (Sequence[_StateDefPredicate]) – a list of grounding values, created by ctx.p('a', 'b').

define_pyobj_feature(feature_name, pyobj_list)[source]#

Define a feature with a list of Python objects. The objects will be converted to tensors using the underlying PyObjStore of the executor.

Parameters:
  • feature_name (str) – the name of the feature.

  • pyobj_list (List[Any]) – a list of Python objects (they can also be nested lists).

get_predicate(name)[source]#

Get a predicate definition helper by name. This can be used to define the grounding values of a predicate, e.g., ctx.get_predicate('p')('a', 'b').

Parameters:

name (str) – the name of the predicate.

Returns:

a predicate definition helper.

Return type:

_StateDefPredicateApplier

init_feature(feature_name)[source]#

Initialize a feature tensor with all zeros. This is useful when you want to define a feature with a custom function.

state, ctx = executor.new_state({'a': ObjectType('person'), 'b': ObjectType('person')})
# assume p is a Boolean predicate with the signature person x person -> bool
state.init_feature('p')
state.set_value('p', ('a', 'b'), 1, quantized=True)
Parameters:

feature_name (str) – the name of the feature.

set_value(feature_name, arguments, value)[source]#

Set a single entry in the feature representation. When the feature tensor has not been created, it will be created automatically. Note that, when creating the feature tensor, we will use quantized to determine whether the feature should be quantized or not in the state.

state, ctx = executor.new_state({'a': ObjectType('person'), 'b': ObjectType('person')})
# assume p is a Boolean predicate with the signature person x person -> bool
state.set_value('p', ('a', 'b'), 1, quantized=True)
Parameters: