# The solve uses the saved reduced matrix. This checker generates full exact # coefficients from the unchanged map with the separate stdlib checker model. import ast,hashlib,json,pathlib,sys,time,resource from common1133 import read,ROOT,SOURCE,RED_SHA,BASIS_SHA start=time.process_time();tag=sys.argv[2] if len(sys.argv)>2 else 'check' result={'ok':False} try: raw=pathlib.Path(sys.argv[1]).read_bytes();candidate=json.loads(raw) assert candidate['source_reduced_sha256']==RED_SHA and candidate['source_basis_sha256']==BASIS_SHA,'source digest' y=candidate['inequality_multipliers'];z=candidate['equality_multipliers'];den=candidate['denominator'] assert type(den) is int and den>0,'denominator' assert len(y)==5091 and len(z)==3939,'multiplier lengths' assert all(type(v) is int for v in y+z),'Python integer types' assert all(v>=0 for v in y),'inequality multiplier sign' C,B,F,e,b=read();v=y+z;assert all(v[i]==0 for i in F),'nonbasic lift' reduced=[-den*q for q in b] for i,j,a in e:reduced[i]+=a*v[B[j]] assert all(a==0 for a in reduced),'exact reduced residual' maps_path=ROOT/'in451'/'maps1086.json';map_raw=maps_path.read_bytes() MAP_SHA='ef8a0916df05899f858e69bb67fa0f292b41416614ef87ad2ee9a869dbd424a1' assert hashlib.sha256(map_raw).hexdigest()==MAP_SHA,'map digest' mapping=json.loads(map_raw);D=mapping['slots'];Q=mapping['Q'];H=mapping['anchors'];maps=mapping['phase_maps'] size={q:len(maps[str(q)]['representatives']) for q in Q};ordq=[q for q in Q if q not in H] checker=(SOURCE/'check1090.py').read_bytes();CHECK_SHA='a73e29212b0da4519d7024e8f19b8fd84c4fe555e37dceda8f231aa07da3655e' assert hashlib.sha256(checker).hexdigest()==CHECK_SHA,'full checker source digest' nodes=[n for n in ast.parse(checker).body if isinstance(n,ast.FunctionDef) and n.name in ['build_model','combined']] assert {n.name for n in nodes}=={'build_model','combined'} ns={'mapping':mapping,'D':D,'Q':Q,'H':H,'maps':maps,'size':size,'ordq':ordq} exec(compile(ast.Module(body=nodes,type_ignores=[]),'separate-stdlib-model-functions','exec'),ns) ncol,E,A,labels,cov=ns['build_model'](split=True) assert ncol==107572 and len(cov)==len(y) and len(labels)==len(z),'full model arity' # Check not only the candidate residual, but the supplied reduction/lift's # coefficient identity against the full independently generated model. ci={a:i for i,a in enumerate(C)};bi={a:i for i,a in enumerate(B)};expected={} def add(row,col,a): if row in ci and col in bi: key=(ci[row],bi[col]);expected[key]=expected.get(key,0)+a for r,c,a in A:add(c,r,a) for r,c,a in E:add(c,len(y)+r,a) norm=[i for i,L in enumerate(labels) if L[0] in ['normalization','normalization_copy']] for i in norm:add(ncol,len(y)+i,1) expected={k:a for k,a in expected.items() if a} assert expected=={(i,j):a for i,j,a in e},'saved reduction does not match full exact model' coef=ns['combined'](ncol,E,A,y,z);rhs=sum(z[i] for i in norm) assert rhs==den and rhs>0,'exact full RHS' assert max(coef)<=0,'full combined coefficient' result={'ok':True,'candidate_sha256':hashlib.sha256(raw).hexdigest(),'maps_sha256':MAP_SHA,'checker_model_sha256':CHECK_SHA, 'columns':ncol,'max_combined_coefficient':max(coef),'zero_columns':sum(a==0 for a in coef), 'negative_columns':sum(a<0 for a in coef),'normalization_multiplier_sum':rhs,'nonnegative_y':True, 'reduced_exact_residual':True,'saved_reduction_matches_full_model':True, 'scope':'exact frozen constructed relaxation only, map/model-to-cover premises remain conditional'} print('CHECK1133 PASS COLUMNS'+str(ncol)+' RHS_POSITIVE SIGN_PASS REDUCED_EXACT_FULL_MATCH') except (AssertionError,KeyError,ValueError,TypeError) as exc: result={'ok':False,'failure':str(exc)};print('CHECK1133 FAIL '+str(exc)) finally: (ROOT/f'{tag}-result1133.json').write_text(json.dumps(result,sort_keys=True,separators=(',',':'))+'\n') (ROOT/f'{tag}-receipt1133.json').write_text(json.dumps({'cpu_seconds':time.process_time()-start,'maxrss_bytes':resource.getrusage(resource.RUSAGE_SELF).ru_maxrss},sort_keys=True)+'\n') if not result['ok']:sys.exit(1)