concepts.dm.pdsketch.domain.Domain#

class Domain[source]#

Bases: DSLDomainBase

The planning domain definition.

Methods

declare_external_function(function_name, ...)

Declare an external function.

declare_external_function_crossref(...)

Declare a cross-reference to an external function.

define_axiom(name, parameters, ...)

Define a new axiom.

define_const(dtype, value)

Define a constant with the given type and value.

define_derived(name, arguments[, ...])

Define a new derived predicate.

define_fancy_generator(name, certifies[, ...])

Declare a new fancy generator.

define_function(function[, implementation])

Define a function in the domain.

define_generator(name, parameters, ...[, ...])

Define a new generator.

define_macro(name, parameters, sub_operators)

Define a new macro.

define_operator(name, parameters, ...[, ...])

Define a new operator.

define_operator_inner(name, operator)

define_predicate(name, arguments[, ...])

Define a new predicate.

define_predicate_inner(name, predicate_def)

define_regression_rule(name, parameters, ...)

Define a new regression rule.

define_type(typename[, parent_name])

Define a new type.

get_function(name)

Get the function with the given name.

get_generator(name)

get_operator(name)

get_predicate(name)

Get a predicate by name.

get_regression_rule(name)

get_type(typename)

Get a type by name.

has_function(name)

Check whether the domain has a function with the given name.

has_generator(name)

has_operator(name)

has_regression_rule(name)

incremental_define(string)

Incrementally define new parts of the domain.

make_executor()

Make an executor for this domain.

parse(string[, state, variables])

Parse a string into an expression.

post_init()

Post-initialization of the domain.

print_summary([external_functions, ...])

Print a summary of the domain.

set_name(name)

Set the name of the domain.

Attributes

BUILTIN_NUMERIC_TYPES

BUILTIN_PYOBJ_TYPES

BUILTIN_TYPES

pdsketch_version

The version of the PDSketch language.

name

The name of the domain.

types

The types defined in the domain, as a dictionary from type names to types.

functions

A mapping from function name to the corresponding Predicate class.

constants

The constants defined in the domain, as a dictionary from constant names to values.

operators

from operator name to the corresponding Operator class.

operator_templates

from operator name to the corresponding Operator class.

regression_rules

from regression rule name to the corresponding RegressionRule class.

axioms

from axiom name to the corresponding Operator class.

generators

from generator name to the corresponding Generator class.

fancy_generators

from fancy generator name to the corresponding FancyGenerator class.

external_functions

from function name to the corresponding Function class.

external_function_crossrefs

A mapping from function name to another function name.

tv

A helper function that returns a variable with the given type.

__init__(name=None, pdsketch_version=2)[source]#

Initialize a planning domain.

Parameters:
  • name (str | None) – The name of the domain.

  • pdsketch_version (int)

__new__(**kwargs)#
declare_external_function(function_name, argument_types, return_type, kwargs=None)[source]#

Declare an external function.

Parameters:
Return type:

Function

declare_external_function_crossref(function_name, cross_ref_name)[source]#

Declare a cross-reference to an external function. This is useful when one function is an derived function of another function.

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

  • cross_ref_name (str) – the name of the cross-reference.

define_axiom(name, parameters, preconditions, effects)[source]#

Define a new axiom.

Parameters:
  • name (str | None) – the name of the new axiom. If None, a unique name will be generated.

  • parameters (Sequence[Variable]) – the parameters of the new axiom.

  • preconditions (Sequence[Precondition]) – the preconditions of the new axiom.

  • effects (Sequence[Effect]) – the effects of the new axiom.

Returns:

the newly defined axiom.

Return type:

Operator

define_const(dtype, value)#

Define a constant with the given type and value.

Parameters:
  • dtype (ObjectType | ValueType) – the type of the constant.

  • value (str) – the value of the constant. The value should be a string that is the name of the constant.

define_derived(name, arguments, return_type=None, expr=None, *, state=False, generator_placeholder=False, simulation=False, execution=False)[source]#

Define a new derived predicate. Note that a derived predicate can not be an observation variable.

Parameters:
Returns:

the newly defined derived predicate.

