Datasets:
Formats:
json
Languages:
English
Size:
1K - 10K
Tags:
matter-embryogenesis
developmental-fabrication
nanotechnology
self-assembly
materials-science
passive-networks
| """Reproducible finite checks and reduced-model experiments, v2. | |
| No result from this script is molecular or laboratory evidence. A conventional | |
| joint sensing/control design is included and intentionally ties the same policy. | |
| """ | |
| from pathlib import Path | |
| import argparse, json, csv, sys, platform | |
| from dataclasses import replace | |
| import numpy as np | |
| from scipy.linalg import eigh | |
| from contracts import (laplacian,kron,relative_spectrum,assemble_responses, | |
| conductance,energy_weights,weighted_response_bounds) | |
| from contract_genome import capsule,compile_grid | |
| from contract_growth import Config,manufacture | |
| from recovery import recoverability,posterior,joint_value | |
| ROOT=Path(__file__).resolve().parents[1] | |
| def theorem_checks(): | |
| rng=np.random.default_rng(845117) | |
| min_slack=1.; comp_max=0.; trials=[] | |
| for run in range(300): | |
| # Overlapping four-port modules. Shared nodes are the only interactions. | |
| count=2+run%18; nodes=2*count+2 | |
| local=[]; nominal=[]; maps=[]; deviations=[] | |
| for j in range(count): | |
| # Actual module has one interior node. No target stores its coordinate. | |
| edge=np.array([[a,b] for a in range(5) for b in range(a+1,5)]) | |
| w=np.exp(rng.normal(0,.8,len(edge))) | |
| # Shared modulation makes module errors strongly correlated. | |
| shared=.055*np.sin(run) | |
| ratio=1+shared+rng.uniform(-.04,.04,len(edge)) | |
| D0=kron(laplacian(5,edge,w),[0,1,2,3]) | |
| D=kron(laplacian(5,edge,w*ratio),[0,1,2,3]) | |
| nominal.append(D0); local.append(D); maps.append(np.arange(2*j,2*j+4)) | |
| deviations.append(max(abs(relative_spectrum(D,D0)-1))) | |
| target=assemble_responses(nominal,maps,nodes,[0,1,nodes-2,nodes-1]) | |
| actual=assemble_responses(local,maps,nodes,[0,1,nodes-2,nodes-1]) | |
| deviation=max(abs(relative_spectrum(actual,target)-1)) | |
| eta=max(deviations); min_slack=min(min_slack,eta-deviation) | |
| comp_max=max(comp_max,deviation) | |
| assert deviation<=eta+2e-12 | |
| trials.append({'modules':count,'largest_local_error':eta,'global_error':deviation}) | |
| # Single-probe blindness: deleting the edge between equal-voltage ports. | |
| D0=laplacian(3,[[0,1],[0,2],[1,2]],[1,1,1]).toarray() | |
| D1=laplacian(3,[[0,1],[0,2],[1,2]],[1,1,0]).toarray() | |
| u=np.array([1.,0.,0.]); v=np.array([0.,1.,0.]) | |
| blind={'first_probe_current_difference':float(np.linalg.norm((D1-D0)@u)), | |
| 'second_probe_current_difference':float(np.linalg.norm((D1-D0)@v)), | |
| 'relative_spectrum':relative_spectrum(D1,D0).tolist()} | |
| # General noncommuting quadratic evidence-control complementarity. | |
| errs=[]; synerg=[] | |
| for _ in range(400): | |
| A=rng.normal(size=(5,5)); S=A@A.T+.2*np.eye(5) | |
| O=rng.normal(size=(3,5)); noise=.4*np.eye(3) | |
| Sp=posterior(S,O,noise); Om=S-Sp | |
| B=rng.normal(size=(5,3)); U=rng.normal(size=(5,2)) | |
| B2=np.c_[B,U] | |
| Aobs=rng.normal(size=(5,5)); dOm=Aobs@Aobs.T | |
| def val(b,o):return recoverability(S,o,b)['dividend'] | |
| synergy=val(B2,Om+dOm)-val(B2,Om)-val(B,Om+dOm)+val(B,Om) | |
| synerg.append(synergy) | |
| mu=rng.normal(size=5) | |
| ctrl=np.linalg.solve(B.T@B+np.eye(3),B.T@mu) | |
| direct=.5*np.linalg.norm(mu-B@ctrl)**2+.5*np.dot(ctrl,ctrl) | |
| W=B@B.T | |
| formula=.5*mu@np.linalg.solve(W+np.eye(5),mu) | |
| errs.append(abs(direct-formula)) | |
| assert min(synerg)>-1e-12 | |
| # Weighted deterministic response bounds with independent and adversarial damage. | |
| net=compile_grid(capsule(9,2)); N=len(net['parent']); w=energy_weights(N,net['edges'],net['target'],net['left'],net['right']) | |
| G0=conductance(N,net['edges'],net['target'],net['left'],net['right']) | |
| worst_slack=1. | |
| weighted=[] | |
| for _ in range(250): | |
| ratio=np.exp(rng.normal(-.2,.4,len(w))) | |
| lo,hi=weighted_response_bounds(w,ratio) | |
| true=conductance(N,net['edges'],net['target']*ratio,net['left'],net['right'])/G0 | |
| assert lo-1e-12<=true<=hi+1e-12 | |
| worst_slack=min(worst_slack,true-lo,hi-true) | |
| weighted.append([lo,true,hi]) | |
| return {'composition_trials':300,'composition_min_slack':min_slack, | |
| 'composition_largest_global_error':comp_max,'composition_examples':trials, | |
| 'blind_probe_counterexample':blind,'quadratic_trials':400, | |
| 'quadratic_max_absolute_error':max(errs),'minimum_complementarity':min(synerg), | |
| 'weighted_trials':250,'weighted_min_slack':worst_slack, | |
| 'power_participation':float(1/np.dot(w,w)),'weighted_examples':weighted} | |
| def run(reps): | |
| (ROOT/'results').mkdir(exist_ok=True) | |
| methods=['open_loop','blueprint','blind_reserve','sensor_only','early_seal', | |
| 'contract','conventional_joint','biased_reference'] | |
| allrows=[]; summaries=[] | |
| for dim,n in [(2,8),(3,5)]: | |
| for method in methods: | |
| rows=[] | |
| for k in range(reps): | |
| cfg=Config(dim=dim,n=n,seed=20260919+1000*dim+k) | |
| row,snapshot=manufacture(cfg,method) | |
| rows.append(row); allrows.append(row) | |
| if k==0 and method in ('contract','open_loop','early_seal'): | |
| np.savez_compressed(ROOT/'results'/f'{dim}d_{method}.npz',**snapshot) | |
| summary={'dimension':dim,'method':method,'replicates':reps, | |
| 'complete_count':sum(r['complete'] for r in rows), | |
| 'functional_yield_count':sum(r['completed_function_ok'] for r in rows), | |
| 'all_contract_count':sum(r['all_local_contracts'] for r in rows), | |
| 'false_certificate_count':sum(r['false_certificate'] for r in rows)} | |
| for field in ['functional_ratio','total_time','additional_material','nominal_material', | |
| 'inspection_samples','maturation_rounds','blocked_unaccepted_modules', | |
| 'local_contract_fraction','measurement_radius']: | |
| vals=[r[field] for r in rows] | |
| summary[field+'_mean']=float(np.mean(vals)) | |
| summary[field+'_sd']=float(np.std(vals,ddof=1)) if len(vals)>1 else 0. | |
| summaries.append(summary) | |
| print(dim,method,summary['functional_yield_count'],reps,round(summary['functional_ratio_mean'],5),flush=True) | |
| result={'replicates':reps,'total_runs':len(allrows),'summaries':summaries, | |
| 'methods':methods,'measure': 'completed object within 8% of target two-terminal conductance', | |
| 'python':platform.python_version(),'numpy':np.__version__, | |
| 'scope':'finite reduced module simulation; bounded ideal actuator and calibrated terminal reference'} | |
| (ROOT/'results/runs.json').write_text(json.dumps(allrows,indent=2)) | |
| (ROOT/'results/summary.json').write_text(json.dumps(result,indent=2)) | |
| with (ROOT/'results/summary.csv').open('w') as f: | |
| writer=csv.DictWriter(f,fieldnames=summaries[0].keys()); writer.writeheader(); writer.writerows(summaries) | |
| checks=theorem_checks() | |
| (ROOT/'results/theorem_checks.json').write_text(json.dumps(checks,indent=2)) | |
| # Closure drift deliberately violates the claimed 1% envelope: negative control. | |
| stressed=[] | |
| for k in range(reps): | |
| cfg=Config(seed=707400+k,seal_actual_bound=.18) | |
| r,_=manufacture(cfg,'contract'); stressed.append(r) | |
| (ROOT/'results/seal_stress.json').write_text(json.dumps(stressed,indent=2)) | |
| print('theorem_checks:',{k:v for k,v in checks.items() if not isinstance(v,list)},flush=True) | |
| print('seal_stress',sum(r['false_certificate'] for r in stressed),'false certificates;', | |
| sum(r['completed_function_ok'] for r in stressed),'completed function passes',flush=True) | |
| if __name__=='__main__': | |
| p=argparse.ArgumentParser();p.add_argument('--reps',type=int,default=32) | |
| run(p.parse_args().reps) | |