Skip to content

Commit

Permalink
get rid of interim stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
sanjanasrivastava committed Oct 23, 2023
1 parent b7f39f6 commit 567c2ce
Show file tree
Hide file tree
Showing 77 changed files with 3 additions and 2,058 deletions.
154 changes: 3 additions & 151 deletions tests/bddl_tests.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import json
import os
import sys
# from bddl.bddl_verification import *
import bddl.bddl_verification as ver
import bddl.parsing as parse

Expand All @@ -28,13 +27,10 @@ def verify_definition(activity, syns_to_props, domain_predicates, csv=False):
ver.no_substances_with_multiple_instances(objects, syns_to_props)
ver.agent_present(init)
ver.problem_name_correct(activity)
if csv:
no_filled_in_tm_recipe_goal(activity)
sync_csv(activity)


# Master planning sheet
def batch_verify_all(csv=False):
def batch_verify():
with open(ver.SYNS_TO_PROPS_JSON, "r") as f:
syns_to_props = json.load(f)
*__, domain_predicates = parse.parse_domain("omnigibson")
Expand All @@ -43,159 +39,15 @@ def batch_verify_all(csv=False):
if not os.path.isdir(os.path.join(ver.PROBLEM_FILE_DIR, activity)): continue
print()
print(activity)
if os.path.exists(os.path.join(ver.CSVS_DIR, activity + ".csv")):
try:
verify_definition(activity, syns_to_props, domain_predicates, csv=csv)
except FileNotFoundError:
print()
print("file not found for", activity)
continue
except AssertionError as e:
print()
print(activity)
print(e)
to_continue = input("continue? y/n: ")
while to_continue != "y":
to_continue = input("continue? y/n: ")
continue
else:
verify_definition(activity, syns_to_props, domain_predicates, csv=False)


def unpack_nested_lines(sec):
'''
takes in a list of lines such as init or goal
returns non-nested sublines (i.e. unpacks forall statements, or statements, etc.) that describe object(s)
does not preserve order, because order doesn't matter when scanning through all lines
'''
lines = sec.copy()
res = []
while lines:
line = lines.pop(0)

if type(line[1]) is list:
for subline in line[1:]:
if len(subline) >= 2 and '-' not in subline:
lines.append(subline)
else:
res.append(line)

return res


# Transition maps

def no_filled_in_tm_recipe_goal(activity):
defn_fn = os.path.join(ver.PROBLEM_FILE_DIR, activity, "problem0.bddl")
with open(defn_fn, "r") as f:
defn = f.read()
goal_section = defn.split(":goal")[-1]
assert "filled" not in goal_section, "filled in TM BDDL :goal"

csv = os.path.join(ver.CSVS_DIR, activity + ".csv")
with open(csv, "r") as f:
lines = list(f.readlines())
container_lines = [lines[i + 1] for i in range(len(lines) - 1) if "container," in lines[i]]
for container_line in container_lines:
assert "filled" not in container_line, f"filled in TM CSV container line: {container_line}"


def sync_csv(activity):
csv = os.path.join(ver.CSVS_DIR, activity + ".csv")

csv_objs = set()
bddl_objs = set()
bddl_ignore = set()

with open(csv) as f:
output_objs = []
output_flag = False
for row in f:
first = row.split(',')[0]
# collect output objects
# remove if they weren't the last step
if first == 'output-objects':
output_flag = True
# removing objects here allows us to exclude input objects which are outputs of the previous step
csv_objs.difference_update(output_objs)
output_objs = []
if '.n.' in first:
csv_objs.add(first)
if output_flag == True:
output_objs.append(first)
if first == "tool":
output_flag = False

csv_objs.discard('')

__, objects, init, _ = _get_defn_elements_from_file(activity)
bddl_objs, _ = _get_objects_from_object_list(objects)
for literal in init:
formula = literal[1] if literal[0] == "not" else literal
#things to ignore
if formula[0] in ["insource", "filled"]:
bddl_ignore.add(formula[1])
things_to_ignore = [
# can't put jar here because sometimes output container is a mason_jar
"countertop",
"bottle",
"sack",
"agent.n.01",
"floor.n.01",
"electric_refrigerator.n.01",
"cabinet.n.01",
"tupperware.n.01"
]
for obj in list(bddl_objs):
for thing in things_to_ignore:
if thing in obj:
bddl_objs.remove(obj)

bddl_objs = bddl_objs - bddl_ignore

assert len(csv_objs - bddl_objs) == 0 and len(bddl_objs - csv_objs) == 0, f"Items in csv but not bddl: {csv_objs - bddl_objs} \nItems in bddl but not csv: {bddl_objs - csv_objs}"


def batch_sync_csv():
for fname in os.listdir(ver.CSVS_DIR):
activity = fname[:-len(".csv")]
print()
print(activity)
try:
sync_csv(activity)
except FileNotFoundError:
print()
print("file not found for", activity)
continue
except AssertionError as e:
print()
print(activity)
print(e)
to_continue = input("continue? y/n: ")
while to_continue != "y":
to_continue = input("continue? y/n: ")
continue

verify_definition(activity, syns_to_props, domain_predicates, csv=False)


def main():
if sys.argv[1] == "verify":
verify_definition(sys.argv[2])

elif sys.argv[1] == "verify_csv":
verify_definition(sys.argv[2], csv=True)

elif sys.argv[1] == "batch_verify":
batch_verify_all()

elif sys.argv[1] == "batch_verify_csv":
batch_verify_all(csv=True)

elif sys.argv[1] == "sync_csv":
sync_csv(sys.argv[2])

elif sys.argv[1] == "batch_sync_csv":
batch_sync_csv()
batch_verify()


if __name__ == "__main__":
Expand Down
Loading

0 comments on commit 567c2ce

Please sign in to comment.