Manuscript En02-E@2 · En02-E-v2.tex · section · c2769986

Unexecuted reproducibility supplement

Unexecuted reproducibility supplement · lines 2173–2227

Back to manuscript

def solve_archived(problem,name,expressions): """Save raw variables/duals immediately, even if solving raises.""" need(problem.is_dcp(),"non-DCP problem "+name) options = "solver":"SCS","eps":1e-7,"max_iters":50000, "verbose":False,"warm_start":False error = None try: problem.solve(**options) except BaseException: error = traceback.format_exc() raise finally: arrays,missing = {},[] for key,expression in expressions.items(): value = expression.value if value is None: missing.append(key) else: arrays[key] = np.asarray(value) for i,c in enumerate(problem.constraints): if c.dual_value is not None: arrays["constraint_dual_"+str(i)] = np.asarray(c.dual_value) save(name+"_raw",**arrays) stats = problem.solver_stats info = {"name":name,"status":problem.status,"objective":problem.value, "options":options,"missing_values":missing,"exception":error, "solver_statistics":None if stats is None else "solver_name":stats.solver_name,"solve_time":stats.solve_time, "setup_time":stats.setup_time,"num_iters":stats.num_iters, "extra_stats":stats.extra_stats} jwrite(name+"_solve",info) DATA["solves"].append(info) dump() # Raw artifact is already durable before diagnostics or acceptance. diagnostics = [] for i,c in enumerate(problem.constraints): try: diagnostics.append("index":i,"violation":c.violation()) except Exception as e: diagnostics.append("index":i,"unavailable":repr(e)) jwrite(name+"_CVXPY_diagnostics",diagnostics) need(problem.status in ("optimal","optimal_inaccurate"),"solver status "+name) need(problem.value is not None and np.isfinite(problem.value),"objective "+name) for key,e in expressions.items(): need(e.value is not None and np.all(np.isfinite(e.value)), "missing/nonfinite "+name+" "+key) return float(problem.value)

def decoder_apply(R,N): b = len(N[0,0]) return (i,j):np.array([[np.trace( R[a*b:(a+1)*b,z*b:(z+1)*b]@N[i,j].T) for z in range(2)] for a in range(2)]) for i,j,E in units()

Nearby in this section