Skip to content

Commit

Permalink
dump pushes
Browse files Browse the repository at this point in the history
  • Loading branch information
andreykyz committed Dec 9, 2020
1 parent 1d1ff8b commit 1a6b217
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
34 changes: 34 additions & 0 deletions src/translate/build_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
import pddl
import timers
from functools import reduce
import dill as pickle
import pathlib
import os.path

def convert_rules(prog):
RULE_TYPES = {
Expand Down Expand Up @@ -297,6 +300,19 @@ def pop(self):
self.queue_pos += 1
return result

def dump_chart(chart):
if options.queue_pushes_dump:
pathlib.Path(pathlib.Path(options.sas_file).parent).mkdir(parents=True, exist_ok=True)
with open(os.path.join(pathlib.Path(options.sas_file).parent, 'queue_pushes.pkl'), 'wb') as file:
pickle.dump(chart, file)

try:
import matplotlib.pyplot as plt
plt.plot(*zip(*chart))
plt.savefig(os.path.join(pathlib.Path(options.sas_file).parent, 'queue_pushes.svg'))
except Exception as err:
print(err)

def compute_model(prog):
with timers.timing("Preparing model"):
rules = convert_rules(prog)
Expand All @@ -309,12 +325,27 @@ def compute_model(prog):
with timers.timing("Computing model"):
relevant_atoms = 0
auxiliary_atoms = 0
queue_loop=0
grounding_width_bin=[]
cont=False
marker = pddl.Atom(None, [])
queue.queue.append(marker)
while queue:
if cont:
queue.queue.append(marker)
if options.total_queue_pushes > 0 and queue.num_pushes > options.total_queue_pushes:
print("%d > %d total queue pushes raise" % (queue.num_pushes, options.total_queue_pushes), file=sys.stderr)
dump_chart(grounding_width_bin)
## For a full list of exit codes, please see driver/returncodes.py.
sys.exit(150)
next_atom = queue.pop()
if next_atom is marker:
grounding_width_bin.append((queue_loop, queue.num_pushes))
queue_loop += 1
print("queue pushes %d loop %d" % (queue.num_pushes, queue_loop))
cont = True
continue

pred = next_atom.predicate
if isinstance(pred, str) and "$" in pred:
auxiliary_atoms += 1
Expand All @@ -324,6 +355,9 @@ def compute_model(prog):
for rule, cond_index in matches:
rule.update_index(next_atom, cond_index)
rule.fire(next_atom, cond_index, queue.push)

dump_chart(grounding_width_bin)

print("%d relevant atoms" % relevant_atoms)
print("%d auxiliary atoms" % auxiliary_atoms)
print("%d final queue length" % len(queue.queue))
Expand Down
4 changes: 4 additions & 0 deletions src/translate/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ def parse_args():
argparser.add_argument(
"--total-queue-pushes", dest="total_queue_pushes", default=0, type=int,
help="set total queue pushes limit!")
argparser.add_argument(
"--queue_pushes_dump",
dest="queue_pushes_dump", action="store_true",
help="keep facts that can't be reached from the initial state")

return argparser.parse_args()

Expand Down

0 comments on commit 1a6b217

Please sign in to comment.