Skip to content
Snippets Groups Projects
Commit 52c25ef5 authored by tuhe's avatar tuhe
Browse files

Update with new norm test and easier pre-computed test building

parent b6ead38d
No related branches found
No related tags found
No related merge requests found
...@@ -23,8 +23,13 @@ def cache_read(file_name): ...@@ -23,8 +23,13 @@ def cache_read(file_name):
import compress_pickle # Import here because if you import in top the __version__ tag will fail. import compress_pickle # Import here because if you import in top the __version__ tag will fail.
# file_name = cn_(file_name) if cache_prefix else file_name # file_name = cn_(file_name) if cache_prefix else file_name
if os.path.exists(file_name): if os.path.exists(file_name):
try:
with open(file_name, 'rb') as f: with open(file_name, 'rb') as f:
return compress_pickle.load(f, compression="lzma") return compress_pickle.load(f, compression="lzma")
except Exception as e:
print("Tried to load a bad pickle file at", file_name)
print("If the file appears to be automatically generated, you can try to delete it, otherwise download a new version")
print(e)
# return pickle.load(f) # return pickle.load(f)
else: else:
return None return None
......
No preview for this file type
No preview for this file type
No preview for this file type
...@@ -94,6 +94,17 @@ class QItem(unittest.TestCase): ...@@ -94,6 +94,17 @@ class QItem(unittest.TestCase):
if self.title is None: if self.title is None:
self.title = self.name self.title = self.name
def assertNorm(self, computed, expected, tol=None):
if tol == None:
tol = self.tol
diff = np.abs( (np.asarray(computed).flat- np.asarray(expected)).flat )
nrm = np.sum( diff ** 2)
if nrm > tol:
print(f"Not equal within tolerance {tol}; norm of difference was {nrm}")
print(f"Element-wise differences {diff.tolist()}")
self.assertEqual(computed, expected, msg=f"Not equal within tolerance {tol}")
def assertL2(self, computed, expected, tol=None): def assertL2(self, computed, expected, tol=None):
if tol == None: if tol == None:
tol = self.tol tol = self.tol
...@@ -332,24 +343,46 @@ class ActiveProgress(): ...@@ -332,24 +343,46 @@ class ActiveProgress():
self.t = t self.t = t
self._running = False self._running = False
self.title = title self.title = title
self.dt = 0.1
self.n = int(np.round(self.t / self.dt))
# self.pbar = tqdm.tqdm(total=self.n)
if start: if start:
self.start() self.start()
def start(self): def start(self):
self._running = True self._running = True
self.thread = threading.Thread(target=self.run, args=(10,)) self.thread = threading.Thread(target=self.run)
self.thread.start() self.thread.start()
def terminate(self): def terminate(self):
self._running = False self._running = False
self.thread.join() self.thread.join()
if hasattr(self, 'pbar') and self.pbar is not None:
self.pbar.update(1)
self.pbar.close()
self.pbar=None
sys.stdout.flush() sys.stdout.flush()
def run(self, n): def run(self):
dt = 0.1 self.pbar = tqdm.tqdm(total=self.n, file=sys.stdout, position=0, leave=False, desc=self.title, ncols=100,
bar_format='{l_bar}{bar}| [{elapsed}<{remaining}]') # , unit_scale=dt, unit='seconds'):
n = int(np.round(self.t/dt)) for _ in range(self.n-1): # Don't terminate completely; leave bar at 99% done until terminate.
for _ in tqdm.tqdm(range(n), file=sys.stdout, position=0, leave=False, desc=self.title, ncols=100, bar_format='{l_bar}{bar}| [{elapsed}<{remaining}]'): #, unit_scale=dt, unit='seconds'):
if not self._running: if not self._running:
self.pbar.close()
self.pbar = None
break break
time.sleep(dt)
\ No newline at end of file time.sleep(self.dt)
self.pbar.update(1)
# if self.pbar is not None:
# self.pbar.close()
# self.pbar = None
# for _ in tqdm.tqdm(range(n), file=sys.stdout, position=0, leave=False, desc=self.title, ncols=100, bar_format='{l_bar}{bar}| [{elapsed}<{remaining}]'): #, unit_scale=dt, unit='seconds'):
...@@ -76,10 +76,12 @@ def evaluate_report_student(report, question=None, qitem=None, unmute=None, pass ...@@ -76,10 +76,12 @@ def evaluate_report_student(report, question=None, qitem=None, unmute=None, pass
table = table_data table = table_data
print(tabulate(table)) print(tabulate(table))
print(" ") print(" ")
print("Note your results have not yet been registered. \nTo register your results, please run the file:")
fr = inspect.getouterframes(inspect.currentframe())[1].filename fr = inspect.getouterframes(inspect.currentframe())[1].filename
print(">>>", os.path.basename(fr)[:-3] + "_grade.py") gfile = os.path.basename(fr)[:-3] + "_grade.py"
if os.path.exists(gfile):
print("Note your results have not yet been registered. \nTo register your results, please run the file:")
print(">>>", gfile)
print("In the same manner as you ran this file.") print("In the same manner as you ran this file.")
return results return results
...@@ -133,7 +135,6 @@ def evaluate_report(report, question=None, qitem=None, passall=False, verbose=Fa ...@@ -133,7 +135,6 @@ def evaluate_report(report, question=None, qitem=None, passall=False, verbose=Fa
start = time.time() start = time.time()
cc = None cc = None
if show_progress_bar: if show_progress_bar:
# cc.start() # cc.start()
cc = ActiveProgress(t=q.estimated_time, title=q_title_print) cc = ActiveProgress(t=q.estimated_time, title=q_title_print)
...@@ -143,12 +144,12 @@ def evaluate_report(report, question=None, qitem=None, passall=False, verbose=Fa ...@@ -143,12 +144,12 @@ def evaluate_report(report, question=None, qitem=None, passall=False, verbose=Fa
q.init() # Initialize the question. Useful for sharing resources. q.init() # Initialize the question. Useful for sharing resources.
if show_progress_bar: if show_progress_bar:
cc.terminate() cc.terminate()
sys.stdout.flush()
print(q_title_print, end="") print(q_title_print, end="")
q.has_called_init_ = True q.has_called_init_ = True
q_time =np.round( time.time()-start, 2) q_time =np.round( time.time()-start, 2)
print(" "* max(0,nL - len(q_title_print) ) + " (" + str(q_time) + " seconds)") # if q.name in report.payloads else "") print(" "* max(0,nL - len(q_title_print) ) + " (" + str(q_time) + " seconds)") # if q.name in report.payloads else "")
print("=" * nL) print("=" * nL)
...@@ -159,7 +160,6 @@ def evaluate_report(report, question=None, qitem=None, passall=False, verbose=Fa ...@@ -159,7 +160,6 @@ def evaluate_report(report, question=None, qitem=None, passall=False, verbose=Fa
cc = ActiveProgress(t=item.estimated_time, title=item_title_print) cc = ActiveProgress(t=item.estimated_time, title=item_title_print)
else: else:
print(item_title_print + ( '.'*max(0, nL-4-len(ss)) ), end="") print(item_title_print + ( '.'*max(0, nL-4-len(ss)) ), end="")
hidden = issubclass(item.__class__, Hidden) hidden = issubclass(item.__class__, Hidden)
# if not hidden: # if not hidden:
# print(ss, end="") # print(ss, end="")
......
__version__ = "0.1.3" __version__ = "0.1.4"
\ No newline at end of file \ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment