0hmX/am3352
This code suite comprises TypeScript scripts that analyze, verify, and assemble complex DDR memory interface hardware, focusing on physical routing, via and pad placement, electrical clearance, and physical constraints, often involving precise geometric calculations and consistent provenance tracking.
- Version
- 1.0.5
- License
- unset
- Stars
- 0
scripts/experiment-ddr-cpu-d11-d13-swap.ts
/** Exact isolated retirement plus existing retained-via winding; never publishes a router solution by hand. */
import {readFileSync,writeFileSync,mkdirSync} from 'node:fs'
import {resolve} from 'node:path'
import {objectHash as hash} from './improve-ddr-a9-power-launches'
import {verifyDdrCapture} from './ddr-capture-provenance'
const [parentArg='dist/ddr-twenty-d15-power57',outArg='dist/ddr-cpu-d11-d13-swap']=process.argv.slice(2),parent=resolve(parentArg),out=resolve(outArg),capture='dist/ddr-system/host-taps-54af3e346b5e',read=(p:string)=>JSON.parse(readFileSync(p,'utf8')),{captureHash}=verifyDdrCapture(capture),original=read(parent+'/candidate.circuit.json'),report=read(parent+'/report.json'),hosts=read(parent+'/host-bundle.json'),input=read(parent+'/routing-input.json'),budget=read(parent+'/current-byte-budgets.json')
if(hash(original)!==report.candidateCircuitSha256||hash(hosts.traces)!==report.hostTracesSha256||hosts.traces.length!==20)throw Error('Parent identity differs')
const removed=hosts.traces.filter((t:any)=>t.source_trace_id==='source_trace_689');if(removed.length!==1)throw Error('Expected one D11 host')
const retained=hosts.traces.filter((t:any)=>!removed.includes(t)),replacements=['source_trace_332','source_trace_334'].map(source=>{const before=original.find((t:any)=>t.type==='pcb_trace'&&t.source_trace_id===source);if(!before||before.route.filter((p:any)=>p.route_type==='via').length!==1)throw Error('Expected exact single retained via');const i=before.route.findIndex((p:any)=>p.route_type==='via');return{before,after:{...before,route:before.route.slice(0,i+1)}}})
const initial=original.filter((e:any)=>!removed.some((t:any)=>hash(t)===hash(e))).map((e:any)=>replacements.find(r=>hash(r.before)===hash(e))?.after??e)
const write=(dir:string,n:string,v:any)=>{mkdirSync(dir,{recursive:true});writeFileSync(dir+'/'+n,JSON.stringify(v,null,2)+'\n')}
const scaffold=(dir:string,c:any[],prevDir:string,prev:any[],connections:any[])=>{const rep=prev.filter(e=>c.some(q=>q.type===e.type&&q[`${e.type}_id`]===e[`${e.type}_id`]&&hash(q)!==hash(e))).map(before=>({before,after:c.find(q=>q.type===before.type&&q[`${before.type}_id`]===before[`${before.type}_id`])})),rem=prev.filter(e=>!c.some(q=>q.type===e.type&&q[`${e.type}_id`]===e[`${e.type}_id`])),manifest={captureHash,parentDirectory:prevDir,parentCircuitSha256:hash(prev),candidateCircuitSha256:hash(c),replacements:rep,removals:rem};write(dir,'candidate.circuit.json',c);write(dir,'host-bundle.json',{...hosts,traces:retained});write(dir,'routing-input.json',{...input,traces:retained,connections});write(dir,'original-copper-replacements.json',manifest);write(dir,'report.json',{captureHash,candidateCircuitSha256:hash(c),hostTracesSha256:hash(retained),originalCopperReplacementsSha256:hash(manifest),scope:'Explicit temporary CPU tail retirement and D11 host invalidation; only19 retained hosts. Local-only experiment, not accepted board.'});write(dir,'current-byte-budgets.json',{...budget,candidateCircuitSha256:hash(c),scope:'Inherited nominal policy only; source lengths are recomputed by the local experiment, not current completeness evidence.'})}
scaffold(out+'/retired',initial,parent,original,input.connections)
let current=out+'/retired',c=initial
const stages=[['DDR_D13','-1.2','inner6'],['DDR_D11','-.4','inner4']];if(process.argv.includes('--reverse'))stages.reverse();let acceptedStages=0;for(const [signal,y,layer]of stages){const dest=out+'/'+signal;const p=Bun.spawn(['bun','scripts/plan-ddr-d13-cpu-facing-exit.ts',capture,current,dest,y,layer,signal,'--local-only',...(process.argv.includes('--pad-aligned')?['--pad-aligned']:[])],{stdout:'inherit',stderr:'inherit'});const code=await p.exited;if(code!==0){write(out,'report.json',{captureHash,accepted:false,failedStage:signal,parentCandidateSha256:hash(original),retiredHostHashes:removed.map(hash),retainedHostCount:19,diagnostic:dest});process.exitCode=1;break}const next=read(dest+'/candidate.circuit.json'),connections=read(dest+'/routing-input.json').connections;scaffold(dest+'/prepared',next,current,c,connections);current=dest+'/prepared';c=next;write(out,'report.json',{captureHash,acceptedLocalStages:++acceptedStages,parentCandidateSha256:hash(original),retainedHostCount:19,latest:current,scope:'Local-only proposal; D11 host invalidated and D13 host missing. Not an accepted20-host board.'})}
if(hash(read(parent+'/candidate.circuit.json'))!==hash(original))throw Error('Parent mutated')