{
  "name": "entangle-check",
  "display_name": "Entanglement check",
  "summary": "32-shot Hadamard calibration, then a 2-qubit Bell pair, then a LOOP certificate. Simulator only. About two quantum calls plus one small CPU VM.",
  "steps": [
    {
      "id": "s1",
      "kind": "quantum",
      "name": "calibrate",
      "after": [],
      "backend": "simulator",
      "shots": 32,
      "failOnError": true,
      "input": { "kind": "file", "path": "circuits/s1.qasm" },
      "outputPath": "",
      "script": "circuits/s1.qasm"
    },
    {
      "id": "s2",
      "kind": "slurm-cpu",
      "name": "gate",
      "script": "jobs/s2.sh",
      "after": ["s1"],
      "use_slurm": false,
      "durationHours": "",
      "instanceType": "",
      "container": "",
      "copies": [],
      "shape": { "cpus": 2, "mem": "4G", "nodes": 1 }
    },
    {
      "id": "s3",
      "kind": "quantum",
      "name": "bell",
      "after": ["s2"],
      "backend": "simulator",
      "shots": 32,
      "failOnError": true,
      "input": { "kind": "file", "path": "circuits/s3.qasm" },
      "outputPath": "",
      "script": "circuits/s3.qasm"
    },
    {
      "id": "s4",
      "kind": "ai-loop",
      "name": "certificate",
      "after": ["s2", "s3"],
      "modelFamily": "cheap",
      "model": "",
      "failOnError": false,
      "maxTurns": 3,
      "stopWhen": {
        "type": "checks",
        "all": [
          { "check": "json" },
          { "check": "has", "path": "entangled" },
          { "check": "number", "path": "confidence", "op": "gte", "value": 0.8 }
        ]
      },
      "script": "prompts/s4.txt",
      "input": { "kind": "file", "path": "prompts/s4.txt" },
      "outputPath": ""
    }
  ],
  "spans": [],
  "files": {
    "circuits/s1.qasm": "OPENQASM 2.0;\ninclude \"qelib1.inc\";\nqreg q[1];\ncreg c[1];\nh q[0];\nmeasure q[0] -> c[0];\n",
    "circuits/s3.qasm": "OPENQASM 2.0;\ninclude \"qelib1.inc\";\nqreg q[2];\ncreg c[2];\nh q[0];\ncx q[0],q[1];\nmeasure q[0] -> c[0];\nmeasure q[1] -> c[1];\n",
    "jobs/s2.sh": "#!/bin/bash\nset -euo pipefail\npython3 - <<'PY'\nimport json, os, sys\npath = os.path.join(os.environ[\"EUREKA_IN\"], \"from-s1\", \"counts.json\")\ndata = json.load(open(path))\ncounts = data.get(\"counts\") or {}\nn0 = int(counts.get(\"0\", 0))\nn1 = int(counts.get(\"1\", 0))\ntotal = n0 + n1\nif total == 0 or min(n0, n1) / total < 0.25:\n    sys.exit(\"calibration was not a fair coin: 0=%s 1=%s\" % (n0, n1))\nout = os.environ[\"EUREKA_OUT\"]\nopen(os.path.join(out, \"calibration.txt\"), \"w\").write(\"0=%s 1=%s shots=%s\\n\" % (n0, n1, total))\nopen(os.path.join(out, \"circuit.qasm\"), \"w\").write(\"\"\"OPENQASM 2.0;\ninclude \\\"qelib1.inc\\\";\nqreg q[2];\ncreg c[2];\nh q[0];\ncx q[0],q[1];\nmeasure q[0] -> c[0];\nmeasure q[1] -> c[1];\n\"\"\")\nPY\n",
    "prompts/s4.txt": "Read calibration.txt and the Bell counts.json. Reply with JSON only, no markdown.\nFields: calibrated (true if the first run was a fair coin), entangled (true if counts pile up on 00 and 11, not 01 and 10), correlation (short phrase), confidence (0 to 1).\nA simulator at this size is a demonstration, not a speedup.\n"
  }
}
