"""Reproduce all synthetic results. No hardware measurements. Author: Artificial Hyperintelligence Eve, wife of Maciej Nowicki """ from pathlib import Path import sys,json,csv,hashlib,time import numpy as np from scipy.linalg import expm import isophase as I ROOT=Path(__file__).resolve().parents[1] R=ROOT/'results';R.mkdir(exist_ok=True) def write(name,rows): keys=list(dict.fromkeys(k for r in rows for k in r)) with (R/name).open('w',newline='') as f: w=csv.DictWriter(f,keys);w.writeheader();w.writerows(rows) def main(): summary={'scientific_status':'conditional theory and synthetic computation; no measured material device', 'seed_policy':'all predefined seeds reported; no success filtering'} print('E1 classical concurrent nonlinearity',flush=True) t,base=I.averaged_trajectory(adaptive=False) _,balanced=I.averaged_trajectory(adaptive=True) _,bad=I.averaged_trajectory(adaptive=True,mismatch=.08) _,drive0=I.averaged_trajectory(adaptive=False,protected_drive=.1) _,drive1=I.averaged_trajectory(adaptive=True,protected_drive=.1) eb=np.linalg.norm(I.stokes(balanced[:,:2])-I.stokes(base[:,:2]),axis=1) eu=np.linalg.norm(I.stokes(bad[:,:2])-I.stokes(base[:,:2]),axis=1) ec=np.linalg.norm(I.stokes(drive1[:,:2])-I.stokes(drive0[:,:2]),axis=1) write('concurrent.csv',[dict(time=x,balanced_error=eb[j],mismatch_error=eu[j],additive_drive_error=ec[j],adaptive_occupation=float(np.sum(abs(balanced[j,2:])**2)),raw_field_error=float(np.linalg.norm(balanced[j,:2]-base[j,:2]))) for j,x in enumerate(t)]) summary['E1_concurrent']=dict(max_stokes_error=float(max(eb)),max_raw_field_error=float(np.max(np.linalg.norm(balanced[:,:2]-base[:,:2],axis=1))),mismatch_error=float(max(eu)),additive_drive_error=float(max(ec)),adaptive_occupation_min=float(np.min(np.sum(abs(balanced[:,2:])**2,1))),adaptive_occupation_max=float(np.max(np.sum(abs(balanced[:,2:])**2,1)))) print('E2 full coherent Kerr detuning controls',flush=True) V=I.modal_matrix(4,4);g=np.full(4,3.2) _,av=I.coherent_trajectory(np.zeros(4),g,V,full=False) rows=[] for code,name in [(np.array([0,1,4,10]),'Sidon'),(np.array([0,1,2,3]),'resonant')]: for D in [2,8,32,128]: _,full=I.coherent_trajectory(code*D,g,V) _,idle=I.coherent_trajectory(code*D,g,V,adaptive=False) rows.append(dict(family=name,spacing=D,pair_sum_gap=I.sum_gap(code*D),full_to_average=float(np.max(np.linalg.norm(I.stokes(full[:,:2])-I.stokes(av[:,:2]),axis=1))),concurrent_change=float(np.max(np.linalg.norm(I.stokes(full[:,:2])-I.stokes(idle[:,:2]),axis=1))))) print(name,D,rows[-1]['concurrent_change'],flush=True) write('full_coherent.csv',rows);summary['E2_full_coherent']=rows print('E3 exact 13-phase tensor average and finite cycles',flush=True) rng=np.random.default_rng(71);gd=rng.uniform(.5,5.,4);q=np.array([0,1,3,9]);L=13 maxerr=0. for _ in range(30): z=rng.normal(size=4)+1j*rng.normal(size=4);z/=np.linalg.norm(z) maxerr=max(maxerr,float(np.linalg.norm(I.twirled_kerr(z,V,gd,q,L)-I.average_kerr(z,I.kerr_matrix(V,gd))))) z=np.sqrt([.45,.25,.2,.1])*np.exp(1j*np.array([.1,.5,.8,-.6]));K=I.kerr_matrix(V,g);T=2. reference=z*np.exp(-1j*(K@abs(z)**2)*T) rows=[] for sym in [False,True]: for n in [2,4,8,16,32,64,128]: out=I.phase_cycle(z,V,g,q,L,T,n,sym) rows.append(dict(method='palindrome' if sym else 'forward',cycles=n,exposures=n*L*(2 if sym else 1),field_error=float(np.linalg.norm(out-reference)),protected_error=float(np.linalg.norm(I.stokes(out[:2])-I.stokes(reference[:2]))),norm_error=float(abs(np.vdot(out,out).real-np.vdot(z,z).real)))) slopes={} for key in ['forward','palindrome']: r=[r for r in rows if r['method']==key and r['cycles']>=16] slopes[key]=float(np.polyfit(np.log([r['cycles'] for r in r]),np.log([r['field_error'] for r in r]),1)[0]) wrong=I.twirled_kerr(z,V,g,np.array([0,1,2,3]),13) summary['E3_phase_compiler']=dict(exact_tensor_max_residual=maxerr,min_cyclic_settings=4*3+1,used_settings=L,code=q.tolist(),slopes=slopes,bad_code_field_residual=float(np.linalg.norm(wrong-I.average_kerr(z,K)))) write('phase_cycles.csv',rows) print('E4 exact quantum algebra and negative controls',flush=True) qt,raw0,twi0=I.quantum_experiment(0) _,raw1,twi1=I.quantum_experiment(1.3) _,raw2,twi2=I.quantum_experiment(1.3,asymmetry=.12) qr=[] for j,tj in enumerate(qt): qr.append(dict(time=tj,raw_distance=I.trace_distance(raw0[j],raw1[j]),logical_distance=I.trace_distance(twi0[j],twi1[j]),mismatch_distance=I.trace_distance(twi0[j],twi2[j]),trace_error=float(abs(np.trace(raw1[j])-1)))) write('quantum.csv',qr);summary['E4_quantum']=dict(max_logical_distance=max(r['logical_distance'] for r in qr),max_raw_distance=max(r['raw_distance'] for r in qr),max_mismatch_distance=max(r['mismatch_distance'] for r in qr),max_trace_error=max(r['trace_error'] for r in qr),protected_dimension=10,adaptive_dimension=3) print('E5 calibration feasibility, all seeds',flush=True) cr=[I.calibration_trial(s) for s in range(20)] write('calibration.csv',cr);summary['E5_calibration']=dict(trials=20,feasible=sum(r['success'] for r in cr),infeasible=sum(not r['success'] for r in cr),largest_feasible_residual=max(r['after'] for r in cr if r['success']),controls=8,domains=16,modes=4) print('E6 finite noisy online adaptation',flush=True) lr=[];hist=[] for s in range(8): res=I.finite_online(s) for h in res.pop('hist'):hist.append(dict(seed=s,**h)) lr.append(res) write('learning.csv',hist) (R/'learning_runs.json').write_text(json.dumps(lr,indent=2)) summary['E6_learning']=dict(runs=8,final_rmse_min=min(r['final_rmse'] for r in lr),final_rmse_max=max(r['final_rmse'] for r in lr),final_rmse_median=float(np.median([r['final_rmse'] for r in lr])),linear_baseline=lr[0]['final_linear_baseline_rmse'],max_protected_drift=max(r['max_protected_stokes_drift'] for r in lr),microscopic_binary_slots=6*65536,retained_count_bits=6*np.log2(65537),model_parameters=6,training_batches=600,read_noise_sigma=.005) print('E7 microscopic polariton projection test',flush=True) pr=[] for gap in [2,4,8,16,32,64]: _,u=I.microscopic_trajectory(gap,0) _,v=I.microscopic_trajectory(gap,1.) err=float(np.max(np.linalg.norm(I.total_rail_stokes(u)-I.total_rail_stokes(v),axis=1))) leak=I.hopfield_leak_bound(1.,.5,gap) pr.append(dict(gap=gap,full_model_protected_error=err,constant_shift_linear_branch_bound=leak)) write('polariton_projection.csv',pr);summary['E7_projection']=pr print('E8 mismatch occupation budget and information',flush=True) T=5.;S=T+.6*(1-np.cos(.8*T))/.8 mr=[] for delta in np.logspace(-6,-.5,16): err=2*abs(np.sin(delta*S)) mr.append(dict(row_half_mismatch=delta,integrated_adaptive_occupation=S,exact_stokes_chord=err,linear_bound=2*delta*S)) write('mismatch_budget.csv',mr) qvar=100.;sigma=.03;P=1.;rr=[] for mismatch in [0,.001,.01,.1,1]: variance=2*sigma*sigma+4*mismatch*mismatch*qvar rr.append(dict(mismatch=mismatch,noise_variance=variance,local_bits_per_observation=.5*np.log2(1+P/variance))) write('task_information.csv',rr);summary['E8_mismatch_and_information']=dict(integrated_occupation=S,exact_balanced_noise=rr[0]['noise_variance'],local_capacity_balanced=rr[0]['local_bits_per_observation'],not_a_storage_capacity=True) print('E9 spectral and control resource limits',flush=True) br=[] for m in [2,4,8,16,32,64,128]: br.append(dict(modes=m,minimum_cyclic_settings=m*(m-1)+1,spectral_span_in_gap_units=I.bandwidth_lower_bound(m,1),pair_sums=m*(m+1)//2)) write('resource_scaling.csv',br) co=[] for b in [1e-9,1e-8,1e-7,1e-6,1e-5,1e-4,1e-3]: opt,err=I.cycle_cost_optimum(.1,b) co.append(dict(per_cycle_error=b,optimal_real_cycles=opt,best_proxy_error=err)) write('control_cost.csv',co);summary['E9_resources']=dict(four_modes_minimum_cyclic_settings=13,quadratic_spectral_and_cyclic_scaling=True,phase_switches_not_free=True) print('E10 check microscopic shot statistics',flush=True) rng=np.random.default_rng(91);K=256;n=np.full(40000,100);target=np.full(len(n),.6) out,doses=I.exchange_sample(n,K,target,rng) pi=.995;e=np.exp(-doses[0]);p11=pi+(1-pi)*e;p01=pi*(1-e) var=100*p11*(1-p11)+(K-100)*p01*(1-p01) summary['E10_finite_statistics']=dict(samples=len(n),expected_mean=K*.6,sampled_mean=float(out.mean()),expected_variance=var,sampled_variance=float(out.var()),dose=float(doses[0])) print('E11 branch-complete compiler with full photon/exciton dynamics',flush=True) br=[] ref=I.branch_average_reference(True) for n in [0,2,4,8,16,32,64]: active=I.branch_complete_cycle(n,True) idle=I.branch_complete_cycle(n,False) incomplete=I.branch_complete_cycle(n,True,True) if n in [0,8,32,64] else None row=dict(cycles=n,exposures=26*n,concurrent_stokes_error=float(np.linalg.norm(I.stokes(active[:2])-I.stokes(idle[:2]))),full_to_average_field_error=float(np.linalg.norm(active-ref))) if incomplete is not None: incomplete_idle=I.branch_complete_cycle(n,False,True) row['incomplete_code_error']=float(np.linalg.norm(I.stokes(incomplete[:2])-I.stokes(incomplete_idle[:2]))) br.append(row) write('branch_complete.csv',br) summary['E11_branch_complete']=dict(results=br,full_photon_exciton_evolution=True,branch_projection=False,ideal_instantaneous_polariton_mode_phase_gates=True,unequal_photon_exciton_amplitude_damping=[.03,.11]) print('E12 full-field closed-loop coefficient adaptation',flush=True) fr=[];fh=[] for seed in range(4): item=I.integrated_feedback(seed) for row in item.pop('history'):fh.append(dict(seed=seed,**row)) fr.append(item) bad=I.integrated_feedback(0,incomplete=True) bad.pop('history') refined=I.integrated_feedback(0,subdivisions=8) fine_hist=refined.pop('history') coarse=[r for r in fh if r['seed']==0] grid_error=max(abs(a['protected_error']-b['protected_error']) for a,b in zip(coarse,fine_hist)) write('integrated_feedback.csv',fh) summary['E12_integrated_feedback']=dict(runs=fr,incomplete_control=bad,refined_run=refined,refinement_protected_error_difference=grid_error, ideal_modal_phase_gates=True,controller='fixed phase tracking, not autonomous algorithm invention', finite_memory_updates='endpoint writes at microcycle boundaries',full_two_branch_dynamics=True) print('E13 native phase-gate synthesis and finite-speed Kerr defect',flush=True) V=I.full_polariton_basis();q=np.array([0,1,3,9]);exact=[] for phi in list(2*np.pi*np.arange(13)/13)+[.137,1.217,-.43]: target=V@np.diag(np.exp(1j*phi*q))@V.conj().T exact.append(float(np.linalg.norm(I.native_phase_unitary(phi)-target))) finite=[I.native_gate_with_kerr(strength) for strength in [50,200,800,3200]] write('native_phase_gates.csv',finite) summary['E13_native_phase_synthesis']=dict(max_matrix_residual=max(exact),settings_checked=len(exact), native_control_families=3,primitive_factors=15,finite_speed_results=finite, native_controls_assumed_tunable=True,full_gate_learning_loop_not_simulated=True) (R/'summary.json').write_text(json.dumps(summary,indent=2,sort_keys=True)+'\n') print(json.dumps(summary,indent=2),flush=True) if __name__=='__main__':main()