pyrddl package

Submodules

pyrddl.cpf module

class pyrddl.cpf.CPF(pvar: Tuple[str, Tuple[str, List[str]]], expr: pyrddl.expr.Expression)

Bases: object

Conditional Probability Function.

Note

This class is intended to be solely used by the parser and compiler. Do not attempt to directly use this class to build a CPF object.

Parameters:
  • pvar – CPF’s parameterized variable.
  • expr – CPF’s expression.
pvar

CPF’s parameterized variable.

Type:PVariable
expr

CPF’s expression.

Type:Expression
__repr__() → str

Returns the CPF’s canonical representation.

name

Returns the CPF’s pvariable name.

pyrddl.domain module

class pyrddl.domain.Domain(name: str, requirements: List[str], sections: Dict[str, Sequence[T_co]])

Bases: object

Domain class for accessing RDDL domain sections.

Note

This class is intended to be solely used by the parser and compiler. Do not attempt to directly use this class to build a Domain object.

Parameters:
  • name – Name of RDDL domain.
  • requirements – List of RDDL requirements.
  • sections – Mapping from string to domain section.
name

Domain identifier.

Type:str
requirements

List of requirements.

Type:List[str]
types

List of types.

Type:List[Type]
pvariables

List of parameterized variables.

Type:List[PVariable]
cpfs

List of Conditional Probability Functions.

Type:List[CPF]
reward

Reward function.

Type:Expression
preconds

List of action preconditions.

Type:List[Expression]
constraints

List of state-action constraints.

Type:List[Expression]
invariants

List of state invariants.

Type:List[Expression]
_build_action_bound_constraints_table()

Builds the lower and upper action bound constraint expressions.

_build_preconditions_table()

Builds the local action precondition expressions.

_extract_lower_bound(name: str, expr: pyrddl.expr.Expression) → Optional[pyrddl.expr.Expression]

Returns the lower bound expression of the action with given name.

_extract_upper_bound(name: str, expr: pyrddl.expr.Expression) → Optional[pyrddl.expr.Expression]

Returns the upper bound expression of the action with given name.

action_fluent_ordering

The list of action-fluent names in canonical order.

Returns:A list of fluent names.
Return type:List[str]
action_fluents

Returns action-fluent pvariables.

build()
get_intermediate_cpf(name)
interm_fluent_ordering

The list of intermediate-fluent names in canonical order.

Returns:A list of fluent names.
Return type:List[str]
intermediate_cpfs

Returns list of intermediate-fluent CPFs in level order.

intermediate_fluents

Returns interm-fluent pvariables.

next_state_fluent_ordering

The list of next state-fluent names in canonical order.

Returns:A list of fluent names.
Return type:List[str]
non_fluent_ordering

The list of non-fluent names in canonical order.

Returns:A list of fluent names.
Return type:List[str]
non_fluents

Returns non-fluent pvariables.

state_cpfs

Returns list of state-fluent CPFs.

state_fluent_ordering

The list of state-fluent names in canonical order.

Returns:A list of fluent names.
Return type:List[str]
state_fluents

Returns state-fluent pvariables.

pyrddl.expr module

class pyrddl.expr.Expression(expr: Union[Expression, Tuple])

Bases: object

Expression class represents a RDDL expression.

Note

This class is intended to be solely used by the parser and compiler. Do not attempt to directly use this class to build an Expression object.

Parameters:expr – Expression object or nested tuple of Expressions.
classmethod _Expression__expr_str(expr, level)

Returns string representing the expression.

classmethod _Expression__get_scope(expr: Union[Expression, Tuple]) → Set[str]

Returns the set of fluents in the expression’s scope.

Parameters:expr – Expression object or nested tuple of Expressions.
Returns:The set of fluents in the expression’s scope.
__str__() → str

Returns string representing the expression.

classmethod _pvar_to_name(pvar_expr)

Returns the name of pvariable.

Returns:Name of pvariable.
args

Returns the expression’s arguments.

etype

Returns the expression’s type.

is_constant_expression() → bool

Returns True if constant expression. False, othersize.

is_pvariable_expression() → bool

