Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Save before cleaning up threads #114

Merged
merged 1 commit into from
Dec 29, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions cozy/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,12 @@ def run():

start = datetime.datetime.now()

if not args.simple:
if args.simple:
if args.save:
with open(args.save, "wb") as f:
pickle.dump(ast, f)
print("Saved implementation to file {}".format(args.save))
else:
callback = None
server = None

Expand Down Expand Up @@ -146,16 +151,12 @@ def callback(impl):
ast,
timeout = datetime.timedelta(seconds=args.timeout),
progress_callback = callback,
improve_count=improve_count)
improve_count=improve_count,
dump_synthesized_in_file=args.save)

if server is not None:
server.join()

if args.save:
with open(args.save, "wb") as f:
pickle.dump(ast, f)
print("Saved implementation to file {}".format(args.save))

print("Generating IR...")
code = ast.code

Expand Down
13 changes: 12 additions & 1 deletion cozy/synthesis/high_level_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from typing import Callable, Any
import sys
import os
import pickle
from queue import Empty
from multiprocessing import Value

Expand Down Expand Up @@ -99,7 +100,8 @@ def improve_implementation(
impl : Implementation,
timeout : datetime.timedelta = datetime.timedelta(seconds=60),
progress_callback : Callable[[Implementation], Any] = None,
improve_count : Value = None) -> Implementation:
improve_count : Value = None,
dump_synthesized_in_file: str = None) -> Implementation:
"""Improve an implementation.

This function tries to synthesize a better version of the given
Expand All @@ -108,6 +110,10 @@ def improve_implementation(
If provided, progress_callback will be called whenever a better
implementation is found. It will be given the better implementation, which
it should not modify or cache.

If provided, the synthesized implementation will be dumped to dump_synthesized_in_file
before cleaning up the running threads when the loop terminates (because of time-outs etc.).
This is useful when thread that invokes Z3 is not responsive to cleanup.
"""

start_time = datetime.datetime.now()
Expand Down Expand Up @@ -241,6 +247,11 @@ def index_of(l, p):
else:
print(" (skipped; {} was aleady cleaned up)".format(q.name))

if dump_synthesized_in_file is not None:
with open(dump_synthesized_in_file, "wb") as f:
pickle.dump(impl, f)
print("Dumped implementation to file {}".format(dump_synthesized_in_file))

# stop jobs
print("Stopping jobs")
stop_jobs(list(improvement_jobs))
Expand Down