define_fancy_generator(name, certifies, implementation=None, priority=10, unsolvable=False)[source]#

Declare a new fancy generator. The difference between a fancy generator and a normal generator is that a fancy generator is not directional. That is, it can generate a set of variables satisfies the constraints, without requiring specific contexts to generates directions. Therefore, we don’t need to specify the context and generates of a fancy generator.

Parameters:
  • name (str) – the name of the new fancy generator.

  • certifies (ValueOutputExpression) – the certified condition of the new fancy generator.

  • implementation (Implementation | None) – the implementation of the new fancy generator.

  • priority (int) – the priority of the new fancy generator.

  • unsolvable (bool) – whether the new fancy generator is unsolvable.

Returns:

the newly declared fancy generator.

Return type:

FancyGenerator

define_function(function, implementation=True)#

Define a function in the domain.

Parameters:
  • function (Function | Callable) – the function to be defined.

  • implementation (bool) – whether to store the function body of function as the implementation of the function.

Returns:

the function that is defined.

Return type:

Function

define_generator(name, parameters, certifies, context, generates, implementation=None, priority=0, unsolvable=False)[source]#

Define a new generator.

Parameters:
Returns:

the newly defined generator.

Return type:

Generator

define_macro(name, parameters, sub_operators, preconditions=tuple(), effects=tuple())[source]#

Define a new macro.

Parameters:
Returns:

the newly defined macro.

Return type:

MacroOperator

define_operator(name, parameters, preconditions, effects, controller, template=False, extends=None)[source]#

Define a new operator.

Parameters:
  • name (str) – the name of the new operator.

  • parameters (Sequence[Variable]) – the parameters of the new operator.

  • preconditions (Sequence[Precondition]) – the preconditions of the new operator.

  • effects (Sequence[Effect]) – the effects of the new operator.

  • controller (Implementation) – the controller of the new operator.

  • template (bool) – whether the new operator is a template.

  • extends (str | None) – the parent operator of the new operator.

Returns:

the newly defined operator.

Return type:

Operator

define_operator_inner(name, operator)[source]#
Parameters:
Return type:

Operator

define_predicate(name, arguments, return_type=BOOL, *, observation=None, state=None, generator_placeholder=False, inplace_generators=None, simulation=False, execution=False, is_generator_function=False)[source]#

Define a new predicate.

Parameters:
  • name (str) – the name of the new predicate.

  • arguments (Sequence[ObjectType | ValueType | FunctionType | SequenceType] | Sequence[Variable] | Dict[str, ObjectType | ValueType | FunctionType | SequenceType]) – the arguments of the new predicate.

  • return_type (ObjectType | ValueType | FunctionType | SequenceType) – the return type of the new predicate.

  • observation (bool | None) – whether the new predicate is an observation variable.

  • state (bool | None) – whether the new predicate is a state variable.

  • generator_placeholder (bool) – whether the new predicate is a generator placeholder.

  • inplace_generators (Sequence[str] | None) – a list of generators that will be defined in-place for this predicate.

  • simulation (bool) – whether the new predicate requires the up-to-date simulation state to evaluate.

  • execution (bool) – whether the new predicate requires the up-to-date execution state to evaluate.

  • is_generator_function (bool) – whether the new predicate is a generator function.

Returns:

the newly defined predicate.

define_predicate_inner(name, predicate_def)[source]#
Parameters:
define_regression_rule(name, parameters, preconditions, goal_expression, side_effects, body, always=False)[source]#

Define a new regression rule.

Parameters:
Returns:

the newly defined regression rule.

define_type(typename, parent_name='object')[source]#

Define a new type.

Parameters:
Returns:

the newly defined type.

Return type:

ObjectType | PyObjValueType | VectorValueType | ScalarValueType

get_function(name)#

Get the function with the given name.

Parameters:

name (str) – the name of the function.

Returns:

the function with the given name.

Return type:

Function

get_generator(name)[source]#
Parameters:

name (str)

Return type:

Generator | FancyGenerator

get_operator(name)[source]#
Parameters:

name (str)

Return type:

Operator

get_predicate(name)[source]#