Returns True if pvariable expression. False, otherwise.

name

Returns the name of pvariable.

Returns:Name of pvariable.
Raises:ValueError – If not a pvariable expression.
scope

Returns the set of fluents in the expression’s scope.

Returns:The set of fluents in the expression’s scope.
value

Returns the value of a constant expression.

Returns:Value of constant.
Raises:ValueError – If not a constant expression.

pyrddl.instance module

class pyrddl.instance.Instance(name: str, sections: Dict[str, Sequence[T_co]])

Bases: object

Instance class for accessing RDDL instance sections.

Note

This class is intended to be solely used by the parser and compiler. Do not attempt to directly use this class to build an Instance object.

Parameters:
  • name – Name of RDDL instance.
  • sections – Mapping from string to instance section.
name

Name of RDDL instance.

Type:str
domain

Name of RDDL domain.

Type:str
non_fluents

Name of RDDL non-fluents.

Type:str
init_state

List of initial state initializers.

Type:FluentInitializerList
max_nondef_actions

Maximum number of non-default actions.

Type:Union[int, str]
horizon

Number of decision timesteps.

Type:Union[int, str]
discount

Discount factor.

Type:float

pyrddl.nonfluents module

class pyrddl.nonfluents.NonFluents(name: str, sections: Dict[str, Sequence[T_co]])

Bases: object

NonFluents class for accessing RDDL non-fluents sections.

Note

This class is intended to be solely used by the parser and compiler. Do not attempt to directly use this class to build a NonFluents object.

Parameters:
  • name – Name of RDDL non-fluents.
  • sections – Mapping from string to non-fluents section.
name

Name of RDDL non-fluents block.

Type:str
domain

Name of RDDL domain block.

Type:str
objects

List of RDDL objects for each type.

Type:ObjectsList
init_non_fluent

List of non-fluent initializers.

Type:FluentInitializerList

pyrddl.parser module

class pyrddl.parser.RDDLParser(lexer=None, verbose=False)

Bases: object

build(**kwargs)
p_action_precond_def(p)

action_precond_def : expr SEMI

p_action_precond_list(p)

action_precond_list : action_precond_list action_precond_def | action_precond_def

p_action_precond_section(p)

action_precond_section : ACTION_PRECONDITIONS LCURLY action_precond_list RCURLY SEMI | ACTION_PRECONDITIONS LCURLY RCURLY SEMI

p_actionfluent_def(p)

actionfluent_def : IDENT LPAREN param_list RPAREN COLON LCURLY ACTION COMMA type_spec COMMA DEFAULT ASSIGN_EQUAL range_const RCURLY SEMI | IDENT COLON LCURLY ACTION COMMA type_spec COMMA DEFAULT ASSIGN_EQUAL range_const RCURLY SEMI

p_aggregation_expr(p)

aggregation_expr : IDENT UNDERSCORE LCURLY typed_var_list RCURLY expr %prec AGG_OPER

p_bool_type(p)

bool_type : TRUE | FALSE

p_boolean_expr(p)

boolean_expr : expr AND expr | expr AMPERSAND expr | expr OR expr | expr IMPLY expr | expr EQUIV expr | NOT expr %prec UMINUS | bool_type

p_case_def(p)

case_def : CASE term COLON expr | DEFAULT COLON expr

p_case_list(p)

case_list : case_list COMMA case_def | case_def

p_control_expr(p)

control_expr : IF LPAREN expr RPAREN THEN expr ELSE expr %prec IF | SWITCH LPAREN term RPAREN LCURLY case_list RCURLY

p_cpf_def(p)

cpf_def : pvar_expr ASSIGN_EQUAL expr SEMI

p_cpf_header(p)

cpf_header : CPFS | CDFS

p_cpf_list(p)

cpf_list : cpf_list cpf_def | empty

p_cpf_section(p)

cpf_section : cpf_header LCURLY cpf_list RCURLY SEMI

p_discount_section(p)

discount_section : DISCOUNT ASSIGN_EQUAL DOUBLE SEMI

p_domain_block(p)

domain_block : DOMAIN IDENT LCURLY req_section domain_list RCURLY

