Skip to content

Commit 7219b9a

Browse files
committed
have state
1 parent d59eba1 commit 7219b9a

File tree

3 files changed

+37
-8
lines changed

3 files changed

+37
-8
lines changed
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"outputs": [],
1010
"source": [
1111
"# Please run this cell first.\n",
12-
"from study.study import next_puzzle, cur_puzzle, puzzle, give_up"
12+
"from demo.demo import next_puzzle, cur_puzzle, puzzle, give_up"
1313
]
1414
},
1515
{
@@ -18,13 +18,13 @@
1818
"source": [
1919
"# Instructions\n",
2020
"\n",
21-
"* This notebook is simulating the study used for the [Programming Puzzles](https://arxiv.org/abs/2106.05784) paper (with some modifications to run locally).\n",
21+
"* This notebook is a demo simulating the study used for the [Programming Puzzles](https://arxiv.org/abs/2106.05784) paper (with some modifications to run locally).\n",
2222
"* Visit our repository to explore the full dataset and contribute new puzzles: https://github.com/microsoft/PythonProgrammingPuzzles \n",
2323
"\n",
2424
"## Overview\n",
2525
"\n",
2626
"\n",
27-
"* The first 3 problems are \"practice\" and the time you take will not be used in the study. This is a good chance to see how the system works.\n",
27+
"* The first 3 problems are \"practice\" and the time you take will not be counted. This is a good chance to see how the system works.\n",
2828
"* Puzzles are defined by `def puzzle(...)`. For each puzzle, you will try to find an input `x` which makes `puzzle(x)` return `True`.\n",
2929
"* Type `next_puzzle()` when you are ready to start the first problem or to advance to the next problem.\n",
3030
"* There is **no option to revisit a puzzle** and once you call `next_puzzle()` the clock starts ticking (you have up to 6 minutes per puzzle).\n",
Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import ipywidgets as widgets
33
from IPython.display import clear_output, display, Markdown, Javascript
44
import IPython
5-
from study import study_puzzles
5+
from demo import study_puzzles
66

77
from typing import List, Set, Tuple, Callable
88
import inspect
@@ -18,11 +18,13 @@
1818
from tempfile import TemporaryDirectory
1919

2020

21-
IPYNP_FILE = 'Study.ipynb'
21+
IPYNP_FILE = 'Demo.ipynb'
2222
LOCAL = True
2323

24-
temp_dir = TemporaryDirectory() # local version. Will create a new dir each time so it's not stateful...
25-
out_dir = temp_dir.name
24+
#temp_dir = TemporaryDirectory() # local version. Will create a new dir each time so it's not stateful...
25+
#out_dir = temp_dir.name
26+
out_dir = "state"
27+
os.makedirs(out_dir, exist_ok=True)
2628
log_path = os.path.join(out_dir, 'run.log')
2729

2830
logger = logging.getLogger(__name__)
@@ -72,7 +74,7 @@ def update_progress_bar():
7274

7375

7476
# globals
75-
STATE_FILENAME = os.path.join(out_dir, "study_results.pkl")
77+
STATE_FILENAME = os.path.join(out_dir, "state.pkl")
7678

7779
state = None # set by load_state function
7880
__puzzle__ = None # set by next_puzzle function
@@ -190,6 +192,7 @@ def cur_puzzle(reload_state=True):
190192
load_state()
191193
if state.cur is None:
192194
print(f"All parts complete!")
195+
print_solving_times()
193196
return
194197

195198
if state.cur.start_time is None or state.cur.solve_time is not None or state.cur.give_up_time is not None:
@@ -235,6 +238,27 @@ def reset_widgets(): # close existing widgets
235238
logger.error("reset_widgets exception")
236239

237240

241+
def print_solving_times():
242+
print("=" * 10)
243+
print('Check our "Programming Puzzles" paper (section 5.1) to see how difficult GPT-3 and others found each puzzle to be: https://arxiv.org/abs/2106.05784')
244+
print("=" * 10)
245+
print("Your solving times:")
246+
for i, puz in enumerate(state.puzzles):
247+
if i < 3:
248+
# Warmup.
249+
continue
250+
251+
if state.cur is not None and state.cur.num < puz.num:
252+
return
253+
254+
if puz.solve_time:
255+
elapsed = puz.solve_time - puz.start_time
256+
time_str = time.strftime("%M:%S", time.gmtime(elapsed))
257+
print(f"Puzzle {puz.num - 2}: {time_str} seconds")
258+
else:
259+
print(f"Puzzle {puz.num - 2}: Unsolved")
260+
261+
238262
def check_finished_part():
239263
if state.cur is None:
240264
cur_puzzle(reload_state=False)
@@ -246,6 +270,11 @@ def check_finished_part():
246270
else:
247271
if state.cur.part != state.puzzles[state.cur.num + 1].part:
248272
print(f"Finished {state.cur.part}!!!")
273+
print("Continue to the next part when you are ready.")
274+
if state.cur.part != "WARM UP": # Warmup
275+
print_solving_times()
276+
else:
277+
print("You will get a summary of your solving times after each part.")
249278
state.cur = state.puzzles[state.cur.num + 1]
250279
save_state()
251280
return True

0 commit comments

Comments
 (0)