{
  "name": "route-choice",
  "display_name": "Route choice",
  "summary": "Two real routes, 64 simulator shots as the coin flip, then a CPU reads the counts and a LOOP writes the recommendation. Not a quantum advantage. One small CPU VM.",
  "steps": [
    {
      "id": "s1",
      "kind": "slurm-cpu",
      "name": "routes",
      "script": "jobs/s1.sh",
      "after": [],
      "use_slurm": false,
      "durationHours": "",
      "instanceType": "",
      "container": "",
      "copies": [],
      "shape": {
        "cpus": 2,
        "mem": "4G",
        "nodes": 1
      }
    },
    {
      "id": "s2",
      "kind": "quantum",
      "name": "sample",
      "after": [
        "s1"
      ],
      "backend": "simulator",
      "shots": 64,
      "failOnError": true,
      "input": {
        "kind": "file",
        "path": "circuits/s2.qasm"
      },
      "outputPath": "",
      "script": "circuits/s2.qasm"
    },
    {
      "id": "s3",
      "kind": "slurm-cpu",
      "name": "choose",
      "script": "jobs/s3.sh",
      "after": [
        "s1",
        "s2"
      ],
      "use_slurm": false,
      "durationHours": "",
      "instanceType": "",
      "container": "",
      "copies": [],
      "shape": {
        "cpus": 2,
        "mem": "4G",
        "nodes": 1
      }
    },
    {
      "id": "s4",
      "kind": "ai-loop",
      "name": "recommend",
      "after": [
        "s3"
      ],
      "modelFamily": "cheap",
      "model": "",
      "failOnError": false,
      "maxTurns": 3,
      "stopWhen": {
        "type": "checks",
        "all": [
          {
            "check": "json"
          },
          {
            "check": "has",
            "path": "route"
          },
          {
            "check": "number",
            "path": "confidence",
            "op": "gte",
            "value": 0.8
          }
        ]
      },
      "script": "prompts/s4.txt",
      "input": {
        "kind": "file",
        "path": "prompts/s4.txt"
      },
      "outputPath": ""
    }
  ],
  "spans": [],
  "files": {
    "jobs/s1.sh": "#!/bin/bash\nset -euo pipefail\nmkdir -p \"${EUREKA_OUT:-.}\"\ncat > \"${EUREKA_OUT:-.}/routes.txt\" <<'EOF'\nA  coastal  42 km  55 min  US-17, fewer lights\nB  inland   38 km  61 min  I-95, more traffic at 8am\nEOF\ncat > \"${EUREKA_OUT:-.}/circuit.qasm\" <<'EOF'\nOPENQASM 2.0;\ninclude \"qelib1.inc\";\nqreg q[1];\ncreg c[1];\nh q[0];\nmeasure q[0] -> c[0];\nEOF\n",
    "circuits/s2.qasm": "OPENQASM 2.0;\ninclude \"qelib1.inc\";\nqreg q[1];\ncreg c[1];\nh q[0];\nmeasure q[0] -> c[0];\n",
    "jobs/s3.sh": "#!/bin/bash\nset -euo pipefail\npython3 - <<'PY'\nimport json, os\ncounts = json.load(open(os.path.join(os.environ[\"EUREKA_IN\"], \"from-s2\", \"counts.json\"))).get(\"counts\") or {}\nn0 = int(counts.get(\"0\", 0))\nn1 = int(counts.get(\"1\", 0))\nroute = \"A\" if n0 >= n1 else \"B\"\nmargin = abs(n0 - n1)\ntext = open(os.path.join(os.environ[\"EUREKA_IN\"], \"from-s1\", \"routes.txt\")).read()\nopen(os.path.join(os.environ[\"EUREKA_OUT\"], \"choice.txt\"), \"w\").write(\n    \"route=%s margin=%s shots0=%s shots1=%s\\n%s\" % (route, margin, n0, n1, text))\nPY\n",
    "prompts/s4.txt": "Read choice.txt. Return one JSON object for the single route already chosen there.\nDo not return a list. Do not return a second route.\nFields: route (A or B), name (coastal or inland), why (one sentence using the km and minutes), margin (number of shots), confidence (0 to 1).\nThe counts are only a sample. They are not a reason to prefer a quantum computer.\n"
  }
}
