Download src/run_experiments.py from PureOne/aelyrion-vaelith: direct link, hf CLI and curl.
- Browser
- Download file 4.6 kB
-
https://huggingface.co/datasets/PureOne/aelyrion-vaelith/resolve/main/src/run_experiments.py
- Command line
-
hf download hf://datasets/PureOne/aelyrion-vaelith/src/run_experiments.py
-
curl -L -o run_experiments.py https://huggingface.co/datasets/PureOne/aelyrion-vaelith/resolve/main/src/run_experiments.py
4.6 kB
| """Reproduce deterministic research figures and raw tables (not hardware data).""" | |
| from pathlib import Path | |
| import sys,json,csv | |
| import numpy as np | |
| from scipy.linalg import eigh | |
| import matplotlib | |
| matplotlib.use('Agg') | |
| import matplotlib.pyplot as plt | |
| from aelyrion import MirrorState,chain,density_optimum,coherence_witness,complete_frame,polynomial_graph | |
| ROOT=Path(__file__).resolve().parents[1] | |
| OUT=ROOT/'results';FIG=ROOT/'figures' | |
| OUT.mkdir(exist_ok=True);FIG.mkdir(exist_ok=True) | |
| def save(name): | |
| plt.tight_layout() | |
| plt.savefig(FIG/(name+'.pdf'),bbox_inches='tight') | |
| plt.savefig(FIG/(name+'.png'),dpi=170,bbox_inches='tight') | |
| plt.close() | |
| def table(name,header,rows): | |
| with open(OUT/(name+'.csv'),'w',newline='') as f: | |
| w=csv.writer(f);w.writerow(header);w.writerows(rows) | |
| n=20;b=chain(n);rho,lam=density_optimum(b,float(n));j=np.arange(1,n+1) | |
| plt.figure(figsize=(6.7,3.6));plt.plot(j,rho,'o-',label='Globally optimal density');plt.plot(j,np.ones(n),'--',label='Uniform density') | |
| plt.xlabel('Residual index j');plt.ylabel('Density (budget = 20)');plt.legend();save('density_profile') | |
| table('density_profile',['j','optimal_density','uniform_density'],zip(j,rho,np.ones(n))) | |
| rows=[] | |
| for n in range(2,101): | |
| b=chain(n);rr,ll=density_optimum(b,float(n));un=eigh(b.T@b,eigvals_only=True)[0] | |
| rows.append((n,ll,un,ll/un)) | |
| rows=np.array(rows) | |
| plt.figure(figsize=(6.7,3.6));plt.loglog(rows[:,0],rows[:,1],label='Best allocation, exact');plt.loglog(rows[:,0],rows[:,2],'--',label='Uniform allocation') | |
| plt.xlabel('Number of hidden modes');plt.ylabel('Slowest relaxation rate');plt.legend();save('chain_scaling') | |
| table('chain_scaling',['n','optimal_rate','uniform_rate','rate_ratio'],rows) | |
| q=2.;b=np.array([[1.,0],[-q,1.]]) | |
| rhos=[1.,.1,.01,.001,0.];s=np.logspace(-7,1,240) | |
| plt.figure(figsize=(6.7,3.6));cusp=[] | |
| for r in rhos: | |
| st=MirrorState(b,[[1],[0]],np.diag([1.,r]),[[1.]]) | |
| vals=[float(((st.response(z)-st.S)/z)[0,0].real) for z in s] | |
| plt.semilogx(s,vals,label=f'rho = {r:g}') | |
| cusp.extend((r,z,y) for z,y in zip(s,vals)) | |
| plt.xlabel('Positive Laplace parameter s');plt.ylabel('(Y(s) - S) / s');plt.legend();save('rank_cusp') | |
| table('rank_cusp',['rho','s','normalized_boundary_departure'],cusp) | |
| hierarchy=[] | |
| for r in range(2,8): | |
| f=complete_frame(r);n=len(f);o=coherence_witness(f,1.) | |
| val=np.trace(o['C']@o['X']).real | |
| hierarchy.append((r,n,int(np.linalg.matrix_rank(o['X'],tol=1e-8)),val,1/val)) | |
| plt.figure(figsize=(6.7,3.6));plt.plot([x[1] for x in hierarchy],[x[2] for x in hierarchy],'o-') | |
| plt.xlabel('Ambient hidden modes n = 2r^2 - r');plt.ylabel('Unique optimal certificate rank r');save('coherence_hierarchy') | |
| table('coherence_hierarchy',['r','n','verified_rank','dual_optimum','rate_for_budget_one'],hierarchy) | |
| n=12;b=chain(n);rho,lam=density_optimum(b,n);e=np.eye(n)[:,:1] | |
| t=np.linspace(0,350,220);init=np.zeros(n) | |
| su=MirrorState(b,e,np.eye(n),[[1]]);so=MirrorState(b,e,np.diag(rho),[[1]]) | |
| # Use the respective worst-mode initial error, so the plotted decay is exact rate decay. | |
| plt.figure(figsize=(6.7,3.6));lu=eigh(su.A,eigvals_only=True)[0] | |
| plt.semilogy(t,np.exp(-lu*t),label='Uniform: worst-mode error');plt.semilogy(t,np.exp(-lam*t),label='Optimal: worst-mode error') | |
| plt.xlabel('Dimensionless time');plt.ylabel('Normalized worst-mode error');plt.legend();save('relaxation') | |
| table('relaxation',['time','uniform_worst_error','optimal_worst_error'],zip(t,np.exp(-lu*t),np.exp(-lam*t))) | |
| rho0=1.;T=2.;t=np.linspace(0,T,200);rr=rho0*(1-t/T)**2 | |
| integral=rho0*T/3*(1-(1-t/T)**3);z=np.exp(-integral) | |
| plt.figure(figsize=(6.7,3.6));plt.plot(t,rr,label='Collapsing density');plt.plot(t,z,label='Remaining residual amplitude') | |
| plt.xlabel('Time');plt.ylabel('Normalized value');plt.legend();save('collapse_freeze') | |
| table('collapse_freeze',['time','density','residual'],zip(t,rr,z)) | |
| terms=[(2,(0,0,1)),(-3,(1,2)),(1,()),(.5,(2,2,2))] | |
| b,e,f=polynomial_graph(terms,[.5,1/3,.25]);value=(f@np.linalg.solve(b,e))[0,0] | |
| summary={'seed_policy':'All plotted data are deterministic; randomized tests fix seed per test.', | |
| 'polynomial_value':float(value.real),'polynomial_exact':'355/384','polynomial_modes':len(b), | |
| 'chain_20_optimal_rate':float(6*20/(20*21*41)), | |
| 'chain_20_uniform_rate':float(eigh(chain(20).T@chain(20),eigvals_only=True)[0]), | |
| 'chain_100_rate_ratio':float(rows[-1,3]), | |
| 'cusp_positive_density_slope':5.,'cusp_zero_density_slope':1., | |
| 'collapse_final_residual':float(z[-1]),'physical_measurements':0,'pytest_cases':90} | |
| (OUT/'experiment_summary.json').write_text(json.dumps(summary,indent=2)) | |
| print(json.dumps(summary,indent=2)) | |