concepts.dm.pdsketch.strips.strips_grounded_expression.GSBoolOutputExpression#

class GSBoolOutputExpression[source]#

Bases: GSExpression, ABC

The base class for all Boolean expressions.

Methods

compile()

Compile the expression into a function that takes a state as input.

enable_forward_diff_ctx()

A context manager that enables the forward difference flag.

filter_propositions(propositions[, state])

Filter the propositions in this expression.

forward(state)

Compute the expression on the given state.

iter_propositions()

Iterate over all propositions that are used in this expression.

set_forward_diff([value])

Set the forward difference flag.

Attributes

FORWARD_DIFF

A static variable that indicates whether we want to enable forward difference for expressions.

__init__()#
__new__(**kwargs)#
compile()[source]#

Compile the expression into a function that takes a state as input.

Return type:

Callable[[SState], bool | GSBoolForwardDiffReturn]

static enable_forward_diff_ctx()[source]#

A context manager that enables the forward difference flag. Example:

state = SState({'a', 'b'})
expr = GSSimpleBoolExpression({'a', 'b'})
compiled_function = expr.compile()
with GSBoolExpression.enable_forward_diff_ctx():
    rv = compiled_function(state)
    assert isinstance(rv, GSBoolForwardDiffReturn)
    assert rv.rv is True
    assert rv.propositions == {'a', 'b'}
filter_propositions(propositions, state=None)[source]#

Filter the propositions in this expression. Only the propositions in the given set will be kept. Note that this function also takes a state as input, essentially, the state is the initial state of the environment, and the propositions contains all propositions that will be possibly changed by actions. Therefore, for propositions outside the propositions set, their value will stay as the same value as in the initial state. See, for example, the implementation for GSSimpleBoolExpression.filter_propositions() for more details.

Parameters:
  • propositions (SState | Set[str]) – the propositions that should be kept.

  • state (SState | None) – the initial state, default to None.

Returns:

the filtered expression.

Return type:

GSBoolOutputExpression

forward(state)[source]#

Compute the expression on the given state.

Parameters:

state (SState) – the state to compute the expression on.

Returns:

the return value of the expression.

Return type:

bool | GSBoolForwardDiffReturn

abstract iter_propositions()#

Iterate over all propositions that are used in this expression.

Return type:

Iterable[str]

static set_forward_diff(value=True)[source]#

Set the forward difference flag. If the forward difference flag is set to True, the compiled function will return a tuple of (bool, Set[SProposition]) instead of a bool.

Parameters:

value (bool) – the value to set, default to True.

FORWARD_DIFF = False#

A static variable that indicates whether we want to enable forward difference for expressions.