Open scastro-bdai opened 5 months ago
Thanks @Framba-Luca -- indeed that solves my use case!
with SequentialSimulator(problem) as sim:
state = sim.get_initial_state()
print(f"Initial sim state: {state}")
act = result.plan.actions[0]
res = sim.is_applicable(state, act)
print(f"Is action {act} applicable? {res}")
state._values[robot_at(robby, kitchen)] = Bool(False)
res = sim.is_applicable(state, act)
print(f"Is action {act} applicable? {res}")
yields
Initial sim state: {can_move(robby): true, hand_empty(robby): true, holding(robby, apple): false, holding(robby, banana): false, robot_at(robby, kitchen): true, robot_at(robby, bedroom): false, at(apple, kitchen): true, at(apple, bedroom): false, at(banana, kitchen): false, at(banana, bedroom): true}
Is action pick(robby, apple, kitchen) applicable? True
Is action pick(robby, apple, kitchen) applicable? False
I can also do:
sim.get_unsatisfied_conditions(state, act)
to get
([robot_at(robby, kitchen)], <InapplicabilityReasons.VIOLATES_CONDITIONS: 1>)
Maybe my one piece of feedback is to add a set_value()
method to State
so the line to manually mutate the state value doesn't index a private attribute _values
.
@scastro-bdai Actually the State should be immutable (eq and hash methods require immutability, otherwise bugs might arise; the internal implementations assumes immutability).
So, instead of changing a value, we designed the make_child
method, that creates a new state with the updated values.
I am copy-pasting here the method because the UPState is not in the api documentation.
def make_child(
self,
updated_values: Dict["up.model.FNode", "up.model.FNode"],
) -> "UPState":
"""
Returns a different `UPState` in which every value in updated_values.keys() is evaluated as his mapping
in new the `updated_values` dict and every other value is evaluated as in `self`.
:param updated_values: The dictionary that contains the `values` that need to be updated in the new `UPState`.
:return: The new `UPState` created.
"""
Worked perfectly. Thanks for all your help!
User Story
As a user who wants to track the execution of plans to see if any preconditions have been violated, I want the ability to easily check the (grounded) preconditions and effects of my actual action instances.
Basically, the workflow would be to iteratively
Acceptance Criteria
Additional Material
I am not sure if I'm duplicating functionality because I can't read the code/documentation correctly, but this worked for me for the first criterion:
I was able to hack around this with the following code:
This code would yield something like this:
I guess there are "Grounders" available in this library that appear to do the above, but they seem very heavyweight for what I'm trying to achieve.
Then, you could start with a specific state and apply the effects by doing:
Finally, you could validate the preconditions by checking whether the new state includes them.
Am I on the right track? Would this be useful?
Attention Points
N/A