[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M7ECK4PZYTGWSER1E4MPY496":3,"skill-same:01M7ECK4PZYTGWSER1E4MPY496":49},{"skillNo":4,"name":5,"nameZh":6,"description":6,"descriptionZh":6,"repositoryFullName":7,"ownerLogin":8,"ownerAvatarUrl":9,"ownerAccountNo":10,"ownerDisplayName":11,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":15,"categories":16,"keywords":17,"publishedAt":18,"linkOnly":19,"markdownContent":20,"markdownBody":20,"frontMatter":21,"refName":22,"commitSha":23,"skillDirectory":24,"forksCount":13,"repositoryHtmlUrl":25,"repositoryHomepageUrl":6,"ownerHtmlUrl":26,"ownerBlogUrl":6,"ownerDescription":27,"updatedAt":28,"install":29,"resources":42},"01M7ECK4PZYTGWSER1E4MPY496","quantum-provider-integration",null,"jonahthan433\u002FCortexOS","jonahthan433","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F211465495?v=4","01M7ECH9HPHGA89DCXHHJBTS3C","jonah.ai","01M7ECH9JCEM45DZMWPT7148S1",0,"Apache-2.0","https:\u002F\u002Fgithub.com\u002Fjonahthan433\u002FCortexOS\u002Fblob\u002Fmain\u002Fskills\u002Fimported\u002F.archive\u002Fquantum-provider-integration\u002FSKILL.md",[],[],"2026-11-15 14:19:17",false,"# quantum-provider-integration\n\n# Quantum Provider Integration (Braket \u002F IBM Qiskit Runtime)\n\nUse when wiring a quantum compute provider (Amazon Braket, IBM Quantum) into\nan API\u002Fsolver adapter: dynamic backend discovery, availability, real\nworkloads, cost modeling. Learned on CortexCloud production, 2026-08.\n\n## AWS Braket (boto3 + braket-sdk)\n\n- **`search_devices(filters=[])` does NOT return `deviceCapabilities`** — the\n  field is absent in list responses. Capability-based filtering (e.g. exclude\n  AHS-only devices) requires a **`get_device(deviceArn=...)` call per device**\n  (cached). Filtering on `deviceCapabilities` from search_devices yields an\n  empty string → silently excludes every QPU. Classic trap.\n- QuEra Aquila is `deviceType=QPU` + ONLINE but **analog (AHS) only** — it\n  cannot run QUBO\u002FIsing IR; submitting fails with\n  `CreateQuantumTask ... supports ['braket.ir.ahs.program']`. Gate-model\n  capability check: caps JSON contains `jaqcd` \u002F `annealing` \u002F `openqasm`.\n- Regions: Rigetti QPUs in us-west-1; IonQ\u002FQuEra in us-east-1. Discovery must\n  iterate both.\n- `SearchQuantumTasks` (listing jobs) often **AccessDenied** even when\n  Create\u002FGet task works — the IAM role may only allow the run path.\n- Provider cost per task ≈ task fee + per-shot (Rigetti Cepheus ~$0.30 +\n  $0.000425\u002Fshot at 1024 shots ≈ $0.74; observed bills vary — verify from\n  real runs, don't trust list prices).\n\n## IBM Quantum (qiskit-ibm-runtime ≥0.4x)\n\n- **Channel renamed**: `QiskitRuntimeService(channel=\"ibm_quantum_platform\", token=...)`.\n  The old `\"ibm_quantum\"` channel name raises\n  `ValueError 'channel' can only be 'ibm_cloud', or 'ibm_quantum_platform'`.\n- **SamplerV2 signature changed**: `SamplerV2(mode=backend)` — passing\n  `backend=` raises `unexpected keyword argument 'backend'`.\n- **No auto-transpile since 2024-03-04**: circuits that don't match the\n  target raise `The instruction h on qubits (0,) is not supported by the\n  target system`. Always `transpile(circ, backend=backend, optimization_level=1)`\n  before `sampler.run`.\n- **Heron RZZ constraint**: `The instruction rzz is supported only for angles\n  in the range [0, pi\u002F2]`. Decompose: `RZZ(θ) = CX(i,j)·RZ(θ,j)·CX(i,j)`\n  (exact for any angle).\n- Discovery: `service.backends(simulator=False, operational=True)` → filter\n  real-time QPUs; sort by `num_qubits` desc. Warning \"Instance was not set\"\n  → pass `instance=\"open-instance\"` (open plan).\n- `service.jobs(limit=N)` lists submitted jobs; `str(job.status())` returns a\n  plain string (\"QUEUED\"\u002F\"DONE\"\u002F...), not an enum.\n- **Open-plan economics**: free QPU quota is *execution* time (10 min\u002F28 days);\n  queue wait is free but can be **20-60+ min** (free tier = lowest priority).\n  `job.result(timeout=...)` is a client-side wait — generous timeout (≥1200s)\n  or async polling required. Client timeouts leave jobs queued server-side;\n  cancel them (`job.cancel()`) to protect quota.\n\n## Worker wedge (silent job hang) — the #1 operational trap\n\nSymptom: a job stays `status: \"running\"` forever with **zero worker log\nlines** after creation; `GET \u002Fv1\u002Fjobs\u002F{id}` keeps returning 200\u002Frunning;\nclassical & hybrid jobs unaffected. Correlates with *fresh* provider\ndiscovery (works in a long-lived process, wedges after a restart once the\ndiscovery TTL expires).\n\nRoot cause: the job worker's `pick_solver` → router → `availability()` →\nprovider SDK discovery call runs synchronously, and **QiskitRuntimeService \u002F\nboto3 calls have no effective timeout** — a stalled provider API (IBM\nsaturated, AWS throttled) blocks the worker forever. The status was already\ncommitted as `running`, so the job looks alive but never progresses.\n\nDiagnosis: `journalctl -u \u003Csvc>` around job creation — the SDK's network\nlines appear (`qiskit_runtime_service._discover_account`, instance\nresolution) and then nothing.\n\nFix (root cause, single point): **bound every provider discovery call** —\nrun it in a thread with a hard timeout:\n```python\ndef _list_backends(service):\n    import concurrent.futures as _cf\n    with _cf.ThreadPoolExecutor(max_workers=1) as ex:\n        fut = ex.submit(service.backends, simulator=False, operational=True)\n        try:\n            backends = fut.result(timeout=15.0)\n        except _cf.TimeoutError:\n            ex.shutdown(wait=False)   # do NOT `with`-join a hung thread\n            raise TimeoutError(\"provider API discovery timed out\")\n    return [{\"name\": b.name, \"num_qubits\": int(getattr(b, \"num_qubits\", 0) or 0),\n             \"simulator\": bool(getattr(b, \"simulator\", False))} for b in backends]\n```\nNever use the ThreadPoolExecutor as a context manager around the submit\n(`__exit__` joins the thread and hangs again) — call `shutdown(wait=False)`\nin the timeout path. Cache failures too (TTL), so a flaky provider degrades\nto `unavailable`, not to wedged workers. See\n`references\u002Fwedge-and-verification.md` for the full diagnosis transcript.\n\n## Routing vs provider cost — \"primary provider\" is a ranking problem\n\nCost-based router ranking (`_cost = provider_cost + runtime_s × LATENCY_TAX`)\nsilently makes the **cheapest provider win every auto\u002Fquantum selection**.\nA $0.00-cost fallback (IBM open plan) therefore *replaces* the intended\nprimary (Braket) even when the fallback's queue is unusable. Three honest\nlevers, no special-casing:\n\n- **Provider-family preference (the one that actually shipped)**: add a\n  preference tier to the sort key — `_pref = 0 if solver.provider ==\n  \"aws_braket\" else 1` — and sort `(c[\"_pref\"], c[\"_cost\"])`. The primary\n  FAMILY wins whenever any of its members is available; the fallback is\n  used only when no primary-family backend exists. Cost parity within a\n  family is preserved (cheapest member still wins).\n- give the fallback a **realistic runtime estimate** reflecting actual queue\n  latency (IBM open plan ≈ 1200s, not 1s) — the latency-inclusive sort then\n  prefers the fast primary naturally; AND\n- keep the fallback's provider cost ≤ the margin guard's ceiling\n  (`provider_cost ≤ effective_price \u002F MARKUP`) so it stays sellable as a\n  genuine fallback when the primary is down.\n\nNote: the runtime-estimate lever alone is NOT sufficient when the fallback's\nhonest cost is $0.00 and the latency tax is tiny (1e-4 × 1200s = $0.12 still\nbeats the primary's $0.75+). The family-preference sort key is the reliable\nmechanism.\n\n## Test isolation & live verification\n\n- **Real tokens in `.env` leak into tests**: once a live provider adapter\n  exists, router\u002Favailability tests hit the real API (slow, flaky, and IBM's\n  queue state can change assertions). Add an autouse fixture resetting the\n  registry's module-global solver singletons\n  (`registry._origin_wukong = registry._braket_backends = registry._ibm_backend = None`),\n  plus a per-test `no_ibm`-style fixture that nulls the provider token.\n- Adapter solve tests: mock the SDK seam (`_new_service`) AND `qiskit.transpile`\n  (fake backends lack `.target`; transpile runs real pass managers).\n- Live paid verification: gate real QPU execution behind a flag\n  (`QUANTUM_LIVE_EXECUTION=true` in the unit env) — **never flip the gate off\n  mid-job**: the worker picks the flag up later and fails an already-paid,\n  already-submitted run. Flag on → paid request → poll to completion → flag\n  off → verify ledger. Wallet-balance checks via public RPCs need a browser\n  User-Agent header or most public endpoints 403.\n\n## Cost model pattern\n\nProvider cost per adapter (`price_usd`), charged price =\n`max(list_price, provider_cost × MARKUP)`; margin guards must compare against\nthe **effective (charged)** price, not the list price. IBM open plan → cost\n$0.00 → tier sells at list price with full margin (but see \"Routing vs\nprovider cost\" above — set cost ≥ primary's for ranking parity if the primary\nmust win selection).\n",{},"main","38b32c99e7ed0b8e215d638e92cfa452c1ec3079","skills\u002Fimported\u002F.archive\u002Fquantum-provider-integration","https:\u002F\u002Fgithub.com\u002Fjonahthan433\u002FCortexOS","https:\u002F\u002Fgithub.com\u002Fjonahthan433","AI Consultant","2026-10-24 05:13:39",{"source":7,"skillName":5,"commands":30,"prompt":40,"zipAvailable":41},[31,34,37],{"tool":32,"command":33},"npx","npx skills add jonahthan433\u002FCortexOS --skill quantum-provider-integration",{"tool":35,"command":36},"bunx","bunx skills add jonahthan433\u002FCortexOS --skill quantum-provider-integration",{"tool":38,"command":39},"pnpm","pnpm dlx skills add jonahthan433\u002FCortexOS --skill quantum-provider-integration","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002Fjonahthan433\u002FCortexOS\u002Fblob\u002Fmain\u002Fskills\u002Fimported\u002F.archive\u002Fquantum-provider-integration\u002FSKILL.md",true,[43],{"path":44,"resourceType":45,"resourceTypeDesc":46,"sizeBytes":47,"sourceHtmlUrl":48},"skill.json","REFERENCE","参考文档",384,"https:\u002F\u002Fgithub.com\u002Fjonahthan433\u002FCortexOS\u002Fblob\u002Fmain\u002Fskills\u002Fimported\u002F.archive\u002Fquantum-provider-integration\u002Fskill.json",[50,56,62,68,74,80],{"skillNo":51,"name":52,"nameZh":6,"description":6,"descriptionZh":6,"repositoryFullName":7,"ownerLogin":8,"ownerAvatarUrl":9,"ownerAccountNo":10,"ownerDisplayName":11,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":53,"categories":54,"keywords":55,"publishedAt":18},"01M7EDQZDQX3Q8Y7GCQX6KN9V7","opportunity-brief","https:\u002F\u002Fgithub.com\u002Fjonahthan433\u002FCortexOS\u002Fblob\u002Fmain\u002Fskills\u002Fsales\u002Fopportunity-brief\u002FSKILL.md",[],[],{"skillNo":57,"name":58,"nameZh":6,"description":6,"descriptionZh":6,"repositoryFullName":7,"ownerLogin":8,"ownerAvatarUrl":9,"ownerAccountNo":10,"ownerDisplayName":11,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":59,"categories":60,"keywords":61,"publishedAt":18},"01M7EDQYA0V9Y99VKBREJJ3MRT","morning-intel","https:\u002F\u002Fgithub.com\u002Fjonahthan433\u002FCortexOS\u002Fblob\u002Fmain\u002Fskills\u002Fresearch\u002Fmorning-intel\u002FSKILL.md",[],[],{"skillNo":63,"name":64,"nameZh":6,"description":6,"descriptionZh":6,"repositoryFullName":7,"ownerLogin":8,"ownerAvatarUrl":9,"ownerAccountNo":10,"ownerDisplayName":11,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":65,"categories":66,"keywords":67,"publishedAt":18},"01M7EDQVX1JVY0B6PDHKKGM19G","decision-brief","https:\u002F\u002Fgithub.com\u002Fjonahthan433\u002FCortexOS\u002Fblob\u002Fmain\u002Fskills\u002Fresearch\u002Fdecision-brief\u002FSKILL.md",[],[],{"skillNo":69,"name":70,"nameZh":6,"description":6,"descriptionZh":6,"repositoryFullName":7,"ownerLogin":8,"ownerAvatarUrl":9,"ownerAccountNo":10,"ownerDisplayName":11,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":71,"categories":72,"keywords":73,"publishedAt":18},"01M7EDQV1GENZAC2SZSD8KZ3GM","weekly-review","https:\u002F\u002Fgithub.com\u002Fjonahthan433\u002FCortexOS\u002Fblob\u002Fmain\u002Fskills\u002Fproductivity\u002Fweekly-review\u002FSKILL.md",[],[],{"skillNo":75,"name":76,"nameZh":6,"description":6,"descriptionZh":6,"repositoryFullName":7,"ownerLogin":8,"ownerAvatarUrl":9,"ownerAccountNo":10,"ownerDisplayName":11,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":77,"categories":78,"keywords":79,"publishedAt":18},"01M7EDQT2KETJ1Y3CGVN9EKW2J","system-health","https:\u002F\u002Fgithub.com\u002Fjonahthan433\u002FCortexOS\u002Fblob\u002Fmain\u002Fskills\u002Fops\u002Fsystem-health\u002FSKILL.md",[],[],{"skillNo":81,"name":82,"nameZh":6,"description":6,"descriptionZh":6,"repositoryFullName":7,"ownerLogin":8,"ownerAvatarUrl":9,"ownerAccountNo":10,"ownerDisplayName":11,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":83,"categories":84,"keywords":85,"publishedAt":18},"01M7EDQQN2JK3XPWMS1M4T0F3K","backup-restore","https:\u002F\u002Fgithub.com\u002Fjonahthan433\u002FCortexOS\u002Fblob\u002Fmain\u002Fskills\u002Fops\u002Fbackup-restore\u002FSKILL.md",[],[]]