p_domain_list(p)

domain_list : domain_list type_section | domain_list pvar_section | domain_list cpf_section | domain_list reward_section | domain_list action_precond_section | domain_list state_action_constraint_section | domain_list state_invariant_section | empty

p_domain_section(p)

domain_section : DOMAIN ASSIGN_EQUAL IDENT SEMI

p_double_type(p)

double_type : DOUBLE | MINUS DOUBLE | POS_INF | NEG_INF

p_empty(p)

empty :

p_enum_list(p)

enum_list : enum_list COMMA ENUM_VAL | ENUM_VAL | empty

p_error(p)
p_expr(p)

expr : pvar_expr | group_expr | function_expr | relational_expr | boolean_expr | quantifier_expr | numerical_expr | aggregation_expr | control_expr | randomvar_expr

p_expr_list(p)

expr_list : expr_list COMMA expr | expr

p_function_expr(p)

function_expr : IDENT LBRACK expr_list RBRACK

p_group_expr(p)

group_expr : LBRACK expr RBRACK | LPAREN expr RPAREN

p_horizon_spec_section(p)

horizon_spec_section : HORIZON ASSIGN_EQUAL pos_int_type_or_pos_inf SEMI | HORIZON ASSIGN_EQUAL TERMINATE_WHEN LPAREN expr RPAREN

p_init_non_fluent_section(p)

init_non_fluent_section : NON_FLUENTS LCURLY pvar_inst_list RCURLY SEMI

p_init_state_section(p)

init_state_section : INIT_STATE LCURLY pvar_inst_list RCURLY SEMI

p_instance_block(p)

instance_block : INSTANCE IDENT LCURLY instance_list RCURLY

p_instance_list(p)

instance_list : instance_list domain_section | instance_list nonfluents_section | instance_list objects_section | instance_list init_state_section | instance_list max_nondef_actions_section | instance_list horizon_spec_section | instance_list discount_section | empty

p_int_type(p)

int_type : INTEGER | MINUS INTEGER

p_intermfluent_def(p)

intermfluent_def : IDENT LPAREN param_list RPAREN COLON LCURLY INTERMEDIATE COMMA type_spec COMMA LEVEL ASSIGN_EQUAL range_const RCURLY SEMI | IDENT COLON LCURLY INTERMEDIATE COMMA type_spec COMMA LEVEL ASSIGN_EQUAL range_const RCURLY SEMI

p_lconst(p)

lconst : IDENT | ENUM_VAL

p_lconst_case_list(p)

lconst_case_list : lconst COLON expr | lconst COLON OTHERWISE | lconst_case_list COMMA lconst COLON expr

p_lconst_list(p)

lconst_list : lconst_list COMMA lconst | lconst

p_max_nondef_actions_section(p)

max_nondef_actions_section : MAX_NONDEF_ACTIONS ASSIGN_EQUAL pos_int_type_or_pos_inf SEMI

p_nonfluent_block(p)

nonfluent_block : NON_FLUENTS IDENT LCURLY nonfluent_list RCURLY

p_nonfluent_def(p)

nonfluent_def : IDENT LPAREN param_list RPAREN COLON LCURLY NON_FLUENT COMMA type_spec COMMA DEFAULT ASSIGN_EQUAL range_const RCURLY SEMI | IDENT COLON LCURLY NON_FLUENT COMMA type_spec COMMA DEFAULT ASSIGN_EQUAL range_const RCURLY SEMI

p_nonfluent_list(p)

nonfluent_list : nonfluent_list domain_section | nonfluent_list objects_section | nonfluent_list init_non_fluent_section | empty

p_nonfluents_section(p)

nonfluents_section : NON_FLUENTS ASSIGN_EQUAL IDENT SEMI

p_numerical_expr(p)

numerical_expr : expr PLUS expr | expr MINUS expr | expr TIMES expr | expr DIV expr | MINUS expr %prec UMINUS | PLUS expr %prec UMINUS | INTEGER | DOUBLE

p_object_const_list(p)

object_const_list : object_const_list COMMA IDENT | IDENT

