| """Embed full Amyloid beta-42 circuit into the model package as Python data.""" |
|
|
| from __future__ import annotations |
|
|
| import hashlib |
| import json |
| from pathlib import Path |
|
|
| ROOT = Path(__file__).resolve().parents[1] |
| PKG = ROOT / "models" / "amyloid_beta" |
| OUT = ROOT / "symbolic_recursion" / "models" / "amyloid_beta_circuit_data.py" |
|
|
|
|
| def main() -> None: |
| circuit_path = PKG / "Amyloid_beta-42_circuit.txt" |
| json_path = PKG / "Amyloid_beta-42_circuit.json" |
| circuit = circuit_path.read_text(encoding="utf-8") |
| cjson_text = json_path.read_text(encoding="utf-8") |
| cjson = json.loads(cjson_text) |
| sha = hashlib.sha256(circuit_path.read_bytes()).hexdigest() |
|
|
| header = ( |
| '"""Embedded Amyloid beta-42 full circuit data ' |
| "(byte-identical to package artifact).\n\n" |
| "Generated from models/amyloid_beta/Amyloid_beta-42_circuit.txt\n" |
| "Regenerate with: python scripts/embed_amyloid_circuit.py\n" |
| '"""\n' |
| "from __future__ import annotations\n\n" |
| ) |
| body = ( |
| f"CIRCUIT_SHA256 = {json.dumps(sha)}\n" |
| f"CIRCUIT_BYTES = {len(circuit.encode('utf-8'))}\n" |
| f"CIRCUIT_MOMENTS = {len(cjson.get('moments', []))}\n" |
| f"CIRCUIT_N_QUBITS = {cjson.get('n_qubits', 4)}\n" |
| f"FULL_CIRCUIT = {json.dumps(circuit)}\n" |
| f"CIRCUIT_JSON_TEXT = {json.dumps(cjson_text)}\n" |
| ) |
| OUT.write_text(header + body, encoding="utf-8") |
|
|
| |
| ns: dict = {} |
| exec(OUT.read_text(encoding="utf-8"), ns) |
| assert ns["FULL_CIRCUIT"] == circuit |
| assert ns["CIRCUIT_SHA256"] == sha |
| print(f"wrote {OUT} ({OUT.stat().st_size} bytes)") |
| print(f"sha256={sha} moments={ns['CIRCUIT_MOMENTS']}") |
|
|
|
|
| if __name__ == "__main__": |
| main() |
|
|