"""Regenerate synthetic data and publication figures; no experimental records.""" from __future__ import annotations import csv, json, pathlib, sys import numpy as np import matplotlib matplotlib.use('Agg') import matplotlib.pyplot as plt from scipy.constants import h, k as k_B from lioraen_omega import (phase_model, reflection, sigma, pick_matrices, spectral_mass_bound, recover, full_response, quadratic_value, controls) ROOT=pathlib.Path(__file__).resolve().parents[1] SEED=16102027 def write_csv(path, header, rows): with path.open('w',newline='',encoding='utf-8') as f: writer=csv.writer(f);writer.writerow(header);writer.writerows(rows) def save_fig(name): plt.tight_layout() plt.savefig(ROOT/'manuscript'/'figures'/f'{name}.pdf',bbox_inches='tight') plt.savefig(ROOT/'manuscript'/'figures'/f'{name}.png',dpi=160,bbox_inches='tight') plt.close() def main(): rng=np.random.default_rng(SEED) for directory in ['physics','data','results','manuscript/figures']: (ROOT/directory).mkdir(parents=True,exist_ok=True) eta=.05;kext=.05;tau=.2;phis=[np.pi/2,-np.pi/2] models=[phase_model(p) for p in phis] omegas=np.linspace(-1.2,1.2,801) values=np.array([[reflection(*model,float(w),1j*tau,eta,kext) for w in omegas] for model in models]) contrast=np.abs(values[0]-values[1]);index=int(np.argmax(contrast));w0=float(omegas[index]) std_single=.001; repeats=25;std_mean=std_single/np.sqrt(repeats) noisy=values+std_mean/np.sqrt(2)*(rng.normal(size=values.shape)+1j*rng.normal(size=values.shape)) rows=[] for j,w in enumerate(omegas): rows.append([w,values[0,j].real,values[0,j].imag,values[1,j].real, values[1,j].imag,contrast[j],noisy[0,j].real,noisy[0,j].imag, noisy[1,j].real,noisy[1,j].imag]) write_csv(ROOT/'physics'/'phase_scan.csv', ['omega_over_Omega0','S_plus_real','S_plus_imag','S_minus_real','S_minus_imag', 'absolute_contrast','noisy_plus_real','noisy_plus_imag', 'noisy_minus_real','noisy_minus_imag'],rows) plt.figure(figsize=(7.0,4.2)) plt.plot(omegas,np.abs(values[0]),label=r'$\phi=+\pi/2$') plt.plot(omegas,np.abs(values[1]),label=r'$\phi=-\pi/2$') plt.xlabel(r'Drive detuning $\omega/\Omega_0$');plt.ylabel('Reflection amplitude magnitude') plt.title('Synthetic phase-controlled one-port response');plt.legend() save_fig('reflection_phase') plt.figure(figsize=(7.0,4.2)) plt.plot(omegas,contrast) plt.xlabel(r'Drive detuning $\omega/\Omega_0$');plt.ylabel(r'$|S_{+}-S_{-}|$') plt.title('Synthetic complex-reflection contrast') save_fig('phase_contrast') # Raw four-setting reconstruction and withheld checks use full resolvents. ts=[tau*t for t in controls(1)];H,L,C=models[0];z=w0+1j*eta fs=[full_response(H,L,C,z,t) for t in ts] cal_records=[];fmeas=[] for j,(t,f) in enumerate(zip(ts,fs)): sexact=1-1j*kext/f sm=sexact+std_mean/np.sqrt(2)*(rng.normal()+1j*rng.normal()) gm=(1-sm)/(1j*kext);fm=1/gm;fmeas.append(fm) cal_records.append([j,t[0].real,t[0].imag,sexact.real,sexact.imag, sm.real,sm.imag,f.real,f.imag,fm.real,fm.imag]) write_csv(ROOT/'physics'/'raw_control_records.csv', ['setting','t_real','t_imag','S_exact_real','S_exact_imag','S_measured_real', 'S_measured_imag','F_exact_real','F_exact_imag','F_measured_real', 'F_measured_imag'],cal_records) rec=recover(ts,fs);recnoise=recover(ts,fmeas) withheld=[] for j in range(20): t=tau*(rng.normal(size=1)+1j*rng.normal(size=1)) truth=full_response(H,L,C,z,t);pred=quadratic_value(rec,t) noisy_pred=quadratic_value(recnoise,t) # An intentional hidden-mode shift only at validation invalidates the model. Ldrift=L.copy();Ldrift[0,0]+=.025 drift=full_response(H,Ldrift,C,z,t) withheld.append([j,t[0].real,t[0].imag,truth.real,truth.imag, abs(pred-truth),abs(noisy_pred-truth),abs(pred-drift)]) write_csv(ROOT/'physics'/'withheld_controls.csv', ['index','t_real','t_imag','F_true_real','F_true_imag','exact_prediction_error', 'noisy_prediction_error','deliberate_drift_error'],withheld) # Return-memory cross-pole invariant. times=np.linspace(0,10,501) mem=np.array([abs(np.exp(.6j*times)+np.exp(1j*p)*np.exp(-.6j*times))**2 for p in phis]) write_csv(ROOT/'data'/'memory_phase.csv',['time_times_Omega0','plus','minus'], zip(times,mem[0],mem[1])) plt.figure(figsize=(7,4.2)) for p,m in zip(phis,mem): plt.plot(times,m,label=r'$\phi=+\pi/2$' if p>0 else r'$\phi=-\pi/2$') plt.xlabel(r'Dimensionless time $t\Omega_0$');plt.ylabel(r'$|\mathcal{M}_{12}(t)|^2/g^4$') plt.legend();plt.title('A phase relation across two spectral poles') save_fig('memory_phase') ns=np.arange(1,9);profile=np.minimum(ns,3)+2*np.minimum(ns,2) write_csv(ROOT/'data'/'rank_profiles.csv',['nodes','seven_state_Hermitian','one_damped_state'],zip(ns,profile,ns)) plt.figure(figsize=(7,4.2)) plt.plot(ns,profile,'o-',label='Seven-state Hermitian model (q=3)') plt.plot(ns,ns,'s--',label='One damped state, unshifted kernel (q=1)') plt.xlabel('Number of distinct sample frequencies');plt.ylabel('Exact kernel rank') plt.xticks(ns);plt.legend();plt.title('Completion versus persistent rank growth') save_fig('rank_profiles') zs=np.linspace(-2,2,8)+.7j;gamma=.4 vals=[np.array([[1/(z+1j*gamma)]]) for z in zs] K,_,_=pick_matrices(zs,vals);Kcorrect,_,_=pick_matrices(zs+1j*gamma,vals) eig=np.linalg.eigvalsh(K)[::-1];correct=np.linalg.eigvalsh(Kcorrect)[::-1] write_csv(ROOT/'data'/'damping_kernel_spectrum.csv', ['index','uncorrected_eigenvalue','known_shift_eigenvalue'],zip(range(1,9),eig,correct)) plt.figure(figsize=(7,4.2)) plt.semilogy(range(1,9),np.maximum(abs(eig),1e-18),'o-',label='Unshifted Pick kernel') plt.semilogy(range(1,9),np.maximum(abs(correct),1e-18),'s--',label='Known common linewidth shift') plt.xlabel('Eigenvalue index');plt.ylabel('Absolute numerical eigenvalue') plt.legend();plt.title('One damped mode: two different dimension questions') save_fig('damping_spectrum') # A nonvacuous but deliberately conservative support witness. wz=np.array([-.7+.5j,0+.5j,.7+.5j]);roots=np.array([-.5,.5]) masses=np.array([1.,1.,1e-6]);poles=np.array([-.5,.5,.9]) vals=[np.array([[sum(masses/(z-poles))]]) for z in wz] Kw,_,_=pick_matrices(wz,vals) result=spectral_mass_bound(wz,roots,Kw,1,1.,.2,sample_error=1e-10) result['weights']=[[float(a.real),float(a.imag)] for a in result['weights']] result.update(actual_outside_mass=1e-6,total_mass=float(sum(masses)), support_radius=1.,band_radius=.2,assumed_sample_error=1e-10) assert result['bound']>=result['actual_outside_mass'] (ROOT/'results'/'spectral_witness.json').write_text(json.dumps(result,indent=2)+'\n') occupation=float(1/np.expm1(h*10e6/(k_B*.01))) real_null=max(abs(full_response(*models[0],z,[x])-full_response(*models[1],z,[x])) for x in np.linspace(-.5,.5,31)) report=dict(status='entirely synthetic; no physical experiment',seed=SEED, angular_frequency_unit_rad_per_s=float(2*np.pi*1e6), parameter_units='Hamiltonian, linewidth, and drive detuning divided by Omega0', eta=.05,kappa_external=.05,g=.3,tau=.2, visible_detunings=[-.1,.15],hidden_detunings=[-.6,.6], maximum_complex_reflection_contrast=float(contrast[index]), omega_at_maximum=w0,frequency_grid_points=len(omegas), maximum_absolute_reflection=float(abs(values).max()), real_control_transpose_null_max=float(real_null), assumed_single_record_complex_rms=std_single,repeats=repeats, assumed_averaged_complex_rms=std_mean,assumed_systematic_target=.005, thermal_example=dict(frequency_Hz=10e6,temperature_K=.01,occupation=occupation), control_design_condition=rec['condition'], maximum_exact_withheld_error=float(max(row[5] for row in withheld)), maximum_noisy_withheld_error=float(max(row[6] for row in withheld)), minimum_deliberate_drift_error=float(min(row[7] for row in withheld)), maximum_deliberate_drift_error=float(max(row[7] for row in withheld)), witness_bound=float(result['bound'])) assert report['maximum_absolute_reflection']<=1+1e-10 assert real_null<1e-10 assert report['maximum_exact_withheld_error']<1e-8 (ROOT/'physics'/'parameters_and_results.json').write_text(json.dumps(report,indent=2)+'\n') tex=(r'\newcommand{\PeakContrast}{'+f"{report['maximum_complex_reflection_contrast']:.4f}"+'}\n'+ r'\newcommand{\PeakFrequency}{'+f'{w0:.3f}'+'}\n'+ r'\newcommand{\ThermalOccupation}{'+f'{occupation:.2f}'+'}\n'+ r'\newcommand{\WitnessBound}{'+f"{result['bound']:.6f}"+'}\n') (ROOT/'manuscript'/'generated_numbers.tex').write_text(tex) print(json.dumps(report,indent=2)) if __name__=='__main__':main()