p_objects_def(p)

objects_def : IDENT COLON LCURLY object_const_list RCURLY SEMI

p_objects_list(p)

objects_list : objects_list objects_def | objects_def | empty

p_objects_section(p)

objects_section : OBJECTS LCURLY objects_list RCURLY SEMI

p_param_list(p)

param_list : string_list

p_pos_int_type_or_pos_inf(p)

pos_int_type_or_pos_inf : INTEGER | POS_INF

p_pvar_def(p)

pvar_def : nonfluent_def | statefluent_def | actionfluent_def | intermfluent_def

p_pvar_expr(p)

pvar_expr : IDENT LPAREN term_list RPAREN | IDENT

p_pvar_inst_def(p)

pvar_inst_def : IDENT LPAREN lconst_list RPAREN SEMI | IDENT SEMI | NOT IDENT LPAREN lconst_list RPAREN SEMI | NOT IDENT SEMI | IDENT LPAREN lconst_list RPAREN ASSIGN_EQUAL range_const SEMI | IDENT ASSIGN_EQUAL range_const SEMI

p_pvar_inst_list(p)

pvar_inst_list : pvar_inst_list pvar_inst_def | pvar_inst_def

p_pvar_list(p)

pvar_list : pvar_list pvar_def | empty

p_pvar_section(p)

pvar_section : PVARIABLES LCURLY pvar_list RCURLY SEMI

p_quantifier_expr(p)

quantifier_expr : FORALL UNDERSCORE LCURLY typed_var_list RCURLY expr %prec FORALL | EXISTS UNDERSCORE LCURLY typed_var_list RCURLY expr %prec EXISTS

p_randomvar_expr(p)

randomvar_expr : BERNOULLI LPAREN expr RPAREN | DIRAC_DELTA LPAREN expr RPAREN | KRON_DELTA LPAREN expr RPAREN | UNIFORM LPAREN expr COMMA expr RPAREN | NORMAL LPAREN expr COMMA expr RPAREN | EXPONENTIAL LPAREN expr RPAREN | DISCRETE LPAREN IDENT COMMA lconst_case_list RPAREN | DIRICHLET LPAREN IDENT COMMA expr RPAREN | POISSON LPAREN expr RPAREN | WEIBULL LPAREN expr COMMA expr RPAREN | GAMMA LPAREN expr COMMA expr RPAREN

p_range_const(p)

range_const : bool_type | double_type | int_type | IDENT

p_rddl(p)

rddl : rddl_block

p_rddl_block(p)

rddl_block : rddl_block domain_block | rddl_block instance_block | rddl_block nonfluent_block | empty

p_relational_expr(p)

relational_expr : expr COMP_EQUAL expr | expr NEQ expr | expr GREATER expr | expr GREATEREQ expr | expr LESS expr | expr LESSEQ expr

p_req_section(p)

req_section : REQUIREMENTS ASSIGN_EQUAL LCURLY string_list RCURLY SEMI | REQUIREMENTS LCURLY string_list RCURLY SEMI | empty

p_reward_section(p)

reward_section : REWARD ASSIGN_EQUAL expr SEMI

p_state_action_constraint_section(p)

state_action_constraint_section : STATE_ACTION_CONSTRAINTS LCURLY state_cons_list RCURLY SEMI | STATE_ACTION_CONSTRAINTS LCURLY RCURLY SEMI

p_state_cons_def(p)

state_cons_def : expr SEMI

p_state_cons_list(p)

state_cons_list : state_cons_list state_cons_def | state_cons_def

p_state_invariant_def(p)

state_invariant_def : expr SEMI

p_state_invariant_list(p)

state_invariant_list : state_invariant_list state_invariant_def | state_invariant_def

p_state_invariant_section(p)

state_invariant_section : STATE_INVARIANTS LCURLY state_invariant_list RCURLY SEMI | STATE_INVARIANTS LCURLY RCURLY SEMI

p_statefluent_def(p)

