def run_grader(part_id): graded_funcs = { "r9hUX": Test_tf_constant, "kWeLo": Test_tf_square, "E1weD": Test_tf_reshape, "AuDvh": Test_tf_cast, "NI9Co": Test_tf_multiply, "Yz2KA": Test_tf_add, "4uBzv": Test_tf_gradient_tape } g_func = graded_funcs.get(part_id) if g_func is None: print_stderr("The partID provided did not correspond to any graded function.") return failed_cases, num_cases = g_func() score = 1.0 - len(failed_cases) / num_cases if failed_cases: failed_msg = "" for failed_case in failed_cases: failed_msg += f"Failed {failed_case.get('name')}.\nExpected:\n{failed_case.get('expected')},\nbut got:\n{failed_case.get('got')}.\n\n" send_feedback(score, failed_msg) else: send_feedback(score, "All tests passed! Congratulations!")
def run_grader(part_id): graded_funcs = { "xV8vX": Test_distribute_datasets, "dmTKR": Test_train_test_step_fns, "cst37": Test_distributed_train_test_step_fns } g_func = graded_funcs.get(part_id) if g_func is None: print_stderr( "The partID provided did not correspond to any graded function.") return try: failed_cases, num_cases = g_func() except: traceback.print_exc() send_feedback( 0.0, "There was a problem grading your submission. Check stderr for more details." ) exit() score = 1.0 - len(failed_cases) / num_cases if failed_cases: failed_msg = "" for failed_case in failed_cases: failed_msg += f"Failed {failed_case.get('name')}.\nExpected:\n{failed_case.get('expected')},\nbut got:\n{failed_case.get('got')}.\n\n" send_feedback(score, failed_msg) else: send_feedback(score, "All tests passed! Congratulations!")
def run_grader(part_id): graded_funcs = { "pxgPU": Test_map_fn, "fX2cS": Test_set_adam_optimizer, "M6COK": Test_set_sparse_cat_crossentropy_loss, "fbLog": Test_set_sparse_cat_crossentropy_accuracy, "FaW22": Test_prepare_dataset, "C8oAS": Test_train_one_step, "NG4Bn": Test_train } g_func = graded_funcs.get(part_id) if g_func is None: print_stderr( "The partID provided did not correspond to any graded function.") return failed_cases, num_cases = g_func() score = 1.0 - len(failed_cases) / num_cases if failed_cases: failed_msg = "" for failed_case in failed_cases: failed_msg += f"Failed {failed_case.get('name')}.\nExpected:\n{failed_case.get('expected')},\nbut got:\n{failed_case.get('got')}.\n\n" send_feedback(score, failed_msg) else: send_feedback(score, "All tests passed! Congratulations!")
def run_grader(part_id): graded_funcs = { "mylyu": Test_F1ScoreResult, "YQutN": Test_apply_gradients, "8dNmL": Test_train_data_for_one_epoch } g_func = graded_funcs.get(part_id) if g_func is None: print_stderr("The partID provided did not correspond to any graded function.") return failed_cases, num_cases = g_func() score = 1.0 - len(failed_cases) / num_cases if failed_cases: failed_msg = "" for failed_case in failed_cases: failed_msg += f"Failed {failed_case.get('name')}.\nExpected:\n{failed_case.get('expected')},\nbut got:\n{failed_case.get('got')}.\n\n" send_feedback(score, failed_msg) else: send_feedback(score, "All tests passed! Congratulations!")
def cell_output_pattern_matching(cell, patterns): if cell.get('cell_type') != 'code': err_msg = "evaluated cell is not a code cell." print_stderr(err_msg) return False, err_msg output_dict = cell.get('outputs')[0] if output_dict.get('ename'): return False, 'cell has errors.' if output_dict.get('name'): output_txt = output_dict.get('text') for line in output_txt: missing_patterns = [k for k, v in patterns.items() if not v] for mp in missing_patterns: if mp in line: patterns.update({mp: True}) if not all(patterns.values()): return False, "missing patterns." return True, "passed!"
"mylyu": Test_F1ScoreResult, "YQutN": Test_apply_gradients, "8dNmL": Test_train_data_for_one_epoch } g_func = graded_funcs.get(part_id) if g_func is None: print_stderr("The partID provided did not correspond to any graded function.") return failed_cases, num_cases = g_func() score = 1.0 - len(failed_cases) / num_cases if failed_cases: failed_msg = "" for failed_case in failed_cases: failed_msg += f"Failed {failed_case.get('name')}.\nExpected:\n{failed_case.get('expected')},\nbut got:\n{failed_case.get('got')}.\n\n" send_feedback(score, failed_msg) else: send_feedback(score, "All tests passed! Congratulations!") if __name__ == "__main__": try: part_id = sys.argv[2] except IndexError: print_stderr("Missing partId. Required to continue.") send_feedback(0.0, "Missing partId.") else: run_grader(part_id)
import ast import types import sys import converter from tools import print_stderr # Learner Block with open("submission/submission.py") as f: try: learner_py = ast.parse(f.read()) except SyntaxError: print_stderr( "The notebook you provided has a syntax error that prevents it from compiling." ) exit() for node in learner_py.body[:]: if not isinstance( node, (ast.FunctionDef, ast.Import, ast.ImportFrom, ast.ClassDef)): learner_py.body.remove(node) learner_module = types.ModuleType("learner_mod") learner_code = compile(learner_py, "learner_mod.py", 'exec') sys.modules["learner_mod"] = learner_module exec(learner_code, learner_module.__dict__) # Solution Block with open("solution/solution.py") as f: solution_py = ast.parse(f.read()) for node in solution_py.body[:]: