Skip to content

Commit

Permalink
chore(up): improve cli tool for up testing.
Browse files Browse the repository at this point in the history
  • Loading branch information
arbimo committed Jan 24, 2024
1 parent 081eebb commit dbfc27c
Showing 1 changed file with 34 additions and 12 deletions.
46 changes: 34 additions & 12 deletions planning/unified/scripts/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
parser.add_argument("-m", "--mode", default="solve")
parser.add_argument("-o", "--outfile", default="/tmp/problem.upp")
parser.add_argument("--timeout", default="1800")
parser.add_argument('-f', '--from-file', action='store_true')
parser.add_argument("problem_name")


Expand All @@ -25,30 +26,51 @@


packages = ["builtin", "unified_planning.test"]
problem_test_cases = get_test_cases_from_packages(packages)


test_case = problem_test_cases[args.problem_name]
if args.from_file:
# reads from a protobuf file
with open(args.problem_name, "rb") as file:
content = file.read()
pb_msg = proto.Problem()
pb_msg.ParseFromString(content)
reader = ProtobufReader()
problem = reader.convert(pb_msg)
else:
problem_test_cases = get_test_cases_from_packages(packages)
test_case = problem_test_cases[args.problem_name]
problem = test_case.problem

if args.mode == "solve":
print("SOLVING")
# with OneshotPlanner(name=args.solver) as planner:
# result = planner.solve(test_case.problem, output_stream=sys.stdout)
#
# print(result)
with AnytimePlanner(name=args.solver) as planner:
for r in planner.get_solutions(test_case.problem, timeout=float(args.timeout), output_stream=sys.stdout):
print(r)
print("\n===================\n")

# print(result)
print(problem.kind)
print(problem)

plan = None
try:
with AnytimePlanner(name=args.solver) as planner:
for r in planner.get_solutions(problem, timeout=float(args.timeout), output_stream=sys.stdout):
print(r)
plan = r.plan
print("\n===================\n")
except AssertionError:
with OneshotPlanner(name=args.solver) as planner:
result = planner.solve(problem, output_stream=sys.stdout)
plan = result.plan
print(result)

with PlanValidator(problem_kind=problem.kind) as validator:
val_result = validator.validate(problem, plan)
print(val_result)

elif args.mode == "dump":
print(problem)
print(f"Dumping problem to {args.outfile}")
print(test_case.problem)

writer = ProtobufWriter()
msg = writer.convert(test_case.problem)
msg = writer.convert(problem)
with open(args.outfile, "wb") as file:
file.write(msg.SerializeToString())

Expand Down

0 comments on commit dbfc27c

Please sign in to comment.