statefluent_def : IDENT LPAREN param_list RPAREN COLON LCURLY STATE COMMA type_spec COMMA DEFAULT ASSIGN_EQUAL range_const RCURLY SEMI | IDENT COLON LCURLY STATE COMMA type_spec COMMA DEFAULT ASSIGN_EQUAL range_const RCURLY SEMI

p_string_list(p)

string_list : string_list COMMA IDENT | IDENT | empty

p_term(p)

term : VAR | ENUM_VAL | pvar_expr

p_term_list(p)

term_list : term_list COMMA term | term | empty

p_type_def(p)

type_def : IDENT COLON OBJECT SEMI | IDENT COLON LCURLY enum_list RCURLY SEMI

p_type_list(p)

type_list : type_list type_def | empty

p_type_section(p)

type_section : TYPES LCURLY type_list RCURLY SEMI

p_type_spec(p)

type_spec : IDENT | INT | REAL | BOOL

p_typed_var(p)

typed_var : VAR COLON IDENT

p_typed_var_list(p)

typed_var_list : typed_var_list COMMA typed_var | typed_var

parse(input)
class pyrddl.parser.RDDLlex

Bases: object

build(**kwargs)
input(data)
t_AMPERSAND = '\\&'
t_AND = '\\^'
t_ASSIGN_EQUAL = '='
t_COLON = ':'
t_COMMA = '\\,'
t_COMMENT(t)

//[^rn]*

t_COMP_EQUAL = '=='
t_DIV = '/'
t_DOLLAR_SIGN = '\\$'
t_DOT = '\\.'
t_DOUBLE(t)
t_ENUM_VAL(t)
t_EQUIV = '<=>'
t_GREATER = '>'
t_GREATEREQ = '>='
t_IDENT(t)
t_IMPLY = '=>'
t_INTEGER(t)
t_LBRACK = '\\['
t_LCURLY = '\\{'
t_LESS = '<'
t_LESSEQ = '<='
t_LPAREN = '\\('
t_MINUS = '-'
t_NEQ = '~='
t_NOT = '~'
t_OR = '\\|'
t_PLUS = '\\+'
t_QUESTION = '\\?'
t_RBRACK = '\\]'
t_RCURLY = '\\}'
t_RPAREN = '\\)'
t_SEMI = ';'
t_TIMES = '\\*'
t_UNDERSCORE = '\\_'
t_VAR(t)
t_error(t)
t_ignore = ' \t'
t_newline(t)

n+

token()

pyrddl.parsetab module

pyrddl.pvariable module

class pyrddl.pvariable.PVariable(name: str, fluent_type: str, range_type: str, param_types: Optional[List[str]] = None, default: Union[bool, int, float, None] = None, level: Optional[int] = None)

Bases: object

Parameterized Variable.

Note

This class is intended to be solely used by the parser and compiler. Do not attempt to directly use this class to build a PVariable object.

Parameters:
  • name (str) – Name of fluent.
  • fluent_type (str) – Type of fluent.
  • range (str) – Range of fluent.
  • param_types (Optional[List[str]]) – List of parameter types.
  • default (Optional[FluentValue]) – Default value of fluent.
  • level (Optional[int]) – Level of intermediate fluent.
name

Name of fluent.

Type:str
fluent_type

Type of fluent.

Type:str
range

Range of fluent.

Type:str
param_types

List of parameter types.

Type:Optional[List[str]]
default

Default value of fluent.

Type:Optional[FluentValue]
level

Level of intermediate fluent.

Type:Optional[int]
__repr__() → str

Returns canonical string representation of PVariable.

__str__() → str

Returns string value of PVariable.

arity

Returns arity of fluent.

is_action_fluent() → bool

Returns True if fluent is of action-fluent type. False, otherwise.

is_fluent() → bool

Returns True if fluent is not a non-fluent type. False, otherwise.

is_intermediate_fluent() → bool

Returns True if fluent is of interm-fluent type. False, otherwise.

is_non_fluent() → bool

Returns True if fluent is of non-fluent type. False, otherwise.

is_state_fluent() → bool

Returns True if fluent is of state-fluent type. False, otherwise.

pyrddl.rddl module

