Skip to content

Commit

Permalink
Fix some processing issues
Browse files Browse the repository at this point in the history
  • Loading branch information
cgokmen committed Jan 14, 2025
1 parent 661ec70 commit 2f10173
Showing 1 changed file with 22 additions and 8 deletions.
30 changes: 22 additions & 8 deletions bddl/knowledge_base/processing.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,8 +294,6 @@ def create_tasks(self):
synset.is_used_as_non_substance = synset.is_used_as_non_substance or is_used_as_non_substance
synset.is_used_as_fillable = synset.is_used_as_fillable or is_used_as_fillable
synset_used_predicates = object_used_predicates(combined_conds, synset_name)
if not synset_used_predicates:
self.debug_print(f"Synset {synset_name} is not used in any predicate in {task_name}")
for predicate in synset_used_predicates:
pred_obj, _ = Predicate.get_or_create(name=predicate)
if pred_obj not in synset.used_in_predicates:
Expand All @@ -310,15 +308,19 @@ def create_tasks(self):
if "future" not in initial_preds:
self.debug_print(f"Synset {synset_name} is not used as future in initial in {task_name}")
if "real" in initial_preds:
self.debug_print(f"Synset {synset_name} is used as real in initial in {task_name}")
raise ValueError(f"Synset {synset_name} is used as real in initial in {task_name}")

goal_preds = object_used_predicates(goal_conds, synset_name)
if "real" not in goal_preds:
self.debug_print(f"Synset {synset_name} is not used as real in goal in {task_name}")
if "future" in goal_preds:
self.debug_print(f"Synset {synset_name} is used as future in goal in {task_name}")
raise ValueError(f"Synset {synset_name} is used as future in goal in {task_name}")

task.future_synsets.add(synset)
# We only add it if it's used in the initial predicates. Sometimes things will be real()
# in the goal but they will already exist in the initial, and the real is just being
# used to say that the object is not entirely used up during the transition.
if "future" in initial_preds:
task.future_synsets.add(synset)

# generate room requirements for task
room_synset_requirements = defaultdict(Counter) # room[synset] = count
Expand All @@ -340,7 +342,8 @@ def create_transitions(self):
json_paths = glob.glob(str(GENERATED_DATA_DIR / "transition_map/tm_jsons/*.json"))
transitions = []
for jp in json_paths:
if "washer" in jp:
# This file is in a different format and not relevant.
if jp.endswith("washer.json"):
continue
with open(jp) as f:
transitions.extend(json.load(f))
Expand All @@ -349,11 +352,22 @@ def create_transitions(self):
for transition_data in self.tqdm(transitions):
rule_name = transition_data["rule_name"]
transition = TransitionRule.create(name=rule_name)

# Add the default inputs and outputs
inputs = set(transition_data["input_synsets"].keys())
assert inputs, f"Transition {transition.name} has no inputs!"
outputs = set(transition_data["output_synsets"].keys())

# Add the washer rules' washed item both to inputs and outputs
if "washed_item" in transition_data:
washed_items = set(transition_data["washed_item"].keys())
inputs.update(washed_items)
outputs.update(washed_items)

assert inputs, f"Transition {transition.name} has no inputs!"
assert outputs, f"Transition {transition.name} has no outputs!"
assert inputs & outputs == set(), f"Inputs and outputs of {transition.name} overlap!"
# TODO: With washer rules, this is no longer true. Check if this is important
# assert inputs & outputs == set(), f"Inputs and outputs of {transition.name} overlap!"

for synset_name in inputs:
synset = Synset.get(name=synset_name)
transition.input_synsets.add(synset)
Expand Down

0 comments on commit 2f10173

Please sign in to comment.