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 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 an executor for this domain.
parse
(string[, state, variables])Parse a string into an expression.
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
The version of the PDSketch language.
The name of the domain.
The types defined in the domain, as a dictionary from type names to types.
A mapping from function name to the corresponding
Predicate
class.The constants defined in the domain, as a dictionary from constant names to values.
from operator name to the corresponding
Operator
class.from operator name to the corresponding
Operator
class.from regression rule name to the corresponding
RegressionRule
class.from axiom name to the corresponding
Operator
class.from generator name to the corresponding
Generator
class.from fancy generator name to the corresponding
FancyGenerator
class.from function name to the corresponding
Function
class.A mapping from function name to another function name.
A helper function that returns a variable with the given type.
- __new__(**kwargs)#
- declare_external_function(function_name, argument_types, return_type, kwargs=None)[source]#
Declare an external function.
- Parameters:
function_name (str) – the name of the external function.
argument_types (Sequence[ObjectType | ValueType | FunctionType | SequenceType] | Sequence[Variable] | Dict[str, ObjectType | ValueType | FunctionType | SequenceType]) – the argument types of the external function.
return_type (ObjectType | ValueType | FunctionType | SequenceType) – the return type of the external function.
kwargs (Dict[str, Any] | None) – the keyword arguments of the external function. Supported keyword arguments are: -
observation
: whether the external function is an observation variable. -state
: whether the external function is a state variable.
- Return type:
- 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.
- define_axiom(name, parameters, preconditions, effects)[source]#
Define a new axiom.
- Parameters:
- Returns:
the newly defined axiom.
- Return type:
- 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:
name (str) – the name of the new derived predicate.
arguments (Sequence[ObjectType | ValueType | FunctionType | SequenceType] | Sequence[Variable] | Dict[str, ObjectType | ValueType | FunctionType | SequenceType]) – the arguments of the new derived predicate.
return_type (ObjectType | ValueType | FunctionType | SequenceType | None) – the return type of the new derived predicate.
expr (ValueOutputExpression) – the expression of the new derived predicate.
state (bool) – whether the new derived predicate is a state variable.
generator_placeholder (bool) – whether the new derived predicate is a generator placeholder.
simulation (bool) – whether the new derived predicate requires the up-to-date simulation state to evaluate.
execution (bool) – whether the new derived predicate requires the up-to-date execution state to evaluate.
- 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:
- define_function(function, implementation=True)#
Define a function in the domain.
- define_generator(name, parameters, certifies, context, generates, implementation=None, priority=0, unsolvable=False)[source]#
Define a new generator.
- Parameters:
name (str) – the name of the new generator.
parameters (Sequence[Variable]) – the parameters of the new generator.
certifies (ValueOutputExpression) – the certified condition of the new generator.
context (Sequence[VariableExpression | ValueOutputExpression]) – the context of the new generator.
generates (Sequence[VariableExpression | ValueOutputExpression]) – the generates of the new generator.
implementation (Implementation | None) – the implementation of the new generator.
priority (int) – the priority of the new generator.
unsolvable (bool) – whether the new generator is unsolvable.
- Returns:
the newly defined generator.
- Return type:
- define_macro(name, parameters, sub_operators, preconditions=tuple(), effects=tuple())[source]#
Define a new macro.
- Parameters:
name (str) – the name of the new macro.
parameters (Sequence[Variable]) – the parameters of the new macro.
sub_operators (Sequence[OperatorApplier]) – the sub operators of the new macro.
preconditions (Sequence[Precondition]) – the preconditions of the new macro.
- Returns:
the newly defined macro.
- Return type:
- 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:
- 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_regression_rule(name, parameters, preconditions, goal_expression, side_effects, body, always=False)[source]#
Define a new regression rule.
- Parameters:
name (str) – the name of the new regression rule.
parameters (Sequence[Variable]) – the parameters of the new regression rule.
preconditions (Sequence[Precondition]) – the preconditions of the new regression rule.
goal_expression (ValueOutputExpression) – the goal expression of the new regression rule, as a single expression.
side_effects (Sequence[Effect]) – the side effects of the new regression rule.
body (Sequence[AchieveExpression | BindExpression | RuntimeAssignExpression | ListExpansionExpression | RegressionCommitFlag | OperatorApplicationExpression | RegressionRuleApplicationExpression | ConditionalRegressionRuleBodyExpression | LoopRegressionRuleBodyExpression]) – the body of the new regression rule.
always (bool) – whether the new regression rule is always applicable.
- Returns:
the newly defined regression rule.
- define_type(typename, parent_name='object')[source]#
Define a new type.
- Parameters:
typename – the name of the new type.
parent_name (VectorValueType | ScalarValueType | str | None) – the parent type of the new type, default to ‘object’.
- Returns:
the newly defined type.
- Return type:
ObjectType | PyObjValueType | VectorValueType | ScalarValueType
- get_function(name)#
Get the function with the given name.
- 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.
- incremental_define(string)[source]#
Incrementally define new parts of the domain.
- Parameters:
string (str) – the string to be parsed and defined.
- parse(string, state=None, variables=None)[source]#
Parse a string into an expression.
- Parameters:
string (str | Expression) – the string to be parsed.
variables (Sequence[Variable] | None) – the variables to be used in the expression.
state (State | None)
- Returns:
the parsed expression.
- Return type:
- 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:
Analyze the static predicates.
- print_summary(external_functions=False, full_generators=False)[source]#
Print a summary of the domain.
- 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 basicDSLDomainBase
, in planning domain, all functions should be of typePredicate
.
- generators: Dict[str, Generator]#
from generator name to the corresponding
Generator
class.- Type:
A mapping of generators
- 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.