class pyrddl.rddl.RDDL(blocks: Dict[str, Union[pyrddl.domain.Domain, pyrddl.nonfluents.NonFluents, pyrddl.instance.Instance]])

Bases: object

RDDL class for accessing RDDL blocks.

Note

This class is intended to be solely used by the parser and compiler. Do not attempt to directly use this class to build a RDDL object.

Parameters:blocks – Mapping from string to RDDL block.
domain

RDDL domain block.

Type:Domain
non_fluents

RDDL non-fluents block.

Type:NonFluents
instance

RDDL instance block.

Type:Instance
object_table

The object table for each RDDL type.

Type:ObjectTable
_build_fluent_table()

Builds the fluent table for each RDDL pvariable.

_build_object_table()

Builds the object table for each RDDL type.

_fluent_params(fluents, ordering) → Sequence[Tuple[str, List[str]]]

Returns the instantiated fluents for the given ordering.

For each fluent in fluents, it instantiates each parameter type w.r.t. the contents of the object table.

Returns:A tuple of pairs of fluent name and a list of instantiated fluents represented as strings.
Return type:Sequence[Tuple[str, List[str]]]
classmethod _fluent_range_type(fluents, ordering) → Sequence[str]

Returns the range types of fluents following the given ordering.

Returns:A tuple of range types representing the range of each fluent.
Return type:Sequence[str]
_fluent_size(fluents, ordering) → Sequence[Sequence[int]]

Returns the sizes of fluents following the given ordering.

Returns:A tuple of tuple of integers representing the shape and size of each fluent.
Return type:Sequence[Sequence[int]]
_param_types_to_shape(param_types: Optional[str]) → Sequence[int]

Returns the fluent shape given its param_types.

action_fluent_variables

Returns the instantiated action fluents in canonical order.

Returns:A tuple of pairs of fluent name and a list of instantiated fluents represented as strings.
Return type:Sequence[Tuple[str, List[str]]]
action_range_type

The range type of each action fluent in canonical order.

Returns:A tuple of range types representing the range of each fluent.
Return type:Sequence[str]
action_size

The size of each action fluent in canonical order.

Returns:A tuple of tuple of integers representing the shape and size of each fluent.
Return type:Sequence[Sequence[int]]
build()
get_dependencies(expr)
interm_fluent_variables

Returns the instantiated intermediate fluents in canonical order.

Returns:A tuple of pairs of fluent name and a list of instantiated fluents represented as strings.
Return type:Sequence[Tuple[str, List[str]]]
interm_range_type

The range type of each intermediate fluent in canonical order.

Returns:A tuple of range types representing the range of each fluent.
Return type:Sequence[str]
interm_size

The size of each intermediate fluent in canonical order.

Returns:A tuple of tuple of integers representing the shape and size of each fluent.
Return type:Sequence[Sequence[int]]
non_fluent_size

The size of each non-fluent in canonical order.

Returns:A tuple of tuple of integers representing the shape and size of each non-fluent.
Return type:Sequence[Sequence[int]]
non_fluent_variables

Returns the instantiated non-fluents in canonical order.

Returns:A tuple of pairs of fluent name and a list of instantiated fluents represented as strings.
Return type:Sequence[Tuple[str, List[str]]]
state_fluent_variables

Returns the instantiated state fluents in canonical order.

Returns:A tuple of pairs of fluent name and a list of instantiated fluents represented as strings.
Return type:Sequence[Tuple[str, List[str]]]
state_range_type

The range type of each state fluent in canonical order.

Returns:A tuple of range types representing the range of each fluent.
Return type:Sequence[str]
state_size

The size of each state fluent in canonical order.

Returns:A tuple of tuple of integers representing the shape and size of each fluent.
Return type:Sequence[Sequence[int]]

pyrddl.utils module

pyrddl.utils.rename_next_state_fluent(name: str) → str

Returns next state fluent canonical name.

Parameters:name (str) – The current state fluent name.
Returns:The next state fluent name.
Return type:str
pyrddl.utils.rename_state_fluent(name: str) → str

Returns current state fluent canonical name.

Parameters:name (str) – The next state fluent name.
Returns:The current state fluent name.
Return type:str

Module contents