Get a predicate by name.

Parameters:

name (str) – the name of the predicate.

Returns:

the predicate with the given name.

Return type:

Predicate

get_regression_rule(name)[source]#
Parameters:

name (str)

Return type:

RegressionRule

get_type(typename)[source]#

Get a type by name.

Parameters:

typename (str) – the name of the type.

Returns:

the type with the given name.

Return type:

ObjectType | PyObjValueType | VectorValueType | ScalarValueType | NamedTensorValueType

has_function(name)#

Check whether the domain has a function with the given name.

Parameters:

name (str) – the name of the function.

Returns:

whether the domain has a function with the given name.

Return type:

bool

has_generator(name)[source]#
Parameters:

name (str)

Return type:

bool

has_operator(name)[source]#
Parameters:

name (str)

Return type:

bool

has_regression_rule(name)[source]#
Parameters:

name (str)

Return type:

bool

incremental_define(string)[source]#

Incrementally define new parts of the domain.

Parameters:

string (str) – the string to be parsed and defined.

make_executor()[source]#

Make an executor for this domain.

Return type:

PDSketchExecutor

parse(string, state=None, variables=None)[source]#

Parse a string into an expression.

Parameters:
Returns:

the parsed expression.

Return type:

Expression

post_init()[source]#

Post-initialization of the domain. This function should be called by the domain generator after all the domain definitions (predicates and operators) are done. Currently, the following post-initialization steps are performed:

  1. Analyze the static predicates.

print_summary(external_functions=False, full_generators=False)[source]#

Print a summary of the domain.

Parameters:
  • external_functions (bool)

  • full_generators (bool)

set_name(name)[source]#

Set the name of the domain.

Parameters:

name (str) – the new name of the domain.

BUILTIN_NUMERIC_TYPES = {'bool': ScalarValueType<bool>, 'float32': ScalarValueType<float32>, 'int64': ScalarValueType<int64>}#
BUILTIN_PYOBJ_TYPES = {'__control__': PyObjValueType<__control__>, '__regression_body_item__': PyObjValueType<__regression_body_item__>, '__totally_ordered_plan__': ListType<__totally_ordered_plan__>}#
BUILTIN_TYPES = ['object', 'pyobject', 'bool', 'int64', 'float32', '__totally_ordered_plan__', '__partially_ordered_plan__']#
axioms: Dict[str, Operator]#

from axiom name to the corresponding Operator class.

Type:

A mapping of axioms

constants: Dict[str, ObjectConstant]#

The constants defined in the domain, as a dictionary from constant names to values.

external_function_crossrefs: Dict[str, str]#

A mapping from function name to another function name. This is useful when defining one function as an derived function of another function.

external_functions: Dict[str, Function]#

from function name to the corresponding Function class.

Type:

A mapping of external functions

fancy_generators: Dict[str, FancyGenerator]#

from fancy generator name to the corresponding FancyGenerator class.

Type:

A mapping of fancy generators

functions: Dict[str, Predicate]#

A mapping from function name to the corresponding Predicate class. Note that, unlike the basic DSLDomainBase, in planning domain, all functions should be of type Predicate.

generators: Dict[str, Generator]#

from generator name to the corresponding Generator class.

Type:

A mapping of generators

name: str#

The name of the domain.

operator_templates: Dict[str, Operator]#

from operator name to the corresponding Operator class.

Type:

A mapping of operator templates

operators: Dict[str, Operator | MacroOperator]#

from operator name to the corresponding Operator class.

Type:

A mapping of operators

pdsketch_version: int#

The version of the PDSketch language. Currently, two supported versions are 2 and 3. This will be used to determine the parsing behavior of the domain.

regression_rules: Dict[str, RegressionRule]#

from regression rule name to the corresponding RegressionRule class.

Type:

A mapping of regression rules

tv: _TypedVariableView#

A helper function that returns a variable with the given type. For example, domain.tv[‘object’](‘x’) returns a variable of type object with name x.

types: Dict[str, ObjectType | PyObjValueType | TensorValueTypeBase]#

The types defined in the domain, as a dictionary from type names to types.