[{"data":1,"prerenderedAt":14003},["ShallowReactive",2],{"blog-post-using-quantum-in-a-real-application":3,"sibling-dives-using-quantum-in-a-real-application":75,"learn-track-using-quantum-in-a-real-application":76,"learn-prereq-using-quantum-in-a-real-application":7314},{"id":4,"title":5,"authors":6,"body":8,"breadcrumb":25,"builders":28,"byline":29,"category":33,"categoryName":33,"challenge":33,"courseAuthor":34,"courseLead":43,"dek":44,"description":45,"draft":46,"extension":47,"eyebrow":33,"featured":46,"finish":33,"fork":33,"group":33,"groupName":33,"hero":33,"heroAlt":33,"heroCta":33,"heroImage":33,"homepageFeatured":46,"kind":48,"lessonCount":33,"meta":49,"navigation":50,"newsItems":33,"next":33,"ogImage":33,"order":51,"outcomes":52,"path":59,"prerequisite":60,"prerequisiteLinks":61,"publishDate":66,"readingTime":33,"related":67,"relatedProjects":33,"section":33,"seo":68,"stem":71,"tags":72,"track":73,"trackName":33,"__hash__":74},"blog\u002Fblog\u002Flearn\u002Fusing-quantum-in-a-real-application.md","Using quantum in a real application",[7],"nico",{"type":9,"value":10,"toc":21},"minimark",[11],[12,13,14,15,20],"p",{},"Builders are putting quantum circuits into applications in finance, music, art and chemistry, and building one is easier than it was a few years ago. You run circuits from your browser, on a free simulator or on IonQ hardware for credits, and you can fork any public project on Qollab. After ",[16,17,19],"a",{"href":18},"\u002Flearn\u002Fprogramming-your-first-quantum-circuits","Programming your first quantum circuits",", where you write a circuit and read its tally, the next step is the program that sends the circuit and uses the tally.",{"title":22,"searchDepth":23,"depth":23,"links":24},"",2,[],[26,27,5],"Qollab","Learn",[],{"username":7,"name":30,"role":31,"avatar":32},"Nicolaas Spijker","Community manager, Qollab","\u002F_content\u002Fimages\u002Fbuilders\u002Fnicolaas-spijker.webp",null,{"name":30,"role":31,"bio":35,"avatar":32,"links":36},"Nico runs the builder community at Qollab and wrote this course from projects builders published there.",[37,40],{"label":38,"href":39},"Qollab ↗","https:\u002F\u002Fqollab.xyz\u002Fu\u002Fnico",{"label":41,"href":42},"GitHub ↗","https:\u002F\u002Fgithub.com\u002Fnicolaasspijker","You look inside five projects, then build a weighted random picker around a one-qubit circuit and run it on the IonQ simulator.","Put a quantum circuit inside an ordinary program: where the circuit sits, what crosses the boundary, and whether quantum is worth it.","Six free lessons on putting a quantum circuit inside an ordinary program: where the circuit sits, what crosses the boundary, and whether quantum is worth it.",false,"md","landing",{},true,5,[53,54,55,56,57,58],"Where a circuit sits in an application, and what the program around it has to do","What crosses the boundary in each direction, and why a circuit returns a distribution of outcomes","How to turn application data into a circuit and decode the tally into a typed result","How to drive an interface from circuit output, both while the run is in flight and when the run fails","How to race a quantum approach against conventional code and judge the result against thresholds you set first","How to go from an application idea to the circuit inside it, or rule the idea out quickly","\u002Fblog\u002Flearn\u002Fusing-quantum-in-a-real-application","programming-your-first-quantum-circuits",[62],{"title":63,"href":64,"meta":65},"A free Qollab account","\u002Flogin","Google or GitHub sign-in","2026-09-22",[],{"title":69,"description":70},"Using quantum in a real application · Free six-lesson course","Six lessons on putting a quantum circuit in an ordinary program: the classical\u002Fquantum boundary, an interface for its output and a race against classical code.","blog\u002Flearn\u002Fusing-quantum-in-a-real-application",[],"using-quantum-in-a-real-application","edhEbzZzedQvaK8c5KQS-bIAELkQnmCFo7mApi0mnJo",[],[77,915,2085,3571,5114,6190],{"id":78,"title":79,"authors":80,"body":81,"breadcrumb":898,"builders":899,"byline":900,"category":33,"categoryName":33,"challenge":33,"courseAuthor":33,"courseLead":33,"dek":901,"description":902,"draft":46,"extension":47,"eyebrow":33,"featured":46,"finish":33,"fork":33,"group":33,"groupName":33,"hero":33,"heroAlt":33,"heroCta":33,"heroImage":33,"homepageFeatured":46,"kind":903,"lessonCount":557,"meta":904,"navigation":50,"newsItems":33,"next":905,"ogImage":33,"order":192,"outcomes":33,"path":909,"prerequisite":33,"prerequisiteLinks":33,"publishDate":66,"readingTime":33,"related":910,"relatedProjects":33,"section":33,"seo":911,"stem":912,"tags":913,"track":73,"trackName":5,"__hash__":914},"blog\u002Fblog\u002Flearn\u002Fusing-quantum-in-a-real-application\u002Fwhere-the-circuit-sits.md","Where the circuit sits",[7],{"type":9,"value":82,"toc":887},[83,86,89,97,107,110,115,122,157,160,163,166,174,320,326,330,333,363,366,372,375,379,385,388,397,400,403,406,415,418,425,428,434,437,443,451,460,463,467,475,484,490,497,720,727,730,754,767,770,773,781,788,870,874,880,883],[12,84,85],{},"A quantum circuit is a component your program calls. You send the quantum computer a circuit, you wait, and you get a tally of results back. The rest of your program stays in the Python or JavaScript you already write.",[12,87,88],{},"Programs like that are being built for finance, music, art and chemistry, and they are easier to build than they were a few years ago.",[12,90,91,92,96],{},"In spring 2026, after more than a decade in enterprise data architecture at a global bank, Jamie Dominguez started building with quantum computers. He built the ",[16,93,95],{"href":94},"\u002Fexplore\u002Fquantum-systemic-oracle","Quantum Systemic Oracle"," alone, in a few weeks, to find out what he could make on real hardware with AI coding tools. The Oracle turns a day's market data into a risk score. Only one part of it, the portfolio optimization, is a quantum circuit, and Jamie treated that part as one component to wire in.",[98,99,104],"pull-quote",{"avatar":100,"name":101,"role":102,"username":103},"\u002F_content\u002Fimages\u002Fbuilders\u002Fjamie-dominguez.webp","Jamie Dominguez","Creator, Quantum Systemic Oracle","jamie",[12,105,106],{},"This was my first QPU job and Qiskit run. I learned it's much easier to get started now than ever before.",[12,108,109],{},"You can wire a circuit into a program of your own the same way. Lesson 3 gives you one to start from, a weighted random picker built around a one-qubit circuit, which you fork and change, and lesson 5 races it against ordinary Python.",[111,112,114],"h2",{"id":113},"the-five-steps-around-a-circuit","The five steps around a circuit",[116,117],"blog-figure",{"caption":118,"no":119,"alt":120,"src":121},"Only two arrows cross the boundary. Application data goes right as circuit parameters; a tally comes back left as ordinary data. Both sides of the line are code you write.","Fig. 1","A dashed vertical line divides the picture. On the left, ordinary code: app state feeds a prepare step. On the right, the quantum computer: a circuit feeds a measure step. An arrow labelled angles crosses the line to the right, and an arrow labelled a tally not a value crosses back to the left into a decode step, which feeds the result the program uses.","\u002F_content\u002Fimages\u002Freal-app\u002Fthe-boundary.svg",[123,124,125,133,139,145,151],"ol",{},[126,127,128,132],"li",{},[129,130,131],"strong",{},"App state."," Your application has some state: a request, a dataset or something a user just did.",[126,134,135,138],{},[129,136,137],{},"Prepare."," Ordinary code turns that state into numbers the circuit can take, usually angles.",[126,140,141,144],{},[129,142,143],{},"Circuit."," The circuit runs on the backend: a quantum computer, or a simulator of one.",[126,146,147,150],{},[129,148,149],{},"Measure."," Each shot ends in a measurement that reads one bitstring, and the tally of those bitstrings, the counts, comes back to your program.",[126,152,153,156],{},[129,154,155],{},"Decode."," Ordinary code turns the tally into a value the rest of your program can use.",[12,158,159],{},"Steps three and four run on the backend, and you reach them through one function call.",[12,161,162],{},"In the Oracle, the application state is the day's market data. The prepare step turns that data into the coefficients of a portfolio-optimization problem, and the coefficients set the circuit's rotation angles. IonQ runs the circuit and sends back a tally of sampled portfolios. In each 14-bit string, eight bits mark which of the eight candidate assets that portfolio holds.",[12,164,165],{},"The decode step measures the quality of the sampled portfolios and blends it with eight market signals into the risk score. The pipeline is built to publish the risk score to an Ethereum test network, where other programs can read it.",[12,167,168,169,173],{},"In the Oracle's listing, the function call between the two sides is ",[170,171,172],"code",{},"backend.run",", with the circuit built above it and the tally read below it:",[175,176,180],"code-block",{"name":177,"no-picker":22,"run-href":178,"tag":179},"Qollab.py","\u002Fu\u002Fjamie\u002Fsystemic-oracle","Python · excerpt",[181,182,186],"pre",{"className":183,"code":184,"language":185,"meta":22,"style":22},"language-python shiki shiki-themes one-dark-pro","qc = build_circuit(gammas, betas, ising_h, ising_J_pairs, SNAPSHOT)\njob = backend.run(transpile(qc, backend), shots=SHOTS)\nwhile job.status() is not JobStatus.DONE:\n    time.sleep(2)\ncounts = job.result().get_counts()   # sampled portfolios -> risk score (BPS)\n","python",[170,187,188,215,248,279,295],{"__ignoreMap":22},[189,190,193,197,201,205,208,212],"span",{"class":191,"line":192},"line",1,[189,194,196],{"class":195},"sn6KH","qc ",[189,198,200],{"class":199},"sjrmR","=",[189,202,204],{"class":203},"sVbv2"," build_circuit",[189,206,207],{"class":195},"(gammas, betas, ising_h, ising_J_pairs, ",[189,209,211],{"class":210},"sVC51","SNAPSHOT",[189,213,214],{"class":195},")\n",[189,216,217,220,222,225,228,231,234,237,241,243,246],{"class":191,"line":23},[189,218,219],{"class":195},"job ",[189,221,200],{"class":199},[189,223,224],{"class":195}," backend.",[189,226,227],{"class":203},"run",[189,229,230],{"class":195},"(",[189,232,233],{"class":203},"transpile",[189,235,236],{"class":195},"(qc, backend), ",[189,238,240],{"class":239},"s_ZVi","shots",[189,242,200],{"class":199},[189,244,245],{"class":210},"SHOTS",[189,247,214],{"class":195},[189,249,251,255,258,261,264,267,270,273,276],{"class":191,"line":250},3,[189,252,254],{"class":253},"seHd6","while",[189,256,257],{"class":195}," job.",[189,259,260],{"class":203},"status",[189,262,263],{"class":195},"() ",[189,265,266],{"class":253},"is",[189,268,269],{"class":253}," not",[189,271,272],{"class":195}," JobStatus.",[189,274,275],{"class":210},"DONE",[189,277,278],{"class":195},":\n",[189,280,282,285,288,290,293],{"class":191,"line":281},4,[189,283,284],{"class":195},"    time.",[189,286,287],{"class":203},"sleep",[189,289,230],{"class":195},[189,291,292],{"class":210},"2",[189,294,214],{"class":195},[189,296,297,300,302,304,307,310,313,316],{"class":191,"line":51},[189,298,299],{"class":195},"counts ",[189,301,200],{"class":199},[189,303,257],{"class":195},[189,305,306],{"class":203},"result",[189,308,309],{"class":195},"().",[189,311,312],{"class":203},"get_counts",[189,314,315],{"class":195},"()   ",[189,317,319],{"class":318},"sV9Aq","# sampled portfolios -> risk score (BPS)\n",[116,321],{"caption":322,"no":323,"poster":324,"video":325},"The Oracle's dashboard for one day's run: the risk score moving as someone drags the market-signal sliders, the portfolio the quantum job picked beside the best one found by brute force, and the diagnostics of that run on IonQ Forte hardware.","Fig. 2","\u002F_content\u002Fimages\u002Freal-app\u002Foracle-poster.webp","https:\u002F\u002Fapi.cms.qollab.xyz\u002Fassets\u002Fe2405685-d94e-4678-95ff-78c4a081aa9c",[111,327,329],{"id":328},"a-music-studio-a-market-tool-and-an-artwork","A music studio, a market tool and an artwork",[12,331,332],{},"Musiq, Quantum Regime Radar and Quantum Butterfly Field were also built in spring 2026, in a few weeks each. All three have a listing on Qollab that you can run and fork.",[334,335,336,345,354],"ul",{},[126,337,338,344],{},[129,339,340],{},[16,341,343],{"href":342},"\u002Fexplore\u002Fmusiq","Musiq"," is a music studio in the browser that plays a circuit's outcomes as notes.",[126,346,347,353],{},[129,348,349],{},[16,350,352],{"href":351},"\u002Fexplore\u002Fquantum-regime-radar","Quantum Regime Radar"," is a market tool that scores a window of market returns against five volatility regimes taken from market history.",[126,355,356,362],{},[129,357,358],{},[16,359,361],{"href":360},"\u002Fexplore\u002Fquantum-butterfly-field","Quantum Butterfly Field"," is an artwork in which five butterflies are five qubits, one of them damaged and then recovered.",[12,364,365],{},"Figure 3 lines the three programs up against the five steps.",[116,367],{"caption":368,"no":369,"alt":370,"src":371},"The three projects differ in the data entering prepare, the raw result each one asks for, and what decode turns that result into.","Fig. 3","Three rows share five columns: app state, prepare, circuit and run, raw result, decode. Musiq goes from a circuit the user designed, through no preparation, to amplitudes and probabilities, to a waveform. Regime Radar goes from market returns, through fingerprint angles, to a comparison circuit, to the share of all-zero shots, to a regime score. Butterfly Field goes from scrambling settings, through a layer count and a seed, to an evolution circuit, to purities, entanglement and fidelities, to opacity and threads.","\u002F_content\u002Fimages\u002Freal-app\u002Fone-boundary-three-products.svg",[12,373,374],{},"All three programs use more than a tally. Musiq and Butterfly Field read values that only a simulator can hand back, such as amplitudes, phases and purities. The Radar computes exact overlaps to rank its regimes before it spends any shots. Lesson 2 covers when a program can have those values.",[376,377,343],"h3",{"id":378},"musiq",[116,380],{"caption":381,"no":382,"poster":383,"video":384},"Building a circuit in Musiq, running it, and hearing the result, with its waveform and spectrum on screen. The video has sound.","Fig. 4","\u002F_content\u002Fimages\u002Fmusiq\u002Fhero.webp","https:\u002F\u002Fapi.cms.qollab.xyz\u002Fassets\u002F064dd3e0-1e11-4ebc-8646-a5b4444fbbca",[12,386,387],{},"Tomoya Hatanaka, who led Musiq, wanted music generated directly from quantum states, because he finds music built on classical random-number generators repetitive. Emmanuella Adams, a creative technologist, worked on how circuits become sound and on the studio's interface.",[98,389,394],{"avatar":390,"name":391,"role":392,"username":393},"\u002F_content\u002Fimages\u002Fbuilders\u002Femmanuella-adams.webp","Emmanuella Adams","Creative technologist, Musiq","emmanuellaadams",[12,395,396],{},"Curiosity, not fear. Quantum computing is often presented as this impossible, gatekept thing. I want someone to hear their circuit and think, \"Oh, that's mine. I made that.\" The feeling of creating something you don't fully understand yet. That is where learning starts.",[12,398,399],{},"Musiq has no separate prepare step, because the circuit you design in the studio is its input. Musiq's decode step is a mapping table. Each measured outcome picks which note plays, how often the outcome came up sets how strong that note is, and the statevector's phases shape how the notes interfere. The output is a waveform you can play and export.",[376,401,352],{"id":402},"quantum-regime-radar",[12,404,405],{},"The Radar's premise is that a volatility model fitted in a calm market breaks in a crisis, so a modeller needs to know which regime the market is in first. Two of its five regimes are the low-volatility rally of 2017 and the 2020 COVID crash. The regime library is built on Alireza Khodaei's doctoral research, which estimated volatility-model parameters on a quantum annealer. An annealer is a different kind of quantum machine from the gate circuits in this course.",[98,407,412],{"avatar":408,"name":409,"role":410,"username":411},"\u002F_content\u002Fimages\u002Fbuilders\u002Falireza-khodaei.webp","Alireza Khodaei","Creator, Quantum Regime Radar","alireza",[12,413,414],{},"We have a bunch of known market regimes with respect to volatility, and we make a quantum fingerprint out of each. Then, given live data: how similar are these two days to the pre-crisis regime? There is no yes-or-no answer. There is a probability.",[12,416,417],{},"The Radar's prepare step turns a window of market returns into the angles of a circuit whose state encodes how the market's volatility has behaved, a fingerprint of those conditions. The playground cell ships those angles already fitted.",[12,419,420,421,424],{},"The circuit prepares that fingerprint, runs a reference regime's circuit backwards over it, and measures. Running a circuit and then its reverse returns every qubit to 0, the way two ",[170,422,423],{},"h"," gates in a row do. So when the two fingerprints are identical, every shot on a noise-free simulator reads all zeros. The decode step reads the share of all-zero shots as a similarity score.",[12,426,427],{},"Figure 5 shows our run of the Radar on 22 September 2026, for NVDA in 2022, on the built-in simulator. The console shows the exact ranking first, with the COVID crash on top, then tests the top-ranked regime with one circuit. In the Probabilities panel, 17.68% of the 2,048 shots came back all zeros. The console reports that share as K = 0.1768, within shot noise of the exact 0.1779.",[116,429],{"caption":430,"no":431,"alt":432,"src":433},"Regime Radar on the Qollab Playground: the console's ranking on the left, the Probabilities panel for the tally on the right.","Fig. 5","The Regime Radar project's output on the Qollab Playground, run on the built-in simulator. On the left, the console ranks five volatility regimes for NVDA in 2022, with the 2020 COVID crash on top at K 0.1779, runs one circuit for 2,048 shots, and reports a measured K of 0.1768. On the right, the Probabilities panel lists twelve-bit outcomes; the all-zeros outcome's bar, at 17.68%, is far longer than the others in view.","\u002F_content\u002Fimages\u002Freal-app\u002Fregime-radar-run.webp",[376,435,361],{"id":436},"quantum-butterfly-field",[116,438],{"caption":439,"no":440,"poster":441,"video":442},"The opening of Quantum Butterfly Field: two butterflies arrive one at a time, then the field fills with threads as more fly in and the first scrambling beat begins. The video has sound.","Fig. 6","\u002F_content\u002Fimages\u002Freal-app\u002Fbutterfly-poster.webp","https:\u002F\u002Fapi.cms.qollab.xyz\u002Fassets\u002F3768811c-0ddc-4ad3-b2cd-416c8cebee9c",[12,444,445,446,450],{},"Xinyi Zhang, an artist and technologist, first painted Butterfly Field in 2024, while she lived on Oʻahu. She had the idea for the circuit after reading a Scientific American article on the quantum no-butterfly effect, a 2020 result by ",[16,447,449],{"href":448},"https:\u002F\u002Farxiv.org\u002Fabs\u002F2003.07267","Yan and Sinitsyn",". Once information is scrambled deeply enough across an entangled system, damage to one part cannot destroy it, and running the scramble backwards recovers the damaged part almost completely.",[98,452,457],{"avatar":453,"name":454,"role":455,"username":456},"\u002F_content\u002Fimages\u002Fbuilders\u002Fxinyi-zhang.webp","Xinyi Zhang","Creator, Quantum Butterfly Field","xinyi",[12,458,459],{},"The one rule I held onto throughout was that every visual parameter had to be driven by a real quantum value, nothing decorative, nothing faked. The wing opacity really is the purity, the threads really are the mutual information between the qubit pairs. When something didn't look right, the solution was not to invent a prettier number, but to find a better mapping. The beauty had to be grounded in the physics.",[12,461,462],{},"Butterfly Field's prepare step picks a scrambling depth and a random seed, which fix the circuit's gates. The circuit scrambles the five butterflies into one field, damages one of them, and runs the scramble backwards. For each layer, the simulation returns every butterfly's purity, how much each pair of butterflies shares, and a fidelity for how far the damaged butterfly has recovered. The final fidelity comes from recorded runs on IonQ Forte hardware. The decode step turns those numbers into the picture, and the fidelity, for instance, sets how brightly the damaged butterfly glows.",[111,464,466],{"id":465},"find-the-boundary-in-quantum-garden","Find the boundary in Quantum Garden",[12,468,469,470,474],{},"Amber Wang and Justin Pincar, a data scientist and a software engineer, built ",[16,471,473],{"href":472},"\u002Fexplore\u002Fquantum-garden","Quantum Garden",", a digital garden where every plant gets its form from a circuit. They wanted to see what a garden based on the randomness of quantum measurement would look like. Neither came from quantum research. Justin had followed quantum computing for years before access to real hardware and the garden idea got him building.",[98,476,481],{"avatar":477,"name":478,"role":479,"username":480},"\u002F_content\u002Fimages\u002Fbuilders\u002Famber-wang.webp","Amber Wang","Co-creator, Quantum Garden","AmberPincar",[12,482,483],{},"Designing for quantum means treating concepts like superposition, entanglement, and probabilistic measurement as actual creative materials, not just technical details. Instead of thinking, \"What output do I want?\" you're asking, \"What distribution of possible states do I want, and how should people encounter those states over time?\"",[116,485],{"caption":486,"no":487,"alt":488,"src":489},"Quantum Garden's field, where plants germinate, bloom and fade on the garden's own schedule.","Fig. 7","The Quantum Garden field: flowers, grasses and small trees scattered across a pale lavender sky with soft clouds, several of them glowing, and a counter in the corner reading 129 plants.","\u002F_content\u002Fimages\u002Fquantum-garden\u002Ffig1-garden-preview.webp",[12,491,492,493,496],{},"Quantum Garden's listing on Qollab is about eighty lines and uses four gates, all of which you met in ",[16,494,495],{"href":18},"Course 2",". The excerpt below shows the first three of the listing's six layers, verbatim. The other three add phases, a second entangling pass and a final rotation, all from the same seed.",[175,498,501],{"name":499,"no-picker":22,"run-href":500,"tag":179},"plant_circuit.py","\u002Fu\u002FAmberPincar\u002Fquantum-garden",[181,502,504],{"className":183,"code":503,"language":185,"meta":22,"style":22},"seed = 42  # Each plant gets a deterministic seed from its ID hash\n\ncircuit = QuantumCircuit(5, 5)\n\n# Layer 1: Full superposition — all 32 outcomes initially possible\nfor i in range(5):\n    circuit.h(i)\n\n# Layer 2: Seed-based Ry rotations — parameterized bias per qubit\nfor i in range(5):\n    angle = (seed * (i + 1) * 0.1) % (2 * math.pi)\n    circuit.ry(angle, i)\n\n# Layer 3: Linear entanglement chain — correlates neighboring qubits\nfor i in range(4):\n    circuit.cx(i, i + 1)\n",[170,505,506,519,524,546,550,555,577,588,593,599,616,663,674,679,685,703],{"__ignoreMap":22},[189,507,508,511,513,516],{"class":191,"line":192},[189,509,510],{"class":195},"seed ",[189,512,200],{"class":199},[189,514,515],{"class":210}," 42",[189,517,518],{"class":318},"  # Each plant gets a deterministic seed from its ID hash\n",[189,520,521],{"class":191,"line":23},[189,522,523],{"emptyLinePlaceholder":50},"\n",[189,525,526,529,531,534,536,539,542,544],{"class":191,"line":250},[189,527,528],{"class":195},"circuit ",[189,530,200],{"class":199},[189,532,533],{"class":203}," QuantumCircuit",[189,535,230],{"class":195},[189,537,538],{"class":210},"5",[189,540,541],{"class":195},", ",[189,543,538],{"class":210},[189,545,214],{"class":195},[189,547,548],{"class":191,"line":281},[189,549,523],{"emptyLinePlaceholder":50},[189,551,552],{"class":191,"line":51},[189,553,554],{"class":318},"# Layer 1: Full superposition — all 32 outcomes initially possible\n",[189,556,558,561,564,567,570,572,574],{"class":191,"line":557},6,[189,559,560],{"class":253},"for",[189,562,563],{"class":195}," i ",[189,565,566],{"class":253},"in",[189,568,569],{"class":199}," range",[189,571,230],{"class":195},[189,573,538],{"class":210},[189,575,576],{"class":195},"):\n",[189,578,580,583,585],{"class":191,"line":579},7,[189,581,582],{"class":195},"    circuit.",[189,584,423],{"class":203},[189,586,587],{"class":195},"(i)\n",[189,589,591],{"class":191,"line":590},8,[189,592,523],{"emptyLinePlaceholder":50},[189,594,596],{"class":191,"line":595},9,[189,597,598],{"class":318},"# Layer 2: Seed-based Ry rotations — parameterized bias per qubit\n",[189,600,602,604,606,608,610,612,614],{"class":191,"line":601},10,[189,603,560],{"class":253},[189,605,563],{"class":195},[189,607,566],{"class":253},[189,609,569],{"class":199},[189,611,230],{"class":195},[189,613,538],{"class":210},[189,615,576],{"class":195},[189,617,619,622,624,627,630,633,636,639,642,644,647,649,652,655,657,660],{"class":191,"line":618},11,[189,620,621],{"class":195},"    angle ",[189,623,200],{"class":199},[189,625,626],{"class":195}," (seed ",[189,628,629],{"class":199},"*",[189,631,632],{"class":195}," (i ",[189,634,635],{"class":199},"+",[189,637,638],{"class":210}," 1",[189,640,641],{"class":195},") ",[189,643,629],{"class":199},[189,645,646],{"class":210}," 0.1",[189,648,641],{"class":195},[189,650,651],{"class":199},"%",[189,653,654],{"class":195}," (",[189,656,292],{"class":210},[189,658,659],{"class":199}," *",[189,661,662],{"class":195}," math.pi)\n",[189,664,666,668,671],{"class":191,"line":665},12,[189,667,582],{"class":195},[189,669,670],{"class":203},"ry",[189,672,673],{"class":195},"(angle, i)\n",[189,675,677],{"class":191,"line":676},13,[189,678,523],{"emptyLinePlaceholder":50},[189,680,682],{"class":191,"line":681},14,[189,683,684],{"class":318},"# Layer 3: Linear entanglement chain — correlates neighboring qubits\n",[189,686,688,690,692,694,696,698,701],{"class":191,"line":687},15,[189,689,560],{"class":253},[189,691,563],{"class":195},[189,693,566],{"class":253},[189,695,569],{"class":199},[189,697,230],{"class":195},[189,699,700],{"class":210},"4",[189,702,576],{"class":195},[189,704,706,708,711,714,716,718],{"class":191,"line":705},16,[189,707,582],{"class":195},[189,709,710],{"class":203},"cx",[189,712,713],{"class":195},"(i, i ",[189,715,635],{"class":199},[189,717,638],{"class":210},[189,719,214],{"class":195},[12,721,722,723,726],{},"The prepare step is that ",[170,724,725],{},"seed",". The listing's comment says each plant's seed comes from its ID hash, and the seed sets every rotation angle in the circuit.",[12,728,729],{},"The listing's own header says the circuit's layers create a \"quantum fingerprint\" that determines a plant's glyph pattern, colour palette, growth rate and opacity. The decode step that turns the fingerprint into those traits lives in the garden's app, outside the eighty lines you are looking at. Five qubits give thirty-two possible outcomes, and each plant's traits come from one of them. The app draws that outcome from a pool of results computed in advance, which lesson 4 comes back to.",[12,731,732,733,737,738,741,742,745,746,749,750,753],{},"Open ",[16,734,736],{"href":735},"https:\u002F\u002Fqollab.xyz\u002Fu\u002FAmberPincar\u002Fquantum-garden","the project",", press ",[129,739,740],{},"Run on Qollab",", and pick ",[129,743,744],{},"IonQ Aria 1 (25q)"," under ",[129,747,748],{},"Remotely Run Simulators"," in the Run Experiment dialog, then press ",[129,751,752],{},"Run",".",[12,755,756,757,759,760,762,763,766],{},"The ",[129,758,744],{}," row under ",[129,761,748],{}," is IonQ's simulator with a noise model of the Aria 1 machine, and it is free. The same name appears again further down under ",[129,764,765],{},"Quantum Computer",", which is the real machine and costs credits. Every run we pressed for this course used a simulator.",[12,768,769],{},"The first press takes a while, because the browser loads Python and Qiskit before anything runs. Ours took over a minute.",[12,771,772],{},"In our run on 22 September 2026 the console ended like this:",[181,774,779],{"className":775,"code":777,"language":778,"meta":22},[776],"language-text","Job status is JobStatus.DONE\nCounts for 100 shots: {'00001': 13, '00011': 15, '01001': 7, '01101': 24, '11101': 10}\n","text",[170,780,777],{"__ignoreMap":22},[12,782,783,784,787],{},"Only the ",[170,785,786],{},"Counts"," line carries a result back from IonQ. The counts on that line add up to 69 of the 100 shots.",[789,790,792,796,829],"assignment",{"check":791},"your console shows a 'Counts for 100 shots:' line, and you can say which line of the listing produced it.",[111,793,795],{"id":794},"assignment-find-the-boundary-in-a-project-you-did-not-write","Assignment: find the boundary in a project you did not write",[123,797,798,804,817,820,823,826],{},[126,799,732,800,753],{},[16,801,802],{"href":735},[170,803,500],{},[126,805,806,807,809,810,745,812,814,815,753],{},"Press ",[129,808,740],{},", choose ",[129,811,744],{},[129,813,748],{},", and press ",[129,816,752],{},[126,818,819],{},"Wait for the console to finish. The first press is slow.",[126,821,822],{},"In the printed output, find the one line that came back across the boundary.",[126,824,825],{},"In the listing, find the single line that sends the circuit across the boundary.",[126,827,828],{},"Find the line that decides what the circuit is, and read what it is built from.",[830,831,833,846,860,867],"hint",{"label":832},"Solution",[12,834,756,835,838,839,842,843,845],{},[170,836,837],{},"Counts for 100 shots:"," line is the only result that came through the boundary. The ",[170,840,841],{},"Job status"," lines above the ",[170,844,786],{}," line are the script polling for that result, and the drawn circuit above those was printed by your browser before anything ran.",[12,847,848,851,852,855,856,859],{},[170,849,850],{},"job = backend.run(circuit, shots=shots)",", inside ",[170,853,854],{},"main",", is the line that crosses, and the only place ",[170,857,858],{},"backend"," is used.",[12,861,862,863,866],{},"The circuit is built from ",[170,864,865],{},"seed = 42",". Every angle in the listing is computed from the seed and the qubit's index, so the seed alone sets which circuit runs; the listing draws no random numbers.",[12,868,869],{},"Your tally will not match ours, and a second press will give a different tally again.",[111,871,873],{"id":872},"takeaway","Takeaway",[12,875,876,877,879],{},"In the Qollab listing of each of the five projects, a ",[170,878,172],{}," call hands the circuit to a backend, and the result comes back across that call as ordinary data. To read a quantum application you did not write, find that call first, then read what the program feeds into it and what it makes of the result.",[12,881,882],{},"Lesson 2 presses Quantum Garden again and shows where the 31 shots missing from its tally went.",[884,885,886],"style",{},"html pre.shiki code .sn6KH, html code.shiki .sn6KH{--shiki-default:#ABB2BF}html pre.shiki code .sjrmR, html code.shiki .sjrmR{--shiki-default:#56B6C2}html pre.shiki code .sVbv2, html code.shiki .sVbv2{--shiki-default:#61AFEF}html pre.shiki code .sVC51, html code.shiki .sVC51{--shiki-default:#D19A66}html pre.shiki code .s_ZVi, html code.shiki .s_ZVi{--shiki-default:#E06C75;--shiki-default-font-style:italic}html pre.shiki code .seHd6, html code.shiki .seHd6{--shiki-default:#C678DD}html pre.shiki code .sV9Aq, html code.shiki .sV9Aq{--shiki-default:#7F848E;--shiki-default-font-style:italic}html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}",{"title":22,"searchDepth":23,"depth":23,"links":888},[889,890,895,896,897],{"id":113,"depth":23,"text":114},{"id":328,"depth":23,"text":329,"children":891},[892,893,894],{"id":378,"depth":250,"text":343},{"id":402,"depth":250,"text":352},{"id":436,"depth":250,"text":361},{"id":465,"depth":23,"text":466},{"id":794,"depth":23,"text":795},{"id":872,"depth":23,"text":873},[26,27,5,79],[],{"username":7,"name":30,"role":31,"avatar":32},"A risk pipeline, a music studio, a market tool, an artwork and a garden each call a quantum circuit from ordinary code.","A quantum circuit is a component your program calls, and a risk pipeline, a music studio, a market tool, an artwork and a garden each show where that call sits.","lesson",{},{"slug":906,"title":907,"desc":908},"\u002Fblog\u002Flearn\u002Fusing-quantum-in-a-real-application\u002Fwhat-crosses-the-boundary","What crosses the boundary","A quantum computer sends its results back as a tally, and a program that needs the exact state simulates the circuit instead.","\u002Fblog\u002Flearn\u002Fusing-quantum-in-a-real-application\u002Fwhere-the-circuit-sits",[],{"title":79,"description":902},"blog\u002Flearn\u002Fusing-quantum-in-a-real-application\u002Fwhere-the-circuit-sits",[],"kjGGywxJozASb7jEkYZfiwgGqxVpdm5Xgg_DPt-6Kyc",{"id":916,"title":907,"authors":917,"body":918,"breadcrumb":2071,"builders":2072,"byline":2073,"category":33,"categoryName":33,"challenge":33,"courseAuthor":33,"courseLead":33,"dek":908,"description":2074,"draft":46,"extension":47,"eyebrow":33,"featured":46,"finish":33,"fork":33,"group":33,"groupName":33,"hero":33,"heroAlt":33,"heroCta":33,"heroImage":33,"homepageFeatured":46,"kind":903,"lessonCount":557,"meta":2075,"navigation":50,"newsItems":33,"next":2076,"ogImage":33,"order":23,"outcomes":33,"path":906,"prerequisite":33,"prerequisiteLinks":33,"publishDate":66,"readingTime":33,"related":2080,"relatedProjects":33,"section":33,"seo":2081,"stem":2082,"tags":2083,"track":73,"trackName":5,"__hash__":2084},"blog\u002Fblog\u002Flearn\u002Fusing-quantum-in-a-real-application\u002Fwhat-crosses-the-boundary.md",[7],{"type":9,"value":919,"toc":2061},[920,926,933,939,943,946,949,952,958,963,967,981,1681,1688,1694,1697,1806,1810,1816,1827,1834,1841,1845,1871,1874,1925,1929,1935,1941,1952,1957,1960,1976,1979,2050,2052,2055,2058],[12,921,922,923,925],{},"A tally is the only result a quantum computer sends back across the boundary: the number of shots that read each bitstring. In lesson 1 you pressed Quantum Garden on IonQ's Aria 1 simulator, and Garden printed its counts on the ",[170,924,837],{}," line. Our run on 22 September 2026 printed counts that added up to 69 of the 100 shots.",[12,927,928,929,932],{},"Musiq, Quantum Regime Radar and Quantum Butterfly Field, from lesson 1, use more than a tally. The three projects read exact amplitudes, phases, purities or overlaps, which come from a circuit's exact state, its ",[129,930,931],{},"statevector",". Programs get a statevector only by simulating the circuit, so the parts of an application that need one run on a simulator.",[12,934,935,936,938],{},"You read one circuit both ways in the lesson's listing, as a statevector and as a tally, and moving a phase shows which reading changes. At the end you press Quantum Garden twice and work out why neither ",[170,937,786],{}," line adds up to 100 shots.",[111,940,942],{"id":941},"why-hardware-cannot-hand-you-a-statevector","Why hardware cannot hand you a statevector",[12,944,945],{},"A physical quantum state does not expose its amplitudes. The only way to learn anything from one is to measure it, and measuring returns a single bitstring and changes the state into the one you just read. Run the same circuit again and you get another single bitstring; a thousand runs give a tally of bitstrings that estimates the distribution.",[12,947,948],{},"A simulator holds the amplitudes in memory as ordinary floating-point numbers, so it can hand them to you directly, phases included, without measuring anything.",[12,950,951],{},"Better hardware will not add amplitudes to the output, because the limit comes from measurement itself: reading a physical qubit returns one outcome, however good the qubit is.",[12,953,954,957],{},[129,955,956],{},"If your application needs amplitudes or phases, it runs on a simulator",", which caps how many qubits you can use, because holding the state of n qubits takes 2ⁿ numbers. If your application can work from a distribution, it can run on hardware.",[116,959],{"alt":960,"caption":961,"no":119,"src":962},"Two panels. On the left, hardware: the circuit is rebuilt for every shot, each measurement yields one bitstring, and repeating 1,000 times gives a tally, labelled probabilities estimated and phase absent. On the right, a simulator: it holds an array of 2 to the n complex amplitudes, and can either hand that array over directly or sample it to imitate hardware and produce a tally, labelled amplitudes and phases available.","A simulator can hand over the amplitudes it holds, or sample them to imitate hardware.","\u002F_content\u002Fimages\u002Freal-app\u002Ftwo-observation-paths.svg",[111,964,966],{"id":965},"read-one-circuit-both-ways","Read one circuit both ways",[12,968,969,970,973,974,977,978,980],{},"The circuit in this listing is a Hadamard followed by an ",[170,971,972],{},"rz"," that puts a phase on one of the two paths. The listing reads the circuit both ways: ",[170,975,976],{},"Statevector"," asks the simulator for the amplitudes, which costs no shots and files no job, and ",[170,979,172],{}," samples the same circuit a thousand times.",[175,982,986],{"name":983,"no-picker":22,"run-href":984,"tag":985},"observe.py","\u002Fu\u002Fqollab\u002Flearn-app-observe","Python · Playground",[181,987,989],{"className":183,"code":988,"language":185,"meta":22,"style":22},"# 'backend' already exists when this runs: it is whatever you pick in the Run Experiment dialog.\nfrom math import pi\nfrom qiskit import QuantumCircuit\nfrom qiskit.quantum_info import Statevector\nfrom qiskit.providers.jobstatus import JobStatus\nimport time\n\nshots = 1000\nphi = 0.0\n\n\ndef build(measured):\n    qc = QuantumCircuit(1, 1)\n    qc.h(0)\n    qc.rz(phi, 0)\n    if measured:\n        qc.measure(0, 0)\n    return qc\n\n\nsv = Statevector(build(measured=False))\namps = [complex(a) for a in sv.data]\nprint(f\"statevector: |0> {amps[0]:+.3f}   |1> {amps[1]:+.3f}\")\nprint(f\"from it:     P(0)={abs(amps[0])**2:.3f}  P(1)={abs(amps[1])**2:.3f}\")\n\njob = backend.run(build(measured=True), shots=shots)\nwhile job.status() not in (JobStatus.DONE, JobStatus.ERROR, JobStatus.CANCELLED):\n    time.sleep(5)\n\ncounts = job.result().get_counts()\nprint(f\"counts:      {counts}\")\nz = counts.get(\"0\", 0)\nprint(f\"from them:   P(0)={z \u002F shots:.3f}  P(1)={(shots - z) \u002F shots:.3f}\")\n",[170,990,991,1001,1017,1031,1045,1059,1068,1075,1087,1101,1107,1113,1131,1152,1168,1183,1193,1214,1225,1232,1239,1270,1299,1353,1415,1422,1458,1495,1510,1517,1537,1562,1589,1642],{"__ignoreMap":22},[189,992,993,998],{"class":191,"line":192},[189,994,997],{"class":995,"aria-hidden":996},"qg-cue qg-cue--empty","true","​",[189,999,1000],{"class":318},"# 'backend' already exists when this runs: it is whatever you pick in the Run Experiment dialog.\n",[189,1002,1003,1005,1008,1011,1014],{"class":191,"line":23},[189,1004,997],{"class":995,"aria-hidden":996},[189,1006,1007],{"class":253},"from",[189,1009,1010],{"class":195}," math ",[189,1012,1013],{"class":253},"import",[189,1015,1016],{"class":195}," pi\n",[189,1018,1019,1021,1023,1026,1028],{"class":191,"line":250},[189,1020,997],{"class":995,"aria-hidden":996},[189,1022,1007],{"class":253},[189,1024,1025],{"class":195}," qiskit ",[189,1027,1013],{"class":253},[189,1029,1030],{"class":195}," QuantumCircuit\n",[189,1032,1033,1035,1037,1040,1042],{"class":191,"line":281},[189,1034,997],{"class":995,"aria-hidden":996},[189,1036,1007],{"class":253},[189,1038,1039],{"class":195}," qiskit.quantum_info ",[189,1041,1013],{"class":253},[189,1043,1044],{"class":195}," Statevector\n",[189,1046,1047,1049,1051,1054,1056],{"class":191,"line":51},[189,1048,997],{"class":995,"aria-hidden":996},[189,1050,1007],{"class":253},[189,1052,1053],{"class":195}," qiskit.providers.jobstatus ",[189,1055,1013],{"class":253},[189,1057,1058],{"class":195}," JobStatus\n",[189,1060,1061,1063,1065],{"class":191,"line":557},[189,1062,997],{"class":995,"aria-hidden":996},[189,1064,1013],{"class":253},[189,1066,1067],{"class":195}," time\n",[189,1069,1070,1072],{"class":191,"line":579},[189,1071,997],{"class":995,"aria-hidden":996},[189,1073,1074],{},"​\n",[189,1076,1077,1079,1082,1084],{"class":191,"line":590},[189,1078,997],{"class":995,"aria-hidden":996},[189,1080,1081],{"class":195},"shots ",[189,1083,200],{"class":199},[189,1085,1086],{"class":210}," 1000\n",[189,1088,1090,1093,1096,1098],{"class":191,"data-cue":1089,"line":595},"1",[189,1091,1089],{"class":1092},"qg-cue",[189,1094,1095],{"class":195},"phi ",[189,1097,200],{"class":199},[189,1099,1100],{"class":210}," 0.0\n",[189,1102,1103,1105],{"class":191,"line":601},[189,1104,997],{"class":995,"aria-hidden":996},[189,1106,1074],{},[189,1108,1109,1111],{"class":191,"line":618},[189,1110,997],{"class":995,"aria-hidden":996},[189,1112,1074],{},[189,1114,1115,1117,1120,1123,1125,1129],{"class":191,"data-cue":292,"line":665},[189,1116,292],{"class":1092},[189,1118,1119],{"class":253},"def",[189,1121,1122],{"class":203}," build",[189,1124,230],{"class":195},[189,1126,1128],{"class":1127},"sb9H8","measured",[189,1130,576],{"class":195},[189,1132,1133,1135,1138,1140,1142,1144,1146,1148,1150],{"class":191,"line":676},[189,1134,997],{"class":995,"aria-hidden":996},[189,1136,1137],{"class":195},"    qc ",[189,1139,200],{"class":199},[189,1141,533],{"class":203},[189,1143,230],{"class":195},[189,1145,1089],{"class":210},[189,1147,541],{"class":195},[189,1149,1089],{"class":210},[189,1151,214],{"class":195},[189,1153,1154,1156,1159,1161,1163,1166],{"class":191,"line":681},[189,1155,997],{"class":995,"aria-hidden":996},[189,1157,1158],{"class":195},"    qc.",[189,1160,423],{"class":203},[189,1162,230],{"class":195},[189,1164,1165],{"class":210},"0",[189,1167,214],{"class":195},[189,1169,1170,1172,1174,1176,1179,1181],{"class":191,"line":687},[189,1171,997],{"class":995,"aria-hidden":996},[189,1173,1158],{"class":195},[189,1175,972],{"class":203},[189,1177,1178],{"class":195},"(phi, ",[189,1180,1165],{"class":210},[189,1182,214],{"class":195},[189,1184,1185,1187,1190],{"class":191,"line":705},[189,1186,997],{"class":995,"aria-hidden":996},[189,1188,1189],{"class":253},"    if",[189,1191,1192],{"class":195}," measured:\n",[189,1194,1196,1198,1201,1204,1206,1208,1210,1212],{"class":191,"line":1195},17,[189,1197,997],{"class":995,"aria-hidden":996},[189,1199,1200],{"class":195},"        qc.",[189,1202,1203],{"class":203},"measure",[189,1205,230],{"class":195},[189,1207,1165],{"class":210},[189,1209,541],{"class":195},[189,1211,1165],{"class":210},[189,1213,214],{"class":195},[189,1215,1217,1219,1222],{"class":191,"line":1216},18,[189,1218,997],{"class":995,"aria-hidden":996},[189,1220,1221],{"class":253},"    return",[189,1223,1224],{"class":195}," qc\n",[189,1226,1228,1230],{"class":191,"line":1227},19,[189,1229,997],{"class":995,"aria-hidden":996},[189,1231,1074],{},[189,1233,1235,1237],{"class":191,"line":1234},20,[189,1236,997],{"class":995,"aria-hidden":996},[189,1238,1074],{},[189,1240,1243,1245,1248,1250,1253,1255,1258,1260,1262,1264,1267],{"class":191,"data-cue":1241,"line":1242},"3",21,[189,1244,1241],{"class":1092},[189,1246,1247],{"class":195},"sv ",[189,1249,200],{"class":199},[189,1251,1252],{"class":203}," Statevector",[189,1254,230],{"class":195},[189,1256,1257],{"class":203},"build",[189,1259,230],{"class":195},[189,1261,1128],{"class":239},[189,1263,200],{"class":199},[189,1265,1266],{"class":210},"False",[189,1268,1269],{"class":195},"))\n",[189,1271,1273,1275,1278,1280,1283,1286,1289,1291,1294,1296],{"class":191,"line":1272},22,[189,1274,997],{"class":995,"aria-hidden":996},[189,1276,1277],{"class":195},"amps ",[189,1279,200],{"class":199},[189,1281,1282],{"class":195}," [",[189,1284,1285],{"class":199},"complex",[189,1287,1288],{"class":195},"(a) ",[189,1290,560],{"class":253},[189,1292,1293],{"class":195}," a ",[189,1295,566],{"class":253},[189,1297,1298],{"class":195}," sv.data]\n",[189,1300,1302,1304,1307,1309,1312,1316,1319,1322,1324,1327,1330,1333,1336,1338,1340,1342,1344,1346,1348,1351],{"class":191,"line":1301},23,[189,1303,997],{"class":995,"aria-hidden":996},[189,1305,1306],{"class":199},"print",[189,1308,230],{"class":195},[189,1310,1311],{"class":253},"f",[189,1313,1315],{"class":1314},"subq3","\"statevector: |0> ",[189,1317,1318],{"class":210},"{",[189,1320,1321],{"class":195},"amps[",[189,1323,1165],{"class":210},[189,1325,1326],{"class":195},"]",[189,1328,1329],{"class":253},":+.3f",[189,1331,1332],{"class":210},"}",[189,1334,1335],{"class":1314},"   |1> ",[189,1337,1318],{"class":210},[189,1339,1321],{"class":195},[189,1341,1089],{"class":210},[189,1343,1326],{"class":195},[189,1345,1329],{"class":253},[189,1347,1332],{"class":210},[189,1349,1350],{"class":1314},"\"",[189,1352,214],{"class":195},[189,1354,1356,1358,1360,1362,1364,1367,1369,1372,1375,1377,1380,1383,1385,1388,1390,1393,1395,1397,1399,1401,1403,1405,1407,1409,1411,1413],{"class":191,"line":1355},24,[189,1357,997],{"class":995,"aria-hidden":996},[189,1359,1306],{"class":199},[189,1361,230],{"class":195},[189,1363,1311],{"class":253},[189,1365,1366],{"class":1314},"\"from it:     P(0)=",[189,1368,1318],{"class":210},[189,1370,1371],{"class":199},"abs",[189,1373,1374],{"class":195},"(amps[",[189,1376,1165],{"class":210},[189,1378,1379],{"class":195},"])",[189,1381,1382],{"class":199},"**",[189,1384,292],{"class":210},[189,1386,1387],{"class":253},":.3f",[189,1389,1332],{"class":210},[189,1391,1392],{"class":1314},"  P(1)=",[189,1394,1318],{"class":210},[189,1396,1371],{"class":199},[189,1398,1374],{"class":195},[189,1400,1089],{"class":210},[189,1402,1379],{"class":195},[189,1404,1382],{"class":199},[189,1406,292],{"class":210},[189,1408,1387],{"class":253},[189,1410,1332],{"class":210},[189,1412,1350],{"class":1314},[189,1414,214],{"class":195},[189,1416,1418,1420],{"class":191,"line":1417},25,[189,1419,997],{"class":995,"aria-hidden":996},[189,1421,1074],{},[189,1423,1425,1427,1429,1431,1433,1435,1437,1439,1441,1443,1445,1448,1451,1453,1455],{"class":191,"data-cue":700,"line":1424},26,[189,1426,700],{"class":1092},[189,1428,219],{"class":195},[189,1430,200],{"class":199},[189,1432,224],{"class":195},[189,1434,227],{"class":203},[189,1436,230],{"class":195},[189,1438,1257],{"class":203},[189,1440,230],{"class":195},[189,1442,1128],{"class":239},[189,1444,200],{"class":199},[189,1446,1447],{"class":210},"True",[189,1449,1450],{"class":195},"), ",[189,1452,240],{"class":239},[189,1454,200],{"class":199},[189,1456,1457],{"class":195},"shots)\n",[189,1459,1461,1463,1465,1467,1469,1471,1474,1477,1480,1482,1485,1488,1490,1493],{"class":191,"line":1460},27,[189,1462,997],{"class":995,"aria-hidden":996},[189,1464,254],{"class":253},[189,1466,257],{"class":195},[189,1468,260],{"class":203},[189,1470,263],{"class":195},[189,1472,1473],{"class":253},"not",[189,1475,1476],{"class":253}," in",[189,1478,1479],{"class":195}," (JobStatus.",[189,1481,275],{"class":210},[189,1483,1484],{"class":195},", JobStatus.",[189,1486,1487],{"class":210},"ERROR",[189,1489,1484],{"class":195},[189,1491,1492],{"class":210},"CANCELLED",[189,1494,576],{"class":195},[189,1496,1498,1500,1502,1504,1506,1508],{"class":191,"line":1497},28,[189,1499,997],{"class":995,"aria-hidden":996},[189,1501,284],{"class":195},[189,1503,287],{"class":203},[189,1505,230],{"class":195},[189,1507,538],{"class":210},[189,1509,214],{"class":195},[189,1511,1513,1515],{"class":191,"line":1512},29,[189,1514,997],{"class":995,"aria-hidden":996},[189,1516,1074],{},[189,1518,1520,1522,1524,1526,1528,1530,1532,1534],{"class":191,"data-cue":538,"line":1519},30,[189,1521,538],{"class":1092},[189,1523,299],{"class":195},[189,1525,200],{"class":199},[189,1527,257],{"class":195},[189,1529,306],{"class":203},[189,1531,309],{"class":195},[189,1533,312],{"class":203},[189,1535,1536],{"class":195},"()\n",[189,1538,1540,1542,1544,1546,1548,1551,1553,1556,1558,1560],{"class":191,"line":1539},31,[189,1541,997],{"class":995,"aria-hidden":996},[189,1543,1306],{"class":199},[189,1545,230],{"class":195},[189,1547,1311],{"class":253},[189,1549,1550],{"class":1314},"\"counts:      ",[189,1552,1318],{"class":210},[189,1554,1555],{"class":195},"counts",[189,1557,1332],{"class":210},[189,1559,1350],{"class":1314},[189,1561,214],{"class":195},[189,1563,1565,1567,1570,1572,1575,1578,1580,1583,1585,1587],{"class":191,"line":1564},32,[189,1566,997],{"class":995,"aria-hidden":996},[189,1568,1569],{"class":195},"z ",[189,1571,200],{"class":199},[189,1573,1574],{"class":195}," counts.",[189,1576,1577],{"class":203},"get",[189,1579,230],{"class":195},[189,1581,1582],{"class":1314},"\"0\"",[189,1584,541],{"class":195},[189,1586,1165],{"class":210},[189,1588,214],{"class":195},[189,1590,1592,1594,1596,1598,1600,1603,1605,1607,1610,1613,1615,1617,1619,1621,1624,1627,1630,1632,1634,1636,1638,1640],{"class":191,"line":1591},33,[189,1593,997],{"class":995,"aria-hidden":996},[189,1595,1306],{"class":199},[189,1597,230],{"class":195},[189,1599,1311],{"class":253},[189,1601,1602],{"class":1314},"\"from them:   P(0)=",[189,1604,1318],{"class":210},[189,1606,1569],{"class":195},[189,1608,1609],{"class":199},"\u002F",[189,1611,1612],{"class":195}," shots",[189,1614,1387],{"class":253},[189,1616,1332],{"class":210},[189,1618,1392],{"class":1314},[189,1620,1318],{"class":210},[189,1622,1623],{"class":195},"(shots ",[189,1625,1626],{"class":199},"-",[189,1628,1629],{"class":195}," z) ",[189,1631,1609],{"class":199},[189,1633,1612],{"class":195},[189,1635,1387],{"class":253},[189,1637,1332],{"class":210},[189,1639,1350],{"class":1314},[189,1641,214],{"class":195},[123,1643,1645,1653,1660,1667,1674],{"class":1644},"qg-cues",[126,1646,1647,1649],{"data-cue":1089},[189,1648,1089],{"class":1092},[189,1650,1652],{"class":1651},"qg-cues__text","the dial: 0 or pi. Change it and run again",[126,1654,1655,1657],{"data-cue":292},[189,1656,292],{"class":1092},[189,1658,1659],{"class":1651},"the same circuit, with or without the measurement",[126,1661,1662,1664],{"data-cue":1241},[189,1663,1241],{"class":1092},[189,1665,1666],{"class":1651},"the simulator hands over the numbers themselves",[126,1668,1669,1671],{"data-cue":700},[189,1670,700],{"class":1092},[189,1672,1673],{"class":1651},"the only job this run files",[126,1675,1676,1678],{"data-cue":538},[189,1677,538],{"class":1092},[189,1679,1680],{"class":1651},"the same circuit, observed by sampling",[12,1682,1683,1684,1687],{},"Our run on 22 September 2026, with ",[170,1685,1686],{},"phi = 0",":",[181,1689,1692],{"className":1690,"code":1691,"language":778,"meta":22},[776],"statevector: |0> +0.707+0.000j   |1> +0.707+0.000j\nfrom it:     P(0)=0.500  P(1)=0.500\ncounts:      {'0': 478, '1': 522}\nfrom them:   P(0)=0.478  P(1)=0.522\n",[170,1693,1691],{"__ignoreMap":22},[12,1695,1696],{},"The statevector gives exactly 0.500, computed from the amplitudes the simulator holds. The tally gives 0.478, counted from a thousand samples of the same circuit in the same press.",[789,1698,1700,1704,1760],{"check":1699},"your two statevector lines differ, and both counts lines hold '0' and '1' at roughly half the shots each.",[111,1701,1703],{"id":1702},"assignment-move-the-phase-and-see-which-reading-changes","Assignment: move the phase and see which reading changes",[123,1705,1706,1721,1732,1743,1749,1752,1755],{},[126,1707,732,1708,737,1713,1716,1717,1720],{},[16,1709,1711],{"href":1710},"https:\u002F\u002Fqollab.xyz\u002Fu\u002Fqollab\u002Flearn-app-observe",[170,1712,984],{},[129,1714,1715],{},"Fork",", then ",[129,1718,1719],{},"Fork Project"," in the dialog.",[126,1722,1723,1724,809,1726,745,1728,814,1730,753],{},"In your fork, press ",[129,1725,740],{},[129,1727,744],{},[129,1729,748],{},[129,1731,752],{},[126,1733,1734,1735,1738,1739,1742],{},"Write down the ",[170,1736,1737],{},"statevector:"," line and the ",[170,1740,1741],{},"counts:"," line.",[126,1744,1745,1746,753],{},"Change line 9 to ",[170,1747,1748],{},"phi = pi",[126,1750,1751],{},"Predict whether the statevector line will change.",[126,1753,1754],{},"Predict whether the measured shares will change.",[126,1756,806,1757,1759],{},[129,1758,752],{}," again, and compare both pairs of lines.",[830,1761,1762,1765,1768,1774,1803],{"label":832},[12,1763,1764],{},"The statevector changes. The ideal shares stay at 0.500 and 0.500, and the sampled shares move a little from press to press, as any tally does.",[12,1766,1767],{},"Our two presses on 22 September 2026:",[181,1769,1772],{"className":1770,"code":1771,"language":778,"meta":22},[776],"phi = 0    statevector: |0> +0.707+0.000j   |1> +0.707+0.000j    counts: {'0': 478, '1': 522}\nphi = pi   statevector: |0> +0.000-0.707j   |1> +0.000+0.707j    counts: {'0': 506, '1': 494}\n",[170,1773,1771],{"__ignoreMap":22},[12,1775,1776,1779,1780,1783,1784,1787,1788,1791,1792,1795,1796,1798,1799,1802],{},[170,1777,1778],{},"rz(phi)"," puts a relative phase of ",[170,1781,1782],{},"phi"," between the two amplitudes. At ",[170,1785,1786],{},"pi"," the relative sign between the two amplitudes reverses, and they read ",[170,1789,1790],{},"-0.707j"," and ",[170,1793,1794],{},"+0.707j",". A measurement in the 0\u002F1 basis, the one ",[170,1797,1203],{}," reads in, uses each amplitude's squared magnitude, ",[170,1800,1801],{},"|a|²",", and a magnitude carries no phase, so both ideal shares stay at one half.",[12,1804,1805],{},"These counts cannot tell the two states apart.",[111,1807,1809],{"id":1808},"which-reading-musiq-regime-radar-and-butterfly-field-chose","Which reading Musiq, Regime Radar and Butterfly Field chose",[1811,1812,1813],"aside-note",{},[12,1814,1815],{},"You do not need to run these three projects; the one this lesson presses is Quantum Garden, from lesson 1.",[12,1817,1818,1822,1823,753],{},[129,1819,1820],{},[16,1821,343],{"href":342}," needs both, and its mapping table says so. The measurement probability sets how strong each frequency component is, which is a counts quantity. The statevector phase sets oscillator phase and interference. The statevector amplitude sets loudness; a tally does carry the share whose square root is the amplitude's size, but not the amplitude's sign. No tally carries a phase as the circuit stands: two states with the same distribution and different phases give identical tallies, unless the circuit rotates the phase into the measured basis first, as the second Hadamard did in ",[16,1824,1826],{"href":1825},"\u002Flearn\u002Fprogramming-your-first-quantum-circuits\u002Finterference","Course 2's interference lesson",[12,1828,1829,1833],{},[129,1830,1831],{},[16,1832,352],{"href":351}," ships three scoring paths in one file. An exact statevector overlap ranks all five regimes offline with no shots. A sampler path runs the same comparison on simulation or hardware. The IonQ path transpiles to the native gate set. The Radar uses the exact path to produce the ranking and spends the single hardware job verifying one row of it, with shot-noise error bars on the measured value.",[12,1835,1836,1840],{},[129,1837,1838],{},[16,1839,361],{"href":360}," splits its work into two tracks. An exact statevector simulation runs live on every visit in a serverless function and drives the animation, because per-layer purities and pairwise entanglement are state quantities. The damage-and-healing fidelities, which measure how completely the damaged butterfly's state is recovered, come from recorded IonQ Forte runs, replayed from a library.",[111,1842,1844],{"id":1843},"four-things-a-tally-does-that-a-return-value-does-not","Four things a tally does that a return value does not",[334,1846,1847,1853,1859,1865],{},[126,1848,1849,1852],{},[129,1850,1851],{},"A tally changes almost every run."," Even the same circuit on the same backend gives a different tally on the next press, so a test that asserts an exact tally will fail intermittently.",[126,1854,1855,1858],{},[129,1856,1857],{},"Some shots read the wrong answer, and nothing marks them."," On real hardware and on a noise-model simulator, the wrong shots sit in your tally alongside the right ones.",[126,1860,1861,1864],{},[129,1862,1863],{},"Nothing throws when the answer is wrong."," A circuit with a bug in it returns a well-formed tally, and so does a circuit that ran on a degraded machine. Your decode step turns either into a number, and your application uses it. You have to write any check on the tally yourself.",[126,1866,1867,1870],{},[129,1868,1869],{},"A tally costs shots, and more shots give more precision."," The uncertainty on a measured share is the standard error, and it shrinks with the square root of the number of shots. At 1,000 shots a measured share lands within about ±0.028 of a true share of 0.300, 95% of the time. To halve the window you run four times as many shots.",[12,1872,1873],{},"Each row of the table quadruples the shots and halves the window:",[1875,1876,1877,1889],"table",{},[1878,1879,1880],"thead",{},[1881,1882,1883,1886],"tr",{},[1884,1885,240],"th",{},[1884,1887,1888],{},"95% window on a 0.300 share",[1890,1891,1892,1901,1909,1917],"tbody",{},[1881,1893,1894,1898],{},[1895,1896,1897],"td",{},"250",[1895,1899,1900],{},"±0.057",[1881,1902,1903,1906],{},[1895,1904,1905],{},"1,000",[1895,1907,1908],{},"±0.028",[1881,1910,1911,1914],{},[1895,1912,1913],{},"4,000",[1895,1915,1916],{},"±0.014",[1881,1918,1919,1922],{},[1895,1920,1921],{},"16,000",[1895,1923,1924],{},"±0.007",[111,1926,1928],{"id":1927},"the-same-circuit-pressed-twice","The same circuit, pressed twice",[12,1930,1931,1932,1934],{},"Quantum Garden hard-codes ",[170,1933,865],{},", so its circuit is identical on every press. We pressed the project twice on the IonQ Aria 1 simulator, IonQ's simulator with the Aria 1 noise model, on 22 September 2026, and changed nothing in between.",[181,1936,1939],{"className":1937,"code":1938,"language":778,"meta":22},[776],"press 1:  {'00001': 13, '00011': 15, '01001': 7, '01101': 24, '11101': 10}\npress 2:  {'00001': 16, '00011': 17, '00101': 8, '01001': 7, '01101': 24}\n",[170,1940,1938],{"__ignoreMap":22},[12,1942,1943,1944,1947,1948,1951],{},"Two of the four shared outcomes changed count, 13 to 16 and 15 to 17, and two stayed at 7 and 24. The two presses also do not agree on which outcomes exist: ",[170,1945,1946],{},"11101"," is in the first and absent from the second, and ",[170,1949,1950],{},"00101"," is in the second and absent from the first.",[116,1953],{"alt":1954,"caption":1955,"no":369,"src":1956},"Two charts of the same circuit pressed twice at 100 shots, with a dashed cutoff at five shots. Press one reports 00001 at 13, 00011 at 15, 01001 at 7, 01101 at 24 and 11101 at 10, while 00101 is dashed and marked five or fewer. Press two reports 00001 at 16, 00011 at 17, 00101 at 8, 01001 at 7 and 01101 at 24, while 11101 is dashed and marked five or fewer. Each press ran 100 shots and printed 69 and 72.","The circuit's distribution did not gain or lose outcomes between presses. Sampling put two outcomes on the other side of the decode threshold, and the printed outcomes changed with them.","\u002F_content\u002Fimages\u002Freal-app\u002Fgarden-threshold.svg",[12,1958,1959],{},"Neither line adds up to 100: the first holds 69 shots and the second 72, so nearly a third of the data is missing from both.",[12,1961,1962,1963,1965,1966,1791,1969,1972,1973,1975],{},"The listing's own ",[170,1964,854],{}," causes both differences: it takes ",[170,1967,1968],{},"excludeLowProbabilityValues=True",[170,1970,1971],{},"lowProbabilityThreshold=0.05",", then drops every outcome that got five shots or fewer. An outcome near the threshold clears the threshold in one press and misses in the next, so the outcome appears and disappears. The missing shots, 31 in the first press and 28 in the second, are the outcomes ",[170,1974,854],{}," discarded.",[12,1977,1978],{},"The filter is a decode-step decision, made for a good reason: at 100 shots across 32 possible outcomes, the rare ones are indistinguishable from noise, so a plant built from them would reflect noise. The filter does not show in the output, though, and it causes the two presses to disagree.",[789,1980,1982,1986,2022],{"check":1981},"you have two different 'Counts for 100 shots:' lines from the same unchanged project, and you can say why neither of them adds up to 100.",[111,1983,1985],{"id":1984},"assignment-press-the-same-circuit-twice","Assignment: press the same circuit twice",[123,1987,1988,1994,2004,2009,2016,2019],{},[126,1989,732,1990,753],{},[16,1991,1992],{"href":735},[170,1993,500],{},[126,1995,806,1996,809,1998,745,2000,814,2002,753],{},[129,1997,740],{},[129,1999,744],{},[129,2001,748],{},[129,2003,752],{},[126,2005,1734,2006,2008],{},[170,2007,837],{}," line exactly.",[126,2010,806,2011,2013,2014,753],{},[129,2012,740],{}," again, choose the same backend, and press ",[129,2015,752],{},[126,2017,2018],{},"Write down the second line, and add up the shots in each.",[126,2020,2021],{},"Work out why two presses of an unchanged circuit disagree about which outcomes exist.",[830,2023,2024,2030,2036,2039],{"label":832},[12,2025,2026,2027,2029],{},"Nothing changed between the presses. ",[170,2028,865],{}," is in the listing, so the circuit is identical and both tallies are samples of one distribution.",[12,2031,2032,2033,2035],{},"The counts differ because a tally is a sample. The outcome list differs because ",[170,2034,854],{}," drops anything with five shots or fewer out of 100, and an outcome near that threshold crosses it in one press and not the next.",[12,2037,2038],{},"Your shots will not add up to 100 for the same reason. Ours came to 69 and 72.",[12,2040,2041,2042,2044,2045,1791,2047,2049],{},"More shots make the two presses agree more closely, and changing the shot count needs a fork, because ",[170,2043,854],{}," pins it at 100. Four times as many shots halve the window on every share. More shots do not make the outcomes under 5% appear, because the threshold is a share of the shots and rises with them, but they do make an outcome near the threshold less likely to cross it by chance, which is what made ",[170,2046,1946],{},[170,2048,1950],{}," appear in one press and not the other.",[111,2051,873],{"id":872},[12,2053,2054],{},"If your application can work from a distribution, it can run on hardware, because every backend returns a tally. Amplitudes and phases themselves come only from a simulator, which caps the qubit count. A tally is a sample that changes almost every run, and nothing in it marks a wrong shot, so your code has to check it.",[12,2056,2057],{},"Lesson 3 keeps the circuit behind three steps, so the rest of your program handles only ordinary values.",[884,2059,2060],{},"html pre.shiki code .sV9Aq, html code.shiki .sV9Aq{--shiki-default:#7F848E;--shiki-default-font-style:italic}html pre.shiki code .seHd6, html code.shiki .seHd6{--shiki-default:#C678DD}html pre.shiki code .sn6KH, html code.shiki .sn6KH{--shiki-default:#ABB2BF}html pre.shiki code .sjrmR, html code.shiki .sjrmR{--shiki-default:#56B6C2}html pre.shiki code .sVC51, html code.shiki .sVC51{--shiki-default:#D19A66}html pre.shiki code .sVbv2, html code.shiki .sVbv2{--shiki-default:#61AFEF}html pre.shiki code .sb9H8, html code.shiki .sb9H8{--shiki-default:#D19A66;--shiki-default-font-style:italic}html pre.shiki code .s_ZVi, html code.shiki .s_ZVi{--shiki-default:#E06C75;--shiki-default-font-style:italic}html pre.shiki code .subq3, html code.shiki .subq3{--shiki-default:#98C379}html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}",{"title":22,"searchDepth":23,"depth":23,"links":2062},[2063,2064,2065,2066,2067,2068,2069,2070],{"id":941,"depth":23,"text":942},{"id":965,"depth":23,"text":966},{"id":1702,"depth":23,"text":1703},{"id":1808,"depth":23,"text":1809},{"id":1843,"depth":23,"text":1844},{"id":1927,"depth":23,"text":1928},{"id":1984,"depth":23,"text":1985},{"id":872,"depth":23,"text":873},[26,27,5,907],[],{"username":7,"name":30,"role":31,"avatar":32},"A tally is the only result a quantum computer sends back across the boundary; a program that needs the exact amplitudes and phases simulates the circuit.",{},{"slug":2077,"title":2078,"desc":2079},"\u002Fblog\u002Flearn\u002Fusing-quantum-in-a-real-application\u002Finputs-in-result-out","Inputs in, a result out","Build the circuit from application data, run it, and decode the tally into a typed result.",[],{"title":907,"description":2074},"blog\u002Flearn\u002Fusing-quantum-in-a-real-application\u002Fwhat-crosses-the-boundary",[],"HUwW-1sySGSAOnLJkSCBap0lD74lTmAAl4HLiuSXKM8",{"id":2086,"title":2078,"authors":2087,"body":2088,"breadcrumb":3557,"builders":3558,"byline":3559,"category":33,"categoryName":33,"challenge":33,"courseAuthor":33,"courseLead":33,"dek":2079,"description":3560,"draft":46,"extension":47,"eyebrow":33,"featured":46,"finish":33,"fork":33,"group":33,"groupName":33,"hero":33,"heroAlt":33,"heroCta":33,"heroImage":33,"homepageFeatured":46,"kind":903,"lessonCount":557,"meta":3561,"navigation":50,"newsItems":33,"next":3562,"ogImage":33,"order":250,"outcomes":33,"path":2077,"prerequisite":33,"prerequisiteLinks":33,"publishDate":66,"readingTime":33,"related":3566,"relatedProjects":33,"section":33,"seo":3567,"stem":3568,"tags":3569,"track":73,"trackName":5,"__hash__":3570},"blog\u002Fblog\u002Flearn\u002Fusing-quantum-in-a-real-application\u002Finputs-in-result-out.md",[7],{"type":9,"value":2089,"toc":3542},[2090,2093,2100,2103,2123,2127,2130,2133,2140,2148,2152,2155,2208,2222,2235,2239,2244,2839,2848,2861,2865,2872,2886,2889,2895,2898,2901,2916,2991,2998,3003,3070,3093,3100,3104,3110,3230,3247,3256,3320,3525,3527,3536,3539],[12,2091,2092],{},"Inputs go in as application data and a result comes back as a tally. Write the code between the two as three steps, and let no other part of your program touch a circuit.",[12,2094,2095,2096,2099],{},"Without the three steps, circuit code turns up all over your program. Angles get computed where the HTTP handler lives, ",[170,2097,2098],{},"counts.get(\"1\", 0)"," turns up in a template, and before long nobody can change the circuit without reading the whole application. With the three steps in place, the rest of your program calls one function and gets a dict back.",[12,2101,2102],{},"The three steps are:",[334,2104,2105,2111,2117],{},[126,2106,2107,2110],{},[170,2108,2109],{},"build_circuit(p)"," takes an application value and returns a circuit. Nothing else in your program builds circuits.",[126,2112,2113,2114,2116],{},"the run submits the circuit and waits. The run is the only place ",[170,2115,858],{}," appears.",[126,2118,2119,2122],{},[170,2120,2121],{},"decode(counts, n)"," takes the tally and returns something typed. Nothing else in your program reads raw counts.",[111,2124,2126],{"id":2125},"a-weighted-random-picker","A weighted random picker",[12,2128,2129],{},"The picker takes a number of draws and a probability, say a thousand draws at thirty percent, and returns how many came up rare. Loot boxes, playlist shuffles and A\u002FB assignments all work this way.",[12,2131,2132],{},"You are going to build the picker on a quantum computer, and lesson 5 measures whether that was worth doing.",[111,2134,2136,2137,2139],{"id":2135},"where-backend-comes-from","Where ",[170,2138,858],{}," comes from",[12,2141,2142,2144,2145,2147],{},[170,2143,858],{}," is the one name in the listing that is never declared: it already exists when your code runs, as a global handed to your script before its first line, and it is whatever you chose in the Run Experiment dialog. You never construct ",[170,2146,858],{}," or name a machine in code, so you change where the circuit runs in the dialog.",[111,2149,2151],{"id":2150},"the-circuit","The circuit",[12,2153,2154],{},"The circuit is three lines:",[181,2156,2158],{"className":183,"code":2157,"language":185,"meta":22,"style":22},"qc = QuantumCircuit(1, 1)\nqc.ry(theta, 0)\nqc.measure(0, 0)\n",[170,2159,2160,2178,2192],{"__ignoreMap":22},[189,2161,2162,2164,2166,2168,2170,2172,2174,2176],{"class":191,"line":192},[189,2163,196],{"class":195},[189,2165,200],{"class":199},[189,2167,533],{"class":203},[189,2169,230],{"class":195},[189,2171,1089],{"class":210},[189,2173,541],{"class":195},[189,2175,1089],{"class":210},[189,2177,214],{"class":195},[189,2179,2180,2183,2185,2188,2190],{"class":191,"line":23},[189,2181,2182],{"class":195},"qc.",[189,2184,670],{"class":203},[189,2186,2187],{"class":195},"(theta, ",[189,2189,1165],{"class":210},[189,2191,214],{"class":195},[189,2193,2194,2196,2198,2200,2202,2204,2206],{"class":191,"line":250},[189,2195,2182],{"class":195},[189,2197,1203],{"class":203},[189,2199,230],{"class":195},[189,2201,1165],{"class":210},[189,2203,541],{"class":195},[189,2205,1165],{"class":210},[189,2207,214],{"class":195},[12,2209,2210,2211,2216,2217,2221],{},"You met ",[16,2212,2214],{"href":2213},"\u002Flearn\u002Fdocs\u002Fry-gate",[170,2215,670],{}," in Course 2, where the lesson on ",[16,2218,2220],{"href":2219},"\u002Flearn\u002Fprogramming-your-first-quantum-circuits\u002Frotations","rotations"," showed that the angle sets how often the qubit reads 1. Your application data enters the circuit through that angle.",[12,2223,2224,2227,2228,2230,2231,2234],{},[170,2225,2226],{},"2 * asin(sqrt(p))"," is the angle that puts the probability of measuring 1 at exactly ",[170,2229,12],{},": at ",[170,2232,2233],{},"p = 0.3"," the qubit reads 1 three times in ten, on average.",[111,2236,2238],{"id":2237},"the-whole-listing","The whole listing",[116,2240],{"alt":2241,"caption":2242,"no":119,"src":2243},"A left-to-right trace. p_rare, a float, enters build_circuit, which converts it with two times arcsine of the square root of p into theta and returns an RY gate followed by a measurement. A shaded region marks the part that runs somewhere else: the run returns a Job, which returns counts as a dict of string to int. Those counts enter decode, which returns a dict of rare, common and share.","build_circuit converts the application value into a circuit before the run submits the circuit, and decode turns the tally back into ordinary values.","\u002F_content\u002Fimages\u002Freal-app\u002Ftyped-boundary-trace.svg",[175,2245,2248],{"name":2246,"no-picker":22,"run-href":2247,"tag":985},"picker.py","\u002Fu\u002Fqollab\u002Flearn-app-boundary",[181,2249,2251],{"className":183,"code":2250,"language":185,"meta":22,"style":22},"# 'backend' already exists when this runs: it is whatever you pick in the Run Experiment dialog.\nfrom math import asin, sqrt\nfrom qiskit import QuantumCircuit\nfrom qiskit.providers.jobstatus import JobStatus\nimport time\n\nshots = 1000\np_rare = 0.3\n\n\ndef build_circuit(p):\n    theta = 2 * asin(sqrt(p))        #   the angle whose RY puts P(1) at exactly p\n    qc = QuantumCircuit(1, 1)\n    qc.ry(theta, 0)\n    qc.measure(0, 0)\n    return qc\n\n\ndef decode(counts, n):\n    rare = counts.get(\"1\", 0)\n    return {\"rare\": rare, \"common\": n - rare, \"share\": rare \u002F n}\n\n\nqc = build_circuit(p_rare)\nprint(qc)\n\njob = backend.run(qc, shots=shots)\nwhile job.status() not in (JobStatus.DONE, JobStatus.ERROR, JobStatus.CANCELLED):\n    time.sleep(5)\n\ncounts = job.result().get_counts()\nprint(counts)\n\nresult = decode(counts, shots)\nprint(f\"opened {shots} boxes: {result['rare']} rare, {result['common']} common\")\nprint(f\"share rare: {result['share']:.3f}   asked for: {p_rare:.3f}\")\n",[170,2252,2253,2259,2272,2284,2296,2304,2310,2320,2332,2338,2344,2358,2386,2406,2420,2438,2446,2452,2458,2478,2502,2539,2545,2551,2564,2573,2579,2600,2630,2644,2650,2668,2677,2683,2699,2752,2795],{"__ignoreMap":22},[189,2254,2255,2257],{"class":191,"line":192},[189,2256,997],{"class":995,"aria-hidden":996},[189,2258,1000],{"class":318},[189,2260,2261,2263,2265,2267,2269],{"class":191,"line":23},[189,2262,997],{"class":995,"aria-hidden":996},[189,2264,1007],{"class":253},[189,2266,1010],{"class":195},[189,2268,1013],{"class":253},[189,2270,2271],{"class":195}," asin, sqrt\n",[189,2273,2274,2276,2278,2280,2282],{"class":191,"line":250},[189,2275,997],{"class":995,"aria-hidden":996},[189,2277,1007],{"class":253},[189,2279,1025],{"class":195},[189,2281,1013],{"class":253},[189,2283,1030],{"class":195},[189,2285,2286,2288,2290,2292,2294],{"class":191,"line":281},[189,2287,997],{"class":995,"aria-hidden":996},[189,2289,1007],{"class":253},[189,2291,1053],{"class":195},[189,2293,1013],{"class":253},[189,2295,1058],{"class":195},[189,2297,2298,2300,2302],{"class":191,"line":51},[189,2299,997],{"class":995,"aria-hidden":996},[189,2301,1013],{"class":253},[189,2303,1067],{"class":195},[189,2305,2306,2308],{"class":191,"line":557},[189,2307,997],{"class":995,"aria-hidden":996},[189,2309,1074],{},[189,2311,2312,2314,2316,2318],{"class":191,"data-cue":1089,"line":579},[189,2313,1089],{"class":1092},[189,2315,1081],{"class":195},[189,2317,200],{"class":199},[189,2319,1086],{"class":210},[189,2321,2322,2324,2327,2329],{"class":191,"data-cue":292,"line":590},[189,2323,292],{"class":1092},[189,2325,2326],{"class":195},"p_rare ",[189,2328,200],{"class":199},[189,2330,2331],{"class":210}," 0.3\n",[189,2333,2334,2336],{"class":191,"line":595},[189,2335,997],{"class":995,"aria-hidden":996},[189,2337,1074],{},[189,2339,2340,2342],{"class":191,"line":601},[189,2341,997],{"class":995,"aria-hidden":996},[189,2343,1074],{},[189,2345,2346,2348,2350,2352,2354,2356],{"class":191,"data-cue":1241,"line":618},[189,2347,1241],{"class":1092},[189,2349,1119],{"class":253},[189,2351,204],{"class":203},[189,2353,230],{"class":195},[189,2355,12],{"class":1127},[189,2357,576],{"class":195},[189,2359,2360,2362,2365,2367,2370,2372,2375,2377,2380,2383],{"class":191,"line":665},[189,2361,997],{"class":995,"aria-hidden":996},[189,2363,2364],{"class":195},"    theta ",[189,2366,200],{"class":199},[189,2368,2369],{"class":210}," 2",[189,2371,659],{"class":199},[189,2373,2374],{"class":203}," asin",[189,2376,230],{"class":195},[189,2378,2379],{"class":203},"sqrt",[189,2381,2382],{"class":195},"(p))        ",[189,2384,2385],{"class":318},"#   the angle whose RY puts P(1) at exactly p\n",[189,2387,2388,2390,2392,2394,2396,2398,2400,2402,2404],{"class":191,"line":676},[189,2389,997],{"class":995,"aria-hidden":996},[189,2391,1137],{"class":195},[189,2393,200],{"class":199},[189,2395,533],{"class":203},[189,2397,230],{"class":195},[189,2399,1089],{"class":210},[189,2401,541],{"class":195},[189,2403,1089],{"class":210},[189,2405,214],{"class":195},[189,2407,2408,2410,2412,2414,2416,2418],{"class":191,"line":681},[189,2409,997],{"class":995,"aria-hidden":996},[189,2411,1158],{"class":195},[189,2413,670],{"class":203},[189,2415,2187],{"class":195},[189,2417,1165],{"class":210},[189,2419,214],{"class":195},[189,2421,2422,2424,2426,2428,2430,2432,2434,2436],{"class":191,"line":687},[189,2423,997],{"class":995,"aria-hidden":996},[189,2425,1158],{"class":195},[189,2427,1203],{"class":203},[189,2429,230],{"class":195},[189,2431,1165],{"class":210},[189,2433,541],{"class":195},[189,2435,1165],{"class":210},[189,2437,214],{"class":195},[189,2439,2440,2442,2444],{"class":191,"line":705},[189,2441,997],{"class":995,"aria-hidden":996},[189,2443,1221],{"class":253},[189,2445,1224],{"class":195},[189,2447,2448,2450],{"class":191,"line":1195},[189,2449,997],{"class":995,"aria-hidden":996},[189,2451,1074],{},[189,2453,2454,2456],{"class":191,"line":1216},[189,2455,997],{"class":995,"aria-hidden":996},[189,2457,1074],{},[189,2459,2460,2462,2464,2467,2469,2471,2473,2476],{"class":191,"data-cue":700,"line":1227},[189,2461,700],{"class":1092},[189,2463,1119],{"class":253},[189,2465,2466],{"class":203}," decode",[189,2468,230],{"class":195},[189,2470,1555],{"class":1127},[189,2472,541],{"class":195},[189,2474,2475],{"class":1127},"n",[189,2477,576],{"class":195},[189,2479,2480,2482,2485,2487,2489,2491,2493,2496,2498,2500],{"class":191,"line":1234},[189,2481,997],{"class":995,"aria-hidden":996},[189,2483,2484],{"class":195},"    rare ",[189,2486,200],{"class":199},[189,2488,1574],{"class":195},[189,2490,1577],{"class":203},[189,2492,230],{"class":195},[189,2494,2495],{"class":1314},"\"1\"",[189,2497,541],{"class":195},[189,2499,1165],{"class":210},[189,2501,214],{"class":195},[189,2503,2504,2506,2508,2511,2514,2517,2520,2523,2525,2528,2531,2534,2536],{"class":191,"line":1242},[189,2505,997],{"class":995,"aria-hidden":996},[189,2507,1221],{"class":253},[189,2509,2510],{"class":195}," {",[189,2512,2513],{"class":1314},"\"rare\"",[189,2515,2516],{"class":195},": rare, ",[189,2518,2519],{"class":1314},"\"common\"",[189,2521,2522],{"class":195},": n ",[189,2524,1626],{"class":199},[189,2526,2527],{"class":195}," rare, ",[189,2529,2530],{"class":1314},"\"share\"",[189,2532,2533],{"class":195},": rare ",[189,2535,1609],{"class":199},[189,2537,2538],{"class":195}," n}\n",[189,2540,2541,2543],{"class":191,"line":1272},[189,2542,997],{"class":995,"aria-hidden":996},[189,2544,1074],{},[189,2546,2547,2549],{"class":191,"line":1301},[189,2548,997],{"class":995,"aria-hidden":996},[189,2550,1074],{},[189,2552,2553,2555,2557,2559,2561],{"class":191,"line":1355},[189,2554,997],{"class":995,"aria-hidden":996},[189,2556,196],{"class":195},[189,2558,200],{"class":199},[189,2560,204],{"class":203},[189,2562,2563],{"class":195},"(p_rare)\n",[189,2565,2566,2568,2570],{"class":191,"line":1417},[189,2567,997],{"class":995,"aria-hidden":996},[189,2569,1306],{"class":199},[189,2571,2572],{"class":195},"(qc)\n",[189,2574,2575,2577],{"class":191,"line":1424},[189,2576,997],{"class":995,"aria-hidden":996},[189,2578,1074],{},[189,2580,2581,2583,2585,2587,2589,2591,2594,2596,2598],{"class":191,"data-cue":538,"line":1460},[189,2582,538],{"class":1092},[189,2584,219],{"class":195},[189,2586,200],{"class":199},[189,2588,224],{"class":195},[189,2590,227],{"class":203},[189,2592,2593],{"class":195},"(qc, ",[189,2595,240],{"class":239},[189,2597,200],{"class":199},[189,2599,1457],{"class":195},[189,2601,2602,2604,2606,2608,2610,2612,2614,2616,2618,2620,2622,2624,2626,2628],{"class":191,"line":1497},[189,2603,997],{"class":995,"aria-hidden":996},[189,2605,254],{"class":253},[189,2607,257],{"class":195},[189,2609,260],{"class":203},[189,2611,263],{"class":195},[189,2613,1473],{"class":253},[189,2615,1476],{"class":253},[189,2617,1479],{"class":195},[189,2619,275],{"class":210},[189,2621,1484],{"class":195},[189,2623,1487],{"class":210},[189,2625,1484],{"class":195},[189,2627,1492],{"class":210},[189,2629,576],{"class":195},[189,2631,2632,2634,2636,2638,2640,2642],{"class":191,"line":1512},[189,2633,997],{"class":995,"aria-hidden":996},[189,2635,284],{"class":195},[189,2637,287],{"class":203},[189,2639,230],{"class":195},[189,2641,538],{"class":210},[189,2643,214],{"class":195},[189,2645,2646,2648],{"class":191,"line":1519},[189,2647,997],{"class":995,"aria-hidden":996},[189,2649,1074],{},[189,2651,2652,2654,2656,2658,2660,2662,2664,2666],{"class":191,"line":1539},[189,2653,997],{"class":995,"aria-hidden":996},[189,2655,299],{"class":195},[189,2657,200],{"class":199},[189,2659,257],{"class":195},[189,2661,306],{"class":203},[189,2663,309],{"class":195},[189,2665,312],{"class":203},[189,2667,1536],{"class":195},[189,2669,2670,2672,2674],{"class":191,"line":1564},[189,2671,997],{"class":995,"aria-hidden":996},[189,2673,1306],{"class":199},[189,2675,2676],{"class":195},"(counts)\n",[189,2678,2679,2681],{"class":191,"line":1591},[189,2680,997],{"class":995,"aria-hidden":996},[189,2682,1074],{},[189,2684,2687,2689,2692,2694,2696],{"class":191,"data-cue":2685,"line":2686},"6",34,[189,2688,2685],{"class":1092},[189,2690,2691],{"class":195},"result ",[189,2693,200],{"class":199},[189,2695,2466],{"class":203},[189,2697,2698],{"class":195},"(counts, shots)\n",[189,2700,2702,2704,2706,2708,2710,2713,2715,2717,2719,2722,2724,2727,2730,2732,2734,2736,2738,2740,2743,2745,2747,2750],{"class":191,"line":2701},35,[189,2703,997],{"class":995,"aria-hidden":996},[189,2705,1306],{"class":199},[189,2707,230],{"class":195},[189,2709,1311],{"class":253},[189,2711,2712],{"class":1314},"\"opened ",[189,2714,1318],{"class":210},[189,2716,240],{"class":195},[189,2718,1332],{"class":210},[189,2720,2721],{"class":1314}," boxes: ",[189,2723,1318],{"class":210},[189,2725,2726],{"class":195},"result[",[189,2728,2729],{"class":1314},"'rare'",[189,2731,1326],{"class":195},[189,2733,1332],{"class":210},[189,2735,2527],{"class":1314},[189,2737,1318],{"class":210},[189,2739,2726],{"class":195},[189,2741,2742],{"class":1314},"'common'",[189,2744,1326],{"class":195},[189,2746,1332],{"class":210},[189,2748,2749],{"class":1314}," common\"",[189,2751,214],{"class":195},[189,2753,2755,2757,2759,2761,2763,2766,2768,2770,2773,2775,2777,2779,2782,2784,2787,2789,2791,2793],{"class":191,"line":2754},36,[189,2756,997],{"class":995,"aria-hidden":996},[189,2758,1306],{"class":199},[189,2760,230],{"class":195},[189,2762,1311],{"class":253},[189,2764,2765],{"class":1314},"\"share rare: ",[189,2767,1318],{"class":210},[189,2769,2726],{"class":195},[189,2771,2772],{"class":1314},"'share'",[189,2774,1326],{"class":195},[189,2776,1387],{"class":253},[189,2778,1332],{"class":210},[189,2780,2781],{"class":1314},"   asked for: ",[189,2783,1318],{"class":210},[189,2785,2786],{"class":195},"p_rare",[189,2788,1387],{"class":253},[189,2790,1332],{"class":210},[189,2792,1350],{"class":1314},[189,2794,214],{"class":195},[123,2796,2797,2804,2811,2818,2825,2832],{"class":1644},[126,2798,2799,2801],{"data-cue":1089},[189,2800,1089],{"class":1092},[189,2802,2803],{"class":1651},"one press buys this many draws",[126,2805,2806,2808],{"data-cue":292},[189,2807,292],{"class":1092},[189,2809,2810],{"class":1651},"the app's input: how often a draw should come up rare",[126,2812,2813,2815],{"data-cue":1241},[189,2814,1241],{"class":1092},[189,2816,2817],{"class":1651},"app value in, circuit out",[126,2819,2820,2822],{"data-cue":700},[189,2821,700],{"class":1092},[189,2823,2824],{"class":1651},"counts in, something the app can use out",[126,2826,2827,2829],{"data-cue":538},[189,2828,538],{"class":1092},[189,2830,2831],{"class":1651},"one job, the circuit run 1,000 times",[126,2833,2834,2836],{"data-cue":2685},[189,2835,2685],{"class":1092},[189,2837,2838],{"class":1651},"the only line the rest of an app would need",[12,2840,2841,2842,2844,2845,2847],{},"Lines 1 to 5 are imports and the note about ",[170,2843,858],{},". Lines 7 and 8 are the two numbers you will change. The two functions and the ",[170,2846,172],{}," call are the boundary. Lines 24 to 36 are the script that uses them: build, run, wait, decode, print.",[12,2849,2850,2852,2853,1791,2855,2857,2858,2860],{},[170,2851,172],{}," returns straight away with a job rather than a result, because the work happens on IonQ's cloud. The loop polls until the job reaches a terminal state, and it checks for ",[170,2854,1487],{},[170,2856,1492],{}," as well as ",[170,2859,275],{},", because a job that fails would otherwise leave you polling forever.",[111,2862,2864],{"id":2863},"predict-then-run","Predict, then run",[12,2866,2867,2868,2871],{},"Before you press anything, write down a number: out of 1,000 shots at ",[170,2869,2870],{},"p_rare = 0.3",", how many do you expect to read 1?",[12,2873,2874,2875,737,2878,809,2880,745,2882,814,2884,753],{},"Then open ",[16,2876,736],{"href":2877},"https:\u002F\u002Fqollab.xyz\u002Fu\u002Fqollab\u002Flearn-app-boundary",[129,2879,740],{},[129,2881,744],{},[129,2883,748],{},[129,2885,752],{},[12,2887,2888],{},"Our run on 22 September 2026 printed this:",[181,2890,2893],{"className":2891,"code":2892,"language":778,"meta":22},[776],"     ┌────────────┐┌─┐\n  q: ┤ Ry(1.1593) ├┤M├\n     └────────────┘└╥┘\nc: 1\u002F═══════════════╩═\n                    0\n{'0': 720, '1': 280}\nopened 1000 boxes: 280 rare, 720 common\nshare rare: 0.280   asked for: 0.300\n",[170,2894,2892],{"__ignoreMap":22},[12,2896,2897],{},"The tally read 280 ones, against the 300 we asked for.",[12,2899,2900],{},"A prediction of exactly 300 is correct for the distribution, and as lesson 2 showed, a tally will almost never match it. The spread to expect at 1,000 shots is about ±28 either side of 300. Our 280 sits inside that band, as would 315, and so will yours nineteen times out of twenty.",[12,2902,2903,2904,2907,2908,2911,2912,2915],{},"The drawn circuit at the top shows ",[170,2905,2906],{},"Ry(1.1593)",", which is ",[170,2909,2910],{},"2 * asin(sqrt(0.3))"," in radians. Your application passed a probability, and ",[170,2913,2914],{},"build_circuit"," converted it to that angle.",[789,2917,2919,2923,2926,2962],{"check":2918},"your drawn circuit reads Ry(π\u002F2) and your tally's '1' count is between about 470 and 530.",[111,2920,2922],{"id":2921},"assignment-change-the-probability-and-predict-the-tally","Assignment: change the probability and predict the tally",[12,2924,2925],{},"You need your own copy before you can change anything, because a published project is read-only to everyone but its owner.",[123,2927,2928,2937,2943,2946,2949,2959],{},[126,2929,2930,2931,2933,2934,2936],{},"On the project page, signed in, press ",[129,2932,1715],{},", then keep or change the name in the Fork Project dialog and press ",[129,2935,1719],{},". You now have your own copy at your own username.",[126,2938,2939,2940,753],{},"In your fork, change line 8 to ",[170,2941,2942],{},"p_rare = 0.5",[126,2944,2945],{},"Work out what the new angle will be, in radians, and what the drawn circuit should show.",[126,2947,2948],{},"Write down how many of the 1,000 shots you expect to read 1.",[126,2950,806,2951,809,2953,745,2955,814,2957,753],{},[129,2952,740],{},[129,2954,744],{},[129,2956,748],{},[129,2958,752],{},[126,2960,2961],{},"Compare the drawn circuit and the tally against both of your predictions.",[830,2963,2964,2981,2984],{"label":832},[12,2965,2966,2969,2970,2907,2973,2976,2977,2980],{},[170,2967,2968],{},"2 * asin(sqrt(0.5))"," is ",[170,2971,2972],{},"2 * asin(0.7071)",[170,2974,2975],{},"pi\u002F2",", or 1.5708 radians. The drawn circuit should read ",[170,2978,2979],{},"Ry(π\u002F2)",": the console writes an angle as a fraction of pi whenever one fits, and none fits the 1.1593 of the run above.",[12,2982,2983],{},"Expect about 500 shots reading 1. At 1,000 shots the 95% spread is roughly 469 to 531, so any count in that range is normal.",[12,2985,2986,2987,2990],{},"At ",[170,2988,2989],{},"p = 0.5"," the rotation is exactly a quarter turn, and the two outcomes are equally likely. Other probabilities give less round angles from the same formula.",[111,2992,2994,2995],{"id":2993},"inside-decode","Inside ",[170,2996,2997],{},"decode",[12,2999,3000,3002],{},[170,3001,2997],{}," is three lines long, and it turns the quantum result into ordinary data.",[181,3004,3006],{"className":183,"code":3005,"language":185,"meta":22,"style":22},"def decode(counts, n):\n    rare = counts.get(\"1\", 0)\n    return {\"rare\": rare, \"common\": n - rare, \"share\": rare \u002F n}\n",[170,3007,3008,3024,3044],{"__ignoreMap":22},[189,3009,3010,3012,3014,3016,3018,3020,3022],{"class":191,"line":192},[189,3011,1119],{"class":253},[189,3013,2466],{"class":203},[189,3015,230],{"class":195},[189,3017,1555],{"class":1127},[189,3019,541],{"class":195},[189,3021,2475],{"class":1127},[189,3023,576],{"class":195},[189,3025,3026,3028,3030,3032,3034,3036,3038,3040,3042],{"class":191,"line":23},[189,3027,2484],{"class":195},[189,3029,200],{"class":199},[189,3031,1574],{"class":195},[189,3033,1577],{"class":203},[189,3035,230],{"class":195},[189,3037,2495],{"class":1314},[189,3039,541],{"class":195},[189,3041,1165],{"class":210},[189,3043,214],{"class":195},[189,3045,3046,3048,3050,3052,3054,3056,3058,3060,3062,3064,3066,3068],{"class":191,"line":250},[189,3047,1221],{"class":253},[189,3049,2510],{"class":195},[189,3051,2513],{"class":1314},[189,3053,2516],{"class":195},[189,3055,2519],{"class":1314},[189,3057,2522],{"class":195},[189,3059,1626],{"class":199},[189,3061,2527],{"class":195},[189,3063,2530],{"class":1314},[189,3065,2533],{"class":195},[189,3067,1609],{"class":199},[189,3069,2538],{"class":195},[12,3071,3072,3074,3075,3077,3078,3081,3082,3085,3086,3088,3089,3092],{},[170,3073,2997],{}," uses ",[170,3076,2098],{}," instead of ",[170,3079,3080],{},"counts[\"1\"]"," because a key you expect can be absent. At ",[170,3083,3084],{},"p_rare = 0.001"," a thousand shots contain no ones about one press in three, and ",[170,3087,3080],{}," would raise a ",[170,3090,3091],{},"KeyError"," in production, intermittently.",[12,3094,3095,3096,3099],{},"The return value is a dict with named keys. A dict like ",[170,3097,3098],{},"{\"rare\": 280, \"common\": 720, \"share\": 0.28}"," can be read by someone who has never heard of a qubit.",[111,3101,3103],{"id":3102},"testing-the-half-you-can-test","Testing the half you can test",[12,3105,3106,3107,3109],{},"A circuit run is slow, costs shots and returns something different every time, which makes it hard to test. ",[170,3108,2997],{}," is none of those: a pure function from a dict to a dict, which you can test without a quantum computer.",[181,3111,3113],{"className":183,"code":3112,"language":185,"meta":22,"style":22},"assert decode({\"0\": 700, \"1\": 300}, 1000) == {\"rare\": 300, \"common\": 700, \"share\": 0.3}\nassert decode({\"0\": 1000}, 1000) == {\"rare\": 0, \"common\": 1000, \"share\": 0.0}\n",[170,3114,3115,3181],{"__ignoreMap":22},[189,3116,3117,3120,3122,3125,3127,3130,3133,3135,3137,3139,3142,3145,3148,3150,3153,3155,3157,3159,3161,3163,3165,3167,3169,3171,3173,3175,3178],{"class":191,"line":192},[189,3118,3119],{"class":253},"assert",[189,3121,2466],{"class":203},[189,3123,3124],{"class":195},"({",[189,3126,1582],{"class":1314},[189,3128,3129],{"class":195},": ",[189,3131,3132],{"class":210},"700",[189,3134,541],{"class":195},[189,3136,2495],{"class":1314},[189,3138,3129],{"class":195},[189,3140,3141],{"class":210},"300",[189,3143,3144],{"class":195},"}, ",[189,3146,3147],{"class":210},"1000",[189,3149,641],{"class":195},[189,3151,3152],{"class":199},"==",[189,3154,2510],{"class":195},[189,3156,2513],{"class":1314},[189,3158,3129],{"class":195},[189,3160,3141],{"class":210},[189,3162,541],{"class":195},[189,3164,2519],{"class":1314},[189,3166,3129],{"class":195},[189,3168,3132],{"class":210},[189,3170,541],{"class":195},[189,3172,2530],{"class":1314},[189,3174,3129],{"class":195},[189,3176,3177],{"class":210},"0.3",[189,3179,3180],{"class":195},"}\n",[189,3182,3183,3185,3187,3189,3191,3193,3195,3197,3199,3201,3203,3205,3207,3209,3211,3213,3215,3217,3219,3221,3223,3225,3228],{"class":191,"line":23},[189,3184,3119],{"class":253},[189,3186,2466],{"class":203},[189,3188,3124],{"class":195},[189,3190,1582],{"class":1314},[189,3192,3129],{"class":195},[189,3194,3147],{"class":210},[189,3196,3144],{"class":195},[189,3198,3147],{"class":210},[189,3200,641],{"class":195},[189,3202,3152],{"class":199},[189,3204,2510],{"class":195},[189,3206,2513],{"class":1314},[189,3208,3129],{"class":195},[189,3210,1165],{"class":210},[189,3212,541],{"class":195},[189,3214,2519],{"class":1314},[189,3216,3129],{"class":195},[189,3218,3147],{"class":210},[189,3220,541],{"class":195},[189,3222,2530],{"class":1314},[189,3224,3129],{"class":195},[189,3226,3227],{"class":210},"0.0",[189,3229,3180],{"class":195},[12,3231,3232,3233,3235,3236,3238,3239,3074,3241,3243,3244,3246],{},"The second assert feeds ",[170,3234,2997],{}," a tally with the ",[170,3237,2495],{}," key missing, the low-probability case, and passes only because ",[170,3240,2997],{},[170,3242,2098],{},". Swap in ",[170,3245,3080],{}," and the second assert raises within milliseconds on your own machine.",[12,3248,3249,3250,3252,3253,3255],{},"You can test ",[170,3251,2914],{}," the same way, by checking the angle it produces for a known ",[170,3254,12],{},". Only the run in the middle needs a backend, and it contains no logic of its own.",[789,3257,3259,3263,3298],{"check":3258},"your console shows a KeyError: '1' raised inside decode, and then finishes cleanly again once you restore .get.",[111,3260,3262],{"id":3261},"assignment-break-the-decoder-without-running-a-circuit","Assignment: break the decoder without running a circuit",[123,3264,3265,3274,3279,3287,3290,3295],{},[126,3266,3267,3268,3270,3271,3273],{},"In your fork, add the two ",[170,3269,3119],{}," lines above, directly under the ",[170,3272,2997],{}," function.",[126,3275,806,3276,3278],{},[129,3277,740],{}," and confirm the script still finishes. Passing asserts print nothing.",[126,3280,3281,3282,3284,3285,753],{},"Change ",[170,3283,2098],{}," to ",[170,3286,3080],{},[126,3288,3289],{},"Predict which of the two asserts fails, and what the error will say.",[126,3291,806,3292,3294],{},[129,3293,752],{}," again.",[126,3296,3297],{},"Read the traceback, then change the line back.",[830,3299,3300,3309,3312],{"label":832},[12,3301,3302,3303,3306,3307,753],{},"The second assert fails, with ",[170,3304,3305],{},"KeyError: '1'",", and the traceback points inside ",[170,3308,2997],{},[12,3310,3311],{},"The first assert passes either way, because that tally has both keys. A test suite containing only the first line would have told you the code was fine.",[12,3313,3314,3315,1791,3317,3319],{},"The asserts sit above the calls to ",[170,3316,2914],{},[170,3318,172],{},", so the failing one stops the script before any circuit is built or submitted.",[789,3321,3323,3327,3333,3371],{"check":3322},"your console prints a percentage near 50%, and it matches the '1' count in the tally printed directly above it.",[111,3324,3326],{"id":3325},"assignment-change-what-the-boundary-hands-back","Assignment: change what the boundary hands back",[12,3328,3329,3330,3332],{},"Leave ",[170,3331,2942],{}," from the previous task in your fork.",[123,3334,3335,3345,3351,3354,3364],{},[126,3336,3337,3338,3340,3341,3344],{},"In your fork, change ",[170,3339,2997],{}," so the returned dict also carries a ",[170,3342,3343],{},"percent"," key, the share expressed out of 100 and rounded to one decimal place.",[126,3346,3347,3348,3350],{},"Change the last ",[170,3349,1306],{}," so it prints that percentage instead of the share.",[126,3352,3353],{},"Before running, work out what the printed percentage should be, given the tally you already have on screen from the previous task.",[126,3355,806,3356,809,3358,745,3360,814,3362,753],{},[129,3357,740],{},[129,3359,744],{},[129,3361,748],{},[129,3363,752],{},[126,3365,3366,3367,3370],{},"Check the printed percentage against the ",[170,3368,3369],{},"'1'"," count in the new tally.",[830,3372,3373,3376,3471,3516,3522],{"label":832},[12,3374,3375],{},"One line added and one changed:",[181,3377,3379],{"className":183,"code":3378,"language":185,"meta":22,"style":22},"def decode(counts, n):\n    rare = counts.get(\"1\", 0)\n    return {\"rare\": rare, \"common\": n - rare, \"share\": rare \u002F n, \"percent\": round(100 * rare \u002F n, 1)}\n",[170,3380,3381,3397,3417],{"__ignoreMap":22},[189,3382,3383,3385,3387,3389,3391,3393,3395],{"class":191,"line":192},[189,3384,1119],{"class":253},[189,3386,2466],{"class":203},[189,3388,230],{"class":195},[189,3390,1555],{"class":1127},[189,3392,541],{"class":195},[189,3394,2475],{"class":1127},[189,3396,576],{"class":195},[189,3398,3399,3401,3403,3405,3407,3409,3411,3413,3415],{"class":191,"line":23},[189,3400,2484],{"class":195},[189,3402,200],{"class":199},[189,3404,1574],{"class":195},[189,3406,1577],{"class":203},[189,3408,230],{"class":195},[189,3410,2495],{"class":1314},[189,3412,541],{"class":195},[189,3414,1165],{"class":210},[189,3416,214],{"class":195},[189,3418,3419,3421,3423,3425,3427,3429,3431,3433,3435,3437,3439,3441,3444,3447,3449,3452,3454,3457,3459,3462,3464,3466,3468],{"class":191,"line":250},[189,3420,1221],{"class":253},[189,3422,2510],{"class":195},[189,3424,2513],{"class":1314},[189,3426,2516],{"class":195},[189,3428,2519],{"class":1314},[189,3430,2522],{"class":195},[189,3432,1626],{"class":199},[189,3434,2527],{"class":195},[189,3436,2530],{"class":1314},[189,3438,2533],{"class":195},[189,3440,1609],{"class":199},[189,3442,3443],{"class":195}," n, ",[189,3445,3446],{"class":1314},"\"percent\"",[189,3448,3129],{"class":195},[189,3450,3451],{"class":199},"round",[189,3453,230],{"class":195},[189,3455,3456],{"class":210},"100",[189,3458,659],{"class":199},[189,3460,3461],{"class":195}," rare ",[189,3463,1609],{"class":199},[189,3465,3443],{"class":195},[189,3467,1089],{"class":210},[189,3469,3470],{"class":195},")}\n",[181,3472,3474],{"className":183,"code":3473,"language":185,"meta":22,"style":22},"print(f\"rare share: {result['percent']}%   asked for: {100 * p_rare}%\")\n",[170,3475,3476],{"__ignoreMap":22},[189,3477,3478,3480,3482,3484,3487,3489,3491,3494,3496,3498,3501,3504,3506,3509,3511,3514],{"class":191,"line":192},[189,3479,1306],{"class":199},[189,3481,230],{"class":195},[189,3483,1311],{"class":253},[189,3485,3486],{"class":1314},"\"rare share: ",[189,3488,1318],{"class":210},[189,3490,2726],{"class":195},[189,3492,3493],{"class":1314},"'percent'",[189,3495,1326],{"class":195},[189,3497,1332],{"class":210},[189,3499,3500],{"class":1314},"%   asked for: ",[189,3502,3503],{"class":210},"{100",[189,3505,659],{"class":199},[189,3507,3508],{"class":195}," p_rare",[189,3510,1332],{"class":210},[189,3512,3513],{"class":1314},"%\"",[189,3515,214],{"class":195},[12,3517,3518,3519,3521],{},"The percentage should be the ",[170,3520,3369],{}," count divided by ten, since there are 1,000 shots. A tally of 507 gives 50.7%.",[12,3523,3524],{},"The printed percentage will not be exactly 50%, and it will differ from the previous task's run, because pressing Run again drew a fresh sample.",[111,3526,873],{"id":872},[12,3528,3529,3530,3532,3533,3535],{},"Keep the circuit behind three steps. ",[170,3531,2914],{}," turns your data into a circuit, the run submits it and waits, and ",[170,3534,2997],{}," turns the tally into a typed value the rest of the program uses. Only the run needs a backend, so both functions can be tested like any other code.",[12,3537,3538],{},"Lesson 4 puts the boundary behind an interface, which has to show something during the wait and handle a failed run.",[884,3540,3541],{},"html pre.shiki code .sn6KH, html code.shiki .sn6KH{--shiki-default:#ABB2BF}html pre.shiki code .sjrmR, html code.shiki .sjrmR{--shiki-default:#56B6C2}html pre.shiki code .sVbv2, html code.shiki .sVbv2{--shiki-default:#61AFEF}html pre.shiki code .sVC51, html code.shiki .sVC51{--shiki-default:#D19A66}html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html pre.shiki code .sV9Aq, html code.shiki .sV9Aq{--shiki-default:#7F848E;--shiki-default-font-style:italic}html pre.shiki code .seHd6, html code.shiki .seHd6{--shiki-default:#C678DD}html pre.shiki code .sb9H8, html code.shiki .sb9H8{--shiki-default:#D19A66;--shiki-default-font-style:italic}html pre.shiki code .subq3, html code.shiki .subq3{--shiki-default:#98C379}html pre.shiki code .s_ZVi, html code.shiki .s_ZVi{--shiki-default:#E06C75;--shiki-default-font-style:italic}",{"title":22,"searchDepth":23,"depth":23,"links":3543},[3544,3545,3547,3548,3549,3550,3551,3553,3554,3555,3556],{"id":2125,"depth":23,"text":2126},{"id":2135,"depth":23,"text":3546},"Where backend comes from",{"id":2150,"depth":23,"text":2151},{"id":2237,"depth":23,"text":2238},{"id":2863,"depth":23,"text":2864},{"id":2921,"depth":23,"text":2922},{"id":2993,"depth":23,"text":3552},"Inside decode",{"id":3102,"depth":23,"text":3103},{"id":3261,"depth":23,"text":3262},{"id":3325,"depth":23,"text":3326},{"id":872,"depth":23,"text":873},[26,27,5,2078],[],{"username":7,"name":30,"role":31,"avatar":32},"Turn application inputs into a typed result in three steps: build the circuit, run it, and decode what comes back.",{},{"slug":3563,"title":3564,"desc":3565},"\u002Fblog\u002Flearn\u002Fusing-quantum-in-a-real-application\u002Fthe-app-around-it","The app around the circuit","A circuit run takes seconds and can fail, and your interface has to handle both.",[],{"title":2078,"description":3560},"blog\u002Flearn\u002Fusing-quantum-in-a-real-application\u002Finputs-in-result-out",[],"yrEmTq8eAsrjOjU-argn12A_tSKYo5IAABfn7dt73_0",{"id":3572,"title":3564,"authors":3573,"body":3574,"breadcrumb":5100,"builders":5101,"byline":5102,"category":33,"categoryName":33,"challenge":33,"courseAuthor":33,"courseLead":33,"dek":3565,"description":5103,"draft":46,"extension":47,"eyebrow":33,"featured":46,"finish":33,"fork":33,"group":33,"groupName":33,"hero":33,"heroAlt":33,"heroCta":33,"heroImage":33,"homepageFeatured":46,"kind":903,"lessonCount":557,"meta":5104,"navigation":50,"newsItems":33,"next":5105,"ogImage":33,"order":281,"outcomes":33,"path":3563,"prerequisite":33,"prerequisiteLinks":33,"publishDate":66,"readingTime":33,"related":5109,"relatedProjects":33,"section":33,"seo":5110,"stem":5111,"tags":5112,"track":73,"trackName":5,"__hash__":5113},"blog\u002Fblog\u002Flearn\u002Fusing-quantum-in-a-real-application\u002Fthe-app-around-it.md",[7],{"type":9,"value":3575,"toc":5088},[3576,3579,3582,3586,3589,3609,3615,3619,4357,4364,4369,4372,4381,4390,4393,4499,4505,4530,4551,4575,4579,4582,4750,4796,4848,4852,4857,4860,4866,4875,4883,4886,4894,4897,4900,5077,5079,5082,5085],[12,3577,3578],{},"The app around a circuit has two jobs the previous lesson ignored. The app has to say something while the run is in flight, and it has to handle the run failing.",[12,3580,3581],{},"A Python script can ignore both jobs, because nobody watches its output while it waits. An interface has a person in front of it, and that person is looking at your screen for the eighty seconds it takes a first press to come back.",[111,3583,3585],{"id":3584},"switching-to-js-qiskit","Switching to JS \u002F Qiskit",[12,3587,3588],{},"The Playground runs quantum projects in two frameworks. The last lesson used Python. JS \u002F Qiskit gives you three editable panes, JavaScript, HTML and CSS, plus a live preview, so you can build a working interface without installing anything.",[12,3590,3591,3592,3595,3596,3599,3600,3603,3604,3608],{},"The API is the Python Qiskit API with three conventions on top: no ",[170,3593,3594],{},"new"," when constructing, ",[170,3597,3598],{},".callKwargs"," for keyword arguments, and ",[170,3601,3602],{},".toJs()"," to unpack a Python value. Course 3's lesson on ",[16,3605,3607],{"href":3606},"\u002Flearn\u002Fbuilding-your-first-qollab-project\u002Frun-in-javascript","running a circuit in JavaScript"," covers the editor itself, the four panes and browser support.",[12,3610,3611,3612,3614],{},"Your JavaScript runs in a sandboxed frame in your browser, and so does ",[170,3613,858],{},". That frame loads the same Python runtime a Python project uses and runs the same prologue, from the same Run Experiment dialog, so a JavaScript project reaches IonQ the way a Python one does.",[111,3616,3618],{"id":3617},"the-interface","The interface",[175,3620,3624],{"name":3621,"no-picker":22,"run-href":3622,"tag":3623},"picker.js","\u002Fu\u002Fqollab\u002Flearn-app-ui","JavaScript · Playground",[181,3625,3629],{"className":3626,"code":3627,"language":3628,"meta":22,"style":22},"language-js shiki shiki-themes one-dark-pro","\u002F\u002F 'backend' already exists when this runs: it is whatever you pick in the Run Experiment dialog.\nimport { QuantumCircuit } from 'qiskit';\n\nconst shots = 1000;          \u002F\u002F one press buys this many draws\nconst pRare = 0.3;           \u002F\u002F the app's input: how often a draw should come up rare\n\nconst out = document.getElementById('out');\nconst bar = document.getElementById('bar');\nconst foot = document.getElementById('foot');\n\nfunction buildCircuit(p) {               \u002F\u002F app value in, circuit out\n  const theta = 2 * Math.asin(Math.sqrt(p));\n  const qc = QuantumCircuit(1, 1);       \u002F\u002F no `new`: the constructor is called like Python's\n  qc.ry(theta, 0);\n  qc.measure(0, 0);\n  return qc;\n}\n\nfunction decode(counts, n) {             \u002F\u002F counts in, something the app can use out\n  const rare = counts['1'] ?? 0;\n  return { rare, common: n - rare, share: rare \u002F n };\n}\n\nout.textContent = 'Opening ' + shots + ' boxes...';   \u002F\u002F the in-flight state, because this takes real time\n\ntry {\n  const job = await backend.run(buildCircuit(pRare), { shots });\n  const result = await job.result();\n  const counts = result.get_counts().toJs();   \u002F\u002F .toJs() unpacks the Python dict into a plain object\n\n  const drawn = decode(counts, shots);\n  out.textContent = drawn.rare + ' rare, ' + drawn.common + ' common';\n  bar.style.width = (drawn.share * 100).toFixed(1) + '%';\n  foot.textContent = 'share ' + drawn.share.toFixed(3) + ', asked for ' + pRare.toFixed(3);\n} catch (err) {\n  out.textContent = 'The run did not finish: ' + err;   \u002F\u002F the failed state, because it can fail\n  foot.textContent = 'Press Run to try again.';\n}\n","js",[170,3630,3631,3636,3658,3662,3682,3700,3704,3729,3751,3773,3777,3795,3833,3858,3878,3896,3905,3909,3913,3933,3961,4002,4006,4010,4041,4045,4053,4090,4110,4135,4139,4160,4197,4246,4297,4313,4336,4352],{"__ignoreMap":22},[189,3632,3633],{"class":191,"line":192},[189,3634,3635],{"class":318},"\u002F\u002F 'backend' already exists when this runs: it is whatever you pick in the Run Experiment dialog.\n",[189,3637,3638,3640,3643,3647,3650,3652,3655],{"class":191,"line":23},[189,3639,1013],{"class":253},[189,3641,3642],{"class":195}," { ",[189,3644,3646],{"class":3645},"sVyAn","QuantumCircuit",[189,3648,3649],{"class":195}," } ",[189,3651,1007],{"class":253},[189,3653,3654],{"class":1314}," 'qiskit'",[189,3656,3657],{"class":195},";\n",[189,3659,3660],{"class":191,"line":250},[189,3661,523],{"emptyLinePlaceholder":50},[189,3663,3664,3667,3670,3673,3676,3679],{"class":191,"line":281},[189,3665,3666],{"class":253},"const",[189,3668,1612],{"class":3669},"sU0A5",[189,3671,3672],{"class":199}," =",[189,3674,3675],{"class":210}," 1000",[189,3677,3678],{"class":195},";          ",[189,3680,3681],{"class":318},"\u002F\u002F one press buys this many draws\n",[189,3683,3684,3686,3689,3691,3694,3697],{"class":191,"line":51},[189,3685,3666],{"class":253},[189,3687,3688],{"class":3669}," pRare",[189,3690,3672],{"class":199},[189,3692,3693],{"class":210}," 0.3",[189,3695,3696],{"class":195},";           ",[189,3698,3699],{"class":318},"\u002F\u002F the app's input: how often a draw should come up rare\n",[189,3701,3702],{"class":191,"line":557},[189,3703,523],{"emptyLinePlaceholder":50},[189,3705,3706,3708,3711,3713,3716,3718,3721,3723,3726],{"class":191,"line":579},[189,3707,3666],{"class":253},[189,3709,3710],{"class":3669}," out",[189,3712,3672],{"class":199},[189,3714,3715],{"class":3669}," document",[189,3717,753],{"class":195},[189,3719,3720],{"class":203},"getElementById",[189,3722,230],{"class":195},[189,3724,3725],{"class":1314},"'out'",[189,3727,3728],{"class":195},");\n",[189,3730,3731,3733,3736,3738,3740,3742,3744,3746,3749],{"class":191,"line":590},[189,3732,3666],{"class":253},[189,3734,3735],{"class":3669}," bar",[189,3737,3672],{"class":199},[189,3739,3715],{"class":3669},[189,3741,753],{"class":195},[189,3743,3720],{"class":203},[189,3745,230],{"class":195},[189,3747,3748],{"class":1314},"'bar'",[189,3750,3728],{"class":195},[189,3752,3753,3755,3758,3760,3762,3764,3766,3768,3771],{"class":191,"line":595},[189,3754,3666],{"class":253},[189,3756,3757],{"class":3669}," foot",[189,3759,3672],{"class":199},[189,3761,3715],{"class":3669},[189,3763,753],{"class":195},[189,3765,3720],{"class":203},[189,3767,230],{"class":195},[189,3769,3770],{"class":1314},"'foot'",[189,3772,3728],{"class":195},[189,3774,3775],{"class":191,"line":601},[189,3776,523],{"emptyLinePlaceholder":50},[189,3778,3779,3782,3785,3787,3789,3792],{"class":191,"line":618},[189,3780,3781],{"class":253},"function",[189,3783,3784],{"class":203}," buildCircuit",[189,3786,230],{"class":195},[189,3788,12],{"class":239},[189,3790,3791],{"class":195},") {               ",[189,3793,3794],{"class":318},"\u002F\u002F app value in, circuit out\n",[189,3796,3797,3800,3803,3805,3807,3809,3812,3814,3817,3819,3822,3824,3826,3828,3830],{"class":191,"line":665},[189,3798,3799],{"class":253},"  const",[189,3801,3802],{"class":3669}," theta",[189,3804,3672],{"class":199},[189,3806,2369],{"class":210},[189,3808,659],{"class":199},[189,3810,3811],{"class":3669}," Math",[189,3813,753],{"class":195},[189,3815,3816],{"class":203},"asin",[189,3818,230],{"class":195},[189,3820,3821],{"class":3669},"Math",[189,3823,753],{"class":195},[189,3825,2379],{"class":203},[189,3827,230],{"class":195},[189,3829,12],{"class":3645},[189,3831,3832],{"class":195},"));\n",[189,3834,3835,3837,3840,3842,3844,3846,3848,3850,3852,3855],{"class":191,"line":676},[189,3836,3799],{"class":253},[189,3838,3839],{"class":3669}," qc",[189,3841,3672],{"class":199},[189,3843,533],{"class":203},[189,3845,230],{"class":195},[189,3847,1089],{"class":210},[189,3849,541],{"class":195},[189,3851,1089],{"class":210},[189,3853,3854],{"class":195},");       ",[189,3856,3857],{"class":318},"\u002F\u002F no `new`: the constructor is called like Python's\n",[189,3859,3860,3863,3865,3867,3869,3872,3874,3876],{"class":191,"line":681},[189,3861,3862],{"class":3669},"  qc",[189,3864,753],{"class":195},[189,3866,670],{"class":203},[189,3868,230],{"class":195},[189,3870,3871],{"class":3645},"theta",[189,3873,541],{"class":195},[189,3875,1165],{"class":210},[189,3877,3728],{"class":195},[189,3879,3880,3882,3884,3886,3888,3890,3892,3894],{"class":191,"line":687},[189,3881,3862],{"class":3669},[189,3883,753],{"class":195},[189,3885,1203],{"class":203},[189,3887,230],{"class":195},[189,3889,1165],{"class":210},[189,3891,541],{"class":195},[189,3893,1165],{"class":210},[189,3895,3728],{"class":195},[189,3897,3898,3901,3903],{"class":191,"line":705},[189,3899,3900],{"class":253},"  return",[189,3902,3839],{"class":3645},[189,3904,3657],{"class":195},[189,3906,3907],{"class":191,"line":1195},[189,3908,3180],{"class":195},[189,3910,3911],{"class":191,"line":1216},[189,3912,523],{"emptyLinePlaceholder":50},[189,3914,3915,3917,3919,3921,3923,3925,3927,3930],{"class":191,"line":1227},[189,3916,3781],{"class":253},[189,3918,2466],{"class":203},[189,3920,230],{"class":195},[189,3922,1555],{"class":239},[189,3924,541],{"class":195},[189,3926,2475],{"class":239},[189,3928,3929],{"class":195},") {             ",[189,3931,3932],{"class":318},"\u002F\u002F counts in, something the app can use out\n",[189,3934,3935,3937,3940,3942,3945,3948,3950,3953,3956,3959],{"class":191,"line":1234},[189,3936,3799],{"class":253},[189,3938,3939],{"class":3669}," rare",[189,3941,3672],{"class":199},[189,3943,3944],{"class":3645}," counts",[189,3946,3947],{"class":195},"[",[189,3949,3369],{"class":1314},[189,3951,3952],{"class":195},"] ",[189,3954,3955],{"class":199},"??",[189,3957,3958],{"class":210}," 0",[189,3960,3657],{"class":195},[189,3962,3963,3965,3967,3970,3972,3975,3977,3979,3982,3984,3986,3989,3991,3993,3996,3999],{"class":191,"line":1242},[189,3964,3900],{"class":253},[189,3966,3642],{"class":195},[189,3968,3969],{"class":3645},"rare",[189,3971,541],{"class":195},[189,3973,3974],{"class":3645},"common",[189,3976,3129],{"class":195},[189,3978,2475],{"class":3645},[189,3980,3981],{"class":199}," -",[189,3983,3939],{"class":3645},[189,3985,541],{"class":195},[189,3987,3988],{"class":3645},"share",[189,3990,3129],{"class":195},[189,3992,3969],{"class":3645},[189,3994,3995],{"class":199}," \u002F",[189,3997,3998],{"class":3645}," n",[189,4000,4001],{"class":195}," };\n",[189,4003,4004],{"class":191,"line":1272},[189,4005,3180],{"class":195},[189,4007,4008],{"class":191,"line":1301},[189,4009,523],{"emptyLinePlaceholder":50},[189,4011,4012,4015,4017,4020,4022,4025,4028,4030,4032,4035,4038],{"class":191,"line":1355},[189,4013,4014],{"class":3669},"out",[189,4016,753],{"class":195},[189,4018,4019],{"class":3645},"textContent",[189,4021,3672],{"class":199},[189,4023,4024],{"class":1314}," 'Opening '",[189,4026,4027],{"class":199}," +",[189,4029,1612],{"class":3645},[189,4031,4027],{"class":199},[189,4033,4034],{"class":1314}," ' boxes...'",[189,4036,4037],{"class":195},";   ",[189,4039,4040],{"class":318},"\u002F\u002F the in-flight state, because this takes real time\n",[189,4042,4043],{"class":191,"line":1417},[189,4044,523],{"emptyLinePlaceholder":50},[189,4046,4047,4050],{"class":191,"line":1424},[189,4048,4049],{"class":253},"try",[189,4051,4052],{"class":195}," {\n",[189,4054,4055,4057,4060,4062,4065,4068,4070,4072,4074,4077,4079,4082,4085,4087],{"class":191,"line":1460},[189,4056,3799],{"class":253},[189,4058,4059],{"class":3669}," job",[189,4061,3672],{"class":199},[189,4063,4064],{"class":253}," await",[189,4066,4067],{"class":3669}," backend",[189,4069,753],{"class":195},[189,4071,227],{"class":203},[189,4073,230],{"class":195},[189,4075,4076],{"class":203},"buildCircuit",[189,4078,230],{"class":195},[189,4080,4081],{"class":3645},"pRare",[189,4083,4084],{"class":195},"), { ",[189,4086,240],{"class":3645},[189,4088,4089],{"class":195}," });\n",[189,4091,4092,4094,4097,4099,4101,4103,4105,4107],{"class":191,"line":1497},[189,4093,3799],{"class":253},[189,4095,4096],{"class":3669}," result",[189,4098,3672],{"class":199},[189,4100,4064],{"class":253},[189,4102,4059],{"class":3669},[189,4104,753],{"class":195},[189,4106,306],{"class":203},[189,4108,4109],{"class":195},"();\n",[189,4111,4112,4114,4116,4118,4120,4122,4124,4126,4129,4132],{"class":191,"line":1512},[189,4113,3799],{"class":253},[189,4115,3944],{"class":3669},[189,4117,3672],{"class":199},[189,4119,4096],{"class":3669},[189,4121,753],{"class":195},[189,4123,312],{"class":203},[189,4125,309],{"class":195},[189,4127,4128],{"class":203},"toJs",[189,4130,4131],{"class":195},"();   ",[189,4133,4134],{"class":318},"\u002F\u002F .toJs() unpacks the Python dict into a plain object\n",[189,4136,4137],{"class":191,"line":1519},[189,4138,523],{"emptyLinePlaceholder":50},[189,4140,4141,4143,4146,4148,4150,4152,4154,4156,4158],{"class":191,"line":1539},[189,4142,3799],{"class":253},[189,4144,4145],{"class":3669}," drawn",[189,4147,3672],{"class":199},[189,4149,2466],{"class":203},[189,4151,230],{"class":195},[189,4153,1555],{"class":3645},[189,4155,541],{"class":195},[189,4157,240],{"class":3645},[189,4159,3728],{"class":195},[189,4161,4162,4165,4167,4169,4171,4173,4175,4177,4179,4182,4184,4186,4188,4190,4192,4195],{"class":191,"line":1564},[189,4163,4164],{"class":3669},"  out",[189,4166,753],{"class":195},[189,4168,4019],{"class":3645},[189,4170,3672],{"class":199},[189,4172,4145],{"class":3669},[189,4174,753],{"class":195},[189,4176,3969],{"class":3645},[189,4178,4027],{"class":199},[189,4180,4181],{"class":1314}," ' rare, '",[189,4183,4027],{"class":199},[189,4185,4145],{"class":3669},[189,4187,753],{"class":195},[189,4189,3974],{"class":3645},[189,4191,4027],{"class":199},[189,4193,4194],{"class":1314}," ' common'",[189,4196,3657],{"class":195},[189,4198,4199,4202,4204,4206,4208,4211,4213,4215,4218,4220,4222,4224,4227,4230,4233,4235,4237,4239,4241,4244],{"class":191,"line":1591},[189,4200,4201],{"class":3669},"  bar",[189,4203,753],{"class":195},[189,4205,884],{"class":3669},[189,4207,753],{"class":195},[189,4209,4210],{"class":3645},"width",[189,4212,3672],{"class":199},[189,4214,654],{"class":195},[189,4216,4217],{"class":3669},"drawn",[189,4219,753],{"class":195},[189,4221,3988],{"class":3645},[189,4223,659],{"class":199},[189,4225,4226],{"class":210}," 100",[189,4228,4229],{"class":195},").",[189,4231,4232],{"class":203},"toFixed",[189,4234,230],{"class":195},[189,4236,1089],{"class":210},[189,4238,641],{"class":195},[189,4240,635],{"class":199},[189,4242,4243],{"class":1314}," '%'",[189,4245,3657],{"class":195},[189,4247,4248,4251,4253,4255,4257,4260,4262,4264,4266,4268,4270,4272,4274,4276,4278,4280,4283,4285,4287,4289,4291,4293,4295],{"class":191,"line":2686},[189,4249,4250],{"class":3669},"  foot",[189,4252,753],{"class":195},[189,4254,4019],{"class":3645},[189,4256,3672],{"class":199},[189,4258,4259],{"class":1314}," 'share '",[189,4261,4027],{"class":199},[189,4263,4145],{"class":3669},[189,4265,753],{"class":195},[189,4267,3988],{"class":3669},[189,4269,753],{"class":195},[189,4271,4232],{"class":203},[189,4273,230],{"class":195},[189,4275,1241],{"class":210},[189,4277,641],{"class":195},[189,4279,635],{"class":199},[189,4281,4282],{"class":1314}," ', asked for '",[189,4284,4027],{"class":199},[189,4286,3688],{"class":3669},[189,4288,753],{"class":195},[189,4290,4232],{"class":203},[189,4292,230],{"class":195},[189,4294,1241],{"class":210},[189,4296,3728],{"class":195},[189,4298,4299,4302,4305,4307,4310],{"class":191,"line":2701},[189,4300,4301],{"class":195},"} ",[189,4303,4304],{"class":253},"catch",[189,4306,654],{"class":195},[189,4308,4309],{"class":3645},"err",[189,4311,4312],{"class":195},") {\n",[189,4314,4315,4317,4319,4321,4323,4326,4328,4331,4333],{"class":191,"line":2754},[189,4316,4164],{"class":3669},[189,4318,753],{"class":195},[189,4320,4019],{"class":3645},[189,4322,3672],{"class":199},[189,4324,4325],{"class":1314}," 'The run did not finish: '",[189,4327,4027],{"class":199},[189,4329,4330],{"class":3645}," err",[189,4332,4037],{"class":195},[189,4334,4335],{"class":318},"\u002F\u002F the failed state, because it can fail\n",[189,4337,4339,4341,4343,4345,4347,4350],{"class":191,"line":4338},37,[189,4340,4250],{"class":3669},[189,4342,753],{"class":195},[189,4344,4019],{"class":3645},[189,4346,3672],{"class":199},[189,4348,4349],{"class":1314}," 'Press Run to try again.'",[189,4351,3657],{"class":195},[189,4353,4355],{"class":191,"line":4354},38,[189,4356,3180],{"class":195},[12,4358,4359,1791,4361,4363],{},[170,4360,4076],{},[170,4362,2997],{}," are the same two functions as lesson 3, in another language.",[116,4365],{"alt":4366,"caption":4367,"no":119,"src":4368},"Ready leads to Running when the reader presses Run. Running leads to Success when the result arrives and the page shows the tally, or to Failed when the catch block runs and the page shows the error. Failed leads back to Running on another press. A note underneath warns that a result from an earlier press must not overwrite a newer one.","A remote quantum call moves through four states, and every path out of Running has to replace the running text.","\u002F_content\u002Fimages\u002Freal-app\u002Fui-state-machine.svg",[12,4370,4371],{},"The new code sits on either side of the call.",[12,4373,4374,4377,4378,4380],{},[129,4375,4376],{},"The in-flight state."," The line before ",[170,4379,172],{}," writes \"Opening 1000 boxes...\" into the page. Without that line the interface sits unchanged for the ten to fifteen seconds the job takes, and a person can decide your app is broken and reload.",[12,4382,4383,4386,4387,4389],{},[129,4384,4385],{},"The failed state."," The ",[170,4388,4304],{}," writes the error where the result would have gone, and tells the reader they can press Run again. A quantum run has more ways to fail than a local function call: the queue can reject the job, the network can drop, and the backend can error. Code that assumes success never replaces the in-flight text.",[12,4391,4392],{},"Both states are ordinary front-end work, needed by any remote call that is slow and can fail, including a circuit run.",[789,4394,4396,4400,4403,4462],{"check":4395},"one press prints 'ui state: failed' and a later press prints 'ui state: success', and neither press leaves the preview on its running message.",[111,4397,4399],{"id":4398},"assignment-make-the-run-fail-on-purpose","Assignment: make the run fail on purpose",[12,4401,4402],{},"A real failure is hard to wait for, so throw one on purpose.",[123,4404,4405,4415,4424,4434,4437,4447,4450,4459],{},[126,4406,4407,4408,4411,4412,4414],{},"In your fork, add ",[170,4409,4410],{},"console.log('ui state: success');"," as the last line inside the ",[170,4413,4049],{}," block, after the bar is set.",[126,4416,4417,4418,4421,4422,753],{},"Add ",[170,4419,4420],{},"console.log('ui state: failed');"," as the first line inside ",[170,4423,4304],{},[126,4425,4417,4426,4421,4429,4431,4432,753],{},[170,4427,4428],{},"throw new Error('test failure');",[170,4430,4049],{},", above ",[170,4433,172],{},[126,4435,4436],{},"Predict what the preview will show, and predict which of the two console lines will appear.",[126,4438,806,4439,809,4441,745,4443,814,4445,753],{},[129,4440,740],{},[129,4442,744],{},[129,4444,748],{},[129,4446,752],{},[126,4448,4449],{},"Write down the console line and the preview text.",[126,4451,4452,4453,4456,4457,3294],{},"Delete the ",[170,4454,4455],{},"throw"," line, and press ",[129,4458,752],{},[126,4460,4461],{},"Write down the console line and the preview text this time.",[830,4463,4464,4480,4490,4493],{"label":832},[12,4465,4466,4467,4469,4470,4472,4473,4475,4476,4479],{},"With the ",[170,4468,4455],{}," in place the circuit never runs. The exception is raised before ",[170,4471,172],{},", control jumps straight to ",[170,4474,4304],{},", the console prints ",[170,4477,4478],{},"ui state: failed",", and the preview reads \"The run did not finish: Error: test failure\" with \"Press Run to try again.\" underneath.",[12,4481,4482,4483,4485,4486,4489],{},"Remove the ",[170,4484,4455],{}," and the same interface comes back through the other path: ",[170,4487,4488],{},"ui state: success",", and the tally in the preview.",[12,4491,4492],{},"Neither path leaves the preview on \"Opening 1000 boxes...\", as Figure 1 shows.",[12,4494,4495,4496,4498],{},"A real failure looks the same to your code: it arrives in ",[170,4497,4304],{},", and the running text needs replacing.",[111,4500,4502,4504],{"id":4501},"tojs-returns-a-plain-object-not-a-map",[170,4503,3602],{}," returns a plain object, not a Map",[181,4506,4508],{"className":3626,"code":4507,"language":3628,"meta":22,"style":22},"const counts = result.get_counts().toJs();\n",[170,4509,4510],{"__ignoreMap":22},[189,4511,4512,4514,4516,4518,4520,4522,4524,4526,4528],{"class":191,"line":192},[189,4513,3666],{"class":253},[189,4515,3944],{"class":3669},[189,4517,3672],{"class":199},[189,4519,4096],{"class":3669},[189,4521,753],{"class":195},[189,4523,312],{"class":203},[189,4525,309],{"class":195},[189,4527,4128],{"class":203},[189,4529,4109],{"class":195},[12,4531,4532,4535,4536,4538,4539,4542,4543,4546,4547,4550],{},[170,4533,4534],{},"get_counts()"," returns a proxy to a Python dict. ",[170,4537,3602],{}," unpacks that proxy, and on this platform the result is a ",[129,4540,4541],{},"plain JavaScript object",", so ",[170,4544,4545],{},"counts['1']"," works and ",[170,4548,4549],{},"Object.keys(counts)"," works.",[12,4552,4553,4554,4556,4557,4560,4561,4563,4564,4567,4568,4570,4571,4574],{},"Our first version wrapped the ",[170,4555,3602],{}," result in ",[170,4558,4559],{},"Object.fromEntries",", the call you would write if ",[170,4562,3602],{}," returned a ",[170,4565,4566],{},"Map",". ",[170,4569,3602],{}," does not, and the run failed with ",[170,4572,4573],{},"TypeError: object is not iterable",". The circuit had executed correctly and the job had completed; the failure was one wrapper call of JavaScript after the boundary.",[111,4576,4578],{"id":4577},"the-page-and-its-styles","The page and its styles",[12,4580,4581],{},"The other two panes are small on purpose, because they are yours to replace.",[175,4583,4586],{"name":4584,"no-picker":22,"run-href":3622,"tag":4585},"picker.html","HTML · Playground",[181,4587,4591],{"className":4588,"code":4589,"language":4590,"meta":22,"style":22},"language-html shiki shiki-themes one-dark-pro","\u003Cdiv id=\"picker\">\n  \u003Ch1>Loot box opener\u003C\u002Fh1>\n  \u003Cp class=\"sub\">One press opens 1,000 boxes. The circuit decides how many are rare.\u003C\u002Fp>\n  \u003Cp id=\"out\" class=\"out\">Ready.\u003C\u002Fp>\n  \u003Cdiv class=\"track\">\u003Cdiv id=\"bar\" class=\"bar\">\u003C\u002Fdiv>\u003C\u002Fdiv>\n  \u003Cp id=\"foot\" class=\"foot\">\u003C\u002Fp>\n\u003C\u002Fdiv>\n","html",[170,4592,4593,4612,4627,4648,4674,4716,4741],{"__ignoreMap":22},[189,4594,4595,4598,4601,4604,4606,4609],{"class":191,"line":192},[189,4596,4597],{"class":195},"\u003C",[189,4599,4600],{"class":3645},"div",[189,4602,4603],{"class":210}," id",[189,4605,200],{"class":195},[189,4607,4608],{"class":1314},"\"picker\"",[189,4610,4611],{"class":195},">\n",[189,4613,4614,4617,4620,4623,4625],{"class":191,"line":23},[189,4615,4616],{"class":195},"  \u003C",[189,4618,4619],{"class":3645},"h1",[189,4621,4622],{"class":195},">Loot box opener\u003C\u002F",[189,4624,4619],{"class":3645},[189,4626,4611],{"class":195},[189,4628,4629,4631,4633,4636,4638,4641,4644,4646],{"class":191,"line":250},[189,4630,4616],{"class":195},[189,4632,12],{"class":3645},[189,4634,4635],{"class":210}," class",[189,4637,200],{"class":195},[189,4639,4640],{"class":1314},"\"sub\"",[189,4642,4643],{"class":195},">One press opens 1,000 boxes. The circuit decides how many are rare.\u003C\u002F",[189,4645,12],{"class":3645},[189,4647,4611],{"class":195},[189,4649,4650,4652,4654,4656,4658,4661,4663,4665,4667,4670,4672],{"class":191,"line":281},[189,4651,4616],{"class":195},[189,4653,12],{"class":3645},[189,4655,4603],{"class":210},[189,4657,200],{"class":195},[189,4659,4660],{"class":1314},"\"out\"",[189,4662,4635],{"class":210},[189,4664,200],{"class":195},[189,4666,4660],{"class":1314},[189,4668,4669],{"class":195},">Ready.\u003C\u002F",[189,4671,12],{"class":3645},[189,4673,4611],{"class":195},[189,4675,4676,4678,4680,4682,4684,4687,4690,4692,4694,4696,4699,4701,4703,4705,4708,4710,4712,4714],{"class":191,"line":51},[189,4677,4616],{"class":195},[189,4679,4600],{"class":3645},[189,4681,4635],{"class":210},[189,4683,200],{"class":195},[189,4685,4686],{"class":1314},"\"track\"",[189,4688,4689],{"class":195},">\u003C",[189,4691,4600],{"class":3645},[189,4693,4603],{"class":210},[189,4695,200],{"class":195},[189,4697,4698],{"class":1314},"\"bar\"",[189,4700,4635],{"class":210},[189,4702,200],{"class":195},[189,4704,4698],{"class":1314},[189,4706,4707],{"class":195},">\u003C\u002F",[189,4709,4600],{"class":3645},[189,4711,4707],{"class":195},[189,4713,4600],{"class":3645},[189,4715,4611],{"class":195},[189,4717,4718,4720,4722,4724,4726,4729,4731,4733,4735,4737,4739],{"class":191,"line":557},[189,4719,4616],{"class":195},[189,4721,12],{"class":3645},[189,4723,4603],{"class":210},[189,4725,200],{"class":195},[189,4727,4728],{"class":1314},"\"foot\"",[189,4730,4635],{"class":210},[189,4732,200],{"class":195},[189,4734,4728],{"class":1314},[189,4736,4707],{"class":195},[189,4738,12],{"class":3645},[189,4740,4611],{"class":195},[189,4742,4743,4746,4748],{"class":191,"line":579},[189,4744,4745],{"class":195},"\u003C\u002F",[189,4747,4600],{"class":3645},[189,4749,4611],{"class":195},[175,4751,4754],{"name":4752,"no-picker":22,"run-href":3622,"tag":4753},"picker.css","CSS · Playground",[181,4755,4759],{"className":4756,"code":4757,"language":4758,"meta":22,"style":22},"language-css shiki shiki-themes one-dark-pro","#picker { font: 15px\u002F1.5 system-ui, sans-serif; color: #1a1a1a; max-width: 460px; margin: 0 auto; padding: 8px; }\n#picker h1 { font-size: 19px; margin: 0 0 4px; }\n#picker .sub { margin: 0 0 18px; color: #555; font-size: 13px; }\n#picker .out { font-size: 17px; font-weight: 600; margin: 0 0 8px; }\n#picker .track { background: #ececf0; border-radius: 999px; height: 14px; overflow: hidden; }\n#picker .bar { background: #6d4aff; height: 100%; width: 0; transition: width .35s ease; }\n#picker .foot { color: #666; font-size: 12px; margin: 8px 0 0; font-variant-numeric: tabular-nums; }\n","css",[170,4760,4761,4766,4771,4776,4781,4786,4791],{"__ignoreMap":22},[189,4762,4763],{"class":191,"line":192},[189,4764,4765],{},"#picker { font: 15px\u002F1.5 system-ui, sans-serif; color: #1a1a1a; max-width: 460px; margin: 0 auto; padding: 8px; }\n",[189,4767,4768],{"class":191,"line":23},[189,4769,4770],{},"#picker h1 { font-size: 19px; margin: 0 0 4px; }\n",[189,4772,4773],{"class":191,"line":250},[189,4774,4775],{},"#picker .sub { margin: 0 0 18px; color: #555; font-size: 13px; }\n",[189,4777,4778],{"class":191,"line":281},[189,4779,4780],{},"#picker .out { font-size: 17px; font-weight: 600; margin: 0 0 8px; }\n",[189,4782,4783],{"class":191,"line":51},[189,4784,4785],{},"#picker .track { background: #ececf0; border-radius: 999px; height: 14px; overflow: hidden; }\n",[189,4787,4788],{"class":191,"line":557},[189,4789,4790],{},"#picker .bar { background: #6d4aff; height: 100%; width: 0; transition: width .35s ease; }\n",[189,4792,4793],{"class":191,"line":579},[189,4794,4795],{},"#picker .foot { color: #666; font-size: 12px; margin: 8px 0 0; font-variant-numeric: tabular-nums; }\n",[789,4797,4799,4803,4837],{"check":4798},"you have seen the in-flight line and the results of two presses of an unchanged fork, pressing once more if the two happen to match.",[111,4800,4802],{"id":4801},"assignment-watch-the-two-states-then-press-again","Assignment: watch the two states, then press again",[123,4804,4805,4816,4826,4829,4832],{},[126,4806,732,4807,737,4812,1716,4814,1720],{},[16,4808,4810],{"href":4809},"https:\u002F\u002Fqollab.xyz\u002Fu\u002Fqollab\u002Flearn-app-ui",[170,4811,3622],{},[129,4813,1715],{},[129,4815,1719],{},[126,4817,1723,4818,809,4820,745,4822,814,4824,753],{},[129,4819,740],{},[129,4821,744],{},[129,4823,748],{},[129,4825,752],{},[126,4827,4828],{},"Watch the preview while the job runs. Write down what the preview says before the result arrives.",[126,4830,4831],{},"When the result lands, write down the two numbers and the share.",[126,4833,806,4834,4836],{},[129,4835,752],{}," again without changing anything, and write down the new numbers.",[830,4838,4839,4842,4845],{"label":832},[12,4840,4841],{},"Before the result arrives the preview reads \"Opening 1000 boxes...\".",[12,4843,4844],{},"Our run on 22 September 2026 came back with 310 rare and 690 common, a share of 0.310 against the 0.300 asked for. Yours will differ, and your second press will differ from your first, for the reason lesson 2 gave.",[12,4846,4847],{},"The bar moves between presses because its width is set from the share.",[111,4849,4851],{"id":4850},"live-recorded-precomputed-or-scheduled","Live, recorded, precomputed or scheduled",[116,4853],{"alt":4854,"caption":4855,"no":323,"src":4856},"Four lanes. Live call: user to job to wait to result, always fresh, the user waits seconds, and failures reach the user. Recorded replay: user to a library of stored runs to an immediate result, fresh as of recording, no waiting, failing at recording time. Precomputed pool: batch jobs to a database to the user, fresh as of the last batch, no waiting, failing in the batch. Scheduled pipeline: scheduler to job to published value to another program, fresh as of the last schedule, with no user waiting at all.","The circuit can be identical in all four shapes. The shapes differ in when the circuit runs, who waits, where the result lives, and how stale the result may be.","\u002F_content\u002Fimages\u002Freal-app\u002Ffour-topologies.svg",[12,4858,4859],{},"Your fork makes a live call: a person presses a button and waits for a quantum computer. A live call is one of four shapes in Figure 2.",[12,4861,4862,4865],{},[129,4863,4864],{},"Live call."," You just built this shape: the user waits the full latency on every press. It suits a tool whose purpose is running the circuit, such as the Playground itself.",[12,4867,4868,4871,4872,4874],{},[129,4869,4870],{},"Recorded, then replayed."," ",[16,4873,361],{"href":360}," runs two tracks. An exact statevector simulation runs live on every visit inside a serverless function and drives the animation. The damage-and-healing fidelities come from IonQ Forte runs captured offline and replayed from a library, per the write-up, so each visit draws a different recorded run. Nobody waits for a queue, and the fidelities still come from hardware.",[12,4876,4877,4871,4880,4882],{},[129,4878,4879],{},"Precomputed pool.",[16,4881,473],{"href":472}," is the project from lessons 1 and 2, and its write-up gives the reasoning. Running circuits live when a visitor arrives would be slow and expensive. So the team computes a pool of measurement results in advance, and each plant draws from it when first observed. The write-up puts the reveal of a plant's traits at under 50 milliseconds.",[12,4884,4885],{},"Garden's stack is Next.js, React, Three.js, Qiskit, IonQ and PostgreSQL. Four of those six, everything except Qiskit and IonQ, are ordinary web tools.",[12,4887,4888,4386,4891,4893],{},[129,4889,4890],{},"Scheduled pipeline.",[16,4892,95],{"href":94}," is built to run once a day: a Python engine pulls market signals, a quantum step runs on IonQ, and the result is published on-chain. Smart contracts can then read the result with the same call they would use for a price feed.",[12,4895,4896],{},"The Oracle's write-up describes the output as a number other code builds on rather than a dashboard for people. When another program consumes your result, neither the in-flight state nor the failed state applies, and a scheduled pipeline is enough.",[12,4898,4899],{},"The choice between the four shapes is a latency and cost decision, made the way you would make it for any expensive third-party call.",[789,4901,4903,4907,4910,4958],{"check":4902},"your fork shows its result as soon as the console says Running... with useRecorded true, and only after a further wait when it is false.",[111,4904,4906],{"id":4905},"assignment-turn-your-live-call-into-a-replay","Assignment: turn your live call into a replay",[12,4908,4909],{},"Your fork currently calls the circuit every time someone presses Run. Make your fork behave like Butterfly Field's recorded replay instead.",[123,4911,4912,4918,4924,4938,4946,4955],{},[126,4913,4914,4915,753],{},"In your fork, copy the tally from your last run into the code as a literal object, for example ",[170,4916,4917],{},"const recorded = { '0': 690, '1': 310 };",[126,4919,4920,4921,753],{},"Add a constant near the top, ",[170,4922,4923],{},"const useRecorded = true;",[126,4925,4926,4927,4930,4931,4934,4935,4937],{},"Change the code so that when ",[170,4928,4929],{},"useRecorded"," is true it decodes ",[170,4932,4933],{},"recorded"," and never calls ",[170,4936,172],{},", and when it is false it runs the circuit as before.",[126,4939,806,4940,4942,4943,4945],{},[129,4941,752],{}," with ",[170,4944,4929],{}," set to true and time how long the result takes to appear.",[126,4947,4948,4949,4951,4952,4954],{},"Set ",[170,4950,4929],{}," back to false, press ",[129,4953,752],{},", and time it again.",[126,4956,4957],{},"Write down what the replay gained and what it gave up.",[830,4959,4960,4963,5071,5074],{"label":832},[12,4961,4962],{},"The shape of the change is a branch around the call:",[181,4964,4966],{"className":3626,"code":4965,"language":3628,"meta":22,"style":22},"let counts;\nif (useRecorded) {\n  counts = recorded;\n} else {\n  const job = await backend.run(buildCircuit(pRare), { shots });\n  counts = (await job.result()).get_counts().toJs();\n}\n",[170,4967,4968,4977,4988,5000,5009,5039,5067],{"__ignoreMap":22},[189,4969,4970,4973,4975],{"class":191,"line":192},[189,4971,4972],{"class":253},"let",[189,4974,3944],{"class":3645},[189,4976,3657],{"class":195},[189,4978,4979,4982,4984,4986],{"class":191,"line":23},[189,4980,4981],{"class":253},"if",[189,4983,654],{"class":195},[189,4985,4929],{"class":3645},[189,4987,4312],{"class":195},[189,4989,4990,4993,4995,4998],{"class":191,"line":250},[189,4991,4992],{"class":3645},"  counts",[189,4994,3672],{"class":199},[189,4996,4997],{"class":3645}," recorded",[189,4999,3657],{"class":195},[189,5001,5002,5004,5007],{"class":191,"line":281},[189,5003,4301],{"class":195},[189,5005,5006],{"class":253},"else",[189,5008,4052],{"class":195},[189,5010,5011,5013,5015,5017,5019,5021,5023,5025,5027,5029,5031,5033,5035,5037],{"class":191,"line":51},[189,5012,3799],{"class":253},[189,5014,4059],{"class":3669},[189,5016,3672],{"class":199},[189,5018,4064],{"class":253},[189,5020,4067],{"class":3669},[189,5022,753],{"class":195},[189,5024,227],{"class":203},[189,5026,230],{"class":195},[189,5028,4076],{"class":203},[189,5030,230],{"class":195},[189,5032,4081],{"class":3645},[189,5034,4084],{"class":195},[189,5036,240],{"class":3645},[189,5038,4089],{"class":195},[189,5040,5041,5043,5045,5047,5050,5052,5054,5056,5059,5061,5063,5065],{"class":191,"line":557},[189,5042,4992],{"class":3645},[189,5044,3672],{"class":199},[189,5046,654],{"class":195},[189,5048,5049],{"class":253},"await",[189,5051,4059],{"class":3669},[189,5053,753],{"class":195},[189,5055,306],{"class":203},[189,5057,5058],{"class":195},"()).",[189,5060,312],{"class":203},[189,5062,309],{"class":195},[189,5064,4128],{"class":203},[189,5066,4109],{"class":195},[189,5068,5069],{"class":191,"line":579},[189,5070,3180],{"class":195},[12,5072,5073],{},"With the branch taken the result appears the moment your code starts, because nothing leaves the machine. The Playground still loads its runtime first, and that load is separate from the job wait the replay removes. With the branch false you are back to waiting for the job too.",[12,5075,5076],{},"The replay removed the job wait and gave up freshness: the tally is fixed, identical on every visit, and it stops being a sample of anything once your circuit changes. Butterfly Field keeps a library of recorded runs and draws a different one each visit, so repeat visits do not all show the same result.",[111,5078,873],{"id":872},[12,5080,5081],{},"A run on IonQ's cloud takes seconds and can fail, so a page that runs the circuit live needs an in-flight state and a failed state. Run the circuit ahead of time when a person should not wait on each press, when each press would cost too much, or when another program reads the result. The three ways to do that are a recorded replay, a precomputed pool and a scheduled pipeline. The result is then only as fresh as the last run.",[12,5083,5084],{},"Lesson 5 measures whether the quantum version was worth building.",[884,5086,5087],{},"html pre.shiki code .sV9Aq, html code.shiki .sV9Aq{--shiki-default:#7F848E;--shiki-default-font-style:italic}html pre.shiki code .seHd6, html code.shiki .seHd6{--shiki-default:#C678DD}html pre.shiki code .sn6KH, html code.shiki .sn6KH{--shiki-default:#ABB2BF}html pre.shiki code .sVyAn, html code.shiki .sVyAn{--shiki-default:#E06C75}html pre.shiki code .subq3, html code.shiki .subq3{--shiki-default:#98C379}html pre.shiki code .sU0A5, html code.shiki .sU0A5{--shiki-default:#E5C07B}html pre.shiki code .sjrmR, html code.shiki .sjrmR{--shiki-default:#56B6C2}html pre.shiki code .sVC51, html code.shiki .sVC51{--shiki-default:#D19A66}html pre.shiki code .sVbv2, html code.shiki .sVbv2{--shiki-default:#61AFEF}html pre.shiki code .s_ZVi, html code.shiki .s_ZVi{--shiki-default:#E06C75;--shiki-default-font-style:italic}html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}",{"title":22,"searchDepth":23,"depth":23,"links":5089},[5090,5091,5092,5093,5095,5096,5097,5098,5099],{"id":3584,"depth":23,"text":3585},{"id":3617,"depth":23,"text":3618},{"id":4398,"depth":23,"text":4399},{"id":4501,"depth":23,"text":5094},".toJs() returns a plain object, not a Map",{"id":4577,"depth":23,"text":4578},{"id":4801,"depth":23,"text":4802},{"id":4850,"depth":23,"text":4851},{"id":4905,"depth":23,"text":4906},{"id":872,"depth":23,"text":873},[26,27,5,3564],[],{"username":7,"name":30,"role":31,"avatar":32},"An app around a circuit handles a call that takes seconds and can fail, in one of four shapes: live, recorded replay, precomputed pool or scheduled pipeline.",{},{"slug":5106,"title":5107,"desc":5108},"\u002Fblog\u002Flearn\u002Fusing-quantum-in-a-real-application\u002Fis-quantum-worth-it","Is quantum worth it in your app","Run the same job both ways and compare the counts and the timings.",[],{"title":3564,"description":5103},"blog\u002Flearn\u002Fusing-quantum-in-a-real-application\u002Fthe-app-around-it",[],"A2gsPE4R_M_cDY4IE3sdMtDzLYoDMJYUr6xC3SCwFTI",{"id":5115,"title":5107,"authors":5116,"body":5117,"breadcrumb":6176,"builders":6177,"byline":6178,"category":33,"categoryName":33,"challenge":33,"courseAuthor":33,"courseLead":33,"dek":5108,"description":6179,"draft":46,"extension":47,"eyebrow":33,"featured":46,"finish":33,"fork":33,"group":33,"groupName":33,"hero":33,"heroAlt":33,"heroCta":33,"heroImage":33,"homepageFeatured":46,"kind":903,"lessonCount":557,"meta":6180,"navigation":50,"newsItems":33,"next":6181,"ogImage":33,"order":51,"outcomes":33,"path":5106,"prerequisite":33,"prerequisiteLinks":33,"publishDate":66,"readingTime":33,"related":6185,"relatedProjects":33,"section":33,"seo":6186,"stem":6187,"tags":6188,"track":73,"trackName":5,"__hash__":6189},"blog\u002Fblog\u002Flearn\u002Fusing-quantum-in-a-real-application\u002Fis-quantum-worth-it.md",[7],{"type":9,"value":5118,"toc":6166},[5119,5126,5130,5133,5884,5891,5905,5911,5914,5919,5925,5928,5932,5935,5938,5942,5948,5951,5955,5962,5965,6019,6022,6031,6035,6038,6044,6050,6056,6062,6066,6072,6078,6084,6090,6096,6155,6157,6160,6163],[12,5120,5121,5122,5125],{},"You answer whether quantum is worth it by measuring: ",[170,5123,5124],{},"race.py"," draws the picker's thousand samples twice, once with one line of ordinary Python and once with the circuit from lesson 3, and compares the two runs on count and on time.",[111,5127,5129],{"id":5128},"the-race","The race",[12,5131,5132],{},"The file runs both methods once and scores them with the same arithmetic.",[175,5134,5136],{"name":5124,"no-picker":22,"run-href":5135,"tag":985},"\u002Fu\u002Fqollab\u002Flearn-app-race",[181,5137,5139],{"className":183,"code":5138,"language":185,"meta":22,"style":22},"# 'backend' already exists when this runs: it is whatever you pick in the Run Experiment dialog.\nfrom math import asin, sqrt\nfrom qiskit import QuantumCircuit\nfrom qiskit.providers.jobstatus import JobStatus\nimport random\nimport time\n\nshots = 1000\np_rare = 0.3\n\n# --- the conventional answer -------------------------------------------------\nt0 = time.perf_counter()\npicks = random.choices([\"common\", \"rare\"], weights=[1 - p_rare, p_rare], k=shots)\nclassical = {\"rare\": picks.count(\"rare\"), \"common\": picks.count(\"common\")}\nclassical_s = time.perf_counter() - t0\n\n# --- the quantum answer ------------------------------------------------------\nqc = QuantumCircuit(1, 1)\nqc.ry(2 * asin(sqrt(p_rare)), 0)\nqc.measure(0, 0)\n\nt1 = time.perf_counter()\njob = backend.run(qc, shots=shots)\nwhile job.status() not in (JobStatus.DONE, JobStatus.ERROR, JobStatus.CANCELLED):\n    time.sleep(1)\ncounts = job.result().get_counts()\nquantum = {\"rare\": counts.get(\"1\", 0), \"common\": counts.get(\"0\", 0)}\nquantum_s = time.perf_counter() - t1\n\n# --- read the result honestly ------------------------------------------------\nprint(f\"classical  {classical}   in {classical_s * 1000:.2f} ms\")\nprint(f\"quantum    {quantum}   in {quantum_s:.1f} s\")\nprint()\ngap = abs(classical[\"rare\"] - quantum[\"rare\"])\nprint(f\"the two draws differ by {gap} out of {shots}\")\nprint(\"two independent 1,000-shot draws land within 40 of each other 95% of the time,\")\nprint(\"so anything up to about 40 here is the two methods agreeing.\")\nprint()\nprint(f\"the quantum run took about {quantum_s \u002F classical_s:,.0f} times as long,\")\nprint(\"almost all of it queue and round trip rather than computation.\")\n",[170,5140,5141,5147,5159,5171,5183,5192,5200,5206,5216,5226,5232,5239,5256,5304,5341,5361,5367,5374,5394,5421,5439,5445,5460,5480,5510,5524,5542,5586,5606,5612,5619,5660,5697,5705,5734,5767,5786,5799,5807,5840,5854],{"__ignoreMap":22},[189,5142,5143,5145],{"class":191,"line":192},[189,5144,997],{"class":995,"aria-hidden":996},[189,5146,1000],{"class":318},[189,5148,5149,5151,5153,5155,5157],{"class":191,"line":23},[189,5150,997],{"class":995,"aria-hidden":996},[189,5152,1007],{"class":253},[189,5154,1010],{"class":195},[189,5156,1013],{"class":253},[189,5158,2271],{"class":195},[189,5160,5161,5163,5165,5167,5169],{"class":191,"line":250},[189,5162,997],{"class":995,"aria-hidden":996},[189,5164,1007],{"class":253},[189,5166,1025],{"class":195},[189,5168,1013],{"class":253},[189,5170,1030],{"class":195},[189,5172,5173,5175,5177,5179,5181],{"class":191,"line":281},[189,5174,997],{"class":995,"aria-hidden":996},[189,5176,1007],{"class":253},[189,5178,1053],{"class":195},[189,5180,1013],{"class":253},[189,5182,1058],{"class":195},[189,5184,5185,5187,5189],{"class":191,"line":51},[189,5186,997],{"class":995,"aria-hidden":996},[189,5188,1013],{"class":253},[189,5190,5191],{"class":195}," random\n",[189,5193,5194,5196,5198],{"class":191,"line":557},[189,5195,997],{"class":995,"aria-hidden":996},[189,5197,1013],{"class":253},[189,5199,1067],{"class":195},[189,5201,5202,5204],{"class":191,"line":579},[189,5203,997],{"class":995,"aria-hidden":996},[189,5205,1074],{},[189,5207,5208,5210,5212,5214],{"class":191,"line":590},[189,5209,997],{"class":995,"aria-hidden":996},[189,5211,1081],{"class":195},[189,5213,200],{"class":199},[189,5215,1086],{"class":210},[189,5217,5218,5220,5222,5224],{"class":191,"line":595},[189,5219,997],{"class":995,"aria-hidden":996},[189,5221,2326],{"class":195},[189,5223,200],{"class":199},[189,5225,2331],{"class":210},[189,5227,5228,5230],{"class":191,"line":601},[189,5229,997],{"class":995,"aria-hidden":996},[189,5231,1074],{},[189,5233,5234,5236],{"class":191,"line":618},[189,5235,997],{"class":995,"aria-hidden":996},[189,5237,5238],{"class":318},"# --- the conventional answer -------------------------------------------------\n",[189,5240,5241,5243,5246,5248,5251,5254],{"class":191,"line":665},[189,5242,997],{"class":995,"aria-hidden":996},[189,5244,5245],{"class":195},"t0 ",[189,5247,200],{"class":199},[189,5249,5250],{"class":195}," time.",[189,5252,5253],{"class":203},"perf_counter",[189,5255,1536],{"class":195},[189,5257,5258,5260,5263,5265,5268,5271,5274,5276,5278,5280,5283,5286,5288,5290,5292,5294,5297,5300,5302],{"class":191,"data-cue":1089,"line":676},[189,5259,1089],{"class":1092},[189,5261,5262],{"class":195},"picks ",[189,5264,200],{"class":199},[189,5266,5267],{"class":195}," random.",[189,5269,5270],{"class":203},"choices",[189,5272,5273],{"class":195},"([",[189,5275,2519],{"class":1314},[189,5277,541],{"class":195},[189,5279,2513],{"class":1314},[189,5281,5282],{"class":195},"], ",[189,5284,5285],{"class":239},"weights",[189,5287,200],{"class":199},[189,5289,3947],{"class":195},[189,5291,1089],{"class":210},[189,5293,3981],{"class":199},[189,5295,5296],{"class":195}," p_rare, p_rare], ",[189,5298,5299],{"class":239},"k",[189,5301,200],{"class":199},[189,5303,1457],{"class":195},[189,5305,5306,5308,5311,5313,5315,5317,5320,5323,5325,5327,5329,5331,5333,5335,5337,5339],{"class":191,"line":681},[189,5307,997],{"class":995,"aria-hidden":996},[189,5309,5310],{"class":195},"classical ",[189,5312,200],{"class":199},[189,5314,2510],{"class":195},[189,5316,2513],{"class":1314},[189,5318,5319],{"class":195},": picks.",[189,5321,5322],{"class":203},"count",[189,5324,230],{"class":195},[189,5326,2513],{"class":1314},[189,5328,1450],{"class":195},[189,5330,2519],{"class":1314},[189,5332,5319],{"class":195},[189,5334,5322],{"class":203},[189,5336,230],{"class":195},[189,5338,2519],{"class":1314},[189,5340,3470],{"class":195},[189,5342,5343,5345,5348,5350,5352,5354,5356,5358],{"class":191,"line":687},[189,5344,997],{"class":995,"aria-hidden":996},[189,5346,5347],{"class":195},"classical_s ",[189,5349,200],{"class":199},[189,5351,5250],{"class":195},[189,5353,5253],{"class":203},[189,5355,263],{"class":195},[189,5357,1626],{"class":199},[189,5359,5360],{"class":195}," t0\n",[189,5362,5363,5365],{"class":191,"line":705},[189,5364,997],{"class":995,"aria-hidden":996},[189,5366,1074],{},[189,5368,5369,5371],{"class":191,"line":1195},[189,5370,997],{"class":995,"aria-hidden":996},[189,5372,5373],{"class":318},"# --- the quantum answer ------------------------------------------------------\n",[189,5375,5376,5378,5380,5382,5384,5386,5388,5390,5392],{"class":191,"line":1216},[189,5377,997],{"class":995,"aria-hidden":996},[189,5379,196],{"class":195},[189,5381,200],{"class":199},[189,5383,533],{"class":203},[189,5385,230],{"class":195},[189,5387,1089],{"class":210},[189,5389,541],{"class":195},[189,5391,1089],{"class":210},[189,5393,214],{"class":195},[189,5395,5396,5398,5400,5402,5404,5406,5408,5410,5412,5414,5417,5419],{"class":191,"data-cue":292,"line":1227},[189,5397,292],{"class":1092},[189,5399,2182],{"class":195},[189,5401,670],{"class":203},[189,5403,230],{"class":195},[189,5405,292],{"class":210},[189,5407,659],{"class":199},[189,5409,2374],{"class":203},[189,5411,230],{"class":195},[189,5413,2379],{"class":203},[189,5415,5416],{"class":195},"(p_rare)), ",[189,5418,1165],{"class":210},[189,5420,214],{"class":195},[189,5422,5423,5425,5427,5429,5431,5433,5435,5437],{"class":191,"line":1234},[189,5424,997],{"class":995,"aria-hidden":996},[189,5426,2182],{"class":195},[189,5428,1203],{"class":203},[189,5430,230],{"class":195},[189,5432,1165],{"class":210},[189,5434,541],{"class":195},[189,5436,1165],{"class":210},[189,5438,214],{"class":195},[189,5440,5441,5443],{"class":191,"line":1242},[189,5442,997],{"class":995,"aria-hidden":996},[189,5444,1074],{},[189,5446,5447,5449,5452,5454,5456,5458],{"class":191,"line":1272},[189,5448,997],{"class":995,"aria-hidden":996},[189,5450,5451],{"class":195},"t1 ",[189,5453,200],{"class":199},[189,5455,5250],{"class":195},[189,5457,5253],{"class":203},[189,5459,1536],{"class":195},[189,5461,5462,5464,5466,5468,5470,5472,5474,5476,5478],{"class":191,"line":1301},[189,5463,997],{"class":995,"aria-hidden":996},[189,5465,219],{"class":195},[189,5467,200],{"class":199},[189,5469,224],{"class":195},[189,5471,227],{"class":203},[189,5473,2593],{"class":195},[189,5475,240],{"class":239},[189,5477,200],{"class":199},[189,5479,1457],{"class":195},[189,5481,5482,5484,5486,5488,5490,5492,5494,5496,5498,5500,5502,5504,5506,5508],{"class":191,"line":1355},[189,5483,997],{"class":995,"aria-hidden":996},[189,5485,254],{"class":253},[189,5487,257],{"class":195},[189,5489,260],{"class":203},[189,5491,263],{"class":195},[189,5493,1473],{"class":253},[189,5495,1476],{"class":253},[189,5497,1479],{"class":195},[189,5499,275],{"class":210},[189,5501,1484],{"class":195},[189,5503,1487],{"class":210},[189,5505,1484],{"class":195},[189,5507,1492],{"class":210},[189,5509,576],{"class":195},[189,5511,5512,5514,5516,5518,5520,5522],{"class":191,"data-cue":1241,"line":1417},[189,5513,1241],{"class":1092},[189,5515,284],{"class":195},[189,5517,287],{"class":203},[189,5519,230],{"class":195},[189,5521,1089],{"class":210},[189,5523,214],{"class":195},[189,5525,5526,5528,5530,5532,5534,5536,5538,5540],{"class":191,"line":1424},[189,5527,997],{"class":995,"aria-hidden":996},[189,5529,299],{"class":195},[189,5531,200],{"class":199},[189,5533,257],{"class":195},[189,5535,306],{"class":203},[189,5537,309],{"class":195},[189,5539,312],{"class":203},[189,5541,1536],{"class":195},[189,5543,5544,5546,5549,5551,5553,5555,5558,5560,5562,5564,5566,5568,5570,5572,5574,5576,5578,5580,5582,5584],{"class":191,"line":1460},[189,5545,997],{"class":995,"aria-hidden":996},[189,5547,5548],{"class":195},"quantum ",[189,5550,200],{"class":199},[189,5552,2510],{"class":195},[189,5554,2513],{"class":1314},[189,5556,5557],{"class":195},": counts.",[189,5559,1577],{"class":203},[189,5561,230],{"class":195},[189,5563,2495],{"class":1314},[189,5565,541],{"class":195},[189,5567,1165],{"class":210},[189,5569,1450],{"class":195},[189,5571,2519],{"class":1314},[189,5573,5557],{"class":195},[189,5575,1577],{"class":203},[189,5577,230],{"class":195},[189,5579,1582],{"class":1314},[189,5581,541],{"class":195},[189,5583,1165],{"class":210},[189,5585,3470],{"class":195},[189,5587,5588,5590,5593,5595,5597,5599,5601,5603],{"class":191,"line":1497},[189,5589,997],{"class":995,"aria-hidden":996},[189,5591,5592],{"class":195},"quantum_s ",[189,5594,200],{"class":199},[189,5596,5250],{"class":195},[189,5598,5253],{"class":203},[189,5600,263],{"class":195},[189,5602,1626],{"class":199},[189,5604,5605],{"class":195}," t1\n",[189,5607,5608,5610],{"class":191,"line":1512},[189,5609,997],{"class":995,"aria-hidden":996},[189,5611,1074],{},[189,5613,5614,5616],{"class":191,"line":1519},[189,5615,997],{"class":995,"aria-hidden":996},[189,5617,5618],{"class":318},"# --- read the result honestly ------------------------------------------------\n",[189,5620,5621,5623,5625,5627,5629,5632,5634,5637,5639,5642,5644,5646,5648,5650,5653,5655,5658],{"class":191,"line":1539},[189,5622,997],{"class":995,"aria-hidden":996},[189,5624,1306],{"class":199},[189,5626,230],{"class":195},[189,5628,1311],{"class":253},[189,5630,5631],{"class":1314},"\"classical  ",[189,5633,1318],{"class":210},[189,5635,5636],{"class":195},"classical",[189,5638,1332],{"class":210},[189,5640,5641],{"class":1314},"   in ",[189,5643,1318],{"class":210},[189,5645,5347],{"class":195},[189,5647,629],{"class":199},[189,5649,3675],{"class":210},[189,5651,5652],{"class":253},":.2f",[189,5654,1332],{"class":210},[189,5656,5657],{"class":1314}," ms\"",[189,5659,214],{"class":195},[189,5661,5662,5664,5666,5668,5670,5673,5675,5678,5680,5682,5684,5687,5690,5692,5695],{"class":191,"line":1564},[189,5663,997],{"class":995,"aria-hidden":996},[189,5665,1306],{"class":199},[189,5667,230],{"class":195},[189,5669,1311],{"class":253},[189,5671,5672],{"class":1314},"\"quantum    ",[189,5674,1318],{"class":210},[189,5676,5677],{"class":195},"quantum",[189,5679,1332],{"class":210},[189,5681,5641],{"class":1314},[189,5683,1318],{"class":210},[189,5685,5686],{"class":195},"quantum_s",[189,5688,5689],{"class":253},":.1f",[189,5691,1332],{"class":210},[189,5693,5694],{"class":1314}," s\"",[189,5696,214],{"class":195},[189,5698,5699,5701,5703],{"class":191,"line":1591},[189,5700,997],{"class":995,"aria-hidden":996},[189,5702,1306],{"class":199},[189,5704,1536],{"class":195},[189,5706,5707,5709,5712,5714,5717,5720,5722,5724,5726,5729,5731],{"class":191,"line":2686},[189,5708,997],{"class":995,"aria-hidden":996},[189,5710,5711],{"class":195},"gap ",[189,5713,200],{"class":199},[189,5715,5716],{"class":199}," abs",[189,5718,5719],{"class":195},"(classical[",[189,5721,2513],{"class":1314},[189,5723,3952],{"class":195},[189,5725,1626],{"class":199},[189,5727,5728],{"class":195}," quantum[",[189,5730,2513],{"class":1314},[189,5732,5733],{"class":195},"])\n",[189,5735,5736,5738,5740,5742,5744,5747,5749,5752,5754,5757,5759,5761,5763,5765],{"class":191,"line":2701},[189,5737,997],{"class":995,"aria-hidden":996},[189,5739,1306],{"class":199},[189,5741,230],{"class":195},[189,5743,1311],{"class":253},[189,5745,5746],{"class":1314},"\"the two draws differ by ",[189,5748,1318],{"class":210},[189,5750,5751],{"class":195},"gap",[189,5753,1332],{"class":210},[189,5755,5756],{"class":1314}," out of ",[189,5758,1318],{"class":210},[189,5760,240],{"class":195},[189,5762,1332],{"class":210},[189,5764,1350],{"class":1314},[189,5766,214],{"class":195},[189,5768,5769,5771,5773,5775,5778,5781,5784],{"class":191,"line":2754},[189,5770,997],{"class":995,"aria-hidden":996},[189,5772,1306],{"class":199},[189,5774,230],{"class":195},[189,5776,5777],{"class":1314},"\"two independent 1,000-shot draws land within 40 of each other 95",[189,5779,5780],{"class":210},"% o",[189,5782,5783],{"class":1314},"f the time,\"",[189,5785,214],{"class":195},[189,5787,5788,5790,5792,5794,5797],{"class":191,"data-cue":700,"line":4338},[189,5789,700],{"class":1092},[189,5791,1306],{"class":199},[189,5793,230],{"class":195},[189,5795,5796],{"class":1314},"\"so anything up to about 40 here is the two methods agreeing.\"",[189,5798,214],{"class":195},[189,5800,5801,5803,5805],{"class":191,"line":4354},[189,5802,997],{"class":995,"aria-hidden":996},[189,5804,1306],{"class":199},[189,5806,1536],{"class":195},[189,5808,5810,5812,5814,5816,5818,5821,5823,5825,5827,5830,5833,5835,5838],{"class":191,"line":5809},39,[189,5811,997],{"class":995,"aria-hidden":996},[189,5813,1306],{"class":199},[189,5815,230],{"class":195},[189,5817,1311],{"class":253},[189,5819,5820],{"class":1314},"\"the quantum run took about ",[189,5822,1318],{"class":210},[189,5824,5592],{"class":195},[189,5826,1609],{"class":199},[189,5828,5829],{"class":195}," classical_s",[189,5831,5832],{"class":253},":,.0f",[189,5834,1332],{"class":210},[189,5836,5837],{"class":1314}," times as long,\"",[189,5839,214],{"class":195},[189,5841,5843,5845,5847,5849,5852],{"class":191,"line":5842},40,[189,5844,997],{"class":995,"aria-hidden":996},[189,5846,1306],{"class":199},[189,5848,230],{"class":195},[189,5850,5851],{"class":1314},"\"almost all of it queue and round trip rather than computation.\"",[189,5853,214],{"class":195},[123,5855,5856,5863,5870,5877],{"class":1644},[126,5857,5858,5860],{"data-cue":1089},[189,5859,1089],{"class":1092},[189,5861,5862],{"class":1651},"the whole classical solution",[126,5864,5865,5867],{"data-cue":292},[189,5866,292],{"class":1092},[189,5868,5869],{"class":1651},"the same distribution, prepared as an amplitude",[126,5871,5872,5874],{"data-cue":1241},[189,5873,1241],{"class":1092},[189,5875,5876],{"class":1651},"poll every second, so the timing below has 1s resolution",[126,5878,5879,5881],{"data-cue":700},[189,5880,700],{"class":1092},[189,5882,5883],{"class":1651},"from the binomial, not from this run",[12,5885,5886,5887,5890],{},"The classical side is one call to ",[170,5888,5889],{},"random.choices"," with weights. The quantum side is the circuit from lesson 3. Both produce 1,000 draws at the same probability, and the file times each.",[12,5892,732,5893,737,5896,809,5898,745,5900,814,5902,5904],{},[16,5894,736],{"href":5895},"https:\u002F\u002Fqollab.xyz\u002Fu\u002Fqollab\u002Flearn-app-race",[129,5897,740],{},[129,5899,744],{},[129,5901,748],{},[129,5903,752],{},". Our run on 22 September 2026:",[181,5906,5909],{"className":5907,"code":5908,"language":778,"meta":22},[776],"classical  {'rare': 281, 'common': 719}   in 0.20 ms\nquantum    {'rare': 292, 'common': 708}   in 13.8 s\n\nthe two draws differ by 11 out of 1000\ntwo independent 1,000-shot draws land within 40 of each other 95% of the time,\nso anything up to about 40 here is the two methods agreeing.\n\nthe quantum run took about 69,044 times as long,\nalmost all of it queue and round trip rather than computation.\n",[170,5910,5908],{"__ignoreMap":22},[12,5912,5913],{},"The two columns hold the same answer. Two samples of one distribution land within about 40 of each other at this many shots, and these are 11 apart, so neither column is more correct than the other.",[116,5915],{"alt":5916,"caption":5917,"no":119,"src":5918},"A bell-shaped curve of the difference between two independent 1,000-shot draws at probability 0.3, centred on zero, with a shaded band from minus 40 to plus 40 covering 95 percent of pairs, and a marker at plus 11 for the gap in the recorded race, sitting well inside the band.","The spread of the gap between two independent 1,000-shot draws at 0.3: 95% of pairs fall inside the shaded band, and the recorded race's 11 sits well inside it.","\u002F_content\u002Fimages\u002Freal-app\u002Feleven-apart.svg",[12,5920,5921,5922,5924],{},"That 40 is the figure for ",[170,5923,2870],{},", and the listing prints it whatever probability you set. The true window is widest near 0.5, about 44, and shrinks toward zero as the probability moves toward 0 or 1.",[12,5926,5927],{},"The two timings differ by about 69,000 times, which no tuning of the circuit would change: nearly all of that time is the round trip to IonQ's cloud.",[111,5929,5931],{"id":5930},"the-quantum-column-came-from-a-simulator","The quantum column came from a simulator",[12,5933,5934],{},"You ran on a simulator. The IonQ simulator is a program on a server, so the numbers in the quantum column were produced by classical hardware doing arithmetic, with no physical measurement involved.",[12,5936,5937],{},"So the race you just ran compares one classical method against another classical method that took 69,000 times longer. On real hardware the quantum column would come from a physical process. The timing gap would grow, because a QPU has a queue in front of it, and each run would cost credits.",[111,5939,5941],{"id":5940},"a-measured-draw-has-no-seed","A measured draw has no seed",[12,5943,5944,5945,5947],{},"On hardware, the draw comes from a measurement rather than from an algorithm. ",[170,5946,5889],{}," is a deterministic function of a seed. Given that seed you can reproduce every draw it will ever make. A measured qubit has no seed.",[12,5949,5950],{},"A loot box does not need an unpredictable draw. A lottery or an encryption key does, because someone has an incentive to predict the next draw, and hardware random number generators are sold on unpredictability.",[111,5952,5954],{"id":5953},"quantum-couriers-five-races","Quantum Courier's five races",[12,5956,5957,5961],{},[16,5958,5960],{"href":5959},"\u002Fexplore\u002Fquantum-courier","Quantum Courier"," is a browser game by Dr. Siti Fariya that races classical and quantum solvers across five logistics problems and publishes which won.",[12,5963,5964],{},"Quantum Courier's published results:",[1875,5966,5967,5977],{},[1878,5968,5969],{},[1881,5970,5971,5974],{},[1884,5972,5973],{},"stage",[1884,5975,5976],{},"who won",[1890,5978,5979,5987,5995,6003,6011],{},[1881,5980,5981,5984],{},[1895,5982,5983],{},"Pizza assignment",[1895,5985,5986],{},"Classical, with the Hungarian algorithm.",[1881,5988,5989,5992],{},[1895,5990,5991],{},"Single-vehicle routing",[1895,5993,5994],{},"Tied at small sizes, classical scales better.",[1881,5996,5997,6000],{},[1895,5998,5999],{},"Multi-vehicle with time windows",[1895,6001,6002],{},"Classical, annealing beating QAOA at 25 customers.",[1881,6004,6005,6008],{},[1895,6006,6007],{},"Graph cutting (MaxCut)",[1895,6009,6010],{},"Quantum, over a random-cut baseline, per the write-up.",[1881,6012,6013,6016],{},[1895,6014,6015],{},"Combined planning",[1895,6017,6018],{},"Depends on the instance.",[12,6020,6021],{},"Siti kept the stage 3 loss in the game deliberately, having tested four QAOA variants on Forte against classical simulated annealing. The write-up explains why: MaxCut has a cost function that counts cut edges, and that lines up with what a shallow parameterized circuit can express. Vehicle routing has no such property at the scales we can run today, and it is measured against classical heuristics that are decades mature.",[98,6023,6028],{"avatar":6024,"name":6025,"role":6026,"username":6027},"\u002F_content\u002Fimages\u002Fbuilders\u002Fsiti-fariya.webp","Dr. Siti Fariya","Creator, Quantum Courier","Sitifar",[12,6029,6030],{},"Operators making real decisions need to know where quantum helps and where classical methods still win.",[111,6032,6034],{"id":6033},"qubits-error-rate-latency-and-cost-as-of-september-2026","Qubits, error rate, latency and cost, as of September 2026",[12,6036,6037],{},"For almost anything you build this year, conventional code is the right answer. That verdict is dated September 2026, and it depends on four quantities you can look up.",[12,6039,6040,6043],{},[129,6041,6042],{},"Qubit count."," The IonQ machines on this platform run 25 to 36 qubits. Your laptop solves a problem over 36 binary variables exactly by trying all 2^36 assignments, which takes about a minute.",[12,6045,6046,6049],{},[129,6047,6048],{},"Error rate."," Gates and measurements are imperfect, so a deep circuit's signal degrades as it runs. Regime Radar's own similarity score shows that degradation. Pressed at 2,048 shots on 22 September 2026, its twelve-qubit inversion test read 0.1768 on the noise-free built-in simulator and 0.0337 on the Aria 1 noise model, the same circuit both times, against an exact offline value of 0.1779.",[12,6051,6052,6055],{},[129,6053,6054],{},"Queue latency."," Your race measured 13.8 seconds against 0.20 milliseconds, on a simulator with no hardware queue in front of it.",[12,6057,6058,6061],{},[129,6059,6060],{},"Cost per run."," Simulators are free on Qollab. QPU time is metered.",[111,6063,6065],{"id":6064},"five-steps-for-the-comparison","Five steps for the comparison",[12,6067,6068,6071],{},[129,6069,6070],{},"Write the thresholds before you run anything."," Decide what the feature needs: how close the answer has to be, how long a user will wait, and what you are willing to spend per call. Write those numbers down before either implementation exists, because a threshold chosen after seeing the result can be chosen to fit it.",[12,6073,6074,6077],{},[129,6075,6076],{},"Solve it the ordinary way first."," The classical version is your baseline and often your answer. The classical version also tells you what \"correct\" looks like, which you need before you can judge the quantum one.",[12,6079,6080,6083],{},[129,6081,6082],{},"Solve it the quantum way, at the same task."," Give the quantum version the same inputs, output format and scoring function. The race listing puts both in one file so that a single function scores both.",[12,6085,6086,6089],{},[129,6087,6088],{},"Compare each result against the thresholds."," A relative comparison is not enough: \"quantum was only a little worse\" says nothing about whether you can ship it. Record whether each requirement was met or missed, and by how much. Our run would pass any reasonable accuracy threshold, since the two tallies were 11 apart, and fail any reasonable latency threshold, at 13.8 seconds against 0.20 milliseconds.",[12,6091,6092,6095],{},[129,6093,6094],{},"Write down the date and the backend."," A comparison with no date on it can mislead once qubit count, error rate, latency or cost have changed.",[789,6097,6099,6103,6142],{"check":6098},"you have two rare counts whose gap fits the 95% window for your probability, two timings that differ by orders of magnitude, and a written answer to step 6.",[111,6100,6102],{"id":6101},"assignment-race-a-probability-your-own-app-would-use","Assignment: race a probability your own app would use",[123,6104,6105,6115,6120,6123,6133,6139],{},[126,6106,732,6107,737,6111,1716,6113,1720],{},[16,6108,6109],{"href":5895},[170,6110,5135],{},[129,6112,1715],{},[129,6114,1719],{},[126,6116,3337,6117,6119],{},[170,6118,2786],{}," to a probability something you have built would use.",[126,6121,6122],{},"Predict whether the two columns will still agree, and predict which will be faster.",[126,6124,806,6125,809,6127,745,6129,814,6131,753],{},[129,6126,740],{},[129,6128,744],{},[129,6130,748],{},[129,6132,752],{},[126,6134,6135,6136,6138],{},"Write down the gap between the two ",[170,6137,3969],{}," counts and the two timings.",[126,6140,6141],{},"Decide, in one sentence, whether you would ship the quantum version of that feature.",[830,6143,6144,6149,6152],{"label":832},[12,6145,6146,6147,753],{},"The two columns agree at any probability, because both are sampling the same distribution. The window that holds 95% of the gaps depends on the probability: about 44 at 0.5, 40 at 0.3, 26 at 0.1 and 19 at 0.05, so compare your gap with the window for your own ",[170,6148,2786],{},[12,6150,6151],{},"The classical side stays in fractions of a millisecond. The quantum side stays in seconds.",[12,6153,6154],{},"The one-sentence answer is almost certainly no, because of the timing gap your own two numbers show.",[111,6156,873],{"id":872},[12,6158,6159],{},"Answer whether quantum is worth it with a race on the backend you would ship on. Write the accuracy, latency and cost the feature needs before building either version, then pass or fail both results against those thresholds, and date the verdict with its backend. As of September 2026, the classical version wins that race for almost any feature you would ship.",[12,6161,6162],{},"Lesson 6 sorts ideas by the output the application needs, before either version is built.",[884,6164,6165],{},"html pre.shiki code .sV9Aq, html code.shiki .sV9Aq{--shiki-default:#7F848E;--shiki-default-font-style:italic}html pre.shiki code .seHd6, html code.shiki .seHd6{--shiki-default:#C678DD}html pre.shiki code .sn6KH, html code.shiki .sn6KH{--shiki-default:#ABB2BF}html pre.shiki code .sjrmR, html code.shiki .sjrmR{--shiki-default:#56B6C2}html pre.shiki code .sVC51, html code.shiki .sVC51{--shiki-default:#D19A66}html pre.shiki code .sVbv2, html code.shiki .sVbv2{--shiki-default:#61AFEF}html pre.shiki code .subq3, html code.shiki .subq3{--shiki-default:#98C379}html pre.shiki code .s_ZVi, html code.shiki .s_ZVi{--shiki-default:#E06C75;--shiki-default-font-style:italic}html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}",{"title":22,"searchDepth":23,"depth":23,"links":6167},[6168,6169,6170,6171,6172,6173,6174,6175],{"id":5128,"depth":23,"text":5129},{"id":5930,"depth":23,"text":5931},{"id":5940,"depth":23,"text":5941},{"id":5953,"depth":23,"text":5954},{"id":6033,"depth":23,"text":6034},{"id":6064,"depth":23,"text":6065},{"id":6101,"depth":23,"text":6102},{"id":872,"depth":23,"text":873},[26,27,5,5107],[],{"username":7,"name":30,"role":31,"avatar":32},"Run the same thousand draws in quantum and classical code in one press, compare counts and timings, and weigh qubit count, error rate, latency and cost.",{},{"slug":6182,"title":6183,"desc":6184},"\u002Fblog\u002Flearn\u002Fusing-quantum-in-a-real-application\u002Fwhat-to-build","What to build","Start from the shape of the output your application needs.",[],{"title":5107,"description":6179},"blog\u002Flearn\u002Fusing-quantum-in-a-real-application\u002Fis-quantum-worth-it",[],"7FNyO1s3kUQE-JUjlwOMGmxdt29FEtkZFmMJScghJ_U",{"id":6191,"title":6183,"authors":6192,"body":6193,"breadcrumb":7299,"builders":7300,"byline":7301,"category":33,"categoryName":33,"challenge":33,"courseAuthor":33,"courseLead":33,"dek":6184,"description":7302,"draft":46,"extension":47,"eyebrow":33,"featured":46,"finish":7303,"fork":33,"group":33,"groupName":33,"hero":33,"heroAlt":33,"heroCta":33,"heroImage":33,"homepageFeatured":46,"kind":903,"lessonCount":557,"meta":7304,"navigation":50,"newsItems":33,"next":7305,"ogImage":33,"order":557,"outcomes":33,"path":6182,"prerequisite":33,"prerequisiteLinks":33,"publishDate":66,"readingTime":33,"related":7309,"relatedProjects":33,"section":33,"seo":7310,"stem":7311,"tags":7312,"track":73,"trackName":5,"__hash__":7313},"blog\u002Fblog\u002Flearn\u002Fusing-quantum-in-a-real-application\u002Fwhat-to-build.md",[7],{"type":9,"value":6194,"toc":7290},[6195,6198,6203,6207,6213,6228,6238,6258,6261,6281,6302,6305,6309,6312,6318,6324,6330,6336,6339,6343,6346,6349,6352,6356,6359,6362,7051,7054,7072,7093,7107,7115,7121,7124,7217,7282,7284,7287],[12,6196,6197],{},"Choose a quantum project by the output your application needs. A circuit gives your program exactly one thing, a distribution over bitstrings, and every application built on one consumes that distribution in one of five ways. An idea that fits none of the five does not need a circuit. Picking a famous algorithm first and then looking for a place to use it often turns up nothing that fits.",[116,6199],{"alt":6200,"caption":6201,"no":119,"src":6202},"A decision tree. It starts by asking what the application must consume. One answer quickly means the baseline wins and there is no circuit. Amplitudes or phases means a simulator-only path with a two-to-the-n ceiling. Samples or a distribution reaches the five shapes. Survivors then pass four gates: latency budget, reproducibility, input size, and whether a mature classical answer exists. Failing any gate returns the idea to the baseline.","The output shape gives a circuit a possible role; whether that role is worth building depends on the four gates and the classical baseline.","\u002F_content\u002Fimages\u002Freal-app\u002Fdecision-tree.svg",[111,6204,6206],{"id":6205},"five-things-you-can-do-with-a-distribution","Five things you can do with a distribution",[12,6208,6209,6212],{},[129,6210,6211],{},"Sample from it."," You want draws, and you use the spread of outcomes directly. The picker you built takes this shape, and so does most generative work, where any given draw is as valid as another.",[12,6214,6215,6217,6218,6222,6223,6227],{},[16,6216,473],{"href":472}," maps five qubits' thirty-two outcomes to a plant's traits. ",[16,6219,6221],{"href":6220},"\u002Fexplore\u002Fsuperposition-sequencer","Superposition Sequencer",", by Francisco Estivallet, turns every note in a music sequencer into a draw from a circuit you designed. ",[16,6224,6226],{"href":6225},"\u002Fexplore\u002Fquantum-patterns","Quantum Patterns",", by Peter Thomas and Paulo Itaboraí, uses partitioned quantum cellular automata to make musical material you can live-code against.",[12,6229,6230,6233,6234,6237],{},[129,6231,6232],{},"Compare two of them."," You have a live state and a reference state, and you want a similarity score between them. ",[16,6235,6236],{"href":351},"Regime Radar"," prepares a fingerprint of current market conditions, runs a stored regime backwards over it, and reads the fraction of shots landing on all zeros as the overlap: when the two states match, the shots concentrate there.",[12,6239,6240,6243,6244,6247,6248,6252,6253,6257],{},[129,6241,6242],{},"Read structure inside it."," You care less about which outcomes appear than about how the bits relate: which qubits agree, which are correlated, how that changes layer by layer. ",[16,6245,6246],{"href":360},"Butterfly Field"," turns pairwise entanglement into the threads between its butterflies. ",[16,6249,6251],{"href":6250},"\u002Fexplore\u002Fqcflows","QCFlows"," renders the same structure as a live graph. ",[16,6254,6256],{"href":6255},"\u002Fexplore\u002Fentangled-body","Entangled Body",", by Chanhyuk Park and Luke Shim, builds a point-cloud figure whose parts, per its write-up, respond to each other across distance.",[12,6259,6260],{},"Classical simulations of many entangled qubits get expensive quickly, so this shape has the least obvious classical shortcut.",[12,6262,6263,6266,6267,6270,6271,6275,6276,6280],{},[129,6264,6265],{},"Reduce it to one number."," You want a score, and the distribution is only an intermediate. ",[16,6268,6269],{"href":94},"The Quantum Systemic Oracle"," reduces an optimization result to a single risk index. ",[16,6272,6274],{"href":6273},"\u002Fexplore\u002Fqorbital","qOrbital",", by Aryan Bawa and Arnav Singh, runs a chemistry calculation and reads out a molecule's energy. ",[16,6277,6279],{"href":6278},"\u002Fexplore\u002Fquantum-market-game","Quantum Market Game",", by Aadarsh Venkat Ramanan, models two traders as two entangled qubits and reads their payoffs out of the tally.",[12,6282,6283,6286,6287,6291,6292,6296,6297,6301],{},[129,6284,6285],{},"Watch it change."," This shape reads the statevector rather than a tally, so per lesson 2 it only exists on a simulator, which is enough for a tool that shows someone what a circuit is doing. ",[16,6288,6290],{"href":6289},"\u002Fexplore\u002Fqave","QAVE",", by Inho Choi, makes an algorithm visible gate by gate. ",[16,6293,6295],{"href":6294},"\u002Fexplore\u002Fquantum-advantage-lab","Quantum Advantage Lab",", by Hossein Sadeghi, streams four algorithms' intermediate state beside their classical counterparts. ",[16,6298,6300],{"href":6299},"\u002Fexplore\u002Fquantum-canvas","Quantum Canvas",", by Shivani Mayekar, lets you drag operations into a circuit and watch the result move.",[12,6303,6304],{},"Watching it change is also the easiest of the five shapes to ship, because nothing queues.",[111,6306,6308],{"id":6307},"ideas-that-do-not-map","Ideas that do not map",[12,6310,6311],{},"Most ideas do not map, for one of four reasons.",[12,6313,6314,6317],{},[129,6315,6316],{},"It needs one correct answer, quickly."," A distribution is not an answer, and lesson 5 measured what the round trip costs. If your feature can be written with a lookup or a solver that returns in milliseconds, it should be.",[12,6319,6320,6323],{},[129,6321,6322],{},"It needs to process a lot of data."," Getting classical data into a quantum state costs roughly one operation per number, so loading a large dataset takes longer than reading it. Your laptop already solves the problems small enough to fit on today's machines, and solves them exactly.",[12,6325,6326,6329],{},[129,6327,6328],{},"It needs the state itself, at scale."," The fifth shape, watch it change, is fine for a teaching tool on a handful of qubits, but simulating n qubits takes 2ⁿ numbers, so an application built on statevectors hits a qubit limit quickly.",[12,6331,6332,6335],{},[129,6333,6334],{},"It needs to be reproducible."," Two presses of an unchanged circuit disagree, as lesson 2's two Garden runs did. If your feature must produce the same output twice, the circuit has to sit behind a cache, which is the precomputed-pool shape from lesson 4.",[12,6337,6338],{},"These four reasons do not stop you learning, prototyping or building something because it interests you; they apply to shipping a feature.",[111,6340,6342],{"id":6341},"the-shape-of-a-good-first-idea","The shape of a good first idea",[12,6344,6345],{},"The projects in this course share three things: a small circuit, a decode step doing most of the visible work, and a stated reason for the quantum part to be there.",[12,6347,6348],{},"Garden needed a supply of unpredictable, structured variation, and a pool of measurement outcomes gave it one. Butterfly Field set out to make entanglement visible. Regime Radar needed a similarity measure and chose a kernel that a circuit computes directly.",[12,6350,6351],{},"None of the three needed to beat a classical computer, which lesson 5 showed is rare today.",[111,6353,6355],{"id":6354},"from-one-probability-to-two-inputs-and-four-named-outcomes","From one probability to two inputs and four named outcomes",[12,6357,6358],{},"A probability is the smallest thing you can put through a circuit. An application has several, and it needs its results named before anything can branch on them.",[12,6360,6361],{},"The next step up has two independent inputs, one qubit for each, and four named outcomes.",[175,6363,6366],{"name":6364,"no-picker":22,"run-href":6365,"tag":985},"slice.py","\u002Fu\u002Fqollab\u002Flearn-app-slice",[181,6367,6369],{"className":183,"code":6368,"language":185,"meta":22,"style":22},"# 'backend' already exists when this runs: it is whatever you pick in the Run Experiment dialog.\nfrom math import asin, sqrt\nfrom qiskit import QuantumCircuit\nfrom qiskit.providers.jobstatus import JobStatus\nimport time\n\nshots = 1000\np_left = 0.2\np_right = 0.8\n\nNAMES = {\n    \"00\": \"neither\",\n    \"01\": \"left_only\",               #   key is c1 c0, so the RIGHT character is qubit 0\n    \"10\": \"right_only\",\n    \"11\": \"both\",\n}\n\n\ndef build_circuit(pl, pr):\n    qc = QuantumCircuit(2, 2)\n    qc.ry(2 * asin(sqrt(pl)), 0)\n    qc.ry(2 * asin(sqrt(pr)), 1)\n    qc.measure([0, 1], [0, 1])\n    return qc\n\n\ndef decode(counts, n):\n    return {NAMES[k]: v \u002F n for k, v in sorted(counts.items())}\n\n\njob = backend.run(build_circuit(p_left, p_right), shots=shots)\nwhile job.status() not in (JobStatus.DONE, JobStatus.ERROR, JobStatus.CANCELLED):\n    time.sleep(5)\n\ncounts = job.result().get_counts()\nprint(counts)\n\nfor name, share in sorted(decode(counts, shots).items()):\n    print(f\"{name:11s} {share:.3f}   {'#' * int(40 * share)}\")\nprint(f\"expected both = {p_left * p_right:.3f}, neither = {(1 - p_left) * (1 - p_right):.3f}\")\n",[170,6370,6371,6377,6389,6401,6413,6421,6427,6437,6449,6461,6467,6478,6493,6511,6525,6539,6545,6551,6557,6577,6597,6624,6651,6678,6686,6692,6698,6716,6753,6759,6765,6790,6820,6834,6840,6858,6866,6872,6897,6955,7014],{"__ignoreMap":22},[189,6372,6373,6375],{"class":191,"line":192},[189,6374,997],{"class":995,"aria-hidden":996},[189,6376,1000],{"class":318},[189,6378,6379,6381,6383,6385,6387],{"class":191,"line":23},[189,6380,997],{"class":995,"aria-hidden":996},[189,6382,1007],{"class":253},[189,6384,1010],{"class":195},[189,6386,1013],{"class":253},[189,6388,2271],{"class":195},[189,6390,6391,6393,6395,6397,6399],{"class":191,"line":250},[189,6392,997],{"class":995,"aria-hidden":996},[189,6394,1007],{"class":253},[189,6396,1025],{"class":195},[189,6398,1013],{"class":253},[189,6400,1030],{"class":195},[189,6402,6403,6405,6407,6409,6411],{"class":191,"line":281},[189,6404,997],{"class":995,"aria-hidden":996},[189,6406,1007],{"class":253},[189,6408,1053],{"class":195},[189,6410,1013],{"class":253},[189,6412,1058],{"class":195},[189,6414,6415,6417,6419],{"class":191,"line":51},[189,6416,997],{"class":995,"aria-hidden":996},[189,6418,1013],{"class":253},[189,6420,1067],{"class":195},[189,6422,6423,6425],{"class":191,"line":557},[189,6424,997],{"class":995,"aria-hidden":996},[189,6426,1074],{},[189,6428,6429,6431,6433,6435],{"class":191,"line":579},[189,6430,997],{"class":995,"aria-hidden":996},[189,6432,1081],{"class":195},[189,6434,200],{"class":199},[189,6436,1086],{"class":210},[189,6438,6439,6441,6444,6446],{"class":191,"data-cue":1089,"line":590},[189,6440,1089],{"class":1092},[189,6442,6443],{"class":195},"p_left ",[189,6445,200],{"class":199},[189,6447,6448],{"class":210}," 0.2\n",[189,6450,6451,6453,6456,6458],{"class":191,"data-cue":292,"line":595},[189,6452,292],{"class":1092},[189,6454,6455],{"class":195},"p_right ",[189,6457,200],{"class":199},[189,6459,6460],{"class":210}," 0.8\n",[189,6462,6463,6465],{"class":191,"line":601},[189,6464,997],{"class":995,"aria-hidden":996},[189,6466,1074],{},[189,6468,6469,6471,6474,6476],{"class":191,"data-cue":1241,"line":618},[189,6470,1241],{"class":1092},[189,6472,6473],{"class":210},"NAMES",[189,6475,3672],{"class":199},[189,6477,4052],{"class":195},[189,6479,6480,6482,6485,6487,6490],{"class":191,"line":665},[189,6481,997],{"class":995,"aria-hidden":996},[189,6483,6484],{"class":1314},"    \"00\"",[189,6486,3129],{"class":195},[189,6488,6489],{"class":1314},"\"neither\"",[189,6491,6492],{"class":195},",\n",[189,6494,6495,6497,6500,6502,6505,6508],{"class":191,"line":676},[189,6496,997],{"class":995,"aria-hidden":996},[189,6498,6499],{"class":1314},"    \"01\"",[189,6501,3129],{"class":195},[189,6503,6504],{"class":1314},"\"left_only\"",[189,6506,6507],{"class":195},",               ",[189,6509,6510],{"class":318},"#   key is c1 c0, so the RIGHT character is qubit 0\n",[189,6512,6513,6515,6518,6520,6523],{"class":191,"line":681},[189,6514,997],{"class":995,"aria-hidden":996},[189,6516,6517],{"class":1314},"    \"10\"",[189,6519,3129],{"class":195},[189,6521,6522],{"class":1314},"\"right_only\"",[189,6524,6492],{"class":195},[189,6526,6527,6529,6532,6534,6537],{"class":191,"line":687},[189,6528,997],{"class":995,"aria-hidden":996},[189,6530,6531],{"class":1314},"    \"11\"",[189,6533,3129],{"class":195},[189,6535,6536],{"class":1314},"\"both\"",[189,6538,6492],{"class":195},[189,6540,6541,6543],{"class":191,"line":705},[189,6542,997],{"class":995,"aria-hidden":996},[189,6544,3180],{"class":195},[189,6546,6547,6549],{"class":191,"line":1195},[189,6548,997],{"class":995,"aria-hidden":996},[189,6550,1074],{},[189,6552,6553,6555],{"class":191,"line":1216},[189,6554,997],{"class":995,"aria-hidden":996},[189,6556,1074],{},[189,6558,6559,6561,6563,6565,6567,6570,6572,6575],{"class":191,"data-cue":700,"line":1227},[189,6560,700],{"class":1092},[189,6562,1119],{"class":253},[189,6564,204],{"class":203},[189,6566,230],{"class":195},[189,6568,6569],{"class":1127},"pl",[189,6571,541],{"class":195},[189,6573,6574],{"class":1127},"pr",[189,6576,576],{"class":195},[189,6578,6579,6581,6583,6585,6587,6589,6591,6593,6595],{"class":191,"line":1234},[189,6580,997],{"class":995,"aria-hidden":996},[189,6582,1137],{"class":195},[189,6584,200],{"class":199},[189,6586,533],{"class":203},[189,6588,230],{"class":195},[189,6590,292],{"class":210},[189,6592,541],{"class":195},[189,6594,292],{"class":210},[189,6596,214],{"class":195},[189,6598,6599,6601,6603,6605,6607,6609,6611,6613,6615,6617,6620,6622],{"class":191,"line":1242},[189,6600,997],{"class":995,"aria-hidden":996},[189,6602,1158],{"class":195},[189,6604,670],{"class":203},[189,6606,230],{"class":195},[189,6608,292],{"class":210},[189,6610,659],{"class":199},[189,6612,2374],{"class":203},[189,6614,230],{"class":195},[189,6616,2379],{"class":203},[189,6618,6619],{"class":195},"(pl)), ",[189,6621,1165],{"class":210},[189,6623,214],{"class":195},[189,6625,6626,6628,6630,6632,6634,6636,6638,6640,6642,6644,6647,6649],{"class":191,"line":1272},[189,6627,997],{"class":995,"aria-hidden":996},[189,6629,1158],{"class":195},[189,6631,670],{"class":203},[189,6633,230],{"class":195},[189,6635,292],{"class":210},[189,6637,659],{"class":199},[189,6639,2374],{"class":203},[189,6641,230],{"class":195},[189,6643,2379],{"class":203},[189,6645,6646],{"class":195},"(pr)), ",[189,6648,1089],{"class":210},[189,6650,214],{"class":195},[189,6652,6653,6655,6657,6659,6661,6663,6665,6667,6670,6672,6674,6676],{"class":191,"line":1301},[189,6654,997],{"class":995,"aria-hidden":996},[189,6656,1158],{"class":195},[189,6658,1203],{"class":203},[189,6660,5273],{"class":195},[189,6662,1165],{"class":210},[189,6664,541],{"class":195},[189,6666,1089],{"class":210},[189,6668,6669],{"class":195},"], [",[189,6671,1165],{"class":210},[189,6673,541],{"class":195},[189,6675,1089],{"class":210},[189,6677,5733],{"class":195},[189,6679,6680,6682,6684],{"class":191,"line":1355},[189,6681,997],{"class":995,"aria-hidden":996},[189,6683,1221],{"class":253},[189,6685,1224],{"class":195},[189,6687,6688,6690],{"class":191,"line":1417},[189,6689,997],{"class":995,"aria-hidden":996},[189,6691,1074],{},[189,6693,6694,6696],{"class":191,"line":1424},[189,6695,997],{"class":995,"aria-hidden":996},[189,6697,1074],{},[189,6699,6700,6702,6704,6706,6708,6710,6712,6714],{"class":191,"data-cue":538,"line":1460},[189,6701,538],{"class":1092},[189,6703,1119],{"class":253},[189,6705,2466],{"class":203},[189,6707,230],{"class":195},[189,6709,1555],{"class":1127},[189,6711,541],{"class":195},[189,6713,2475],{"class":1127},[189,6715,576],{"class":195},[189,6717,6718,6720,6722,6724,6726,6729,6731,6734,6736,6739,6741,6744,6747,6750],{"class":191,"line":1497},[189,6719,997],{"class":995,"aria-hidden":996},[189,6721,1221],{"class":253},[189,6723,2510],{"class":195},[189,6725,6473],{"class":210},[189,6727,6728],{"class":195},"[k]: v ",[189,6730,1609],{"class":199},[189,6732,6733],{"class":195}," n ",[189,6735,560],{"class":253},[189,6737,6738],{"class":195}," k, v ",[189,6740,566],{"class":253},[189,6742,6743],{"class":199}," sorted",[189,6745,6746],{"class":195},"(counts.",[189,6748,6749],{"class":203},"items",[189,6751,6752],{"class":195},"())}\n",[189,6754,6755,6757],{"class":191,"line":1512},[189,6756,997],{"class":995,"aria-hidden":996},[189,6758,1074],{},[189,6760,6761,6763],{"class":191,"line":1519},[189,6762,997],{"class":995,"aria-hidden":996},[189,6764,1074],{},[189,6766,6767,6769,6771,6773,6775,6777,6779,6781,6784,6786,6788],{"class":191,"line":1539},[189,6768,997],{"class":995,"aria-hidden":996},[189,6770,219],{"class":195},[189,6772,200],{"class":199},[189,6774,224],{"class":195},[189,6776,227],{"class":203},[189,6778,230],{"class":195},[189,6780,2914],{"class":203},[189,6782,6783],{"class":195},"(p_left, p_right), ",[189,6785,240],{"class":239},[189,6787,200],{"class":199},[189,6789,1457],{"class":195},[189,6791,6792,6794,6796,6798,6800,6802,6804,6806,6808,6810,6812,6814,6816,6818],{"class":191,"line":1564},[189,6793,997],{"class":995,"aria-hidden":996},[189,6795,254],{"class":253},[189,6797,257],{"class":195},[189,6799,260],{"class":203},[189,6801,263],{"class":195},[189,6803,1473],{"class":253},[189,6805,1476],{"class":253},[189,6807,1479],{"class":195},[189,6809,275],{"class":210},[189,6811,1484],{"class":195},[189,6813,1487],{"class":210},[189,6815,1484],{"class":195},[189,6817,1492],{"class":210},[189,6819,576],{"class":195},[189,6821,6822,6824,6826,6828,6830,6832],{"class":191,"line":1591},[189,6823,997],{"class":995,"aria-hidden":996},[189,6825,284],{"class":195},[189,6827,287],{"class":203},[189,6829,230],{"class":195},[189,6831,538],{"class":210},[189,6833,214],{"class":195},[189,6835,6836,6838],{"class":191,"line":2686},[189,6837,997],{"class":995,"aria-hidden":996},[189,6839,1074],{},[189,6841,6842,6844,6846,6848,6850,6852,6854,6856],{"class":191,"line":2701},[189,6843,997],{"class":995,"aria-hidden":996},[189,6845,299],{"class":195},[189,6847,200],{"class":199},[189,6849,257],{"class":195},[189,6851,306],{"class":203},[189,6853,309],{"class":195},[189,6855,312],{"class":203},[189,6857,1536],{"class":195},[189,6859,6860,6862,6864],{"class":191,"line":2754},[189,6861,997],{"class":995,"aria-hidden":996},[189,6863,1306],{"class":199},[189,6865,2676],{"class":195},[189,6867,6868,6870],{"class":191,"line":4338},[189,6869,997],{"class":995,"aria-hidden":996},[189,6871,1074],{},[189,6873,6874,6876,6878,6881,6883,6885,6887,6889,6892,6894],{"class":191,"line":4354},[189,6875,997],{"class":995,"aria-hidden":996},[189,6877,560],{"class":253},[189,6879,6880],{"class":195}," name, share ",[189,6882,566],{"class":253},[189,6884,6743],{"class":199},[189,6886,230],{"class":195},[189,6888,2997],{"class":203},[189,6890,6891],{"class":195},"(counts, shots).",[189,6893,6749],{"class":203},[189,6895,6896],{"class":195},"()):\n",[189,6898,6899,6901,6904,6906,6908,6910,6912,6915,6918,6920,6922,6924,6926,6928,6931,6934,6936,6939,6941,6944,6946,6949,6951,6953],{"class":191,"line":5809},[189,6900,997],{"class":995,"aria-hidden":996},[189,6902,6903],{"class":199},"    print",[189,6905,230],{"class":195},[189,6907,1311],{"class":253},[189,6909,1350],{"class":1314},[189,6911,1318],{"class":210},[189,6913,6914],{"class":195},"name",[189,6916,6917],{"class":253},":11s",[189,6919,1332],{"class":210},[189,6921,2510],{"class":210},[189,6923,3988],{"class":195},[189,6925,1387],{"class":253},[189,6927,1332],{"class":210},[189,6929,6930],{"class":210},"   {",[189,6932,6933],{"class":1314},"'#'",[189,6935,659],{"class":199},[189,6937,6938],{"class":199}," int",[189,6940,230],{"class":195},[189,6942,6943],{"class":210},"40",[189,6945,659],{"class":199},[189,6947,6948],{"class":195}," share)",[189,6950,1332],{"class":210},[189,6952,1350],{"class":1314},[189,6954,214],{"class":195},[189,6956,6957,6959,6961,6963,6965,6968,6970,6972,6974,6977,6979,6981,6984,6986,6988,6990,6992,6995,6997,6999,7001,7003,7006,7008,7010,7012],{"class":191,"line":5842},[189,6958,997],{"class":995,"aria-hidden":996},[189,6960,1306],{"class":199},[189,6962,230],{"class":195},[189,6964,1311],{"class":253},[189,6966,6967],{"class":1314},"\"expected both = ",[189,6969,1318],{"class":210},[189,6971,6443],{"class":195},[189,6973,629],{"class":199},[189,6975,6976],{"class":195}," p_right",[189,6978,1387],{"class":253},[189,6980,1332],{"class":210},[189,6982,6983],{"class":1314},", neither = ",[189,6985,1318],{"class":210},[189,6987,230],{"class":195},[189,6989,1089],{"class":210},[189,6991,3981],{"class":199},[189,6993,6994],{"class":195}," p_left) ",[189,6996,629],{"class":199},[189,6998,654],{"class":195},[189,7000,1089],{"class":210},[189,7002,3981],{"class":199},[189,7004,7005],{"class":195}," p_right)",[189,7007,1387],{"class":253},[189,7009,1332],{"class":210},[189,7011,1350],{"class":1314},[189,7013,214],{"class":195},[123,7015,7016,7023,7030,7037,7044],{"class":1644},[126,7017,7018,7020],{"data-cue":1089},[189,7019,1089],{"class":1092},[189,7021,7022],{"class":1651},"one input per qubit: how often the left step fires",[126,7024,7025,7027],{"data-cue":292},[189,7026,292],{"class":1092},[189,7028,7029],{"class":1651},"and the right one",[126,7031,7032,7034],{"data-cue":1241},[189,7033,1241],{"class":1092},[189,7035,7036],{"class":1651},"the result schema the rest of the app codes against",[126,7038,7039,7041],{"data-cue":700},[189,7040,700],{"class":1092},[189,7042,7043],{"class":1651},"two app values in, one two-qubit circuit out",[126,7045,7046,7048],{"data-cue":538},[189,7047,538],{"class":1092},[189,7049,7050],{"class":1651},"counts in, named results out",[12,7052,7053],{},"Three things changed from the picker, and all three are the parts you would write for any application.",[12,7055,7056,4871,7059,1791,7062,7065,7066,7068,7069,7071],{},[129,7057,7058],{},"Two inputs, two qubits.",[170,7060,7061],{},"p_left",[170,7063,7064],{},"p_right"," each get their own ",[170,7067,670],{},". Nothing entangles the two qubits, so the four outcomes are the two probabilities multiplied out, and calling ",[170,7070,5889],{}," twice would do the same job.",[12,7073,7074,4871,7077,7079,7080,541,7083,541,7086,1791,7089,7092],{},[129,7075,7076],{},"A result schema.",[170,7078,6473],{}," turns bitstrings into ",[170,7081,7082],{},"neither",[170,7084,7085],{},"left_only",[170,7087,7088],{},"right_only",[170,7090,7091],{},"both",". The rest of the program branches on those words and never sees a bitstring. Adding a third input later means changing this table.",[12,7094,7095,7098,7099,7102,7103,7106],{},[129,7096,7097],{},"The bit order, stated once."," A counts key reads ",[170,7100,7101],{},"c1 c0",", so the rightmost character is qubit 0, and ",[170,7104,7105],{},"01"," means the left step fired and the right one did not. Get this backwards and your application does the opposite of what you meant, silently, because both keys are valid.",[12,7108,1683,7109,1791,7112,1687],{},[170,7110,7111],{},"p_left = 0.2",[170,7113,7114],{},"p_right = 0.8",[181,7116,7119],{"className":7117,"code":7118,"language":778,"meta":22},[776],"{'00': 172, '01': 56, '10': 621, '11': 151}\nboth        0.151   ######\nleft_only   0.056   ##\nneither     0.172   ######\nright_only  0.621   ########################\nexpected both = 0.160, neither = 0.160\n",[170,7120,7118],{"__ignoreMap":22},[12,7122,7123],{},"The ideal shares are 0.160, 0.040, 0.640 and 0.160. Every measured share sits near its ideal.",[789,7125,7127,7131,7176],{"check":7126},"your console prints your own four names, and each share sits near the number you worked out for it.",[111,7128,7130],{"id":7129},"assignment-name-the-results-your-own-idea-needs","Assignment: name the results your own idea needs",[123,7132,7133,7144,7150,7157,7160,7163,7173],{},[126,7134,732,7135,737,7140,1716,7142,1720],{},[16,7136,7138],{"href":7137},"https:\u002F\u002Fqollab.xyz\u002Fu\u002Fqollab\u002Flearn-app-slice",[170,7139,6365],{},[129,7141,1715],{},[129,7143,1719],{},[126,7145,7146,7147,7149],{},"In your fork, rename the four entries in ",[170,7148,6473],{}," to the four outcomes your own idea would branch on.",[126,7151,4948,7152,1791,7154,7156],{},[170,7153,7061],{},[170,7155,7064],{}," to the two probabilities your idea needs.",[126,7158,7159],{},"Work out the ideal share of each of your four outcomes, by multiplying the two probabilities out.",[126,7161,7162],{},"Predict which of your four will be the noisiest, and say why.",[126,7164,806,7165,809,7167,745,7169,814,7171,753],{},[129,7166,740],{},[129,7168,744],{},[129,7170,748],{},[129,7172,752],{},[126,7174,7175],{},"Compare the four printed shares against the four you worked out.",[830,7177,7178,7202,7211],{"label":832},[12,7179,7180,7181,541,7184,541,7187,1791,7190,7193,7194,541,7196,541,7198,541,7200,753],{},"The four ideal shares are ",[170,7182,7183],{},"(1-pl)(1-pr)",[170,7185,7186],{},"pl(1-pr)",[170,7188,7189],{},"(1-pl)pr",[170,7191,7192],{},"pl·pr",", in the order ",[170,7195,7082],{},[170,7197,7085],{},[170,7199,7088],{},[170,7201,7091],{},[12,7203,7204,7205,7207,7208,7210],{},"The noisiest in relative terms is the smallest, because the uncertainty on a share is roughly the square root of its count divided by the shots. Ours was ",[170,7206,7085],{},": 56 shots, an ideal 40, and a measured 0.056 against 0.040. The same absolute error on ",[170,7209,7088],{},", which had 621 shots, is small by comparison.",[12,7212,7213,7214,7216],{},"If your four names do not cover every outcome, the listing raises a ",[170,7215,3091],{}," on the first key you left out, so the mistake shows up in development instead of in production.",[789,7218,7220,7224,7227,7264],{"check":7219},"you have a tally from your own probability, and three written lines naming an idea, its shape, and its circuit, or a written reason it does not map.",[111,7221,7223],{"id":7222},"assignment-encode-one-probability-from-your-own-idea","Assignment: encode one probability from your own idea",[12,7225,7226],{},"Put one probability from your own idea through the boundary you built in lesson 3.",[123,7228,7229,7232,7235,7246,7251,7261],{},[126,7230,7231],{},"Write down an idea in one sentence, and say which of the five shapes it needs.",[126,7233,7234],{},"Find the single probability in it: a drop rate, a chance a note plays, how often a branch is taken, or how likely one of two states is.",[126,7236,7237,7238,7242,7243,7245],{},"Open your fork of ",[16,7239,7240],{"href":2877},[170,7241,2247],{}," from lesson 3. If the ",[170,7244,3343],{}," edit is still there, leave it.",[126,7247,4948,7248,7250],{},[170,7249,2786],{}," to your probability, and predict the tally you expect from 1,000 shots.",[126,7252,806,7253,809,7255,745,7257,814,7259,753],{},[129,7254,740],{},[129,7256,744],{},[129,7258,748],{},[129,7260,752],{},[126,7262,7263],{},"Write down three lines: the idea, its output shape, and the circuit that would sit inside it. If step 1 showed the idea fits none of the five shapes, write down which of the four reasons it hit instead.",[830,7265,7266,7276,7279],{"label":832},[12,7267,7268,7269,7272,7273,7275],{},"A worked example: \"A rhythm generator where each step has a chance of firing.\" The rhythm generator needs shape one, sample from it. The probability is the chance a step fires, say 0.35. Setting ",[170,7270,7271],{},"p_rare = 0.35"," should give about 350 ones in 1,000 shots, inside a 95% window of roughly 320 to 380. The circuit inside the generator is one ",[170,7274,670],{}," per step, or one circuit sampled repeatedly.",[12,7277,7278],{},"A worked rejection: \"A scheduler that picks the cheapest delivery route.\" The scheduler is shape four, reduce to one number, and it hits the first reason. Classical routing heuristics are decades mature, and Quantum Courier's published stage 3 result is one measurement of that: classical annealing beat four QAOA variants at 25 customers.",[12,7280,7281],{},"Your tally will not equal your prediction exactly, for the reason lesson 2 gave.",[111,7283,873],{"id":872},[12,7285,7286],{},"Start from what your application consumes and choose the algorithm last. Match the output to one of the five things a distribution can do, then check the idea against the four reasons ideas fail to map.",[884,7288,7289],{},"html pre.shiki code .sV9Aq, html code.shiki .sV9Aq{--shiki-default:#7F848E;--shiki-default-font-style:italic}html pre.shiki code .seHd6, html code.shiki .seHd6{--shiki-default:#C678DD}html pre.shiki code .sn6KH, html code.shiki .sn6KH{--shiki-default:#ABB2BF}html pre.shiki code .sjrmR, html code.shiki .sjrmR{--shiki-default:#56B6C2}html pre.shiki code .sVC51, html code.shiki .sVC51{--shiki-default:#D19A66}html pre.shiki code .subq3, html code.shiki .subq3{--shiki-default:#98C379}html pre.shiki code .sVbv2, html code.shiki .sVbv2{--shiki-default:#61AFEF}html pre.shiki code .sb9H8, html code.shiki .sb9H8{--shiki-default:#D19A66;--shiki-default-font-style:italic}html pre.shiki code .s_ZVi, html code.shiki .s_ZVi{--shiki-default:#E06C75;--shiki-default-font-style:italic}html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}",{"title":22,"searchDepth":23,"depth":23,"links":7291},[7292,7293,7294,7295,7296,7297,7298],{"id":6205,"depth":23,"text":6206},{"id":6307,"depth":23,"text":6308},{"id":6341,"depth":23,"text":6342},{"id":6354,"depth":23,"text":6355},{"id":7129,"depth":23,"text":7130},{"id":7222,"depth":23,"text":7223},{"id":872,"depth":23,"text":873},[26,27,5,6183],[],{"username":7,"name":30,"role":31,"avatar":32},"Work backwards from the output your application needs: match it to one of five things a distribution can do, or rule the idea out quickly.","You can put a circuit inside a program, decide whether it belongs there, and work out what to build next.",{},{"slug":7306,"title":7307,"desc":7308},"\u002Fexplore","The projects","Open or fork any project built on Qollab.",[],{"title":6183,"description":7302},"blog\u002Flearn\u002Fusing-quantum-in-a-real-application\u002Fwhat-to-build",[],"Xixeh-8DDfgwheUbxwv2vamhdA0TtKoTLaetbz8-xa8",[7315,7356,9093,10059,11098,11852,12875],{"id":7316,"title":19,"authors":7317,"body":7318,"breadcrumb":7328,"builders":7329,"byline":7330,"category":33,"categoryName":33,"challenge":33,"courseAuthor":7331,"courseLead":7336,"dek":7337,"description":7338,"draft":46,"extension":47,"eyebrow":33,"featured":50,"finish":33,"fork":33,"group":33,"groupName":33,"hero":33,"heroAlt":33,"heroCta":33,"heroImage":33,"homepageFeatured":46,"kind":48,"lessonCount":33,"meta":7339,"navigation":50,"newsItems":33,"next":33,"ogImage":33,"order":23,"outcomes":7340,"path":7347,"prerequisite":33,"prerequisiteLinks":33,"publishDate":7348,"readingTime":33,"related":7349,"relatedProjects":33,"section":33,"seo":7350,"stem":7353,"tags":7354,"track":60,"trackName":33,"__hash__":7355},"blog\u002Fblog\u002Flearn\u002Fprogramming-your-first-quantum-circuits.md",[7],{"type":9,"value":7319,"toc":7326},[7320,7323],[12,7321,7322],{},"Each lesson is built on a Qiskit listing of a few lines. You read the circuit line by line, run it, and read the tally that comes back. Then you change one thing and run the circuit again.",[12,7324,7325],{},"You need a free Qollab account; signing in with Google or GitHub creates one.",{"title":22,"searchDepth":23,"depth":23,"links":7327},[],[26,27,19],[],{"username":7,"name":30,"role":31,"avatar":32},{"name":30,"role":31,"bio":7332,"avatar":32,"links":7333},"Nico runs the builder community at Qollab and wrote this course.",[7334,7335],{"label":38,"href":39},{"label":41,"href":42},"The course has seven short Qiskit listings across six lessons, and you run each one from the Code Playground on an IonQ noise-model simulator: IonQ's simulator with an error model set to one of its machines. You start with one qubit and one gate; by the end you have run a two-qubit search algorithm and measured the noise on four IonQ noise models. Every listing is a public project you can open, run, fork and change.","Write circuits in Qiskit and run each one on the IonQ simulator from your browser.","A free six-lesson course: write quantum circuits in Qiskit and run each one on the IonQ simulator from your browser, starting with one gate and working up to a two-qubit search algorithm.",{},[7341,7342,7343,7344,7345,7346],"How a circuit is built: qubits, gates as method calls, measurement, shots","How to read a counts tally and its bars, and why 1,000 shots almost never split exactly in half","What the CNOT does, what a Bell pair is, and how Qiskit orders the bits","How rotation gates set a probability, and why a phase on its own changes no tally","How interference concentrates probability, and how Grover uses it","What a noise model is, what changes on a real quantum computer, and how to publish your circuit","\u002Fblog\u002Flearn\u002Fprogramming-your-first-quantum-circuits","2026-09-15",[],{"title":7351,"description":7352},"Programming your first quantum circuits · Free Qiskit course","Write your first quantum circuits in Qiskit and run them on the IonQ simulator from your browser. Six free lessons and seven short circuits.","blog\u002Flearn\u002Fprogramming-your-first-quantum-circuits",[],"qxQBd_I_UsSBnduqC3KhmCmdhjEaPIWTtLe6vQDqXOk",{"id":7357,"title":7358,"authors":7359,"body":7360,"breadcrumb":9071,"builders":9072,"byline":9073,"category":33,"categoryName":33,"challenge":33,"courseAuthor":33,"courseLead":33,"dek":9074,"description":9075,"draft":46,"extension":47,"eyebrow":33,"featured":46,"finish":33,"fork":33,"group":33,"groupName":33,"hero":9076,"heroAlt":33,"heroCta":33,"heroImage":33,"homepageFeatured":46,"kind":903,"lessonCount":557,"meta":9079,"navigation":50,"newsItems":33,"next":9080,"ogImage":33,"order":51,"outcomes":33,"path":9084,"prerequisite":33,"prerequisiteLinks":33,"publishDate":7348,"readingTime":9085,"related":9086,"relatedProjects":33,"section":33,"seo":9087,"stem":9090,"tags":9091,"track":60,"trackName":19,"__hash__":9092},"blog\u002Fblog\u002Flearn\u002Fprogramming-your-first-quantum-circuits\u002Finterference.md","Interference and your first algorithm",[7],{"type":9,"value":7361,"toc":9061},[7362,7369,7372,7376,7389,7392,7395,7400,7413,7430,7441,7445,7448,7552,7558,7983,7987,8014,8017,8088,8099,8198,8202,8217,8223,8236,8239,8242,8245,8252,8257,8728,8738,8743,8750,8754,8769,8777,8959,9055,9058],[12,7363,7364,7368],{},[16,7365,7367],{"href":7366},"\u002Flearn\u002Fquantum-interference","Interference"," is two paths through a circuit meeting again: where they agree they add up, where they disagree they cancel, and the tally shows which. Lesson 4 spun a fresh qubit around the measurement axis and nothing showed, because a single path has nothing to differ from.",[12,7370,7371],{},"A Hadamard on each side of the spin makes the phase show in the tally, and Grover's search, later in this lesson, uses the same effect.",[111,7373,7375],{"id":7374},"two-paths-and-whether-they-agree","Two paths, and whether they agree",[12,7377,7378,7379,7381,7382,1791,7384,7386,7387,753],{},"The first Hadamard spreads a qubit at ",[170,7380,1165],{}," over two paths, which here means the two weighted options of lesson 2, ",[170,7383,1165],{},[170,7385,1089],{},". The RZ gate turns the phase of one path by ",[170,7388,1782],{},[12,7390,7391],{},"A phase is the continuous version of the sign a weight carried in lesson 2, and turning it changes nothing a measurement can see.",[12,7393,7394],{},"The second Hadamard brings the two paths back together: paths with the same phase add up, and paths with opposite phases cancel.",[116,7396],{"alt":7397,"caption":7398,"no":22,"src":7399},"Two panels. A qubit at 0 is split by H into path 0 and path 1, a phase box sits on path 1, and a second H merges the paths. With the phase at 0 every shot reads 0; with the phase at pi every shot reads 1.","The two panels differ only in the phase. At φ = 0 the two paths add on 0 and every shot reads 0. At φ = π they cancel on 0, add on 1, and every shot reads 1. In between, the phase sets the odds and each shot is still a draw.","\u002F_content\u002Fimages\u002Ffirst-circuits\u002Ftwo-paths.svg",[12,7401,7402,7403,541,7405,541,7407,7409,7410,7412],{},"The rule is lesson 4's with the phase in place of the angle: after ",[170,7404,423],{},[170,7406,1778],{},[170,7408,423],{}," on a fresh qubit, the share of shots that read ",[170,7411,1089],{}," is sin²(φ\u002F2).",[12,7414,2986,7415,7417,7418,7420,7421,7423,7424,7420,7426,7429],{},[170,7416,1686],{}," nothing is turned and every shot reads ",[170,7419,1165],{},"; at ",[170,7422,1748],{}," every shot reads ",[170,7425,1089],{},[170,7427,7428],{},"pi \u002F 2"," it is the even split.",[7431,7432,7435],"gate",{"name":7433,"token":7434},"Hadamard, RZ, Hadamard","h · rz · h",[12,7436,7437,7438,7440],{},"Hadamard, phase rotation, Hadamard. The first H splits the qubit into two paths, RZ turns the phase of one, and the second H recombines them so they add or cancel. The share of ",[170,7439,1089],{}," after it is sin²(φ\u002F2), the RY rule with the phase in place of the angle.",[111,7442,7444],{"id":7443},"the-circuit-then-the-code","The circuit, then the code",[12,7446,7447],{},"The circuit is one qubit and three gates, with the phase at the top of the file:",[181,7449,7451],{"className":183,"code":7450,"language":185,"meta":22,"style":22},"phi = pi \u002F 2\n\nqc = QuantumCircuit(1, 1)\nqc.h(0)                       # two paths\nqc.rz(phi, 0)                 # turn one of them\nqc.h(0)                       # bring them back together\nqc.measure(0, 0)\n",[170,7452,7453,7467,7471,7489,7505,7521,7536],{"__ignoreMap":22},[189,7454,7455,7457,7459,7462,7464],{"class":191,"line":192},[189,7456,1095],{"class":195},[189,7458,200],{"class":199},[189,7460,7461],{"class":195}," pi ",[189,7463,1609],{"class":199},[189,7465,7466],{"class":210}," 2\n",[189,7468,7469],{"class":191,"line":23},[189,7470,523],{"emptyLinePlaceholder":50},[189,7472,7473,7475,7477,7479,7481,7483,7485,7487],{"class":191,"line":250},[189,7474,196],{"class":195},[189,7476,200],{"class":199},[189,7478,533],{"class":203},[189,7480,230],{"class":195},[189,7482,1089],{"class":210},[189,7484,541],{"class":195},[189,7486,1089],{"class":210},[189,7488,214],{"class":195},[189,7490,7491,7493,7495,7497,7499,7502],{"class":191,"line":281},[189,7492,2182],{"class":195},[189,7494,423],{"class":203},[189,7496,230],{"class":195},[189,7498,1165],{"class":210},[189,7500,7501],{"class":195},")                       ",[189,7503,7504],{"class":318},"# two paths\n",[189,7506,7507,7509,7511,7513,7515,7518],{"class":191,"line":51},[189,7508,2182],{"class":195},[189,7510,972],{"class":203},[189,7512,1178],{"class":195},[189,7514,1165],{"class":210},[189,7516,7517],{"class":195},")                 ",[189,7519,7520],{"class":318},"# turn one of them\n",[189,7522,7523,7525,7527,7529,7531,7533],{"class":191,"line":557},[189,7524,2182],{"class":195},[189,7526,423],{"class":203},[189,7528,230],{"class":195},[189,7530,1165],{"class":210},[189,7532,7501],{"class":195},[189,7534,7535],{"class":318},"# bring them back together\n",[189,7537,7538,7540,7542,7544,7546,7548,7550],{"class":191,"line":579},[189,7539,2182],{"class":195},[189,7541,1203],{"class":203},[189,7543,230],{"class":195},[189,7545,1165],{"class":210},[189,7547,541],{"class":195},[189,7549,1165],{"class":210},[189,7551,214],{"class":195},[12,7553,7554,7555,7557],{},"The plumbing is lesson 4's: the measured share of ",[170,7556,1089],{}," beside what the rule says.",[175,7559,7562],{"name":7560,"no-picker":22,"run-href":7561,"tag":985},"interference.py","\u002Fu\u002Fqollab\u002Flearn-interference",[181,7563,7565],{"className":183,"code":7564,"language":185,"meta":22,"style":22},"# 'backend' already exists when this runs: it is whatever you pick in the Run Experiment dialog.\nfrom math import pi, sin\nfrom qiskit import QuantumCircuit\nfrom qiskit.providers.jobstatus import JobStatus\nimport time\n\nshots = 1000\nphi = pi \u002F 2\n\nqc = QuantumCircuit(1, 1)\nqc.h(0)\nqc.rz(phi, 0)\nqc.h(0)\nqc.measure(0, 0)\nprint(qc)\n\njob = backend.run(qc, shots=shots)\nwhile job.status() not in (JobStatus.DONE, JobStatus.ERROR, JobStatus.CANCELLED):\n    time.sleep(5)\n\ncounts = job.result().get_counts()\nprint(counts)\nmeasured = counts.get(\"1\", 0) \u002F shots\nexpected = sin(phi \u002F 2) ** 2\nprint(f\"phi = {phi:.4f}   share of 1: measured {measured:.3f}   rule says {expected:.3f}\")\n",[170,7566,7567,7573,7586,7598,7610,7618,7624,7634,7648,7654,7674,7688,7702,7716,7734,7742,7748,7768,7798,7812,7818,7836,7844,7872,7897,7946],{"__ignoreMap":22},[189,7568,7569,7571],{"class":191,"line":192},[189,7570,997],{"class":995,"aria-hidden":996},[189,7572,1000],{"class":318},[189,7574,7575,7577,7579,7581,7583],{"class":191,"line":23},[189,7576,997],{"class":995,"aria-hidden":996},[189,7578,1007],{"class":253},[189,7580,1010],{"class":195},[189,7582,1013],{"class":253},[189,7584,7585],{"class":195}," pi, sin\n",[189,7587,7588,7590,7592,7594,7596],{"class":191,"line":250},[189,7589,997],{"class":995,"aria-hidden":996},[189,7591,1007],{"class":253},[189,7593,1025],{"class":195},[189,7595,1013],{"class":253},[189,7597,1030],{"class":195},[189,7599,7600,7602,7604,7606,7608],{"class":191,"line":281},[189,7601,997],{"class":995,"aria-hidden":996},[189,7603,1007],{"class":253},[189,7605,1053],{"class":195},[189,7607,1013],{"class":253},[189,7609,1058],{"class":195},[189,7611,7612,7614,7616],{"class":191,"line":51},[189,7613,997],{"class":995,"aria-hidden":996},[189,7615,1013],{"class":253},[189,7617,1067],{"class":195},[189,7619,7620,7622],{"class":191,"line":557},[189,7621,997],{"class":995,"aria-hidden":996},[189,7623,1074],{},[189,7625,7626,7628,7630,7632],{"class":191,"line":579},[189,7627,997],{"class":995,"aria-hidden":996},[189,7629,1081],{"class":195},[189,7631,200],{"class":199},[189,7633,1086],{"class":210},[189,7635,7636,7638,7640,7642,7644,7646],{"class":191,"data-cue":1089,"line":590},[189,7637,1089],{"class":1092},[189,7639,1095],{"class":195},[189,7641,200],{"class":199},[189,7643,7461],{"class":195},[189,7645,1609],{"class":199},[189,7647,7466],{"class":210},[189,7649,7650,7652],{"class":191,"line":595},[189,7651,997],{"class":995,"aria-hidden":996},[189,7653,1074],{},[189,7655,7656,7658,7660,7662,7664,7666,7668,7670,7672],{"class":191,"line":601},[189,7657,997],{"class":995,"aria-hidden":996},[189,7659,196],{"class":195},[189,7661,200],{"class":199},[189,7663,533],{"class":203},[189,7665,230],{"class":195},[189,7667,1089],{"class":210},[189,7669,541],{"class":195},[189,7671,1089],{"class":210},[189,7673,214],{"class":195},[189,7675,7676,7678,7680,7682,7684,7686],{"class":191,"data-cue":292,"line":618},[189,7677,292],{"class":1092},[189,7679,2182],{"class":195},[189,7681,423],{"class":203},[189,7683,230],{"class":195},[189,7685,1165],{"class":210},[189,7687,214],{"class":195},[189,7689,7690,7692,7694,7696,7698,7700],{"class":191,"data-cue":1241,"line":665},[189,7691,1241],{"class":1092},[189,7693,2182],{"class":195},[189,7695,972],{"class":203},[189,7697,1178],{"class":195},[189,7699,1165],{"class":210},[189,7701,214],{"class":195},[189,7703,7704,7706,7708,7710,7712,7714],{"class":191,"data-cue":700,"line":676},[189,7705,700],{"class":1092},[189,7707,2182],{"class":195},[189,7709,423],{"class":203},[189,7711,230],{"class":195},[189,7713,1165],{"class":210},[189,7715,214],{"class":195},[189,7717,7718,7720,7722,7724,7726,7728,7730,7732],{"class":191,"line":681},[189,7719,997],{"class":995,"aria-hidden":996},[189,7721,2182],{"class":195},[189,7723,1203],{"class":203},[189,7725,230],{"class":195},[189,7727,1165],{"class":210},[189,7729,541],{"class":195},[189,7731,1165],{"class":210},[189,7733,214],{"class":195},[189,7735,7736,7738,7740],{"class":191,"line":687},[189,7737,997],{"class":995,"aria-hidden":996},[189,7739,1306],{"class":199},[189,7741,2572],{"class":195},[189,7743,7744,7746],{"class":191,"line":705},[189,7745,997],{"class":995,"aria-hidden":996},[189,7747,1074],{},[189,7749,7750,7752,7754,7756,7758,7760,7762,7764,7766],{"class":191,"line":1195},[189,7751,997],{"class":995,"aria-hidden":996},[189,7753,219],{"class":195},[189,7755,200],{"class":199},[189,7757,224],{"class":195},[189,7759,227],{"class":203},[189,7761,2593],{"class":195},[189,7763,240],{"class":239},[189,7765,200],{"class":199},[189,7767,1457],{"class":195},[189,7769,7770,7772,7774,7776,7778,7780,7782,7784,7786,7788,7790,7792,7794,7796],{"class":191,"line":1216},[189,7771,997],{"class":995,"aria-hidden":996},[189,7773,254],{"class":253},[189,7775,257],{"class":195},[189,7777,260],{"class":203},[189,7779,263],{"class":195},[189,7781,1473],{"class":253},[189,7783,1476],{"class":253},[189,7785,1479],{"class":195},[189,7787,275],{"class":210},[189,7789,1484],{"class":195},[189,7791,1487],{"class":210},[189,7793,1484],{"class":195},[189,7795,1492],{"class":210},[189,7797,576],{"class":195},[189,7799,7800,7802,7804,7806,7808,7810],{"class":191,"line":1227},[189,7801,997],{"class":995,"aria-hidden":996},[189,7803,284],{"class":195},[189,7805,287],{"class":203},[189,7807,230],{"class":195},[189,7809,538],{"class":210},[189,7811,214],{"class":195},[189,7813,7814,7816],{"class":191,"line":1234},[189,7815,997],{"class":995,"aria-hidden":996},[189,7817,1074],{},[189,7819,7820,7822,7824,7826,7828,7830,7832,7834],{"class":191,"line":1242},[189,7821,997],{"class":995,"aria-hidden":996},[189,7823,299],{"class":195},[189,7825,200],{"class":199},[189,7827,257],{"class":195},[189,7829,306],{"class":203},[189,7831,309],{"class":195},[189,7833,312],{"class":203},[189,7835,1536],{"class":195},[189,7837,7838,7840,7842],{"class":191,"line":1272},[189,7839,997],{"class":995,"aria-hidden":996},[189,7841,1306],{"class":199},[189,7843,2676],{"class":195},[189,7845,7846,7848,7851,7853,7855,7857,7859,7861,7863,7865,7867,7869],{"class":191,"line":1301},[189,7847,997],{"class":995,"aria-hidden":996},[189,7849,7850],{"class":195},"measured ",[189,7852,200],{"class":199},[189,7854,1574],{"class":195},[189,7856,1577],{"class":203},[189,7858,230],{"class":195},[189,7860,2495],{"class":1314},[189,7862,541],{"class":195},[189,7864,1165],{"class":210},[189,7866,641],{"class":195},[189,7868,1609],{"class":199},[189,7870,7871],{"class":195}," shots\n",[189,7873,7874,7876,7879,7881,7884,7887,7889,7891,7893,7895],{"class":191,"data-cue":538,"line":1355},[189,7875,538],{"class":1092},[189,7877,7878],{"class":195},"expected ",[189,7880,200],{"class":199},[189,7882,7883],{"class":203}," sin",[189,7885,7886],{"class":195},"(phi ",[189,7888,1609],{"class":199},[189,7890,2369],{"class":210},[189,7892,641],{"class":195},[189,7894,1382],{"class":199},[189,7896,7466],{"class":210},[189,7898,7899,7901,7903,7905,7907,7910,7912,7914,7917,7919,7922,7924,7926,7928,7930,7933,7935,7938,7940,7942,7944],{"class":191,"line":1417},[189,7900,997],{"class":995,"aria-hidden":996},[189,7902,1306],{"class":199},[189,7904,230],{"class":195},[189,7906,1311],{"class":253},[189,7908,7909],{"class":1314},"\"phi = ",[189,7911,1318],{"class":210},[189,7913,1782],{"class":195},[189,7915,7916],{"class":253},":.4f",[189,7918,1332],{"class":210},[189,7920,7921],{"class":1314},"   share of 1: measured ",[189,7923,1318],{"class":210},[189,7925,1128],{"class":195},[189,7927,1387],{"class":253},[189,7929,1332],{"class":210},[189,7931,7932],{"class":1314},"   rule says ",[189,7934,1318],{"class":210},[189,7936,7937],{"class":195},"expected",[189,7939,1387],{"class":253},[189,7941,1332],{"class":210},[189,7943,1350],{"class":1314},[189,7945,214],{"class":195},[123,7947,7948,7955,7962,7969,7976],{"class":1644},[126,7949,7950,7952],{"data-cue":1089},[189,7951,1089],{"class":1092},[189,7953,7954],{"class":1651},"the phase RZ sets. On its own it is invisible; change it and press Run",[126,7956,7957,7959],{"data-cue":292},[189,7958,292],{"class":1092},[189,7960,7961],{"class":1651},"spread the qubit over 0 and 1, two paths",[126,7963,7964,7966],{"data-cue":1241},[189,7965,1241],{"class":1092},[189,7967,7968],{"class":1651},"turn the invisible dial on one of them",[126,7970,7971,7973],{"data-cue":700},[189,7972,700],{"class":1092},[189,7974,7975],{"class":1651},"fold the two paths back together: they add, or they cancel",[126,7977,7978,7980],{"data-cue":538},[189,7979,538],{"class":1092},[189,7981,7982],{"class":1651},"the same rule as RY, now driven by a phase",[111,7984,7986],{"id":7985},"run-the-circuit-three-times","Run the circuit, three times",[12,7988,7989,7990,7992,7993,7995,7996,737,7998,809,8000,814,8003,8005,8006,3284,8008,8010,8011,8013],{},"Predict the share of ",[170,7991,1089],{}," for ",[170,7994,7428],{}," first. Then open ",[16,7997,736],{"href":7561},[129,7999,740],{},[129,8001,8002],{},"IonQ Aria 1",[129,8004,752],{},". Then fork it, as in lesson 1, and in your fork set ",[170,8007,1782],{},[170,8009,1165],{}," and to ",[170,8012,1786],{},", one press each.",[12,8015,8016],{},"Our three presses on 15 September 2026, on the Aria 1 noise model:",[1875,8018,8019,8037],{},[1878,8020,8021],{},[1881,8022,8023,8027,8029,8034],{},[1884,8024,8025],{},[170,8026,1782],{},[1884,8028,1555],{},[1884,8030,8031,8032],{},"measured share of ",[170,8033,1089],{},[1884,8035,8036],{},"rule says",[1890,8038,8039,8055,8072],{},[1881,8040,8041,8045,8050,8053],{},[1895,8042,8043],{},[170,8044,1165],{},[1895,8046,8047],{},[170,8048,8049],{},"{'0': 1000}",[1895,8051,8052],{},"0.000",[1895,8054,8052],{},[1881,8056,8057,8061,8066,8069],{},[1895,8058,8059],{},[170,8060,7428],{},[1895,8062,8063],{},[170,8064,8065],{},"{'0': 474, '1': 526}",[1895,8067,8068],{},"0.526",[1895,8070,8071],{},"0.500",[1881,8073,8074,8078,8083,8086],{},[1895,8075,8076],{},[170,8077,1786],{},[1895,8079,8080],{},[170,8081,8082],{},"{'1': 1000}",[1895,8084,8085],{},"1.000",[1895,8087,8085],{},[12,8089,8090,8091,8093,8094,8096,8097,753],{},"In lesson 4 ",[170,8092,972],{}," changed nothing visible. Between two Hadamards the same gate moves the share from all ",[170,8095,1165],{}," to all ",[170,8098,1089],{},[789,8100,8102,8106,8132],{"check":8101},"the tally splits about half and half at phi = pi, and still does at the second phi you tried.",[111,8103,8105],{"id":8104},"assignment-take-the-second-hadamard-away","Assignment: take the second Hadamard away",[123,8107,8108,8118,8124,8127],{},[126,8109,8110,8111,8113,8114,8117],{},"Keep ",[170,8112,1748],{}," and delete the second ",[170,8115,8116],{},"qc.h(0)",". The circuit is then a Hadamard, a phase and a measurement.",[126,8119,8120,8121,8123],{},"Predict the tally: lesson 4 showed that a phase on its own leaves the share of ",[170,8122,1089],{}," where it was, so ask where the first Hadamard left it.",[126,8125,8126],{},"Press Run on Qollab and choose IonQ Aria 1.",[126,8128,3281,8129,8131],{},[170,8130,1782],{}," to anything else and press again. The rule line keeps printing sin²(φ\u002F2), which no longer applies to this circuit; the tally is the answer.",[830,8133,8134,8144,8189],{"label":832},[12,8135,8136,8137,8139,8140,8143],{},"The circuit is ",[170,8138,423],{}," then ",[170,8141,8142],{},"rz(pi)"," then measure: an even split with a phase on one path and no gate after it to turn the phase into a share.",[181,8145,8147],{"className":183,"code":8146,"language":185,"meta":22,"style":22},"qc.h(0)\nqc.rz(phi, 0)\nqc.measure(0, 0)\n",[170,8148,8149,8161,8173],{"__ignoreMap":22},[189,8150,8151,8153,8155,8157,8159],{"class":191,"line":192},[189,8152,2182],{"class":195},[189,8154,423],{"class":203},[189,8156,230],{"class":195},[189,8158,1165],{"class":210},[189,8160,214],{"class":195},[189,8162,8163,8165,8167,8169,8171],{"class":191,"line":23},[189,8164,2182],{"class":195},[189,8166,972],{"class":203},[189,8168,1178],{"class":195},[189,8170,1165],{"class":210},[189,8172,214],{"class":195},[189,8174,8175,8177,8179,8181,8183,8185,8187],{"class":191,"line":250},[189,8176,2182],{"class":195},[189,8178,1203],{"class":203},[189,8180,230],{"class":195},[189,8182,1165],{"class":210},[189,8184,541],{"class":195},[189,8186,1165],{"class":210},[189,8188,214],{"class":195},[12,8190,8191,8192,8194,8195,8197],{},"The share of ",[170,8193,1089],{}," is one half, whatever ",[170,8196,1782],{}," is, because the measurement reads the split the first Hadamard made and cannot see the phase.",[111,8199,8201],{"id":8200},"grovers-search-on-two-qubits","Grover's search on two qubits",[12,8203,8204,8205,541,8208,541,8210,1791,8213,8216],{},"The search uses two qubits. Hadamards on both spread them evenly over four candidates, ",[170,8206,8207],{},"00",[170,8209,7105],{},[170,8211,8212],{},"10",[170,8214,8215],{},"11",", a quarter each: four weights of one half, since a share is a weight's size squared.",[12,8218,8219,8220,8222],{},"An oracle is the part of a search that checks the condition and marks whatever passes it. Here the condition is fixed, \"both qubits are ",[170,8221,1089],{},"\", and the marking is a CZ gate.",[7431,8224,8227],{"name":8225,"token":8226},"The controlled-Z gate","cz",[12,8228,8229,8232,8233,8235],{},[170,8230,8231],{},"cz(a, b)",". Flips the sign of the weight on the state where both qubits are ",[170,8234,1089],{},", and does nothing anywhere else. A sign is a phase, so a CZ on its own is as invisible as an RZ: after it the tally still shows four quarters.",[12,8237,8238],{},"The diffusion step turns the mark into a change in the tally. It does the second Hadamard's job for four candidates instead of two paths: it reflects every weight about their average. Each weight moves to the same distance on the other side of the average, so the new value is twice the average minus the old one.",[12,8240,8241],{},"After the oracle the three unmarked weights are one half each and the marked one is minus one half, so the average is one quarter.",[12,8243,8244],{},"Twice one quarter is one half, and one half minus one half is zero, so each unmarked weight goes to zero. For the marked weight, one half minus a negative one half is one, so it goes to a full one; the gates below produce that reflection with a minus sign in front, which measurement cannot see. After one round of oracle and diffusion, the marked answer is the only one left.",[12,8246,8247,8248,8251],{},"The five lines below are that reflection written in gates; the diffuser section of the ",[16,8249,8250],{"href":7366},"interference"," article shows how they do it, and you can use them without re-deriving them. The oracle encodes the problem and the diffusion step never changes, so the same five lines find whatever a different oracle marks.",[116,8253],{"alt":8254,"caption":8255,"no":22,"src":8256},"Two wires, q0 and q1, both starting at 0. An H gate on each wire spreads the two qubits over four candidates. A CZ, drawn as a dot on each wire joined by a line, is the oracle that marks 11 with a sign. Then the diffusion step: H, X, CZ, X and H on both wires. Two meters drop into two bit wires. The answer is 11 on every shot.","The search circuit. The two H gates spread the two qubits over the four candidates, the CZ marks 11 with a sign, and the five gates after it are the diffusion step. On a perfect simulator both meters read 1 on every shot.","\u002F_content\u002Fimages\u002Ffirst-circuits\u002Ftwo-qubit-grover-circuit.svg",[175,8258,8261],{"name":8259,"no-picker":22,"run-href":8260,"tag":985},"grover.py","\u002Fu\u002Fqollab\u002Flearn-grover",[181,8262,8264],{"className":183,"code":8263,"language":185,"meta":22,"style":22},"# 'backend' already exists when this runs: it is whatever you pick in the Run Experiment dialog.\nfrom qiskit import QuantumCircuit\nfrom qiskit.providers.jobstatus import JobStatus\nimport time\n\nshots = 1000\n\nqc = QuantumCircuit(2, 2)\nqc.h([0, 1])\nqc.cz(0, 1)\nqc.h([0, 1])\nqc.x([0, 1])\nqc.cz(0, 1)\nqc.x([0, 1])\nqc.h([0, 1])\nqc.measure([0, 1], [0, 1])\nprint(qc)\n\njob = backend.run(qc, shots=shots)\nwhile job.status() not in (JobStatus.DONE, JobStatus.ERROR, JobStatus.CANCELLED):\n    time.sleep(5)\n\ncounts = job.result().get_counts()\nprint(counts)\nfor bits, n in sorted(counts.items()):\n    print(f\"{bits}: {n:4d}  {100 * n \u002F shots:5.1f}%  {'█' * (50 * n \u002F\u002F shots)}\")\n",[170,8265,8266,8272,8284,8296,8304,8310,8320,8326,8346,8364,8382,8400,8419,8437,8455,8473,8499,8507,8513,8533,8563,8577,8583,8601,8609,8628,8705],{"__ignoreMap":22},[189,8267,8268,8270],{"class":191,"line":192},[189,8269,997],{"class":995,"aria-hidden":996},[189,8271,1000],{"class":318},[189,8273,8274,8276,8278,8280,8282],{"class":191,"line":23},[189,8275,997],{"class":995,"aria-hidden":996},[189,8277,1007],{"class":253},[189,8279,1025],{"class":195},[189,8281,1013],{"class":253},[189,8283,1030],{"class":195},[189,8285,8286,8288,8290,8292,8294],{"class":191,"line":250},[189,8287,997],{"class":995,"aria-hidden":996},[189,8289,1007],{"class":253},[189,8291,1053],{"class":195},[189,8293,1013],{"class":253},[189,8295,1058],{"class":195},[189,8297,8298,8300,8302],{"class":191,"line":281},[189,8299,997],{"class":995,"aria-hidden":996},[189,8301,1013],{"class":253},[189,8303,1067],{"class":195},[189,8305,8306,8308],{"class":191,"line":51},[189,8307,997],{"class":995,"aria-hidden":996},[189,8309,1074],{},[189,8311,8312,8314,8316,8318],{"class":191,"line":557},[189,8313,997],{"class":995,"aria-hidden":996},[189,8315,1081],{"class":195},[189,8317,200],{"class":199},[189,8319,1086],{"class":210},[189,8321,8322,8324],{"class":191,"line":579},[189,8323,997],{"class":995,"aria-hidden":996},[189,8325,1074],{},[189,8327,8328,8330,8332,8334,8336,8338,8340,8342,8344],{"class":191,"line":590},[189,8329,997],{"class":995,"aria-hidden":996},[189,8331,196],{"class":195},[189,8333,200],{"class":199},[189,8335,533],{"class":203},[189,8337,230],{"class":195},[189,8339,292],{"class":210},[189,8341,541],{"class":195},[189,8343,292],{"class":210},[189,8345,214],{"class":195},[189,8347,8348,8350,8352,8354,8356,8358,8360,8362],{"class":191,"data-cue":1089,"line":595},[189,8349,1089],{"class":1092},[189,8351,2182],{"class":195},[189,8353,423],{"class":203},[189,8355,5273],{"class":195},[189,8357,1165],{"class":210},[189,8359,541],{"class":195},[189,8361,1089],{"class":210},[189,8363,5733],{"class":195},[189,8365,8366,8368,8370,8372,8374,8376,8378,8380],{"class":191,"data-cue":292,"line":601},[189,8367,292],{"class":1092},[189,8369,2182],{"class":195},[189,8371,8226],{"class":203},[189,8373,230],{"class":195},[189,8375,1165],{"class":210},[189,8377,541],{"class":195},[189,8379,1089],{"class":210},[189,8381,214],{"class":195},[189,8383,8384,8386,8388,8390,8392,8394,8396,8398],{"class":191,"data-cue":1241,"line":618},[189,8385,1241],{"class":1092},[189,8387,2182],{"class":195},[189,8389,423],{"class":203},[189,8391,5273],{"class":195},[189,8393,1165],{"class":210},[189,8395,541],{"class":195},[189,8397,1089],{"class":210},[189,8399,5733],{"class":195},[189,8401,8402,8404,8406,8409,8411,8413,8415,8417],{"class":191,"line":665},[189,8403,997],{"class":995,"aria-hidden":996},[189,8405,2182],{"class":195},[189,8407,8408],{"class":203},"x",[189,8410,5273],{"class":195},[189,8412,1165],{"class":210},[189,8414,541],{"class":195},[189,8416,1089],{"class":210},[189,8418,5733],{"class":195},[189,8420,8421,8423,8425,8427,8429,8431,8433,8435],{"class":191,"line":676},[189,8422,997],{"class":995,"aria-hidden":996},[189,8424,2182],{"class":195},[189,8426,8226],{"class":203},[189,8428,230],{"class":195},[189,8430,1165],{"class":210},[189,8432,541],{"class":195},[189,8434,1089],{"class":210},[189,8436,214],{"class":195},[189,8438,8439,8441,8443,8445,8447,8449,8451,8453],{"class":191,"line":681},[189,8440,997],{"class":995,"aria-hidden":996},[189,8442,2182],{"class":195},[189,8444,8408],{"class":203},[189,8446,5273],{"class":195},[189,8448,1165],{"class":210},[189,8450,541],{"class":195},[189,8452,1089],{"class":210},[189,8454,5733],{"class":195},[189,8456,8457,8459,8461,8463,8465,8467,8469,8471],{"class":191,"line":687},[189,8458,997],{"class":995,"aria-hidden":996},[189,8460,2182],{"class":195},[189,8462,423],{"class":203},[189,8464,5273],{"class":195},[189,8466,1165],{"class":210},[189,8468,541],{"class":195},[189,8470,1089],{"class":210},[189,8472,5733],{"class":195},[189,8474,8475,8477,8479,8481,8483,8485,8487,8489,8491,8493,8495,8497],{"class":191,"line":705},[189,8476,997],{"class":995,"aria-hidden":996},[189,8478,2182],{"class":195},[189,8480,1203],{"class":203},[189,8482,5273],{"class":195},[189,8484,1165],{"class":210},[189,8486,541],{"class":195},[189,8488,1089],{"class":210},[189,8490,6669],{"class":195},[189,8492,1165],{"class":210},[189,8494,541],{"class":195},[189,8496,1089],{"class":210},[189,8498,5733],{"class":195},[189,8500,8501,8503,8505],{"class":191,"line":1195},[189,8502,997],{"class":995,"aria-hidden":996},[189,8504,1306],{"class":199},[189,8506,2572],{"class":195},[189,8508,8509,8511],{"class":191,"line":1216},[189,8510,997],{"class":995,"aria-hidden":996},[189,8512,1074],{},[189,8514,8515,8517,8519,8521,8523,8525,8527,8529,8531],{"class":191,"line":1227},[189,8516,997],{"class":995,"aria-hidden":996},[189,8518,219],{"class":195},[189,8520,200],{"class":199},[189,8522,224],{"class":195},[189,8524,227],{"class":203},[189,8526,2593],{"class":195},[189,8528,240],{"class":239},[189,8530,200],{"class":199},[189,8532,1457],{"class":195},[189,8534,8535,8537,8539,8541,8543,8545,8547,8549,8551,8553,8555,8557,8559,8561],{"class":191,"line":1234},[189,8536,997],{"class":995,"aria-hidden":996},[189,8538,254],{"class":253},[189,8540,257],{"class":195},[189,8542,260],{"class":203},[189,8544,263],{"class":195},[189,8546,1473],{"class":253},[189,8548,1476],{"class":253},[189,8550,1479],{"class":195},[189,8552,275],{"class":210},[189,8554,1484],{"class":195},[189,8556,1487],{"class":210},[189,8558,1484],{"class":195},[189,8560,1492],{"class":210},[189,8562,576],{"class":195},[189,8564,8565,8567,8569,8571,8573,8575],{"class":191,"line":1242},[189,8566,997],{"class":995,"aria-hidden":996},[189,8568,284],{"class":195},[189,8570,287],{"class":203},[189,8572,230],{"class":195},[189,8574,538],{"class":210},[189,8576,214],{"class":195},[189,8578,8579,8581],{"class":191,"line":1272},[189,8580,997],{"class":995,"aria-hidden":996},[189,8582,1074],{},[189,8584,8585,8587,8589,8591,8593,8595,8597,8599],{"class":191,"line":1301},[189,8586,997],{"class":995,"aria-hidden":996},[189,8588,299],{"class":195},[189,8590,200],{"class":199},[189,8592,257],{"class":195},[189,8594,306],{"class":203},[189,8596,309],{"class":195},[189,8598,312],{"class":203},[189,8600,1536],{"class":195},[189,8602,8603,8605,8607],{"class":191,"line":1355},[189,8604,997],{"class":995,"aria-hidden":996},[189,8606,1306],{"class":199},[189,8608,2676],{"class":195},[189,8610,8611,8613,8615,8618,8620,8622,8624,8626],{"class":191,"line":1417},[189,8612,997],{"class":995,"aria-hidden":996},[189,8614,560],{"class":253},[189,8616,8617],{"class":195}," bits, n ",[189,8619,566],{"class":253},[189,8621,6743],{"class":199},[189,8623,6746],{"class":195},[189,8625,6749],{"class":203},[189,8627,6896],{"class":195},[189,8629,8630,8632,8634,8636,8638,8640,8642,8645,8647,8649,8651,8653,8656,8658,8661,8663,8665,8667,8669,8672,8674,8677,8679,8682,8684,8686,8689,8691,8693,8696,8699,8701,8703],{"class":191,"line":1424},[189,8631,997],{"class":995,"aria-hidden":996},[189,8633,6903],{"class":199},[189,8635,230],{"class":195},[189,8637,1311],{"class":253},[189,8639,1350],{"class":1314},[189,8641,1318],{"class":210},[189,8643,8644],{"class":195},"bits",[189,8646,1332],{"class":210},[189,8648,3129],{"class":1314},[189,8650,1318],{"class":210},[189,8652,2475],{"class":195},[189,8654,8655],{"class":253},":4d",[189,8657,1332],{"class":210},[189,8659,8660],{"class":210},"  {100",[189,8662,659],{"class":199},[189,8664,6733],{"class":195},[189,8666,1609],{"class":199},[189,8668,1612],{"class":195},[189,8670,8671],{"class":253},":5.1f",[189,8673,1332],{"class":210},[189,8675,8676],{"class":1314},"%  ",[189,8678,1318],{"class":210},[189,8680,8681],{"class":1314},"'█'",[189,8683,659],{"class":199},[189,8685,654],{"class":195},[189,8687,8688],{"class":210},"50",[189,8690,659],{"class":199},[189,8692,6733],{"class":195},[189,8694,8695],{"class":199},"\u002F\u002F",[189,8697,8698],{"class":195}," shots)",[189,8700,1332],{"class":210},[189,8702,1350],{"class":1314},[189,8704,214],{"class":195},[123,8706,8707,8714,8721],{"class":1644},[126,8708,8709,8711],{"data-cue":1089},[189,8710,1089],{"class":1092},[189,8712,8713],{"class":1651},"all four answers at once, a quarter each",[126,8715,8716,8718],{"data-cue":292},[189,8717,292],{"class":1092},[189,8719,8720],{"class":1651},"the oracle: flip the sign of 11 and nothing else. Invisible on its own",[126,8722,8723,8725],{"data-cue":1241},[189,8724,1241],{"class":1092},[189,8726,8727],{"class":1651},"the diffusion step, five lines: it turns that hidden sign into probability",[12,8729,8730,8731,8734,8735,8737],{},"Predict the tally, then open ",[16,8732,8733],{"href":8260},"the search project"," and run it on ",[129,8736,8002],{},". Fork the search project too; the last two assignments edit it.",[116,8739],{"alt":8740,"caption":8741,"no":22,"src":8742},"The run console after the Grover search: the counts dict {'11': 1000} and one full-length bar at 11","In the text drawing, the first pair of H gates spreads the two qubits over the four candidates and the CZ after them is the oracle; the block after that is the diffusion step. On a perfect simulator every shot reads 11; on this press the noise model put no shots elsewhere either.","\u002F_content\u002Fimages\u002Ffirst-circuits\u002F05-grover.webp",[12,8744,8745,8746,8749],{},"Our press on 15 September 2026, on the Aria 1 noise model, came back ",[170,8747,8748],{},"{'11': 1000}",": the marked answer on all 1,000 shots. The noise model can put a few shots elsewhere on another press; the ideal is all 1,000.",[111,8751,8753],{"id":8752},"changing-the-oracle","Changing the oracle",[12,8755,8756,8757,8759,8760,8762,8763,8765,8766,8768],{},"The CZ marks ",[170,8758,8215],{},". To mark a different string, surround it with X gates on the qubits that should read ",[170,8761,1165],{}," in that string. An X before the CZ turns that qubit's ",[170,8764,1165],{}," into a ",[170,8767,1089],{}," for the CZ to see, and an X after it turns it back. The diffusion step stays exactly as it is.",[12,8770,8771,8772,8776],{},"With exactly four candidates one round lands the marked answer on 100%. With more candidates it takes more rounds: the count grows with the square root of their number, about 0.8 times that root, and Grover's speed-up comes from that square root. ",[16,8773,8775],{"href":8774},"\u002Fu\u002Fqollab\u002Fgrovers-search","Grover's search on Qollab"," runs it on eight candidates, where two rounds are needed.",[789,8778,8780,8784,8807],{"check":8779},"the tally shows 10 on almost every shot.",[111,8781,8783],{"id":8782},"assignment-mark-a-different-answer","Assignment: mark a different answer",[123,8785,8786,8795,8802,8805],{},[126,8787,8788,8789,8791,8792,8794],{},"In your fork of the search, work out which qubit reads ",[170,8790,1165],{}," in the string ",[170,8793,8212],{},". Remember which character is qubit 0.",[126,8796,8797,8798,8801],{},"Put an X gate on that qubit immediately before the first ",[170,8799,8800],{},"qc.cz(0, 1)"," and another immediately after it, as the section above describes. Do not touch the diffusion step.",[126,8803,8804],{},"Predict the tally.",[126,8806,8126],{},[830,8808,8809,8950],{"label":832},[181,8810,8812],{"className":183,"code":8811,"language":185,"meta":22,"style":22},"qc.h([0, 1])\nqc.x(0)\nqc.cz(0, 1)\nqc.x(0)\nqc.h([0, 1])\nqc.x([0, 1])\nqc.cz(0, 1)\nqc.x([0, 1])\nqc.h([0, 1])\n",[170,8813,8814,8830,8842,8858,8870,8886,8902,8918,8934],{"__ignoreMap":22},[189,8815,8816,8818,8820,8822,8824,8826,8828],{"class":191,"line":192},[189,8817,2182],{"class":195},[189,8819,423],{"class":203},[189,8821,5273],{"class":195},[189,8823,1165],{"class":210},[189,8825,541],{"class":195},[189,8827,1089],{"class":210},[189,8829,5733],{"class":195},[189,8831,8832,8834,8836,8838,8840],{"class":191,"line":23},[189,8833,2182],{"class":195},[189,8835,8408],{"class":203},[189,8837,230],{"class":195},[189,8839,1165],{"class":210},[189,8841,214],{"class":195},[189,8843,8844,8846,8848,8850,8852,8854,8856],{"class":191,"line":250},[189,8845,2182],{"class":195},[189,8847,8226],{"class":203},[189,8849,230],{"class":195},[189,8851,1165],{"class":210},[189,8853,541],{"class":195},[189,8855,1089],{"class":210},[189,8857,214],{"class":195},[189,8859,8860,8862,8864,8866,8868],{"class":191,"line":281},[189,8861,2182],{"class":195},[189,8863,8408],{"class":203},[189,8865,230],{"class":195},[189,8867,1165],{"class":210},[189,8869,214],{"class":195},[189,8871,8872,8874,8876,8878,8880,8882,8884],{"class":191,"line":51},[189,8873,2182],{"class":195},[189,8875,423],{"class":203},[189,8877,5273],{"class":195},[189,8879,1165],{"class":210},[189,8881,541],{"class":195},[189,8883,1089],{"class":210},[189,8885,5733],{"class":195},[189,8887,8888,8890,8892,8894,8896,8898,8900],{"class":191,"line":557},[189,8889,2182],{"class":195},[189,8891,8408],{"class":203},[189,8893,5273],{"class":195},[189,8895,1165],{"class":210},[189,8897,541],{"class":195},[189,8899,1089],{"class":210},[189,8901,5733],{"class":195},[189,8903,8904,8906,8908,8910,8912,8914,8916],{"class":191,"line":579},[189,8905,2182],{"class":195},[189,8907,8226],{"class":203},[189,8909,230],{"class":195},[189,8911,1165],{"class":210},[189,8913,541],{"class":195},[189,8915,1089],{"class":210},[189,8917,214],{"class":195},[189,8919,8920,8922,8924,8926,8928,8930,8932],{"class":191,"line":590},[189,8921,2182],{"class":195},[189,8923,8408],{"class":203},[189,8925,5273],{"class":195},[189,8927,1165],{"class":210},[189,8929,541],{"class":195},[189,8931,1089],{"class":210},[189,8933,5733],{"class":195},[189,8935,8936,8938,8940,8942,8944,8946,8948],{"class":191,"line":595},[189,8937,2182],{"class":195},[189,8939,423],{"class":203},[189,8941,5273],{"class":195},[189,8943,1165],{"class":210},[189,8945,541],{"class":195},[189,8947,1089],{"class":210},[189,8949,5733],{"class":195},[12,8951,8952,8953,8955,8956,8958],{},"The oracle now marks ",[170,8954,8212],{},", and the diffusion step finds it: ",[170,8957,8212],{}," on every shot, apart from the tail.",[789,8960,8962,8966,8986],{"check":8961},"the tally shows all four strings at about a quarter each.",[111,8963,8965],{"id":8964},"assignment-search-without-the-diffusion-step","Assignment: search without the diffusion step",[123,8967,8968,8974,8981,8984],{},[126,8969,8970,8971,8973],{},"Put the oracle back to ",[170,8972,8215],{}," by removing the two X lines you added around the first CZ.",[126,8975,8976,8977,8980],{},"Delete the five diffusion lines, the block from the second ",[170,8978,8979],{},"qc.h([0, 1])"," down to the last one, so only the opening Hadamards, the CZ and the measurements remain.",[126,8982,8983],{},"Predict the tally: after the oracle the mark is a sign, and a sign is a phase, so ask what a tally looks like when no gate after the phase turns it into a share.",[126,8985,8126],{},[830,8987,8988,8994],{"label":832},[12,8989,8990,8991,8993],{},"All four strings come up, a quarter each, apart from the tail. The oracle marked ",[170,8992,8215],{},", and without the diffusion step the mark stays invisible.",[181,8995,8997],{"className":183,"code":8996,"language":185,"meta":22,"style":22},"qc.h([0, 1])\nqc.cz(0, 1)\nqc.measure([0, 1], [0, 1])\n",[170,8998,8999,9015,9031],{"__ignoreMap":22},[189,9000,9001,9003,9005,9007,9009,9011,9013],{"class":191,"line":192},[189,9002,2182],{"class":195},[189,9004,423],{"class":203},[189,9006,5273],{"class":195},[189,9008,1165],{"class":210},[189,9010,541],{"class":195},[189,9012,1089],{"class":210},[189,9014,5733],{"class":195},[189,9016,9017,9019,9021,9023,9025,9027,9029],{"class":191,"line":23},[189,9018,2182],{"class":195},[189,9020,8226],{"class":203},[189,9022,230],{"class":195},[189,9024,1165],{"class":210},[189,9026,541],{"class":195},[189,9028,1089],{"class":210},[189,9030,214],{"class":195},[189,9032,9033,9035,9037,9039,9041,9043,9045,9047,9049,9051,9053],{"class":191,"line":250},[189,9034,2182],{"class":195},[189,9036,1203],{"class":203},[189,9038,5273],{"class":195},[189,9040,1165],{"class":210},[189,9042,541],{"class":195},[189,9044,1089],{"class":210},[189,9046,6669],{"class":195},[189,9048,1165],{"class":210},[189,9050,541],{"class":195},[189,9052,1089],{"class":210},[189,9054,5733],{"class":195},[12,9056,9057],{},"Some presses in this course came back with a small tail of wrong answers. Lesson 6 measures that tail on the noise models of four IonQ machines, then looks at the real machines in the same dialog.",[884,9059,9060],{},"html pre.shiki code .sn6KH, html code.shiki .sn6KH{--shiki-default:#ABB2BF}html pre.shiki code .sjrmR, html code.shiki .sjrmR{--shiki-default:#56B6C2}html pre.shiki code .sVC51, html code.shiki .sVC51{--shiki-default:#D19A66}html pre.shiki code .sVbv2, html code.shiki .sVbv2{--shiki-default:#61AFEF}html pre.shiki code .sV9Aq, html code.shiki .sV9Aq{--shiki-default:#7F848E;--shiki-default-font-style:italic}html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html pre.shiki code .seHd6, html code.shiki .seHd6{--shiki-default:#C678DD}html pre.shiki code .s_ZVi, html code.shiki .s_ZVi{--shiki-default:#E06C75;--shiki-default-font-style:italic}html pre.shiki code .subq3, html code.shiki .subq3{--shiki-default:#98C379}",{"title":22,"searchDepth":23,"depth":23,"links":9062},[9063,9064,9065,9066,9067,9068,9069,9070],{"id":7374,"depth":23,"text":7375},{"id":7443,"depth":23,"text":7444},{"id":7985,"depth":23,"text":7986},{"id":8104,"depth":23,"text":8105},{"id":8200,"depth":23,"text":8201},{"id":8752,"depth":23,"text":8753},{"id":8782,"depth":23,"text":8783},{"id":8964,"depth":23,"text":8965},[26,27,19,7358],[],{"username":7,"name":30,"role":31,"avatar":32},"Make a hidden phase visible, then run a two-qubit Grover search.","Interference turns a hidden phase into a readable share when two Hadamards surround it. On two qubits, the same step finds a marked answer on every noise-free shot.",{"image":9077,"alt":9078},"\u002F_content\u002Fimages\u002Ffirst-circuits\u002F05-circuit-panel.webp","The Playground's Circuit panel: qubit q0 runs through H, then Rz(0.5π), then H, into a measurement.",{},{"slug":9081,"title":9082,"desc":9083},"\u002Fblog\u002Flearn\u002Fprogramming-your-first-quantum-circuits\u002Fnoise-and-the-real-machine","6 · Noise, and the real machine","The same Bell pair on four IonQ noise models, what changes on a real quantum computer, and how to publish your circuit as a public project.","\u002Fblog\u002Flearn\u002Fprogramming-your-first-quantum-circuits\u002Finterference","11 min read",[],{"title":9088,"description":9089},"Interference and Grover · Programming your first quantum circuits","See quantum interference in three lines of Qiskit, then run a two-qubit Grover search on the IonQ simulator and read the marked answer off the tally. Lesson 5, free.","blog\u002Flearn\u002Fprogramming-your-first-quantum-circuits\u002Finterference",[],"Sp35ODnRvqlVE9Yrp_NCTg4nvT2GhdRj_tKwMlq3ub0",{"id":9094,"title":9095,"authors":9096,"body":9097,"breadcrumb":10043,"builders":10044,"byline":10045,"category":33,"categoryName":33,"challenge":33,"courseAuthor":33,"courseLead":33,"dek":9083,"description":10046,"draft":46,"extension":47,"eyebrow":33,"featured":46,"finish":10047,"fork":33,"group":33,"groupName":33,"hero":10048,"heroAlt":33,"heroCta":33,"heroImage":33,"homepageFeatured":46,"kind":903,"lessonCount":557,"meta":10051,"navigation":50,"newsItems":33,"next":33,"ogImage":33,"order":557,"outcomes":33,"path":9081,"prerequisite":33,"prerequisiteLinks":33,"publishDate":7348,"readingTime":9085,"related":10052,"relatedProjects":33,"section":33,"seo":10053,"stem":10056,"tags":10057,"track":60,"trackName":19,"__hash__":10058},"blog\u002Fblog\u002Flearn\u002Fprogramming-your-first-quantum-circuits\u002Fnoise-and-the-real-machine.md","Noise, and the real machine",[7],{"type":9,"value":9098,"toc":10032},[9099,9111,9114,9118,9125,9128,9131,9152,9154,9157,9631,9635,9649,9659,9664,9667,9711,9714,9717,9773,9777,9780,9788,9918,9922,9928,9933,9939,9954,9971,9975,9978,9985,9991,10003,10029],[12,9100,9101,9102,9104,9105,9107,9108,9110],{},"Noise produced the small tail some tallies in this course carried: a stray ",[170,9103,1165],{}," under an X gate, a few ",[170,9106,7105],{},"s and ",[170,9109,8212],{},"s from a pair that should always agree.",[12,9112,9113],{},"The listing below measures that tail with lesson 3's Bell pair at four times the shots, so a one-percent tail shows up as about forty shots instead of ten. You run it on the models of four IonQ machines, compare the four tails, then look at where the real machines sit in the same dialog.",[111,9115,9117],{"id":9116},"what-a-noise-model-is","What a noise model is",[12,9119,9120,9121,9124],{},"The four simulators under Remotely Run Simulators share one engine: each is IonQ's simulator with a ",[170,9122,9123],{},"noise_model"," option set to one of IonQ's machines, which the Playground passes along when you pick one.",[12,9126,9127],{},"IonQ describes these as an approximation of the named system's performance, with no guarantee of accuracy. For the two Aria models IonQ publishes how the model works: an error applied after every gate, at a rate measured on the machine. For the two Forte models it has not yet. Either way, the listing treats each model as a black box and measures what it does to the tally.",[12,9129,9130],{},"The circuit is the same on every model here, so a difference between the disagree counts comes from the models or from sampling.",[7431,9132,9135],{"name":9133,"token":9134},"The disagree count","disagree",[12,9136,9137,9138,1791,9140,9142,9143,9145,9146,9148,9149,9151],{},"The ideal Bell tally is ",[170,9139,8207],{},[170,9141,8215],{}," only, so every ",[170,9144,7105],{}," or ",[170,9147,8212],{}," is a wrong answer. The listing adds them up as ",[170,9150,9134],{}," and prints the share. The share of disagreeing shots is one measure of the noise, the errors that made the pair disagree; an error in a phase does not show in it.",[111,9153,7444],{"id":7443},[12,9155,9156],{},"The Bell pair is unchanged. Three things are new around it: 4,000 shots, a line that prints which machine the run imitates, and the two counting lines at the end.",[175,9158,9161],{"name":9159,"no-picker":22,"run-href":9160,"tag":985},"noise.py","\u002Fu\u002Fqollab\u002Flearn-noise",[181,9162,9164],{"className":183,"code":9163,"language":185,"meta":22,"style":22},"# 'backend' already exists when this runs: it is whatever you pick in the Run Experiment dialog.\nfrom qiskit import QuantumCircuit\nfrom qiskit.providers.jobstatus import JobStatus\nimport time\n\nshots = 4000\n\nprint(\"backend:\", backend.name, \"| noise model:\", backend.options.get(\"noise_model\", \"none\"))\n\nqc = QuantumCircuit(2, 2)\nqc.h(0)\nqc.cx(0, 1)\nqc.measure([0, 1], [0, 1])\n\njob = backend.run(qc, shots=shots)\nwhile job.status() not in (JobStatus.DONE, JobStatus.ERROR, JobStatus.CANCELLED):\n    time.sleep(5)\n\ncounts = job.result().get_counts()\nprint(counts)\nagree = counts.get(\"00\", 0) + counts.get(\"11\", 0)\ndisagree = shots - agree\nprint(f\"agree:    {agree:5d}  ({100 * agree \u002F shots:5.2f}%)\")\nprint(f\"disagree: {disagree:5d}  ({100 * disagree \u002F shots:5.2f}%)\")\n",[170,9165,9166,9172,9184,9196,9204,9210,9221,9227,9261,9267,9287,9301,9319,9345,9351,9371,9401,9415,9421,9439,9447,9488,9505,9552,9594],{"__ignoreMap":22},[189,9167,9168,9170],{"class":191,"line":192},[189,9169,997],{"class":995,"aria-hidden":996},[189,9171,1000],{"class":318},[189,9173,9174,9176,9178,9180,9182],{"class":191,"line":23},[189,9175,997],{"class":995,"aria-hidden":996},[189,9177,1007],{"class":253},[189,9179,1025],{"class":195},[189,9181,1013],{"class":253},[189,9183,1030],{"class":195},[189,9185,9186,9188,9190,9192,9194],{"class":191,"line":250},[189,9187,997],{"class":995,"aria-hidden":996},[189,9189,1007],{"class":253},[189,9191,1053],{"class":195},[189,9193,1013],{"class":253},[189,9195,1058],{"class":195},[189,9197,9198,9200,9202],{"class":191,"line":281},[189,9199,997],{"class":995,"aria-hidden":996},[189,9201,1013],{"class":253},[189,9203,1067],{"class":195},[189,9205,9206,9208],{"class":191,"line":51},[189,9207,997],{"class":995,"aria-hidden":996},[189,9209,1074],{},[189,9211,9212,9214,9216,9218],{"class":191,"data-cue":1089,"line":557},[189,9213,1089],{"class":1092},[189,9215,1081],{"class":195},[189,9217,200],{"class":199},[189,9219,9220],{"class":210}," 4000\n",[189,9222,9223,9225],{"class":191,"line":579},[189,9224,997],{"class":995,"aria-hidden":996},[189,9226,1074],{},[189,9228,9229,9231,9233,9235,9238,9241,9244,9247,9249,9251,9254,9256,9259],{"class":191,"data-cue":292,"line":590},[189,9230,292],{"class":1092},[189,9232,1306],{"class":199},[189,9234,230],{"class":195},[189,9236,9237],{"class":1314},"\"backend:\"",[189,9239,9240],{"class":195},", backend.name, ",[189,9242,9243],{"class":1314},"\"| noise model:\"",[189,9245,9246],{"class":195},", backend.options.",[189,9248,1577],{"class":203},[189,9250,230],{"class":195},[189,9252,9253],{"class":1314},"\"noise_model\"",[189,9255,541],{"class":195},[189,9257,9258],{"class":1314},"\"none\"",[189,9260,1269],{"class":195},[189,9262,9263,9265],{"class":191,"line":595},[189,9264,997],{"class":995,"aria-hidden":996},[189,9266,1074],{},[189,9268,9269,9271,9273,9275,9277,9279,9281,9283,9285],{"class":191,"line":601},[189,9270,997],{"class":995,"aria-hidden":996},[189,9272,196],{"class":195},[189,9274,200],{"class":199},[189,9276,533],{"class":203},[189,9278,230],{"class":195},[189,9280,292],{"class":210},[189,9282,541],{"class":195},[189,9284,292],{"class":210},[189,9286,214],{"class":195},[189,9288,9289,9291,9293,9295,9297,9299],{"class":191,"line":618},[189,9290,997],{"class":995,"aria-hidden":996},[189,9292,2182],{"class":195},[189,9294,423],{"class":203},[189,9296,230],{"class":195},[189,9298,1165],{"class":210},[189,9300,214],{"class":195},[189,9302,9303,9305,9307,9309,9311,9313,9315,9317],{"class":191,"data-cue":1241,"line":665},[189,9304,1241],{"class":1092},[189,9306,2182],{"class":195},[189,9308,710],{"class":203},[189,9310,230],{"class":195},[189,9312,1165],{"class":210},[189,9314,541],{"class":195},[189,9316,1089],{"class":210},[189,9318,214],{"class":195},[189,9320,9321,9323,9325,9327,9329,9331,9333,9335,9337,9339,9341,9343],{"class":191,"line":676},[189,9322,997],{"class":995,"aria-hidden":996},[189,9324,2182],{"class":195},[189,9326,1203],{"class":203},[189,9328,5273],{"class":195},[189,9330,1165],{"class":210},[189,9332,541],{"class":195},[189,9334,1089],{"class":210},[189,9336,6669],{"class":195},[189,9338,1165],{"class":210},[189,9340,541],{"class":195},[189,9342,1089],{"class":210},[189,9344,5733],{"class":195},[189,9346,9347,9349],{"class":191,"line":681},[189,9348,997],{"class":995,"aria-hidden":996},[189,9350,1074],{},[189,9352,9353,9355,9357,9359,9361,9363,9365,9367,9369],{"class":191,"line":687},[189,9354,997],{"class":995,"aria-hidden":996},[189,9356,219],{"class":195},[189,9358,200],{"class":199},[189,9360,224],{"class":195},[189,9362,227],{"class":203},[189,9364,2593],{"class":195},[189,9366,240],{"class":239},[189,9368,200],{"class":199},[189,9370,1457],{"class":195},[189,9372,9373,9375,9377,9379,9381,9383,9385,9387,9389,9391,9393,9395,9397,9399],{"class":191,"line":705},[189,9374,997],{"class":995,"aria-hidden":996},[189,9376,254],{"class":253},[189,9378,257],{"class":195},[189,9380,260],{"class":203},[189,9382,263],{"class":195},[189,9384,1473],{"class":253},[189,9386,1476],{"class":253},[189,9388,1479],{"class":195},[189,9390,275],{"class":210},[189,9392,1484],{"class":195},[189,9394,1487],{"class":210},[189,9396,1484],{"class":195},[189,9398,1492],{"class":210},[189,9400,576],{"class":195},[189,9402,9403,9405,9407,9409,9411,9413],{"class":191,"line":1195},[189,9404,997],{"class":995,"aria-hidden":996},[189,9406,284],{"class":195},[189,9408,287],{"class":203},[189,9410,230],{"class":195},[189,9412,538],{"class":210},[189,9414,214],{"class":195},[189,9416,9417,9419],{"class":191,"line":1216},[189,9418,997],{"class":995,"aria-hidden":996},[189,9420,1074],{},[189,9422,9423,9425,9427,9429,9431,9433,9435,9437],{"class":191,"line":1227},[189,9424,997],{"class":995,"aria-hidden":996},[189,9426,299],{"class":195},[189,9428,200],{"class":199},[189,9430,257],{"class":195},[189,9432,306],{"class":203},[189,9434,309],{"class":195},[189,9436,312],{"class":203},[189,9438,1536],{"class":195},[189,9440,9441,9443,9445],{"class":191,"line":1234},[189,9442,997],{"class":995,"aria-hidden":996},[189,9444,1306],{"class":199},[189,9446,2676],{"class":195},[189,9448,9449,9451,9454,9456,9458,9460,9462,9465,9467,9469,9471,9473,9475,9477,9479,9482,9484,9486],{"class":191,"data-cue":700,"line":1242},[189,9450,700],{"class":1092},[189,9452,9453],{"class":195},"agree ",[189,9455,200],{"class":199},[189,9457,1574],{"class":195},[189,9459,1577],{"class":203},[189,9461,230],{"class":195},[189,9463,9464],{"class":1314},"\"00\"",[189,9466,541],{"class":195},[189,9468,1165],{"class":210},[189,9470,641],{"class":195},[189,9472,635],{"class":199},[189,9474,1574],{"class":195},[189,9476,1577],{"class":203},[189,9478,230],{"class":195},[189,9480,9481],{"class":1314},"\"11\"",[189,9483,541],{"class":195},[189,9485,1165],{"class":210},[189,9487,214],{"class":195},[189,9489,9490,9492,9495,9497,9500,9502],{"class":191,"data-cue":538,"line":1272},[189,9491,538],{"class":1092},[189,9493,9494],{"class":195},"disagree ",[189,9496,200],{"class":199},[189,9498,9499],{"class":195}," shots ",[189,9501,1626],{"class":199},[189,9503,9504],{"class":195}," agree\n",[189,9506,9507,9509,9511,9513,9515,9518,9520,9523,9526,9528,9531,9533,9535,9538,9540,9542,9545,9547,9550],{"class":191,"line":1301},[189,9508,997],{"class":995,"aria-hidden":996},[189,9510,1306],{"class":199},[189,9512,230],{"class":195},[189,9514,1311],{"class":253},[189,9516,9517],{"class":1314},"\"agree:    ",[189,9519,1318],{"class":210},[189,9521,9522],{"class":195},"agree",[189,9524,9525],{"class":253},":5d",[189,9527,1332],{"class":210},[189,9529,9530],{"class":1314},"  (",[189,9532,3503],{"class":210},[189,9534,659],{"class":199},[189,9536,9537],{"class":195}," agree ",[189,9539,1609],{"class":199},[189,9541,1612],{"class":195},[189,9543,9544],{"class":253},":5.2f",[189,9546,1332],{"class":210},[189,9548,9549],{"class":1314},"%)\"",[189,9551,214],{"class":195},[189,9553,9554,9556,9558,9560,9562,9565,9567,9569,9571,9573,9575,9577,9579,9582,9584,9586,9588,9590,9592],{"class":191,"line":1355},[189,9555,997],{"class":995,"aria-hidden":996},[189,9557,1306],{"class":199},[189,9559,230],{"class":195},[189,9561,1311],{"class":253},[189,9563,9564],{"class":1314},"\"disagree: ",[189,9566,1318],{"class":210},[189,9568,9134],{"class":195},[189,9570,9525],{"class":253},[189,9572,1332],{"class":210},[189,9574,9530],{"class":1314},[189,9576,3503],{"class":210},[189,9578,659],{"class":199},[189,9580,9581],{"class":195}," disagree ",[189,9583,1609],{"class":199},[189,9585,1612],{"class":195},[189,9587,9544],{"class":253},[189,9589,1332],{"class":210},[189,9591,9549],{"class":1314},[189,9593,214],{"class":195},[123,9595,9596,9603,9610,9617,9624],{"class":1644},[126,9597,9598,9600],{"data-cue":1089},[189,9599,1089],{"class":1092},[189,9601,9602],{"class":1651},"more shots than before, so a small tail is measured rather than guessed",[126,9604,9605,9607],{"data-cue":292},[189,9606,292],{"class":1092},[189,9608,9609],{"class":1651},"which backend ran it, and which machine the model imitates",[126,9611,9612,9614],{"data-cue":1241},[189,9613,1241],{"class":1092},[189,9615,9616],{"class":1651},"the Bell pair from lesson 3: the two qubits should always agree",[126,9618,9619,9621],{"data-cue":700},[189,9620,700],{"class":1092},[189,9622,9623],{"class":1651},"the pair's signal",[126,9625,9626,9628],{"data-cue":538},[189,9627,538],{"class":1092},[189,9629,9630],{"class":1651},"the tail: every shot where the pair disagreed",[111,9632,9634],{"id":9633},"run-the-pair-on-two-models","Run the pair on two models",[12,9636,732,9637,737,9639,809,9641,814,9643,9645,9646,9648],{},[16,9638,736],{"href":9160},[129,9640,740],{},[129,9642,8002],{},[129,9644,752],{},". Copy the console's ",[170,9647,9134],{}," line somewhere; the next press replaces it. Before the second press, write down a guess: will Forte 1's tail be bigger or smaller than Aria 1's? Nothing so far says which; the two presses check the guess.",[12,9650,9651,9652,9655,9656,9658],{},"Then press Run on Qollab again and choose ",[129,9653,9654],{},"IonQ Forte 1",". The code is the same; the first printed line names the model. Copy this ",[170,9657,9134],{}," line too.",[116,9660],{"alt":9661,"caption":9662,"no":22,"src":9663},"The run console: backend ionq_simulator with noise model aria-1, the counts dict, and the lines agree 3962 (99.05%) and disagree 38 (0.95%)","The Aria 1 model's answer for the Bell pair: 38 disagreeing shots in 4,000. The first line names the model; the counts under it vary from press to press, with or without a noise model.","\u002F_content\u002Fimages\u002Ffirst-circuits\u002F06-noise-aria-1.webp",[12,9665,9666],{},"Our two presses on 15 September 2026:",[1875,9668,9669,9680],{},[1878,9670,9671],{},[1881,9672,9673,9676,9678],{},[1884,9674,9675],{},"noise model",[1884,9677,1555],{},[1884,9679,9134],{},[1890,9681,9682,9697],{},[1881,9683,9684,9689,9694],{},[1895,9685,9686],{},[170,9687,9688],{},"aria-1",[1895,9690,9691],{},[170,9692,9693],{},"{'00': 2033, '01': 25, '10': 13, '11': 1929}",[1895,9695,9696],{},"38 (0.95%)",[1881,9698,9699,9704,9709],{},[1895,9700,9701],{},[170,9702,9703],{},"forte-1",[1895,9705,9706],{},[170,9707,9708],{},"{'00': 1922, '01': 14, '10': 24, '11': 2040}",[1895,9710,9696],{},[12,9712,9713],{},"The same number came back twice. A tail of about 1% counted over 4,000 shots has a scatter of about 6 shots, so nineteen presses in twenty land within 13 shots of the true value.",[12,9715,9716],{},"The difference between two presses scatters more than one press does, by the square root of two: about 9 shots. So two presses on the same model can differ by close to 20 shots with nothing changed but the sample.",[789,9718,9720,9724,9752],{"check":9719},"you have four disagree lines, one per model, and a sentence saying whether any two of them differ by more than about 20 shots.",[111,9721,9723],{"id":9722},"assignment-complete-the-table","Assignment: complete the table",[123,9725,9726,9736,9746,9749],{},[126,9727,9728,9729,9732,9733,9735],{},"Run the listing on ",[129,9730,9731],{},"IonQ Aria 2"," and copy the console's ",[170,9734,9134],{}," line; the first line of each console names the model.",[126,9737,9738,9739,9742,9743,9745],{},"Run it on ",[129,9740,9741],{},"IonQ Forte Enterprise 1"," and copy that ",[170,9744,9134],{}," line too, before the next press replaces it. You now have all four models from your own presses.",[126,9747,9748],{},"Compare your four numbers against the 20-shot bar above: two numbers 8 apart cannot be told apart by one press each, and two numbers 40 apart can.",[126,9750,9751],{},"Write one sentence saying whether any two models differ.",[830,9753,9754,9764,9767,9770],{"label":832},[12,9755,9756,9757,9760,9761,753],{},"Our four presses gave 38, 38, 36 and 44 shots. Aria 2 came back ",[170,9758,9759],{},"{'00': 2018, '01': 19, '10': 17, '11': 1946}"," and Forte Enterprise 1 ",[170,9762,9763],{},"{'00': 2007, '01': 22, '10': 22, '11': 1949}",[12,9765,9766],{},"The largest gap is 8, well under 20, so no pair of models differs by more than a fresh press of the same model could.",[12,9768,9769],{},"On this two-gate circuit, then, one press per model cannot tell the four models apart: each put the pair wrong about once in a hundred shots.",[12,9771,9772],{},"Your four numbers will differ from ours, and by the 20-shot bar they will most likely not separate the models either.",[111,9774,9776],{"id":9775},"whether-the-model-counts-depth","Whether the model counts depth",[12,9778,9779],{},"On a real machine every gate is a physical operation with its own small chance of going wrong, so a deeper circuit, more gates executed one after another, is expected to come back with a bigger tail, which is one reason algorithms are counted in gates.",[12,9781,9782,9783,9787],{},"You can test whether the model does the same: make the circuit deeper without changing what it computes, and watch the tail. IonQ ",[16,9784,9786],{"href":9785},"\u002Flearn\u002Fdocs\u002Fhow-your-circuit-is-compiled","compiles"," what you submit before it runs, though, and gates that cancel can be removed on the way.",[789,9789,9791,9795,9818],{"check":9790},"you have a disagree line for the plain pair and one for the padded pair, from the same model, and a sentence on whether the second is larger by more than the scatter.",[111,9792,9794],{"id":9793},"assignment-pad-the-circuit-and-watch-the-tail","Assignment: pad the circuit and watch the tail",[123,9796,9797,9800,9806,9809,9812],{},[126,9798,9799],{},"Fork the project, as in lesson 1.",[126,9801,4407,9802,9805],{},[170,9803,9804],{},"qc.cx(0, 1)"," twice, directly under the existing one, so the circuit runs three CNOTs where the last two undo each other. The ideal tally does not change: two CNOTs in a row are the identity.",[126,9807,9808],{},"Write down what you expect from a model that adds error per gate, and from one that does not.",[126,9810,9811],{},"Press Run on Qollab and choose the same model as your plain-circuit press.",[126,9813,9814,9815,9817],{},"Compare the two ",[170,9816,9134],{}," lines against the 20-shot bar before you call a difference real.",[830,9819,9820,9909,9912,9915],{"label":832},[181,9821,9823],{"className":183,"code":9822,"language":185,"meta":22,"style":22},"qc.h(0)\nqc.cx(0, 1)\nqc.cx(0, 1)\nqc.cx(0, 1)\nqc.measure([0, 1], [0, 1])\n",[170,9824,9825,9837,9853,9869,9885],{"__ignoreMap":22},[189,9826,9827,9829,9831,9833,9835],{"class":191,"line":192},[189,9828,2182],{"class":195},[189,9830,423],{"class":203},[189,9832,230],{"class":195},[189,9834,1165],{"class":210},[189,9836,214],{"class":195},[189,9838,9839,9841,9843,9845,9847,9849,9851],{"class":191,"line":23},[189,9840,2182],{"class":195},[189,9842,710],{"class":203},[189,9844,230],{"class":195},[189,9846,1165],{"class":210},[189,9848,541],{"class":195},[189,9850,1089],{"class":210},[189,9852,214],{"class":195},[189,9854,9855,9857,9859,9861,9863,9865,9867],{"class":191,"line":250},[189,9856,2182],{"class":195},[189,9858,710],{"class":203},[189,9860,230],{"class":195},[189,9862,1165],{"class":210},[189,9864,541],{"class":195},[189,9866,1089],{"class":210},[189,9868,214],{"class":195},[189,9870,9871,9873,9875,9877,9879,9881,9883],{"class":191,"line":281},[189,9872,2182],{"class":195},[189,9874,710],{"class":203},[189,9876,230],{"class":195},[189,9878,1165],{"class":210},[189,9880,541],{"class":195},[189,9882,1089],{"class":210},[189,9884,214],{"class":195},[189,9886,9887,9889,9891,9893,9895,9897,9899,9901,9903,9905,9907],{"class":191,"line":51},[189,9888,2182],{"class":195},[189,9890,1203],{"class":203},[189,9892,5273],{"class":195},[189,9894,1165],{"class":210},[189,9896,541],{"class":195},[189,9898,1089],{"class":210},[189,9900,6669],{"class":195},[189,9902,1165],{"class":210},[189,9904,541],{"class":195},[189,9906,1089],{"class":210},[189,9908,5733],{"class":195},[12,9910,9911],{},"On our presses the padded circuit's tail was 32 shots against 38 for the plain one: no growth beyond the scatter.",[12,9913,9914],{},"Most likely the padding never ran. IonQ says a job to a noisy simulator is compiled and optimised the same way as a job to a machine. Removing gates that cancel is part of that, so two CNOTs in a row can be gone before the model sees them. Every CNOT you wrote is submitted; the console does not say what the compiler kept.",[12,9916,9917],{},"So this experiment cannot tell a model that adds no error per gate from extra gates that were compiled away.",[111,9919,9921],{"id":9920},"where-the-real-machines-sit","Where the real machines sit",[12,9923,9924,9925,9927],{},"Scroll to the bottom of the Run Experiment dialog and the last group is ",[129,9926,765],{},": the physical IonQ machines, in the same list as their models.",[116,9929],{"alt":9930,"caption":9931,"no":22,"src":9932},"The bottom of the Run Experiment dialog: the last free simulator, then the Quantum Computer group with IonQ Forte 1 marked Offline and IonQ Forte Enterprise 1 marked Credits apply and highlighted, and the Run button","The models above the line are free. The machines below it are queued behind other people's jobs and cost credits; the dialog marks them Credits apply. On the day we wrote this, Forte 1 was offline and Forte Enterprise 1 was taking jobs.","\u002F_content\u002Fimages\u002Ffirst-circuits\u002F06-quantum-computer-group.webp",[12,9934,9935,9936,9938],{},"The code does not change: the ",[170,9937,858],{}," global from lesson 1 lets the same listing run on a simulator in your browser, on a machine's model, or on the machine.",[12,9940,9941,9942,9945,9946,9949,9950,9953],{},"On the machine the first line names a different backend, ",[170,9943,9944],{},"ionq_qpu.forte-1"," in place of ",[170,9947,9948],{},"ionq_simulator",", and the model field shows its default, ",[170,9951,9952],{},"ideal",", because on the machine there is no model to set. The tail then comes from the machine's own errors.",[12,9955,9956,9957,9961,9962,9966,9967,753],{},"No lesson in this course needs a paid run. A run on a real machine costs ",[16,9958,9960],{"href":9959},"\u002Flearn\u002Fdocs\u002Fhow-credits-work","credits",", and ",[16,9963,9965],{"href":9964},"\u002Flearn\u002Fdocs\u002Fbefore-you-spend-credits","Before you spend credits"," lists the checks to make first. Every option in the dialog is listed with its qubit count and cost under ",[16,9968,9970],{"href":9969},"\u002Flearn\u002Fdocs\u002Fcompute-backends","compute backends",[111,9972,9974],{"id":9973},"publish-your-circuit","Publish your circuit",[12,9976,9977],{},"The last step is to publish one of your circuits. Anyone can open a public project on Qollab, and anyone signed in can run it and fork it.",[12,9979,9980,9981,9984],{},"In the fork you want to publish, edit the circuit into something of your own. Then open its Project Card tab: the write-up is a Markdown editor with a Preview toggle, and it saves on its own as you type. Write what the circuit does and how to run it, and say which licence it carries; each course project ends with the line ",[170,9982,9983],{},"MIT license. Fork it, change it, keep it.",", which you can keep.",[12,9986,9987,9988,753],{},"Then publish it from the project header. The Draft label clears and the project is public at ",[170,9989,9990],{},"qollab.xyz\u002Fu\u002F\u003Cyour username>\u002F\u003Cyour project>",[12,9992,9993,9994,1791,9998,10002],{},"The docs cover ",[16,9995,9997],{"href":9996},"\u002Flearn\u002Fdocs\u002Fpublish","later versions",[16,9999,10001],{"href":10000},"\u002Flearn\u002Fdocs\u002Fwrite-your-project-page","the project page",", which people read before they press Run.",[789,10004,10006,10010,10021],{"check":10005},"your project has a public URL under your own username, and its page says what the circuit does and how to run it.",[111,10007,10009],{"id":10008},"assignment-publish-a-circuit-of-your-own","Assignment: publish a circuit of your own",[123,10011,10012,10015,10018],{},[126,10013,10014],{},"Take any circuit from this course and change what it computes, not only its name: a Bell pair with a rotation on one qubit before the CNOT, a search that marks a different answer, an X gate on the qubit nobody measured.",[126,10016,10017],{},"On the project page, say what you changed and what the tally shows because of it.",[126,10019,10020],{},"Publish it by the procedure above, then open the URL in a private window.",[830,10022,10023],{"label":832},[12,10024,10025,10026,10028],{},"There is no single answer here. Check that ",[170,10027,9990],{}," opens in a private window where you are not signed in. A good project page also lets a stranger predict the tally before they press Run.",[884,10030,10031],{},"html pre.shiki code .sV9Aq, html code.shiki .sV9Aq{--shiki-default:#7F848E;--shiki-default-font-style:italic}html pre.shiki code .seHd6, html code.shiki .seHd6{--shiki-default:#C678DD}html pre.shiki code .sn6KH, html code.shiki .sn6KH{--shiki-default:#ABB2BF}html pre.shiki code .sjrmR, html code.shiki .sjrmR{--shiki-default:#56B6C2}html pre.shiki code .sVC51, html code.shiki .sVC51{--shiki-default:#D19A66}html pre.shiki code .subq3, html code.shiki .subq3{--shiki-default:#98C379}html pre.shiki code .sVbv2, html code.shiki .sVbv2{--shiki-default:#61AFEF}html pre.shiki code .s_ZVi, html code.shiki .s_ZVi{--shiki-default:#E06C75;--shiki-default-font-style:italic}html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}",{"title":22,"searchDepth":23,"depth":23,"links":10033},[10034,10035,10036,10037,10038,10039,10040,10041,10042],{"id":9116,"depth":23,"text":9117},{"id":7443,"depth":23,"text":7444},{"id":9633,"depth":23,"text":9634},{"id":9722,"depth":23,"text":9723},{"id":9775,"depth":23,"text":9776},{"id":9793,"depth":23,"text":9794},{"id":9920,"depth":23,"text":9921},{"id":9973,"depth":23,"text":9974},{"id":10008,"depth":23,"text":10009},[26,27,19,9095],[],{"username":7,"name":30,"role":31,"avatar":32},"Measure the tail of wrong answers on four IonQ noise models, test whether a deeper circuit grows it, and see what changes on a real IonQ machine.","You have finished Programming your first quantum circuits.",{"image":10049,"alt":10050},"\u002F_content\u002Fimages\u002Ffirst-circuits\u002F06-circuit-panel.webp","The Playground's Circuit panel: the Bell pair, an H gate on q0 and a CNOT from q0 to q1, then a measurement on each qubit.",{},[],{"title":10054,"description":10055},"Noise and the real machine · Programming your first quantum circuits","Measure a Bell pair's noise tail on four IonQ noise-model simulators, test whether depth grows it, and see what changes on a real quantum computer. Lesson 6, free.","blog\u002Flearn\u002Fprogramming-your-first-quantum-circuits\u002Fnoise-and-the-real-machine",[],"76tUsIgcTocTqpkovu-lWwyAcPfHVntNtK2QSmAOFyg",{"id":10060,"title":10061,"authors":10062,"body":10063,"breadcrumb":11078,"builders":11079,"byline":11080,"category":33,"categoryName":33,"challenge":33,"courseAuthor":33,"courseLead":33,"dek":11081,"description":11082,"draft":46,"extension":47,"eyebrow":33,"featured":46,"finish":33,"fork":33,"group":33,"groupName":33,"hero":11083,"heroAlt":33,"heroCta":33,"heroImage":33,"homepageFeatured":46,"kind":903,"lessonCount":557,"meta":11086,"navigation":50,"newsItems":33,"next":11087,"ogImage":33,"order":281,"outcomes":33,"path":11089,"prerequisite":33,"prerequisiteLinks":33,"publishDate":7348,"readingTime":11090,"related":11091,"relatedProjects":33,"section":33,"seo":11092,"stem":11095,"tags":11096,"track":60,"trackName":19,"__hash__":11097},"blog\u002Fblog\u002Flearn\u002Fprogramming-your-first-quantum-circuits\u002Frotations.md","Rotate a qubit by any angle",[7],{"type":9,"value":10064,"toc":11068},[10065,10071,10075,10101,10106,10115,10118,10123,10146,10148,10151,10224,10230,10611,10615,10632,10646,10651,10654,10754,10771,10830,10834,10845,10848,10860,10939,10943,10961,10964,10970,10978,10991,10994,10997,11063,11066],[12,10066,10067,10068,10070],{},"A rotation gate turns a qubit by an angle you choose. With RY, the angle can set a fresh qubit's chance of reading ",[170,10069,1089],{}," to any value from 0 to 1.",[111,10072,10074],{"id":10073},"a-gate-that-takes-an-angle","A gate that takes an angle",[12,10076,10077,10080,10081,10083,10084,10086,10087,10089,10090,10092,10093,10089,10095,10097,10098,10100],{},[170,10078,10079],{},"ry(theta, 0)"," rotates qubit 0 by the angle ",[170,10082,3871],{},", in radians: ",[170,10085,1786],{}," is half a turn, so every angle in this lesson is a fraction of ",[170,10088,1786],{},". At ",[170,10091,1165],{}," it does nothing and the qubit stays at ",[170,10094,1165],{},[170,10096,1786],{}," it flips a fresh qubit all the way to ",[170,10099,1089],{},", the same tally the X gate gave in lesson 1.",[12,10102,2986,10103,10105],{},[170,10104,7428],{},", halfway, it gives the same even split the Hadamard gave in lesson 2.",[12,10107,10108,10109,7409,10112,10114],{},"After ",[170,10110,10111],{},"ry(theta)",[170,10113,1089],{}," is sin²(θ\u002F2): take the sine of half the angle and square it.",[12,10116,10117],{},"The rule comes from the geometry of the qubit, which the Bloch sphere section below draws; the listing checks it against tallies, one press per angle.",[116,10119],{"alt":10120,"caption":10121,"no":22,"src":10122},"A semicircle from reads 0 at the top to reads 1 at the bottom, marked at five angles with the share of 1 at each: 0 percent at 0, 14.6 at pi over 4, 50 at pi over 2, 85.4 at three pi over 4, 100 at pi. A bar chart shows the same five shares.","Five angles and the share of 1 each one gives. The share is not proportional to the angle: sin²(θ\u002F2) rises slowly near the ends and fast through the middle.","\u002F_content\u002Fimages\u002Ffirst-circuits\u002Fry-dial.svg",[7431,10124,10126],{"name":10125,"token":670},"Rotation around Y",[12,10127,10128,10131,10132,10134,10135,541,10137,10139,10140,10142,10143,10145],{},[170,10129,10130],{},"ry(theta, qubit)"," rotates the qubit by an angle in radians: ",[170,10133,1165],{}," leaves it at ",[170,10136,1165],{},[170,10138,1786],{}," flips it, ",[170,10141,7428],{}," is the even split. The share of ",[170,10144,1089],{}," after it is sin²(θ\u002F2), and two rotations in a row add their angles. The Y is the axis it turns around.",[111,10147,7444],{"id":7443},[12,10149,10150],{},"The circuit has a single qubit, an RY rotation and a measurement; the angle sits at the top of the file so you can change it without touching the circuit:",[181,10152,10154],{"className":183,"code":10153,"language":185,"meta":22,"style":22},"theta = pi \u002F 4\n\nqc = QuantumCircuit(1, 1)\nqc.ry(theta, 0)               # rotate qubit 0 by theta\nqc.measure(0, 0)\n",[170,10155,10156,10170,10174,10192,10208],{"__ignoreMap":22},[189,10157,10158,10161,10163,10165,10167],{"class":191,"line":192},[189,10159,10160],{"class":195},"theta ",[189,10162,200],{"class":199},[189,10164,7461],{"class":195},[189,10166,1609],{"class":199},[189,10168,10169],{"class":210}," 4\n",[189,10171,10172],{"class":191,"line":23},[189,10173,523],{"emptyLinePlaceholder":50},[189,10175,10176,10178,10180,10182,10184,10186,10188,10190],{"class":191,"line":250},[189,10177,196],{"class":195},[189,10179,200],{"class":199},[189,10181,533],{"class":203},[189,10183,230],{"class":195},[189,10185,1089],{"class":210},[189,10187,541],{"class":195},[189,10189,1089],{"class":210},[189,10191,214],{"class":195},[189,10193,10194,10196,10198,10200,10202,10205],{"class":191,"line":281},[189,10195,2182],{"class":195},[189,10197,670],{"class":203},[189,10199,2187],{"class":195},[189,10201,1165],{"class":210},[189,10203,10204],{"class":195},")               ",[189,10206,10207],{"class":318},"# rotate qubit 0 by theta\n",[189,10209,10210,10212,10214,10216,10218,10220,10222],{"class":191,"line":51},[189,10211,2182],{"class":195},[189,10213,1203],{"class":203},[189,10215,230],{"class":195},[189,10217,1165],{"class":210},[189,10219,541],{"class":195},[189,10221,1165],{"class":210},[189,10223,214],{"class":195},[12,10225,10226,10227,10229],{},"The plumbing gains two lines at the end. One pulls the measured share of ",[170,10228,1089],{}," out of the dict, which was lesson 1's last assignment. The other computes what the rule says for this angle, so the console shows both side by side.",[175,10231,10234],{"name":10232,"no-picker":22,"run-href":10233,"tag":985},"rotations.py","\u002Fu\u002Fqollab\u002Flearn-rotations",[181,10235,10237],{"className":183,"code":10236,"language":185,"meta":22,"style":22},"# 'backend' already exists when this runs: it is whatever you pick in the Run Experiment dialog.\nfrom math import pi, sin\nfrom qiskit import QuantumCircuit\nfrom qiskit.providers.jobstatus import JobStatus\nimport time\n\nshots = 1000\ntheta = pi \u002F 4\n\nqc = QuantumCircuit(1, 1)\nqc.ry(theta, 0)\nqc.measure(0, 0)\nprint(qc)\n\njob = backend.run(qc, shots=shots)\nwhile job.status() not in (JobStatus.DONE, JobStatus.ERROR, JobStatus.CANCELLED):\n    time.sleep(5)\n\ncounts = job.result().get_counts()\nprint(counts)\nmeasured = counts.get(\"1\", 0) \u002F shots\nexpected = sin(theta \u002F 2) ** 2\nprint(f\"theta = {theta:.4f}   share of 1: measured {measured:.3f}   rule says {expected:.3f}\")\n",[170,10238,10239,10245,10257,10269,10281,10289,10295,10305,10319,10325,10345,10359,10377,10385,10391,10411,10441,10455,10461,10479,10487,10513,10536,10581],{"__ignoreMap":22},[189,10240,10241,10243],{"class":191,"line":192},[189,10242,997],{"class":995,"aria-hidden":996},[189,10244,1000],{"class":318},[189,10246,10247,10249,10251,10253,10255],{"class":191,"line":23},[189,10248,997],{"class":995,"aria-hidden":996},[189,10250,1007],{"class":253},[189,10252,1010],{"class":195},[189,10254,1013],{"class":253},[189,10256,7585],{"class":195},[189,10258,10259,10261,10263,10265,10267],{"class":191,"line":250},[189,10260,997],{"class":995,"aria-hidden":996},[189,10262,1007],{"class":253},[189,10264,1025],{"class":195},[189,10266,1013],{"class":253},[189,10268,1030],{"class":195},[189,10270,10271,10273,10275,10277,10279],{"class":191,"line":281},[189,10272,997],{"class":995,"aria-hidden":996},[189,10274,1007],{"class":253},[189,10276,1053],{"class":195},[189,10278,1013],{"class":253},[189,10280,1058],{"class":195},[189,10282,10283,10285,10287],{"class":191,"line":51},[189,10284,997],{"class":995,"aria-hidden":996},[189,10286,1013],{"class":253},[189,10288,1067],{"class":195},[189,10290,10291,10293],{"class":191,"line":557},[189,10292,997],{"class":995,"aria-hidden":996},[189,10294,1074],{},[189,10296,10297,10299,10301,10303],{"class":191,"line":579},[189,10298,997],{"class":995,"aria-hidden":996},[189,10300,1081],{"class":195},[189,10302,200],{"class":199},[189,10304,1086],{"class":210},[189,10306,10307,10309,10311,10313,10315,10317],{"class":191,"data-cue":1089,"line":590},[189,10308,1089],{"class":1092},[189,10310,10160],{"class":195},[189,10312,200],{"class":199},[189,10314,7461],{"class":195},[189,10316,1609],{"class":199},[189,10318,10169],{"class":210},[189,10320,10321,10323],{"class":191,"line":595},[189,10322,997],{"class":995,"aria-hidden":996},[189,10324,1074],{},[189,10326,10327,10329,10331,10333,10335,10337,10339,10341,10343],{"class":191,"line":601},[189,10328,997],{"class":995,"aria-hidden":996},[189,10330,196],{"class":195},[189,10332,200],{"class":199},[189,10334,533],{"class":203},[189,10336,230],{"class":195},[189,10338,1089],{"class":210},[189,10340,541],{"class":195},[189,10342,1089],{"class":210},[189,10344,214],{"class":195},[189,10346,10347,10349,10351,10353,10355,10357],{"class":191,"data-cue":292,"line":618},[189,10348,292],{"class":1092},[189,10350,2182],{"class":195},[189,10352,670],{"class":203},[189,10354,2187],{"class":195},[189,10356,1165],{"class":210},[189,10358,214],{"class":195},[189,10360,10361,10363,10365,10367,10369,10371,10373,10375],{"class":191,"line":665},[189,10362,997],{"class":995,"aria-hidden":996},[189,10364,2182],{"class":195},[189,10366,1203],{"class":203},[189,10368,230],{"class":195},[189,10370,1165],{"class":210},[189,10372,541],{"class":195},[189,10374,1165],{"class":210},[189,10376,214],{"class":195},[189,10378,10379,10381,10383],{"class":191,"line":676},[189,10380,997],{"class":995,"aria-hidden":996},[189,10382,1306],{"class":199},[189,10384,2572],{"class":195},[189,10386,10387,10389],{"class":191,"line":681},[189,10388,997],{"class":995,"aria-hidden":996},[189,10390,1074],{},[189,10392,10393,10395,10397,10399,10401,10403,10405,10407,10409],{"class":191,"line":687},[189,10394,997],{"class":995,"aria-hidden":996},[189,10396,219],{"class":195},[189,10398,200],{"class":199},[189,10400,224],{"class":195},[189,10402,227],{"class":203},[189,10404,2593],{"class":195},[189,10406,240],{"class":239},[189,10408,200],{"class":199},[189,10410,1457],{"class":195},[189,10412,10413,10415,10417,10419,10421,10423,10425,10427,10429,10431,10433,10435,10437,10439],{"class":191,"line":705},[189,10414,997],{"class":995,"aria-hidden":996},[189,10416,254],{"class":253},[189,10418,257],{"class":195},[189,10420,260],{"class":203},[189,10422,263],{"class":195},[189,10424,1473],{"class":253},[189,10426,1476],{"class":253},[189,10428,1479],{"class":195},[189,10430,275],{"class":210},[189,10432,1484],{"class":195},[189,10434,1487],{"class":210},[189,10436,1484],{"class":195},[189,10438,1492],{"class":210},[189,10440,576],{"class":195},[189,10442,10443,10445,10447,10449,10451,10453],{"class":191,"line":1195},[189,10444,997],{"class":995,"aria-hidden":996},[189,10446,284],{"class":195},[189,10448,287],{"class":203},[189,10450,230],{"class":195},[189,10452,538],{"class":210},[189,10454,214],{"class":195},[189,10456,10457,10459],{"class":191,"line":1216},[189,10458,997],{"class":995,"aria-hidden":996},[189,10460,1074],{},[189,10462,10463,10465,10467,10469,10471,10473,10475,10477],{"class":191,"line":1227},[189,10464,997],{"class":995,"aria-hidden":996},[189,10466,299],{"class":195},[189,10468,200],{"class":199},[189,10470,257],{"class":195},[189,10472,306],{"class":203},[189,10474,309],{"class":195},[189,10476,312],{"class":203},[189,10478,1536],{"class":195},[189,10480,10481,10483,10485],{"class":191,"line":1234},[189,10482,997],{"class":995,"aria-hidden":996},[189,10484,1306],{"class":199},[189,10486,2676],{"class":195},[189,10488,10489,10491,10493,10495,10497,10499,10501,10503,10505,10507,10509,10511],{"class":191,"data-cue":1241,"line":1242},[189,10490,1241],{"class":1092},[189,10492,7850],{"class":195},[189,10494,200],{"class":199},[189,10496,1574],{"class":195},[189,10498,1577],{"class":203},[189,10500,230],{"class":195},[189,10502,2495],{"class":1314},[189,10504,541],{"class":195},[189,10506,1165],{"class":210},[189,10508,641],{"class":195},[189,10510,1609],{"class":199},[189,10512,7871],{"class":195},[189,10514,10515,10517,10519,10521,10523,10526,10528,10530,10532,10534],{"class":191,"data-cue":700,"line":1272},[189,10516,700],{"class":1092},[189,10518,7878],{"class":195},[189,10520,200],{"class":199},[189,10522,7883],{"class":203},[189,10524,10525],{"class":195},"(theta ",[189,10527,1609],{"class":199},[189,10529,2369],{"class":210},[189,10531,641],{"class":195},[189,10533,1382],{"class":199},[189,10535,7466],{"class":210},[189,10537,10538,10540,10542,10544,10546,10549,10551,10553,10555,10557,10559,10561,10563,10565,10567,10569,10571,10573,10575,10577,10579],{"class":191,"line":1301},[189,10539,997],{"class":995,"aria-hidden":996},[189,10541,1306],{"class":199},[189,10543,230],{"class":195},[189,10545,1311],{"class":253},[189,10547,10548],{"class":1314},"\"theta = ",[189,10550,1318],{"class":210},[189,10552,3871],{"class":195},[189,10554,7916],{"class":253},[189,10556,1332],{"class":210},[189,10558,7921],{"class":1314},[189,10560,1318],{"class":210},[189,10562,1128],{"class":195},[189,10564,1387],{"class":253},[189,10566,1332],{"class":210},[189,10568,7932],{"class":1314},[189,10570,1318],{"class":210},[189,10572,7937],{"class":195},[189,10574,1387],{"class":253},[189,10576,1332],{"class":210},[189,10578,1350],{"class":1314},[189,10580,214],{"class":195},[123,10582,10583,10590,10597,10604],{"class":1644},[126,10584,10585,10587],{"data-cue":1089},[189,10586,1089],{"class":1092},[189,10588,10589],{"class":1651},"the dial: change this, press Run, compare. 0 is no rotation, pi is a full flip",[126,10591,10592,10594],{"data-cue":292},[189,10593,292],{"class":1092},[189,10595,10596],{"class":1651},"rotate qubit 0 by theta around the Y axis",[126,10598,10599,10601],{"data-cue":1241},[189,10600,1241],{"class":1092},[189,10602,10603],{"class":1651},"the share of shots that read 1, from lesson 1's last task",[126,10605,10606,10608],{"data-cue":700},[189,10607,700],{"class":1092},[189,10609,10610],{"class":1651},"the rule this lesson is about",[111,10612,10614],{"id":10613},"run-the-circuit-five-times","Run the circuit, five times",[12,10616,10617,10618,7992,10620,10623,10624,737,10626,809,10628,814,10630,753],{},"The listing runs one angle per press. Predict the share of ",[170,10619,1089],{},[170,10621,10622],{},"pi \u002F 4"," first, then open ",[16,10625,736],{"href":10233},[129,10627,740],{},[129,10629,8002],{},[129,10631,752],{},[12,10633,10634,10635,3284,10637,541,10639,541,10641,1791,10644,8013],{},"Then fork the project, as in lesson 1, and in your fork set ",[170,10636,3871],{},[170,10638,1165],{},[170,10640,7428],{},[170,10642,10643],{},"3 * pi \u002F 4",[170,10645,1786],{},[116,10647],{"alt":10648,"caption":10649,"no":22,"src":10650},"The run console after RY by pi over 4: the counts dict and the line theta = 0.7854, share of 1: measured 0.149, rule says 0.146","The console after one press at pi \u002F 4. The last line puts the measured share beside the rule's value for that angle.","\u002F_content\u002Fimages\u002Ffirst-circuits\u002F04-rotations.webp",[12,10652,10653],{},"Our five presses on 15 September 2026, on the Aria 1 noise model:",[1875,10655,10656,10672],{},[1878,10657,10658],{},[1881,10659,10660,10664,10666,10670],{},[1884,10661,10662],{},[170,10663,3871],{},[1884,10665,1555],{},[1884,10667,8031,10668],{},[170,10669,1089],{},[1884,10671,8036],{},[1890,10673,10674,10688,10705,10721,10738],{},[1881,10675,10676,10680,10684,10686],{},[1895,10677,10678],{},[170,10679,1165],{},[1895,10681,10682],{},[170,10683,8049],{},[1895,10685,8052],{},[1895,10687,8052],{},[1881,10689,10690,10694,10699,10702],{},[1895,10691,10692],{},[170,10693,10622],{},[1895,10695,10696],{},[170,10697,10698],{},"{'0': 851, '1': 149}",[1895,10700,10701],{},"0.149",[1895,10703,10704],{},"0.146",[1881,10706,10707,10711,10716,10719],{},[1895,10708,10709],{},[170,10710,7428],{},[1895,10712,10713],{},[170,10714,10715],{},"{'0': 507, '1': 493}",[1895,10717,10718],{},"0.493",[1895,10720,8071],{},[1881,10722,10723,10727,10732,10735],{},[1895,10724,10725],{},[170,10726,10643],{},[1895,10728,10729],{},[170,10730,10731],{},"{'0': 123, '1': 877}",[1895,10733,10734],{},"0.877",[1895,10736,10737],{},"0.854",[1881,10739,10740,10744,10749,10752],{},[1895,10741,10742],{},[170,10743,1786],{},[1895,10745,10746],{},[170,10747,10748],{},"{'0': 1, '1': 999}",[1895,10750,10751],{},"0.999",[1895,10753,8085],{},[12,10755,10756,10757,10759,10760,9145,10762,10764,10765,10767,10768,10770],{},"The measured shares track the rule to within a few hundredths, about the size of lesson 2's scatter at 1,000 shots; the ",[170,10758,10643],{}," press sits at the edge of that band, and one press cannot say whether that is scatter or a small bias in the model. At the two ends, where the ideal share is exactly ",[170,10761,1165],{},[170,10763,1089],{},", the noise model adds its small tail: one stray shot at ",[170,10766,1786],{},", none at ",[170,10769,1165],{}," this time.",[789,10772,10774,10778,10800],{"check":10773},"the console shows a measured share of 1 near 0.25, and the rule line agrees with it.",[111,10775,10777],{"id":10776},"assignment-hit-a-quarter","Assignment: hit a quarter",[123,10779,10780,10783,10795,10797],{},[126,10781,10782],{},"Invert the rule. You want sin²(θ\u002F2) = 0.25. Work out what sin(θ\u002F2) must be, then which angle has that sine, and remember that angle is θ\u002F2, not θ.",[126,10784,4948,10785,10787,10788,10790,10791,10794],{},[170,10786,3871],{}," to the angle that follows, written as a fraction of ",[170,10789,1786],{},"; ",[170,10792,10793],{},"from math import pi"," is already at the top of the file.",[126,10796,8126],{},[126,10798,10799],{},"Compare the measured share with the rule line.",[830,10801,10802,10805,10823],{"label":832},[12,10803,10804],{},"sin(θ\u002F2) = 0.5 when θ\u002F2 = π\u002F6, so θ = π\u002F3.",[181,10806,10808],{"className":183,"code":10807,"language":185,"meta":22,"style":22},"theta = pi \u002F 3\n",[170,10809,10810],{"__ignoreMap":22},[189,10811,10812,10814,10816,10818,10820],{"class":191,"line":192},[189,10813,10160],{"class":195},[189,10815,200],{"class":199},[189,10817,7461],{"class":195},[189,10819,1609],{"class":199},[189,10821,10822],{"class":210}," 3\n",[12,10824,10825,10826,10829],{},"The rule line prints ",[170,10827,10828],{},"0.250",", and the measured share lands near it: within about 0.03 at 1,000 shots, by lesson 2's scatter.",[111,10831,10833],{"id":10832},"rotations-add","Rotations add",[12,10835,10836,10837,10840,10841,10844],{},"Two rotations in a row rotate by the sum of their angles. ",[170,10838,10839],{},"ry(pi \u002F 2)"," twice is ",[170,10842,10843],{},"ry(pi)",", a full flip, even though each half on its own would give an even split.",[12,10846,10847],{},"Lesson 1 showed the same with two X gates: gates compose, and the answer depends on the whole sequence.",[12,10849,10850,10851,10853,10854,10856,10857,10859],{},"On a fresh qubit the Hadamard and ",[170,10852,10839],{}," leave the same state, so they give the same tally. The two gates still differ: they act differently on a qubit that is already in superposition, such as the one the first gate leaves. Applying each gate twice shows the difference. Two Hadamards in a row gave every shot ",[170,10855,1165],{}," in lesson 2, and two ",[170,10858,10839],{}," in a row do something else, which the assignment below asks you to work out from the angle.",[789,10861,10863,10867,10896],{"check":10862},"every shot reads 1, bar the noise model's tail.",[111,10864,10866],{"id":10865},"assignment-two-half-turns","Assignment: two half turns",[123,10868,10869,10876,10883,10886,10888],{},[126,10870,4948,10871,10873,10874,753],{},[170,10872,3871],{}," back to ",[170,10875,7428],{},[126,10877,10878,10879,10882],{},"Add a second ",[170,10880,10881],{},"qc.ry(theta, 0)"," directly under the first.",[126,10884,10885],{},"Add the two angles and predict the share from the total.",[126,10887,8126],{},[126,10889,10890,10891,10893,10894,753],{},"Compare the measured share with the rule for the summed angle. The console's rule line is computed from one ",[170,10892,3871],{},", so it keeps saying ",[170,10895,8071],{},[830,10897,10898,10907,10936],{"label":832},[12,10899,10900,10901,10903,10904,10906],{},"π\u002F2 + π\u002F2 = π, a full flip: every shot reads ",[170,10902,1089],{},", and the measured share prints as ",[170,10905,8085],{}," or just under it.",[181,10908,10910],{"className":183,"code":10909,"language":185,"meta":22,"style":22},"qc.ry(theta, 0)\nqc.ry(theta, 0)\n",[170,10911,10912,10924],{"__ignoreMap":22},[189,10913,10914,10916,10918,10920,10922],{"class":191,"line":192},[189,10915,2182],{"class":195},[189,10917,670],{"class":203},[189,10919,2187],{"class":195},[189,10921,1165],{"class":210},[189,10923,214],{"class":195},[189,10925,10926,10928,10930,10932,10934],{"class":191,"line":23},[189,10927,2182],{"class":195},[189,10929,670],{"class":203},[189,10931,2187],{"class":195},[189,10933,1165],{"class":210},[189,10935,214],{"class":195},[12,10937,10938],{},"The rule applies to the total angle, π.",[111,10940,10942],{"id":10941},"rz-and-the-bloch-sphere","RZ and the Bloch sphere",[12,10944,756,10945,10949,10950,10952,10953,10955,10956,10960],{},[16,10946,10948],{"href":10947},"\u002Flearn\u002Fquantum-foundations\u002Fqubits","Bloch sphere"," draws the qubit as an arrow from the centre of a globe: a fresh qubit points at the north pole, ",[170,10951,1165],{},", and the south pole is ",[170,10954,1089],{},". You can ",[16,10957,10959],{"href":10958},"\u002Fu\u002Fqollab\u002Finteractive-bloch-sphere","drag the arrow around one"," on Qollab.",[12,10962,10963],{},"RY tilts the arrow south, and the measurement reads how far it tilted.",[12,10965,10966,10967,10969],{},"RZ spins the arrow around the pole instead. The spin changes only the arrow's position around the pole, which is the qubit's phase; the north-south position does not change, so the share of ",[170,10968,1089],{}," does not change either.",[12,10971,10972,10973,1791,10975,10977],{},"In lesson 2 a weight carried a sign, plus or minus. A phase is that sign made continuous: a sign has two values, and a phase can be any angle. Call the qubit's two weighted options, ",[170,10974,1165],{},[170,10976,1089],{},", its two paths. Two paths with the same phase add up, two with opposite phases cancel, and anything between does part of each. Lesson 5 turns a phase difference into a tally.",[7431,10979,10981],{"name":10980,"token":972},"Rotation around Z",[12,10982,10983,10984,10987,10988,10990],{},"A rotation around the axis the measurement reads along. ",[170,10985,10986],{},"rz(phi, qubit)"," changes the qubit's phase and leaves the share of ",[170,10989,1089],{}," exactly where it was.",[12,10992,10993],{},"On a fresh qubit the spin changes nothing at all: there is only one path, so there is no second path for its phase to differ from.",[12,10995,10996],{},"A Hadamard before the spin gives two paths, so the spin becomes a difference between them, and a Hadamard after it turns that difference into odds you can read.",[789,10998,11000,11004,11027],{"check":10999},"every shot reads 0, bar the noise model's tail, whatever angle you chose.",[111,11001,11003],{"id":11002},"assignment-replace-ry-with-rz","Assignment: replace RY with RZ",[123,11005,11006,11009,11021,11024],{},[126,11007,11008],{},"Remove the second RY again, so the circuit is back to one rotation.",[126,11010,11011,11012,4942,11014,11017,11018,11020],{},"Replace ",[170,11013,10881],{},[170,11015,11016],{},"qc.rz(theta, 0)",", with any ",[170,11019,3871],{}," you like.",[126,11022,11023],{},"Predict with the globe: RY tips the arrow south, RZ spins it around the pole. Work out where the arrow is after a spin that starts at the pole, and what a measurement that only reports north or south reads.",[126,11025,11026],{},"Press Run on Qollab and choose IonQ Aria 1. The rule line computes sin²(θ\u002F2) whatever gate is in the circuit, so it prints a value that does not apply here; the tally is the answer.",[830,11028,11029,11040,11057],{"label":832},[12,11030,11031,11032,11034,11035,11037,11038,753],{},"Every shot reads ",[170,11033,1165],{},", for any angle. The arrow started at the pole, and spinning around the pole leaves it there; the share of ",[170,11036,1089],{}," stays at ",[170,11039,1165],{},[181,11041,11043],{"className":183,"code":11042,"language":185,"meta":22,"style":22},"qc.rz(theta, 0)\n",[170,11044,11045],{"__ignoreMap":22},[189,11046,11047,11049,11051,11053,11055],{"class":191,"line":192},[189,11048,2182],{"class":195},[189,11050,972],{"class":203},[189,11052,2187],{"class":195},[189,11054,1165],{"class":210},[189,11056,214],{"class":195},[12,11058,11059,11060,11062],{},"The rule applies to RY. RZ has a different rule, and under it the share of ",[170,11061,1089],{}," is always the share you started with.",[12,11064,11065],{},"Lesson 5 puts a Hadamard on each side of the RZ, so the same spin changes the tally, and then uses the effect in a two-qubit search.",[884,11067,9060],{},{"title":22,"searchDepth":23,"depth":23,"links":11069},[11070,11071,11072,11073,11074,11075,11076,11077],{"id":10073,"depth":23,"text":10074},{"id":7443,"depth":23,"text":7444},{"id":10613,"depth":23,"text":10614},{"id":10776,"depth":23,"text":10777},{"id":10832,"depth":23,"text":10833},{"id":10865,"depth":23,"text":10866},{"id":10941,"depth":23,"text":10942},{"id":11002,"depth":23,"text":11003},[26,27,19,10061],[],{"username":7,"name":30,"role":31,"avatar":32},"RY sets the odds of reading 1 with an angle; RZ changes the phase and, on its own, leaves the tally unchanged.","The RY gate's angle sets the share of shots that read 1, by a rule you check in code. The RZ gate changes the phase and, on its own, leaves the tally unchanged.",{"image":11084,"alt":11085},"\u002F_content\u002Fimages\u002Ffirst-circuits\u002F04-circuit-panel.webp","The Playground's Circuit panel: qubit q0 runs through an Ry(0.25π) gate into a measurement.",{},{"slug":9084,"title":11088,"desc":9074},"5 · Interference and your first algorithm","\u002Fblog\u002Flearn\u002Fprogramming-your-first-quantum-circuits\u002Frotations","9 min read",[],{"title":11093,"description":11094},"Rotation gates RY and RZ · Programming your first quantum circuits","Set a qubit's odds with the RY gate in Qiskit, check sin²(θ\u002F2) against runs on the IonQ simulator, and see why RZ on its own changes no tally. Lesson 4, free.","blog\u002Flearn\u002Fprogramming-your-first-quantum-circuits\u002Frotations",[],"V45fc1Ar_TKTHEgSUC8f9NiYVOVcTBcb1RGvShBgBYM",{"id":11099,"title":11100,"authors":11101,"body":11102,"breadcrumb":11830,"builders":11831,"byline":11832,"category":33,"categoryName":33,"challenge":33,"courseAuthor":33,"courseLead":33,"dek":11833,"description":11834,"draft":46,"extension":47,"eyebrow":33,"featured":46,"finish":33,"fork":33,"group":33,"groupName":33,"hero":11835,"heroAlt":33,"heroCta":33,"heroImage":33,"homepageFeatured":46,"kind":903,"lessonCount":557,"meta":11838,"navigation":50,"newsItems":33,"next":11839,"ogImage":33,"order":23,"outcomes":33,"path":11843,"prerequisite":33,"prerequisiteLinks":33,"publishDate":7348,"readingTime":11844,"related":11845,"relatedProjects":33,"section":33,"seo":11846,"stem":11849,"tags":11850,"track":60,"trackName":19,"__hash__":11851},"blog\u002Fblog\u002Flearn\u002Fprogramming-your-first-quantum-circuits\u002Fsuperposition.md","Put a qubit in superposition",[7],{"type":9,"value":11103,"toc":11820},[11104,11107,11113,11117,11126,11133,11136,11139,11142,11159,11161,11166,11506,11517,11521,11524,11537,11542,11555,11558,11561,11600,11604,11610,11613,11616,11619,11661,11665,11673,11682,11703,11814,11817],[12,11105,11106],{},"A qubit in superposition holds no single value. It carries a weight on each answer, a number that sets how likely that answer is, and its answer is not fixed until it is measured.",[12,11108,11109,11110,11112],{},"The Hadamard gate, ",[170,11111,423],{}," in Qiskit, puts a fresh qubit into that state in one line. The circuit below runs it for 1,000 shots and prints the tally.",[111,11114,11116],{"id":11115},"what-a-superposed-qubit-holds","What a superposed qubit holds",[12,11118,11119,11120,11122,11123,11125],{},"An ordinary bit holds a ",[170,11121,1165],{}," or a ",[170,11124,1089],{}," whether or not you have looked at it; looking only tells you which one it already was.",[12,11127,11128,11129,753],{},"A qubit after a Hadamard gate holds no value to find before the measurement. It carries a weight on each outcome, equal here, so each answer is equally likely. A qubit with weights on both answers at once is in a ",[16,11130,11132],{"href":11131},"\u002Flearn\u002Fquantum-superposition","superposition",[12,11134,11135],{},"The measurement turns those weights into one answer, and running the circuit again can give the other answer. To estimate how likely each answer is, a quantum program runs the circuit many times and returns the tally.",[12,11137,11138],{},"A weight has a size, which sets how likely its answer is: the share of shots that read an answer is its weight's size squared, so two equal weights of about 0.7 give shares of one half each. Lesson 4 checks this rule against measured tallies.",[12,11140,11141],{},"A weight also has a sign, which never shows in a tally on its own. The sign shows when another gate acts on the weights before the measurement, because gates transform the weights, sign included; in this lesson, a sign first changes a tally in the two-Hadamard assignment.",[7431,11143,11145],{"name":11144,"token":423},"The Hadamard gate",[12,11146,11147,11148,11150,11151,1791,11153,11155,11156,11158],{},"Takes a qubit at ",[170,11149,1165],{}," and leaves it weighted evenly between ",[170,11152,1165],{},[170,11154,1089],{},"; takes a qubit at ",[170,11157,1089],{}," and does the same with the sign of one weight flipped. Measure either and each answer is equally likely. It is its own inverse: applied twice in a row, it returns the qubit to where it started.",[111,11160,7444],{"id":7443},[116,11162],{"alt":11163,"caption":11164,"no":22,"src":11165},"A wire labelled q0 carries a qubit reading 0 into a box marked H, after which it carries a weight on both 0 and 1, then into a measurement meter; an arrow drops to a doubled wire labelled bit 0 where either answer lands","Between the gate and the meter the qubit carries a weight on 0 and a weight on 1, drawn as the two half-strength chips. The diagram does not show the weights' signs.","\u002F_content\u002Fimages\u002Ffirst-circuits\u002Fone-qubit-h-circuit.svg",[175,11167,11170],{"name":11168,"no-picker":22,"run-href":11169,"tag":985},"superposition.py","\u002Fu\u002Fqollab\u002Flearn-superposition",[181,11171,11173],{"className":183,"code":11172,"language":185,"meta":22,"style":22},"# 'backend' already exists when this runs: it is whatever you pick in the Run Experiment dialog.\nfrom qiskit import QuantumCircuit\nfrom qiskit.providers.jobstatus import JobStatus\nimport time\n\nshots = 1000\n\nqc = QuantumCircuit(1, 1)\nqc.h(0)\nqc.measure(0, 0)\nprint(qc)\n\njob = backend.run(qc, shots=shots)\nwhile job.status() not in (JobStatus.DONE, JobStatus.ERROR, JobStatus.CANCELLED):\n    time.sleep(5)\n\ncounts = job.result().get_counts()\nprint(counts)\nfor bits, n in sorted(counts.items()):\n    print(f\"{bits}: {n:4d}  {100 * n \u002F shots:5.1f}%  {'█' * (50 * n \u002F\u002F shots)}\")\n",[170,11174,11175,11181,11193,11205,11213,11219,11229,11235,11255,11269,11287,11295,11301,11321,11351,11365,11371,11389,11397,11415,11483],{"__ignoreMap":22},[189,11176,11177,11179],{"class":191,"line":192},[189,11178,997],{"class":995,"aria-hidden":996},[189,11180,1000],{"class":318},[189,11182,11183,11185,11187,11189,11191],{"class":191,"line":23},[189,11184,997],{"class":995,"aria-hidden":996},[189,11186,1007],{"class":253},[189,11188,1025],{"class":195},[189,11190,1013],{"class":253},[189,11192,1030],{"class":195},[189,11194,11195,11197,11199,11201,11203],{"class":191,"line":250},[189,11196,997],{"class":995,"aria-hidden":996},[189,11198,1007],{"class":253},[189,11200,1053],{"class":195},[189,11202,1013],{"class":253},[189,11204,1058],{"class":195},[189,11206,11207,11209,11211],{"class":191,"line":281},[189,11208,997],{"class":995,"aria-hidden":996},[189,11210,1013],{"class":253},[189,11212,1067],{"class":195},[189,11214,11215,11217],{"class":191,"line":51},[189,11216,997],{"class":995,"aria-hidden":996},[189,11218,1074],{},[189,11220,11221,11223,11225,11227],{"class":191,"line":557},[189,11222,997],{"class":995,"aria-hidden":996},[189,11224,1081],{"class":195},[189,11226,200],{"class":199},[189,11228,1086],{"class":210},[189,11230,11231,11233],{"class":191,"line":579},[189,11232,997],{"class":995,"aria-hidden":996},[189,11234,1074],{},[189,11236,11237,11239,11241,11243,11245,11247,11249,11251,11253],{"class":191,"line":590},[189,11238,997],{"class":995,"aria-hidden":996},[189,11240,196],{"class":195},[189,11242,200],{"class":199},[189,11244,533],{"class":203},[189,11246,230],{"class":195},[189,11248,1089],{"class":210},[189,11250,541],{"class":195},[189,11252,1089],{"class":210},[189,11254,214],{"class":195},[189,11256,11257,11259,11261,11263,11265,11267],{"class":191,"data-cue":1089,"line":595},[189,11258,1089],{"class":1092},[189,11260,2182],{"class":195},[189,11262,423],{"class":203},[189,11264,230],{"class":195},[189,11266,1165],{"class":210},[189,11268,214],{"class":195},[189,11270,11271,11273,11275,11277,11279,11281,11283,11285],{"class":191,"line":601},[189,11272,997],{"class":995,"aria-hidden":996},[189,11274,2182],{"class":195},[189,11276,1203],{"class":203},[189,11278,230],{"class":195},[189,11280,1165],{"class":210},[189,11282,541],{"class":195},[189,11284,1165],{"class":210},[189,11286,214],{"class":195},[189,11288,11289,11291,11293],{"class":191,"line":618},[189,11290,997],{"class":995,"aria-hidden":996},[189,11292,1306],{"class":199},[189,11294,2572],{"class":195},[189,11296,11297,11299],{"class":191,"line":665},[189,11298,997],{"class":995,"aria-hidden":996},[189,11300,1074],{},[189,11302,11303,11305,11307,11309,11311,11313,11315,11317,11319],{"class":191,"data-cue":292,"line":676},[189,11304,292],{"class":1092},[189,11306,219],{"class":195},[189,11308,200],{"class":199},[189,11310,224],{"class":195},[189,11312,227],{"class":203},[189,11314,2593],{"class":195},[189,11316,240],{"class":239},[189,11318,200],{"class":199},[189,11320,1457],{"class":195},[189,11322,11323,11325,11327,11329,11331,11333,11335,11337,11339,11341,11343,11345,11347,11349],{"class":191,"line":681},[189,11324,997],{"class":995,"aria-hidden":996},[189,11326,254],{"class":253},[189,11328,257],{"class":195},[189,11330,260],{"class":203},[189,11332,263],{"class":195},[189,11334,1473],{"class":253},[189,11336,1476],{"class":253},[189,11338,1479],{"class":195},[189,11340,275],{"class":210},[189,11342,1484],{"class":195},[189,11344,1487],{"class":210},[189,11346,1484],{"class":195},[189,11348,1492],{"class":210},[189,11350,576],{"class":195},[189,11352,11353,11355,11357,11359,11361,11363],{"class":191,"line":687},[189,11354,997],{"class":995,"aria-hidden":996},[189,11356,284],{"class":195},[189,11358,287],{"class":203},[189,11360,230],{"class":195},[189,11362,538],{"class":210},[189,11364,214],{"class":195},[189,11366,11367,11369],{"class":191,"line":705},[189,11368,997],{"class":995,"aria-hidden":996},[189,11370,1074],{},[189,11372,11373,11375,11377,11379,11381,11383,11385,11387],{"class":191,"line":1195},[189,11374,997],{"class":995,"aria-hidden":996},[189,11376,299],{"class":195},[189,11378,200],{"class":199},[189,11380,257],{"class":195},[189,11382,306],{"class":203},[189,11384,309],{"class":195},[189,11386,312],{"class":203},[189,11388,1536],{"class":195},[189,11390,11391,11393,11395],{"class":191,"line":1216},[189,11392,997],{"class":995,"aria-hidden":996},[189,11394,1306],{"class":199},[189,11396,2676],{"class":195},[189,11398,11399,11401,11403,11405,11407,11409,11411,11413],{"class":191,"line":1227},[189,11400,997],{"class":995,"aria-hidden":996},[189,11402,560],{"class":253},[189,11404,8617],{"class":195},[189,11406,566],{"class":253},[189,11408,6743],{"class":199},[189,11410,6746],{"class":195},[189,11412,6749],{"class":203},[189,11414,6896],{"class":195},[189,11416,11417,11419,11421,11423,11425,11427,11429,11431,11433,11435,11437,11439,11441,11443,11445,11447,11449,11451,11453,11455,11457,11459,11461,11463,11465,11467,11469,11471,11473,11475,11477,11479,11481],{"class":191,"data-cue":1241,"line":1234},[189,11418,1241],{"class":1092},[189,11420,6903],{"class":199},[189,11422,230],{"class":195},[189,11424,1311],{"class":253},[189,11426,1350],{"class":1314},[189,11428,1318],{"class":210},[189,11430,8644],{"class":195},[189,11432,1332],{"class":210},[189,11434,3129],{"class":1314},[189,11436,1318],{"class":210},[189,11438,2475],{"class":195},[189,11440,8655],{"class":253},[189,11442,1332],{"class":210},[189,11444,8660],{"class":210},[189,11446,659],{"class":199},[189,11448,6733],{"class":195},[189,11450,1609],{"class":199},[189,11452,1612],{"class":195},[189,11454,8671],{"class":253},[189,11456,1332],{"class":210},[189,11458,8676],{"class":1314},[189,11460,1318],{"class":210},[189,11462,8681],{"class":1314},[189,11464,659],{"class":199},[189,11466,654],{"class":195},[189,11468,8688],{"class":210},[189,11470,659],{"class":199},[189,11472,6733],{"class":195},[189,11474,8695],{"class":199},[189,11476,8698],{"class":195},[189,11478,1332],{"class":210},[189,11480,1350],{"class":1314},[189,11482,214],{"class":195},[123,11484,11485,11492,11499],{"class":1644},[126,11486,11487,11489],{"data-cue":1089},[189,11488,1089],{"class":1092},[189,11490,11491],{"class":1651},"the Hadamard gate: half 0, half 1, and no value at all until it is measured",[126,11493,11494,11496],{"data-cue":292},[189,11495,292],{"class":1092},[189,11497,11498],{"class":1651},"one job per press of Run: press it again for another tally",[126,11500,11501,11503],{"data-cue":1241},[189,11502,1241],{"class":1092},[189,11504,11505],{"class":1651},"the share next to each bar, from lesson 1's second assignment",[12,11507,11508,11509,3077,11511,11513,11514,11516],{},"Two things changed in what the code does since lesson 1. The gate is ",[170,11510,423],{},[170,11512,8408],{},", and the bar loop prints each bar's share next to it, which was lesson 1's second assignment. The qubit, the bit, the measurement, the job and ",[170,11515,858],{}," do the same as before.",[111,11518,11520],{"id":11519},"run-the-circuit-three-presses","Run the circuit, three presses",[12,11522,11523],{},"A shot is one execution of the circuit, start to finish. A job is one press: you press Run on Qollab, choose a simulator in the dialog, then press the dialog's Run. This listing's job holds 1,000 shots. The Playground files one job per press, so a second tally needs a second press.",[12,11525,11526,11527,737,11529,809,11531,11533,11534,11536],{},"Predict the tally. Then open ",[16,11528,736],{"href":11169},[129,11530,740],{},[129,11532,8002],{}," under Remotely Run Simulators, and press ",[129,11535,752],{},". When the tally is in, note it and press twice more, choosing Aria 1 each time. Our first press took 17.9 seconds.",[116,11538],{"alt":11539,"caption":11540,"no":22,"src":11541},"The run console showing the Hadamard circuit drawn in text, the dict {'0': 487, '1': 513} and two bars of almost equal length with their shares, 48.7% and 51.3%","Our first press: 487 against 513.","\u002F_content\u002Fimages\u002Ffirst-circuits\u002F02-superposition.webp",[12,11543,11544,11545,1716,11548,1716,11551,11554],{},"Our three presses on 15 September 2026, on the Aria 1 noise model, came back ",[170,11546,11547],{},"{'0': 487, '1': 513}",[170,11549,11550],{},"{'0': 505, '1': 495}",[170,11552,11553],{},"{'0': 511, '1': 489}",". One circuit gave three different splits, none of them 500\u002F500.",[12,11556,11557],{},"The ideal is exactly one half each, and a finite sample rarely lands on it. Even a perfect simulator gives 500 of 1,000 only about one press in forty.",[12,11559,11560],{},"Fork the project now, the way lesson 1 showed, so the edits below land in your own copy. The three assignments build on each other in order.",[789,11562,11564,11568,11592],{"check":11563},"you have three single-shot tallies from three presses, each with one key and a count of 1, and an answer to the question.",[111,11565,11567],{"id":11566},"assignment-one-shot-at-a-time","Assignment: one shot at a time",[123,11569,11570,11576,11579,11589],{},[126,11571,11572,11573,753],{},"In your fork, set ",[170,11574,11575],{},"shots = 1",[126,11577,11578],{},"Press three times, and write down each tally as it comes in.",[126,11580,11581,11582,9145,11585,11588],{},"Each dict can only be ",[170,11583,11584],{},"{'0': 1}",[170,11586,11587],{},"{'1': 1}",". Try to reconstruct the 50\u002F50 split from your three dicts.",[126,11590,11591],{},"Write one sentence: what does one shot tell you about the weights inside the qubit?",[830,11593,11594],{"label":832},[12,11595,11596,11597,11599],{},"One shot tells you which answer came out this time. A single ",[170,11598,11587],{}," is consistent with odds of 50\u002F50 and with 99\u002F1, so it cannot tell them apart; only the shares across many shots estimate the weights' sizes.",[111,11601,11603],{"id":11602},"why-the-split-is-hardly-ever-exactly-half","Why the split is hardly ever exactly half",[12,11605,11606,11607,11609],{},"Over 1,000 shots of a fair split, the count of ",[170,11608,1089],{},"s scatters from press to press around its expected value, 500. The typical distance from 500, the standard deviation, is the square root of 1,000 × ½ × ½, which is about 16 shots. Nineteen presses in twenty land within twice that, between about 468 and 532.",[12,11611,11612],{},"The same arithmetic at other sizes gives the rule for choosing a shot count. At 100 shots the scatter is 5 shots, which is 5% of the sample. At 10,000 it is 50 shots, which is half a percent.",[12,11614,11615],{},"Multiplying the shots by a hundred divides the scatter, as a share, by ten: precision grows with the square root of the shot count.",[12,11617,11618],{},"The weights inside the qubit are the same on every press; only the sample changes. Sampling also explains lesson 1's two presses, where one caught a stray noise shot and the other did not.",[789,11620,11622,11626,11653,11656],{"check":11621},"you wrote down a band for each shot count before running, you have a tally at 100 shots and one at 10,000, and you can say whether each landed inside its band.",[111,11623,11625],{"id":11624},"assignment-make-the-split-move","Assignment: make the split move",[123,11627,11628,11637,11639,11642,11648,11650],{},[126,11629,4948,11630,11633,11634,11636],{},[170,11631,11632],{},"shots = 100",". Before you run, write down the band you expect the count of ",[170,11635,1089],{},"s to land in: the expected count, 50, plus or minus twice the scatter, where the scatter is half the square root of the shot count: for 100 shots, half of 10, which is 5. That gives 40 to 60.",[126,11638,8126],{},[126,11640,11641],{},"Note whether the count landed inside the band. Read the dict for the count and the Probabilities panel for the share.",[126,11643,4948,11644,11647],{},[170,11645,11646],{},"shots = 10000"," and work out its band the same way. The simulator is free at 10,000 shots too.",[126,11649,8126],{},[126,11651,11652],{},"Note whether the count landed inside its band.",[12,11654,11655],{},"One press cannot prove the rule: a press can only land inside or outside the band the rule predicts.",[830,11657,11658],{"label":832},[12,11659,11660],{},"At 10,000 shots the scatter is 50, so the band is 4,900 to 5,100: within a percentage point of half. At 100 shots the band is 40 to 60: within ten points. Either press can miss its band about once in twenty, so one miss does not break the rule.",[111,11662,11664],{"id":11663},"a-test-for-a-hidden-value","A test for a hidden value",[12,11666,11667,11668,11122,11670,11672],{},"A tally alone cannot tell a superposition from a coin: one shot gives one answer, with no way to predict it. Suppose the qubit after one Hadamard held a ",[170,11669,1165],{},[170,11671,1089],{}," all along, and the measurement only revealed it.",[12,11674,11675,11676,11678,11679,11681],{},"The Hadamard spreads a qubit at ",[170,11677,1165],{}," evenly, and it spreads a qubit at ",[170,11680,1089],{}," evenly too. So if the qubit really held a hidden value, a second Hadamard would spread that value out again. The tally after two Hadamards would be half and half, just like after one.",[12,11683,11684,11685,11687,11688,11690,11691,11693,11694,11696,11697,11699,11700,11702],{},"The Hadamard is its own inverse because of the signs. After one Hadamard the two weights are equal in size and share a sign. The second Hadamard sends the weight on ",[170,11686,1165],{}," to both answers with the same sign, and the weight on ",[170,11689,1089],{}," to both answers with the sign of its ",[170,11692,1089],{}," half flipped. On ",[170,11695,1089],{}," the two halves cancel; on ",[170,11698,1165],{}," they add. So everything collects on ",[170,11701,1165],{},", which a hidden value cannot produce.",[789,11704,11706,11710,11729],{"check":11705},"the tally is all 0, or all 0 but a few stray 1s.",[111,11707,11709],{"id":11708},"assignment-two-hadamards-in-a-row","Assignment: two Hadamards in a row",[123,11711,11712,11718,11723,11726],{},[126,11713,4948,11714,10873,11716,753],{},[170,11715,240],{},[170,11717,3147],{},[126,11719,10878,11720,11722],{},[170,11721,8116],{}," directly under the first, before the measurement.",[126,11724,11725],{},"Write down two predictions: half and half, from the hidden-value argument above, and the gate row's answer, its own inverse.",[126,11727,11728],{},"Decide which you believe, then run.",[830,11730,11731,11739,11802],{"label":832},[12,11732,11031,11733,11735,11736,11738],{},[170,11734,1165],{},", apart from a few stray ",[170,11737,1089],{},"s from the noise model. The hidden-value argument predicted half and half and was wrong.",[181,11740,11742],{"className":183,"code":11741,"language":185,"meta":22,"style":22},"qc = QuantumCircuit(1, 1)\nqc.h(0)\nqc.h(0)\nqc.measure(0, 0)\n",[170,11743,11744,11762,11774,11786],{"__ignoreMap":22},[189,11745,11746,11748,11750,11752,11754,11756,11758,11760],{"class":191,"line":192},[189,11747,196],{"class":195},[189,11749,200],{"class":199},[189,11751,533],{"class":203},[189,11753,230],{"class":195},[189,11755,1089],{"class":210},[189,11757,541],{"class":195},[189,11759,1089],{"class":210},[189,11761,214],{"class":195},[189,11763,11764,11766,11768,11770,11772],{"class":191,"line":23},[189,11765,2182],{"class":195},[189,11767,423],{"class":203},[189,11769,230],{"class":195},[189,11771,1165],{"class":210},[189,11773,214],{"class":195},[189,11775,11776,11778,11780,11782,11784],{"class":191,"line":250},[189,11777,2182],{"class":195},[189,11779,423],{"class":203},[189,11781,230],{"class":195},[189,11783,1165],{"class":210},[189,11785,214],{"class":195},[189,11787,11788,11790,11792,11794,11796,11798,11800],{"class":191,"line":281},[189,11789,2182],{"class":195},[189,11791,1203],{"class":203},[189,11793,230],{"class":195},[189,11795,1165],{"class":210},[189,11797,541],{"class":195},[189,11799,1165],{"class":210},[189,11801,214],{"class":195},[12,11803,11804,11805,11807,11808,11810,11811,11813],{},"The weight on ",[170,11806,1089],{}," reached the measurement as two halves with opposite signs, and they cancelled. A qubit that started at ",[170,11809,1089],{}," would give the same even tally after one Hadamard, with its two weights' signs opposite, and the second Hadamard would send everything to ",[170,11812,1089],{}," instead. Lesson 5 uses this add-and-cancel step for its search.",[12,11815,11816],{},"Lesson 3 adds a second qubit and the CNOT, a gate that acts on two qubits at once.",[884,11818,11819],{},"html pre.shiki code .sV9Aq, html code.shiki .sV9Aq{--shiki-default:#7F848E;--shiki-default-font-style:italic}html pre.shiki code .seHd6, html code.shiki .seHd6{--shiki-default:#C678DD}html pre.shiki code .sn6KH, html code.shiki .sn6KH{--shiki-default:#ABB2BF}html pre.shiki code .sjrmR, html code.shiki .sjrmR{--shiki-default:#56B6C2}html pre.shiki code .sVC51, html code.shiki .sVC51{--shiki-default:#D19A66}html pre.shiki code .sVbv2, html code.shiki .sVbv2{--shiki-default:#61AFEF}html pre.shiki code .s_ZVi, html code.shiki .s_ZVi{--shiki-default:#E06C75;--shiki-default-font-style:italic}html pre.shiki code .subq3, html code.shiki .subq3{--shiki-default:#98C379}html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}",{"title":22,"searchDepth":23,"depth":23,"links":11821},[11822,11823,11824,11825,11826,11827,11828,11829],{"id":11115,"depth":23,"text":11116},{"id":7443,"depth":23,"text":7444},{"id":11519,"depth":23,"text":11520},{"id":11566,"depth":23,"text":11567},{"id":11602,"depth":23,"text":11603},{"id":11624,"depth":23,"text":11625},{"id":11663,"depth":23,"text":11664},{"id":11708,"depth":23,"text":11709},[26,27,19,11100],[],{"username":7,"name":30,"role":31,"avatar":32},"The Hadamard gate, and why 1,000 shots almost never split exactly 500\u002F500.","The Hadamard gate leaves a fresh qubit with no value until it is measured. Run it three times at 1,000 shots and see how far each tally lands from 500.",{"image":11836,"alt":11837},"\u002F_content\u002Fimages\u002Ffirst-circuits\u002F02-circuit-panel.webp","The Playground's Circuit panel: qubit q0 runs through an H gate into a measurement.",{},{"slug":11840,"title":11841,"desc":11842},"\u002Fblog\u002Flearn\u002Fprogramming-your-first-quantum-circuits\u002Ftwo-qubits","3 · Two qubits and the Bell pair","The CNOT gate flips one qubit when another is 1. Use it to build a Bell pair, and learn how Qiskit orders a two-bit string.","\u002Fblog\u002Flearn\u002Fprogramming-your-first-quantum-circuits\u002Fsuperposition","10 min read",[],{"title":11847,"description":11848},"The Hadamard gate · Programming your first quantum circuits","Put a qubit in superposition with the Hadamard gate, run it on the IonQ simulator and see why 1,000 shots almost never split exactly in half. Lesson 2, free.","blog\u002Flearn\u002Fprogramming-your-first-quantum-circuits\u002Fsuperposition",[],"zf773RKoq5YhySZ1oFxo6sj4MIQgICF3et0xTX1VfDI",{"id":11853,"title":11854,"authors":11855,"body":11856,"breadcrumb":12858,"builders":12859,"byline":12860,"category":33,"categoryName":33,"challenge":33,"courseAuthor":33,"courseLead":33,"dek":11842,"description":12861,"draft":46,"extension":47,"eyebrow":33,"featured":46,"finish":33,"fork":33,"group":33,"groupName":33,"hero":12862,"heroAlt":33,"heroCta":33,"heroImage":33,"homepageFeatured":46,"kind":903,"lessonCount":557,"meta":12865,"navigation":50,"newsItems":33,"next":12866,"ogImage":33,"order":250,"outcomes":33,"path":11840,"prerequisite":33,"prerequisiteLinks":33,"publishDate":7348,"readingTime":11090,"related":12868,"relatedProjects":33,"section":33,"seo":12869,"stem":12872,"tags":12873,"track":60,"trackName":19,"__hash__":12874},"blog\u002Fblog\u002Flearn\u002Fprogramming-your-first-quantum-circuits\u002Ftwo-qubits.md","Two qubits and the Bell pair",[7],{"type":9,"value":11857,"toc":12847},[11858,11861,11864,11868,11877,11883,11910,11929,11931,11936,11939,12029,12032,12412,12416,12437,12442,12454,12462,12466,12476,12490,12507,12631,12635,12643,12705,12709,12714,12837,12844],[12,11859,11860],{},"A Bell pair is two qubits whose answers are each uncertain and still agree with each other, on every shot of a perfect simulator. The circuit below builds one with a Hadamard and a CNOT, a gate that acts on two qubits at once.",[12,11862,11863],{},"The answer now has two characters, and Qiskit writes them with qubit 0 on the right; the gate row on two-character answers below explains the order.",[111,11865,11867],{"id":11866},"a-gate-that-acts-on-two-qubits","A gate that acts on two qubits",[12,11869,11870,11871,11873,11874,11876],{},"Every gate so far acted on one qubit. The CNOT acts on two: a control and a target. The CNOT flips the target only if the control is ",[170,11872,1089],{},"; with the control at ",[170,11875,1165],{}," it does nothing.",[12,11878,11879,11880,11882],{},"On its own the rule is a plain conditional, the kind an ordinary program writes with an ",[170,11881,4981],{},". When the control is in superposition, the CNOT applies its rule to each of the control's two options.",[7431,11884,11886],{"name":11885,"token":710},"The CNOT gate",[12,11887,11888,11891,11892,11894,11895,11897,11898,11900,11901,9145,11903,11905,11906,9145,11908,753],{},[170,11889,11890],{},"cx(control, target)",". Flips the target if the control is ",[170,11893,1089],{},", leaves it alone if the control is ",[170,11896,1165],{},". Applied to a target at ",[170,11899,1165],{}," while the control is in superposition, it makes the two qubits agree: measure them and, with no noise, you get ",[170,11902,8207],{},[170,11904,8215],{}," and never ",[170,11907,7105],{},[170,11909,8212],{},[7431,11911,11913],{"name":11912,"token":8207},"Two-character answers",[12,11914,11915,11916,11919,11920,11922,11923,11925,11926,11928],{},"With two ordinary bits, classical bits in Qiskit's words, every shot reads two characters, one per bit. Qiskit writes bit 0, which here holds qubit 0, on the ",[129,11917,11918],{},"right",": the string ",[170,11921,8212],{}," means qubit 1 read ",[170,11924,1089],{}," and qubit 0 read ",[170,11927,1165],{},". Read the string from the right to read it in qubit order.",[111,11930,7444],{"id":7443},[116,11932],{"alt":11933,"caption":11934,"no":22,"src":11935},"Two wires, q0 and q1, both starting at 0. Qubit 0 passes through an H gate, then a CNOT joins the wires with a dot on q0 and a crossed circle on q1. Two meters, one per wire, drop into two bit wires. The answer is 00 or 11, half the time each.","The CNOT is drawn as a dot on the control and a crossed circle on the target, joined by a line. After it, 00 and 11 are the only options the two wires hold.","\u002F_content\u002Fimages\u002Ffirst-circuits\u002Ftwo-qubit-bell-circuit.svg",[12,11937,11938],{},"The circuit is two gates and two measurements:",[181,11940,11942],{"className":183,"code":11941,"language":185,"meta":22,"style":22},"qc = QuantumCircuit(2, 2)     # two qubits, two ordinary bits\nqc.h(0)                       # qubit 0 into superposition\nqc.cx(0, 1)                   # CNOT: control qubit 0, target qubit 1\nqc.measure([0, 1], [0, 1])    # qubit 0 into bit 0, qubit 1 into bit 1\n",[170,11943,11944,11966,11981,12001],{"__ignoreMap":22},[189,11945,11946,11948,11950,11952,11954,11956,11958,11960,11963],{"class":191,"line":192},[189,11947,196],{"class":195},[189,11949,200],{"class":199},[189,11951,533],{"class":203},[189,11953,230],{"class":195},[189,11955,292],{"class":210},[189,11957,541],{"class":195},[189,11959,292],{"class":210},[189,11961,11962],{"class":195},")     ",[189,11964,11965],{"class":318},"# two qubits, two ordinary bits\n",[189,11967,11968,11970,11972,11974,11976,11978],{"class":191,"line":23},[189,11969,2182],{"class":195},[189,11971,423],{"class":203},[189,11973,230],{"class":195},[189,11975,1165],{"class":210},[189,11977,7501],{"class":195},[189,11979,11980],{"class":318},"# qubit 0 into superposition\n",[189,11982,11983,11985,11987,11989,11991,11993,11995,11998],{"class":191,"line":250},[189,11984,2182],{"class":195},[189,11986,710],{"class":203},[189,11988,230],{"class":195},[189,11990,1165],{"class":210},[189,11992,541],{"class":195},[189,11994,1089],{"class":210},[189,11996,11997],{"class":195},")                   ",[189,11999,12000],{"class":318},"# CNOT: control qubit 0, target qubit 1\n",[189,12002,12003,12005,12007,12009,12011,12013,12015,12017,12019,12021,12023,12026],{"class":191,"line":281},[189,12004,2182],{"class":195},[189,12006,1203],{"class":203},[189,12008,5273],{"class":195},[189,12010,1165],{"class":210},[189,12012,541],{"class":195},[189,12014,1089],{"class":210},[189,12016,6669],{"class":195},[189,12018,1165],{"class":210},[189,12020,541],{"class":195},[189,12022,1089],{"class":210},[189,12024,12025],{"class":195},"])    ",[189,12027,12028],{"class":318},"# qubit 0 into bit 0, qubit 1 into bit 1\n",[12,12030,12031],{},"The plumbing is lesson 2's, unchanged. The keys of the counts dict are two characters now, and the bar loop prints one line per string that was read.",[175,12033,12036],{"name":12034,"no-picker":22,"run-href":12035,"tag":985},"two_qubits.py","\u002Fu\u002Fqollab\u002Flearn-two-qubits",[181,12037,12039],{"className":183,"code":12038,"language":185,"meta":22,"style":22},"# 'backend' already exists when this runs: it is whatever you pick in the Run Experiment dialog.\nfrom qiskit import QuantumCircuit\nfrom qiskit.providers.jobstatus import JobStatus\nimport time\n\nshots = 1000\n\nqc = QuantumCircuit(2, 2)\nqc.h(0)\nqc.cx(0, 1)\nqc.measure([0, 1], [0, 1])\nprint(qc)\n\njob = backend.run(qc, shots=shots)\nwhile job.status() not in (JobStatus.DONE, JobStatus.ERROR, JobStatus.CANCELLED):\n    time.sleep(5)\n\ncounts = job.result().get_counts()\nprint(counts)\nfor bits, n in sorted(counts.items()):\n    print(f\"{bits}: {n:4d}  {100 * n \u002F shots:5.1f}%  {'█' * (50 * n \u002F\u002F shots)}\")\n",[170,12040,12041,12047,12059,12071,12079,12085,12095,12101,12121,12135,12153,12179,12187,12193,12213,12243,12257,12263,12281,12289,12307,12375],{"__ignoreMap":22},[189,12042,12043,12045],{"class":191,"line":192},[189,12044,997],{"class":995,"aria-hidden":996},[189,12046,1000],{"class":318},[189,12048,12049,12051,12053,12055,12057],{"class":191,"line":23},[189,12050,997],{"class":995,"aria-hidden":996},[189,12052,1007],{"class":253},[189,12054,1025],{"class":195},[189,12056,1013],{"class":253},[189,12058,1030],{"class":195},[189,12060,12061,12063,12065,12067,12069],{"class":191,"line":250},[189,12062,997],{"class":995,"aria-hidden":996},[189,12064,1007],{"class":253},[189,12066,1053],{"class":195},[189,12068,1013],{"class":253},[189,12070,1058],{"class":195},[189,12072,12073,12075,12077],{"class":191,"line":281},[189,12074,997],{"class":995,"aria-hidden":996},[189,12076,1013],{"class":253},[189,12078,1067],{"class":195},[189,12080,12081,12083],{"class":191,"line":51},[189,12082,997],{"class":995,"aria-hidden":996},[189,12084,1074],{},[189,12086,12087,12089,12091,12093],{"class":191,"line":557},[189,12088,997],{"class":995,"aria-hidden":996},[189,12090,1081],{"class":195},[189,12092,200],{"class":199},[189,12094,1086],{"class":210},[189,12096,12097,12099],{"class":191,"line":579},[189,12098,997],{"class":995,"aria-hidden":996},[189,12100,1074],{},[189,12102,12103,12105,12107,12109,12111,12113,12115,12117,12119],{"class":191,"data-cue":1089,"line":590},[189,12104,1089],{"class":1092},[189,12106,196],{"class":195},[189,12108,200],{"class":199},[189,12110,533],{"class":203},[189,12112,230],{"class":195},[189,12114,292],{"class":210},[189,12116,541],{"class":195},[189,12118,292],{"class":210},[189,12120,214],{"class":195},[189,12122,12123,12125,12127,12129,12131,12133],{"class":191,"data-cue":292,"line":595},[189,12124,292],{"class":1092},[189,12126,2182],{"class":195},[189,12128,423],{"class":203},[189,12130,230],{"class":195},[189,12132,1165],{"class":210},[189,12134,214],{"class":195},[189,12136,12137,12139,12141,12143,12145,12147,12149,12151],{"class":191,"data-cue":1241,"line":601},[189,12138,1241],{"class":1092},[189,12140,2182],{"class":195},[189,12142,710],{"class":203},[189,12144,230],{"class":195},[189,12146,1165],{"class":210},[189,12148,541],{"class":195},[189,12150,1089],{"class":210},[189,12152,214],{"class":195},[189,12154,12155,12157,12159,12161,12163,12165,12167,12169,12171,12173,12175,12177],{"class":191,"data-cue":700,"line":618},[189,12156,700],{"class":1092},[189,12158,2182],{"class":195},[189,12160,1203],{"class":203},[189,12162,5273],{"class":195},[189,12164,1165],{"class":210},[189,12166,541],{"class":195},[189,12168,1089],{"class":210},[189,12170,6669],{"class":195},[189,12172,1165],{"class":210},[189,12174,541],{"class":195},[189,12176,1089],{"class":210},[189,12178,5733],{"class":195},[189,12180,12181,12183,12185],{"class":191,"line":665},[189,12182,997],{"class":995,"aria-hidden":996},[189,12184,1306],{"class":199},[189,12186,2572],{"class":195},[189,12188,12189,12191],{"class":191,"line":676},[189,12190,997],{"class":995,"aria-hidden":996},[189,12192,1074],{},[189,12194,12195,12197,12199,12201,12203,12205,12207,12209,12211],{"class":191,"line":681},[189,12196,997],{"class":995,"aria-hidden":996},[189,12198,219],{"class":195},[189,12200,200],{"class":199},[189,12202,224],{"class":195},[189,12204,227],{"class":203},[189,12206,2593],{"class":195},[189,12208,240],{"class":239},[189,12210,200],{"class":199},[189,12212,1457],{"class":195},[189,12214,12215,12217,12219,12221,12223,12225,12227,12229,12231,12233,12235,12237,12239,12241],{"class":191,"line":687},[189,12216,997],{"class":995,"aria-hidden":996},[189,12218,254],{"class":253},[189,12220,257],{"class":195},[189,12222,260],{"class":203},[189,12224,263],{"class":195},[189,12226,1473],{"class":253},[189,12228,1476],{"class":253},[189,12230,1479],{"class":195},[189,12232,275],{"class":210},[189,12234,1484],{"class":195},[189,12236,1487],{"class":210},[189,12238,1484],{"class":195},[189,12240,1492],{"class":210},[189,12242,576],{"class":195},[189,12244,12245,12247,12249,12251,12253,12255],{"class":191,"line":705},[189,12246,997],{"class":995,"aria-hidden":996},[189,12248,284],{"class":195},[189,12250,287],{"class":203},[189,12252,230],{"class":195},[189,12254,538],{"class":210},[189,12256,214],{"class":195},[189,12258,12259,12261],{"class":191,"line":1195},[189,12260,997],{"class":995,"aria-hidden":996},[189,12262,1074],{},[189,12264,12265,12267,12269,12271,12273,12275,12277,12279],{"class":191,"line":1216},[189,12266,997],{"class":995,"aria-hidden":996},[189,12268,299],{"class":195},[189,12270,200],{"class":199},[189,12272,257],{"class":195},[189,12274,306],{"class":203},[189,12276,309],{"class":195},[189,12278,312],{"class":203},[189,12280,1536],{"class":195},[189,12282,12283,12285,12287],{"class":191,"line":1227},[189,12284,997],{"class":995,"aria-hidden":996},[189,12286,1306],{"class":199},[189,12288,2676],{"class":195},[189,12290,12291,12293,12295,12297,12299,12301,12303,12305],{"class":191,"data-cue":538,"line":1234},[189,12292,538],{"class":1092},[189,12294,560],{"class":253},[189,12296,8617],{"class":195},[189,12298,566],{"class":253},[189,12300,6743],{"class":199},[189,12302,6746],{"class":195},[189,12304,6749],{"class":203},[189,12306,6896],{"class":195},[189,12308,12309,12311,12313,12315,12317,12319,12321,12323,12325,12327,12329,12331,12333,12335,12337,12339,12341,12343,12345,12347,12349,12351,12353,12355,12357,12359,12361,12363,12365,12367,12369,12371,12373],{"class":191,"line":1242},[189,12310,997],{"class":995,"aria-hidden":996},[189,12312,6903],{"class":199},[189,12314,230],{"class":195},[189,12316,1311],{"class":253},[189,12318,1350],{"class":1314},[189,12320,1318],{"class":210},[189,12322,8644],{"class":195},[189,12324,1332],{"class":210},[189,12326,3129],{"class":1314},[189,12328,1318],{"class":210},[189,12330,2475],{"class":195},[189,12332,8655],{"class":253},[189,12334,1332],{"class":210},[189,12336,8660],{"class":210},[189,12338,659],{"class":199},[189,12340,6733],{"class":195},[189,12342,1609],{"class":199},[189,12344,1612],{"class":195},[189,12346,8671],{"class":253},[189,12348,1332],{"class":210},[189,12350,8676],{"class":1314},[189,12352,1318],{"class":210},[189,12354,8681],{"class":1314},[189,12356,659],{"class":199},[189,12358,654],{"class":195},[189,12360,8688],{"class":210},[189,12362,659],{"class":199},[189,12364,6733],{"class":195},[189,12366,8695],{"class":199},[189,12368,8698],{"class":195},[189,12370,1332],{"class":210},[189,12372,1350],{"class":1314},[189,12374,214],{"class":195},[123,12376,12377,12384,12391,12398,12405],{"class":1644},[126,12378,12379,12381],{"data-cue":1089},[189,12380,1089],{"class":1092},[189,12382,12383],{"class":1651},"two qubits, two ordinary bits",[126,12385,12386,12388],{"data-cue":292},[189,12387,292],{"class":1092},[189,12389,12390],{"class":1651},"qubit 0 into superposition, as in lesson 2",[126,12392,12393,12395],{"data-cue":1241},[189,12394,1241],{"class":1092},[189,12396,12397],{"class":1651},"the CNOT: flip qubit 1 if qubit 0 is 1, and it acts inside the superposition",[126,12399,12400,12402],{"data-cue":700},[189,12401,700],{"class":1092},[189,12403,12404],{"class":1651},"read both: qubit 0 into bit 0, qubit 1 into bit 1",[126,12406,12407,12409],{"data-cue":538},[189,12408,538],{"class":1092},[189,12410,12411],{"class":1651},"each key is now two characters: bit 1 on the left, bit 0 on the right",[111,12413,12415],{"id":12414},"run-the-circuit","Run the circuit",[12,12417,12418,12419,541,12421,541,12423,1791,12425,12427,12428,737,12430,809,12432,814,12434,12436],{},"Predict the tally first. Four strings are possible, ",[170,12420,8207],{},[170,12422,7105],{},[170,12424,8212],{},[170,12426,8215],{},". Which of them will you see, and in what shares? Then open ",[16,12429,736],{"href":12035},[129,12431,740],{},[129,12433,8002],{},[129,12435,752],{},". Then fork it, the way lesson 1 showed, so the edits below land in your own copy.",[116,12438],{"alt":12439,"caption":12440,"no":22,"src":12441},"The run console: the two-qubit circuit drawn in text, the counts dict, two long bars for 00 and 11, and lines for 01 and 10 that show a few shots and no bar","Two of the four strings carry almost all the shots. The 01 and 10 lines show their counts but no bar, because a bar is fifty characters for the full shot count and four shots in a thousand round to none.","\u002F_content\u002Fimages\u002Ffirst-circuits\u002F03-two-qubits.webp",[12,12443,8745,12444,12447,12448,12450,12451,12453],{},[170,12445,12446],{},"{'00': 512, '01': 3, '10': 1, '11': 484}",": 51.2% ",[170,12449,8207],{},", 48.4% ",[170,12452,8215],{},", and four shots in a thousand where the two qubits disagreed.",[12,12455,12456,12457,1791,12459,12461],{},"The few ",[170,12458,7105],{},[170,12460,8212],{}," shots come from the noise model; on a perfect simulator the pair never disagrees.",[111,12463,12465],{"id":12464},"why-the-pair-always-agrees","Why the pair always agrees",[12,12467,12468,12469,1791,12471,12473,12474,753],{},"After the Hadamard, qubit 0 carries two options, ",[170,12470,1165],{},[170,12472,1089],{},", with no value chosen. The CNOT's rule is: flip qubit 1 wherever qubit 0 is ",[170,12475,1089],{},[12,12477,12478,12479,12481,12482,12484,12485,12487,12488,753],{},"The CNOT applies that rule to both options at once. Where qubit 0 is ",[170,12480,1165],{},", qubit 1 stays ",[170,12483,1165],{},"; where qubit 0 is ",[170,12486,1089],{},", qubit 1 becomes ",[170,12489,1089],{},[12,12491,12492,12493,9145,12495,12497,12498,9145,12500,12502,12503,753],{},"So the circuit never holds ",[170,12494,7105],{},[170,12496,8212],{}," as an option, and measuring cannot produce them. The circuit holds ",[170,12499,8207],{},[170,12501,8215],{},", weighted half and half, and the measurement returns one of those. Two qubits in that state are called a Bell pair, the smallest case of ",[16,12504,12506],{"href":12505},"\u002Flearn\u002Fquantum-entanglement","entanglement",[789,12508,12510,12514,12539],{"check":12509},"every shot reads 11, bar a few strays from the noise model.",[111,12511,12513],{"id":12512},"assignment-make-the-cnot-copy-a-plain-1","Assignment: make the CNOT copy a plain 1",[123,12515,12516,12528,12534,12536],{},[126,12517,12518,12519,4942,12521,12524,12525,12527],{},"In your fork, replace ",[170,12520,8116],{},[170,12522,12523],{},"qc.x(0)",", so qubit 0 is a definite ",[170,12526,1089],{}," when the CNOT sees it. There is no superposition now, so the CNOT has one case to handle.",[126,12529,12530,12531,12533],{},"Apply the gate row's rule, flip the target if the control is ",[170,12532,1089],{},", and work out what each of the two measurements reads. Write the answer as a string with qubit 0 on the right.",[126,12535,8126],{},[126,12537,12538],{},"Compare the tally with your answer.",[830,12540,12541,12616],{"label":832},[181,12542,12544],{"className":183,"code":12543,"language":185,"meta":22,"style":22},"qc = QuantumCircuit(2, 2)\nqc.x(0)\nqc.cx(0, 1)\nqc.measure([0, 1], [0, 1])\n",[170,12545,12546,12564,12576,12592],{"__ignoreMap":22},[189,12547,12548,12550,12552,12554,12556,12558,12560,12562],{"class":191,"line":192},[189,12549,196],{"class":195},[189,12551,200],{"class":199},[189,12553,533],{"class":203},[189,12555,230],{"class":195},[189,12557,292],{"class":210},[189,12559,541],{"class":195},[189,12561,292],{"class":210},[189,12563,214],{"class":195},[189,12565,12566,12568,12570,12572,12574],{"class":191,"line":23},[189,12567,2182],{"class":195},[189,12569,8408],{"class":203},[189,12571,230],{"class":195},[189,12573,1165],{"class":210},[189,12575,214],{"class":195},[189,12577,12578,12580,12582,12584,12586,12588,12590],{"class":191,"line":250},[189,12579,2182],{"class":195},[189,12581,710],{"class":203},[189,12583,230],{"class":195},[189,12585,1165],{"class":210},[189,12587,541],{"class":195},[189,12589,1089],{"class":210},[189,12591,214],{"class":195},[189,12593,12594,12596,12598,12600,12602,12604,12606,12608,12610,12612,12614],{"class":191,"line":281},[189,12595,2182],{"class":195},[189,12597,1203],{"class":203},[189,12599,5273],{"class":195},[189,12601,1165],{"class":210},[189,12603,541],{"class":195},[189,12605,1089],{"class":210},[189,12607,6669],{"class":195},[189,12609,1165],{"class":210},[189,12611,541],{"class":195},[189,12613,1089],{"class":210},[189,12615,5733],{"class":195},[12,12617,12618,12619,12621,12622,12624,12625,12627,12628,12630],{},"Qubit 0 is ",[170,12620,1089],{},", so the CNOT flips qubit 1 to ",[170,12623,1089],{},". Both read ",[170,12626,1089],{}," and every shot is ",[170,12629,8215],{},". With a definite control the CNOT is an ordinary conditional; the previous press was the same gate with a control in superposition.",[111,12632,12634],{"id":12633},"which-character-is-which-qubit","Which character is which qubit",[12,12636,12637,12638,1791,12640,12642],{},"In the Bell pair ",[170,12639,8207],{},[170,12641,8215],{}," read the same in either bit order, so the order never shows. The next circuit produces a string where the order matters; predict the string before you run.",[789,12644,12646,12650,12680],{"check":12645},"you predicted one of 01 and 10, and the tally shows the string you predicted, bar the noise.",[111,12647,12649],{"id":12648},"assignment-find-qubit-0-in-the-string","Assignment: find qubit 0 in the string",[123,12651,12652,12662,12665,12671,12678],{},[126,12653,12654,12655,12657,12658,12661],{},"Starting from the version with ",[170,12656,12523],{},", change that line to ",[170,12659,12660],{},"qc.x(1)"," and leave the CNOT in.",[126,12663,12664],{},"Work out whether the CNOT changes its target, now that its control, qubit 0, is never flipped.",[126,12666,12667,12668,12670],{},"Work out which character the qubit that reads ",[170,12669,1089],{}," is written in, by the gate row on two-character answers.",[126,12672,12673,12674,9145,12676,753],{},"Write down ",[170,12675,7105],{},[170,12677,8212],{},[126,12679,8126],{},[830,12681,12682,12699],{"label":832},[12,12683,12684,12685,12687,12688,12690,12691,12693,12694,12696,12697,753],{},"Qubit 0 stays ",[170,12686,1165],{},", so the CNOT does nothing to qubit 1, which keeps the ",[170,12689,1089],{}," the X gate gave it. Qubit 1 is ",[170,12692,1089],{}," and qubit 0 is ",[170,12695,1165],{},", and Qiskit writes qubit 0 on the right: the string is ",[170,12698,8212],{},[12,12700,12701,12702,12704],{},"If you expected ",[170,12703,7105],{},", you read the string left to right in qubit order. Read the tally from the right, qubit 0 first.",[111,12706,12708],{"id":12707},"measuring-is-per-qubit","Measuring is per qubit",[12,12710,12711,12712,753],{},"The pair agrees when both qubits are measured. Measuring only one of them is a valid circuit too, and the tally still shows two characters, because there are still two bits. A bit that no measurement writes to stays at ",[170,12713,1165],{},[789,12715,12717,12721,12748],{"check":12716},"the tally shows two strings, 00 and 01, about half each, and nothing else.",[111,12718,12720],{"id":12719},"assignment-read-only-one-qubit-of-the-pair","Assignment: read only one qubit of the pair",[123,12722,12723,12733,12740,12743,12746],{},[126,12724,3281,12725,10873,12727,12729,12730,12732],{},[170,12726,12660],{},[170,12728,8116],{},", so the circuit is the Bell pair again: ",[170,12731,8116],{},", then the CNOT.",[126,12734,12735,12736,12739],{},"Replace the measurement line with ",[170,12737,12738],{},"qc.measure(0, 0)",", so only qubit 0 is read.",[126,12741,12742],{},"Work out what qubit 0 alone reads over many shots, given it was put into superposition, and what bit 1 holds when nothing ever writes to it.",[126,12744,12745],{},"Put the two together into two-character strings, qubit 0 on the right.",[126,12747,8126],{},[830,12749,12750,12817],{"label":832},[181,12751,12753],{"className":183,"code":12752,"language":185,"meta":22,"style":22},"qc = QuantumCircuit(2, 2)\nqc.h(0)\nqc.cx(0, 1)\nqc.measure(0, 0)\n",[170,12754,12755,12773,12785,12801],{"__ignoreMap":22},[189,12756,12757,12759,12761,12763,12765,12767,12769,12771],{"class":191,"line":192},[189,12758,196],{"class":195},[189,12760,200],{"class":199},[189,12762,533],{"class":203},[189,12764,230],{"class":195},[189,12766,292],{"class":210},[189,12768,541],{"class":195},[189,12770,292],{"class":210},[189,12772,214],{"class":195},[189,12774,12775,12777,12779,12781,12783],{"class":191,"line":23},[189,12776,2182],{"class":195},[189,12778,423],{"class":203},[189,12780,230],{"class":195},[189,12782,1165],{"class":210},[189,12784,214],{"class":195},[189,12786,12787,12789,12791,12793,12795,12797,12799],{"class":191,"line":250},[189,12788,2182],{"class":195},[189,12790,710],{"class":203},[189,12792,230],{"class":195},[189,12794,1165],{"class":210},[189,12796,541],{"class":195},[189,12798,1089],{"class":210},[189,12800,214],{"class":195},[189,12802,12803,12805,12807,12809,12811,12813,12815],{"class":191,"line":281},[189,12804,2182],{"class":195},[189,12806,1203],{"class":203},[189,12808,230],{"class":195},[189,12810,1165],{"class":210},[189,12812,541],{"class":195},[189,12814,1165],{"class":210},[189,12816,214],{"class":195},[12,12818,12819,12820,9145,12822,12824,12825,12827,12828,1791,12830,12832,12833,1791,12835,753],{},"Qubit 0 reads ",[170,12821,1165],{},[170,12823,1089],{},", half each. Bit 1 stays ",[170,12826,1165],{},". So the tally is ",[170,12829,8207],{},[170,12831,7105],{},", about half each. Qubit 1 was still in the pair; the circuit did not measure it. Measure both again and the tally goes back to ",[170,12834,8207],{},[170,12836,8215],{},[12,12838,12839,12840,3284,12842,753],{},"Lesson 4's RY gate takes an angle and moves a qubit part of the way from ",[170,12841,1165],{},[170,12843,1089],{},[884,12845,12846],{},"html pre.shiki code .sn6KH, html code.shiki .sn6KH{--shiki-default:#ABB2BF}html pre.shiki code .sjrmR, html code.shiki .sjrmR{--shiki-default:#56B6C2}html pre.shiki code .sVbv2, html code.shiki .sVbv2{--shiki-default:#61AFEF}html pre.shiki code .sVC51, html code.shiki .sVC51{--shiki-default:#D19A66}html pre.shiki code .sV9Aq, html code.shiki .sV9Aq{--shiki-default:#7F848E;--shiki-default-font-style:italic}html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html pre.shiki code .seHd6, html code.shiki .seHd6{--shiki-default:#C678DD}html pre.shiki code .s_ZVi, html code.shiki .s_ZVi{--shiki-default:#E06C75;--shiki-default-font-style:italic}html pre.shiki code .subq3, html code.shiki .subq3{--shiki-default:#98C379}",{"title":22,"searchDepth":23,"depth":23,"links":12848},[12849,12850,12851,12852,12853,12854,12855,12856,12857],{"id":11866,"depth":23,"text":11867},{"id":7443,"depth":23,"text":7444},{"id":12414,"depth":23,"text":12415},{"id":12464,"depth":23,"text":12465},{"id":12512,"depth":23,"text":12513},{"id":12633,"depth":23,"text":12634},{"id":12648,"depth":23,"text":12649},{"id":12707,"depth":23,"text":12708},{"id":12719,"depth":23,"text":12720},[26,27,19,11854],[],{"username":7,"name":30,"role":31,"avatar":32},"Add a second qubit and the CNOT, a gate that flips one qubit when the other is 1. Build a Bell pair with it and read its two-character answers in Qiskit.",{"image":12863,"alt":12864},"\u002F_content\u002Fimages\u002Ffirst-circuits\u002F03-circuit-panel.webp","The Playground's Circuit panel: an H gate on q0, a CNOT from q0 down to q1, and a measurement on each qubit.",{},{"slug":11089,"title":12867,"desc":11081},"4 · Rotate a qubit by any angle",[],{"title":12870,"description":12871},"The Bell pair in Qiskit · Programming your first quantum circuits","Build a Bell pair in Qiskit with a Hadamard and a CNOT, run it on the IonQ simulator, and learn to read two-qubit results. Lesson 3 of a free six-lesson course.","blog\u002Flearn\u002Fprogramming-your-first-quantum-circuits\u002Ftwo-qubits",[],"rQTT7lWTzZgUavb5rk6ixRU6ukcanA3c0xUdHfZwjzY",{"id":12876,"title":12877,"authors":12878,"body":12879,"breadcrumb":13985,"builders":13986,"byline":13987,"category":33,"categoryName":33,"challenge":33,"courseAuthor":33,"courseLead":33,"dek":13988,"description":13988,"draft":46,"extension":47,"eyebrow":33,"featured":46,"finish":33,"fork":33,"group":33,"groupName":33,"hero":13989,"heroAlt":33,"heroCta":33,"heroImage":33,"homepageFeatured":46,"kind":903,"lessonCount":557,"meta":13992,"navigation":50,"newsItems":33,"next":13993,"ogImage":33,"order":192,"outcomes":33,"path":13995,"prerequisite":33,"prerequisiteLinks":33,"publishDate":7348,"readingTime":11090,"related":13996,"relatedProjects":33,"section":33,"seo":13997,"stem":14000,"tags":14001,"track":60,"trackName":19,"__hash__":14002},"blog\u002Fblog\u002Flearn\u002Fprogramming-your-first-quantum-circuits\u002Fyour-first-circuit.md","Your first circuit",[7],{"type":9,"value":12880,"toc":13971},[12881,12884,12887,12891,12894,12909,12923,12935,12950,12956,12958,12961,12966,12969,13032,13038,13047,13392,13396,13402,13420,13425,13440,13445,13453,13457,13462,13481,13490,13493,13496,13500,13517,13528,13532,13540,13543,13548,13669,13673,13676,13679,13827,13831,13841,13855,13959,13963,13969],[12,12882,12883],{},"A quantum circuit is a program whose output is a tally: how many times each possible answer came up when the circuit was run over and over.",[12,12885,12886],{},"The circuit below has one gate. You run it on a simulator of IonQ's Aria 1 machine from your browser and read the tally. Then you do three assignments: one changes the circuit and two change what it prints. The assignments need a free Qollab account, because they run in your own copy of the project; signing in with Google or GitHub creates one, as the first step below.",[111,12888,12890],{"id":12889},"what-a-circuit-is","What a circuit is",[12,12892,12893],{},"An ordinary program moves bits through logic gates and prints the result. A quantum circuit moves qubits through quantum gates, then measures them, and the measurement produces the bit you can print.",[12,12895,12896,12897,12900,12901,12903,12904,9145,12906,12908],{},"A ",[16,12898,12899],{"href":10947},"qubit"," starts every run at ",[170,12902,1165],{},". Gates change the qubit, in order. A measurement reads it and copies the answer, ",[170,12905,1165],{},[170,12907,1089],{},", into an ordinary bit, and the bits come back to you. The listing below uses four terms:",[7431,12910,12912],{"name":12911,"token":12899},"The qubit",[12,12913,12914,12915,12917,12918,12920,12921,753],{},"The thing the gates act on. It starts at ",[170,12916,1165],{}," on every run. In code it is a position number, qubit ",[170,12919,1165],{},". The ordinary bit the measurement writes to has its own position number, bit ",[170,12922,1165],{},[7431,12924,12926],{"name":12925,"token":8408},"The X gate",[12,12927,12928,12929,12931,12932,12934],{},"Flips the qubit: a qubit that reads ",[170,12930,1165],{}," comes out reading ",[170,12933,1089],{},", and the other way round. It is the quantum version of NOT, and the only gate in this lesson.",[7431,12936,12938],{"name":12937,"token":1203},"Measurement",[12,12939,12940,12941,9145,12943,12945,12946,753],{},"Reads a qubit and writes the answer, ",[170,12942,1165],{},[170,12944,1089],{},", into an ordinary bit. In this circuit it is the last step. All of a run's output comes through a ",[16,12947,12949],{"href":12948},"\u002Flearn\u002Fquantum-measurement","measurement",[7431,12951,12953],{"name":12952,"token":240},"Shots",[12,12954,12955],{},"How many times the whole circuit is executed, start to finish, in one press of Run. Each shot gives one answer, and the program gets back the tally of all of them.",[111,12957,7444],{"id":7443},[12,12959,12960],{},"A circuit is drawn left to right, in the order the gates run. The single line is the qubit; the doubled line under it is the ordinary bit. Each box on the qubit's line is a gate acting on it, in order. The meter at the end is the measurement, and its arrow points at the bit the answer lands in.",[116,12962],{"alt":12963,"caption":12964,"no":22,"src":12965},"A wire labelled q0 carries a qubit reading 0 into a box marked X, after which it reads 1, then into a measurement meter; an arrow drops from the meter to a doubled wire labelled bit 0 where the answer 1 lands","The Playground draws yours in the same layout after a run, and so does Qiskit's own text drawing in the console.","\u002F_content\u002Fimages\u002Ffirst-circuits\u002Fone-qubit-x-circuit.svg",[12,12967,12968],{},"In Qiskit, the Python library this course uses, that picture is three lines:",[181,12970,12972],{"className":183,"code":12971,"language":185,"meta":22,"style":22},"qc = QuantumCircuit(1, 1)   # one qubit, one ordinary bit\nqc.x(0)                     # the X gate on qubit 0\nqc.measure(0, 0)            # read qubit 0 into bit 0\n",[170,12973,12974,12996,13012],{"__ignoreMap":22},[189,12975,12976,12978,12980,12982,12984,12986,12988,12990,12993],{"class":191,"line":192},[189,12977,196],{"class":195},[189,12979,200],{"class":199},[189,12981,533],{"class":203},[189,12983,230],{"class":195},[189,12985,1089],{"class":210},[189,12987,541],{"class":195},[189,12989,1089],{"class":210},[189,12991,12992],{"class":195},")   ",[189,12994,12995],{"class":318},"# one qubit, one ordinary bit\n",[189,12997,12998,13000,13002,13004,13006,13009],{"class":191,"line":23},[189,12999,2182],{"class":195},[189,13001,8408],{"class":203},[189,13003,230],{"class":195},[189,13005,1165],{"class":210},[189,13007,13008],{"class":195},")                     ",[189,13010,13011],{"class":318},"# the X gate on qubit 0\n",[189,13013,13014,13016,13018,13020,13022,13024,13026,13029],{"class":191,"line":250},[189,13015,2182],{"class":195},[189,13017,1203],{"class":203},[189,13019,230],{"class":195},[189,13021,1165],{"class":210},[189,13023,541],{"class":195},[189,13025,1165],{"class":210},[189,13027,13028],{"class":195},")            ",[189,13030,13031],{"class":318},"# read qubit 0 into bit 0\n",[12,13033,13034,13035,13037],{},"Everything else in the listing below is plumbing: send the circuit to a machine, wait for it, read the tally, print it. One name in that plumbing, ",[170,13036,858],{},", is not defined anywhere in the file.",[12,13039,13040,13041,13043,13044,13046],{},"The Playground creates ",[170,13042,858],{}," before your code runs. ",[170,13045,858],{}," holds whatever you choose when you press Run: a simulator in your browser, which the dialog lists under Locally Run Simulators, a model of an IonQ machine on IonQ's cloud, or the machine itself. The same code runs on all three.",[175,13048,13051],{"name":13049,"no-picker":22,"run-href":13050,"tag":985},"first_circuit.py","\u002Fu\u002Fqollab\u002Flearn-first-circuit",[181,13052,13054],{"className":183,"code":13053,"language":185,"meta":22,"style":22},"# 'backend' already exists when this runs: it is whatever you pick in the Run Experiment dialog.\nfrom qiskit import QuantumCircuit\nfrom qiskit.providers.jobstatus import JobStatus\nimport time\n\nshots = 1000\n\nqc = QuantumCircuit(1, 1)\nqc.x(0)\nqc.measure(0, 0)\nprint(qc)\n\njob = backend.run(qc, shots=shots)\nwhile job.status() not in (JobStatus.DONE, JobStatus.ERROR, JobStatus.CANCELLED):\n    time.sleep(5)\n\ncounts = job.result().get_counts()\nprint(counts)\nfor bits, n in sorted(counts.items()):\n    print(f\"{bits}: {n:4d}  {'█' * (50 * n \u002F\u002F shots)}\")\n",[170,13055,13056,13062,13074,13086,13094,13100,13110,13116,13136,13150,13168,13176,13182,13202,13232,13246,13252,13270,13278,13296,13349],{"__ignoreMap":22},[189,13057,13058,13060],{"class":191,"line":192},[189,13059,997],{"class":995,"aria-hidden":996},[189,13061,1000],{"class":318},[189,13063,13064,13066,13068,13070,13072],{"class":191,"line":23},[189,13065,997],{"class":995,"aria-hidden":996},[189,13067,1007],{"class":253},[189,13069,1025],{"class":195},[189,13071,1013],{"class":253},[189,13073,1030],{"class":195},[189,13075,13076,13078,13080,13082,13084],{"class":191,"line":250},[189,13077,997],{"class":995,"aria-hidden":996},[189,13079,1007],{"class":253},[189,13081,1053],{"class":195},[189,13083,1013],{"class":253},[189,13085,1058],{"class":195},[189,13087,13088,13090,13092],{"class":191,"line":281},[189,13089,997],{"class":995,"aria-hidden":996},[189,13091,1013],{"class":253},[189,13093,1067],{"class":195},[189,13095,13096,13098],{"class":191,"line":51},[189,13097,997],{"class":995,"aria-hidden":996},[189,13099,1074],{},[189,13101,13102,13104,13106,13108],{"class":191,"line":557},[189,13103,997],{"class":995,"aria-hidden":996},[189,13105,1081],{"class":195},[189,13107,200],{"class":199},[189,13109,1086],{"class":210},[189,13111,13112,13114],{"class":191,"line":579},[189,13113,997],{"class":995,"aria-hidden":996},[189,13115,1074],{},[189,13117,13118,13120,13122,13124,13126,13128,13130,13132,13134],{"class":191,"data-cue":1089,"line":590},[189,13119,1089],{"class":1092},[189,13121,196],{"class":195},[189,13123,200],{"class":199},[189,13125,533],{"class":203},[189,13127,230],{"class":195},[189,13129,1089],{"class":210},[189,13131,541],{"class":195},[189,13133,1089],{"class":210},[189,13135,214],{"class":195},[189,13137,13138,13140,13142,13144,13146,13148],{"class":191,"data-cue":292,"line":595},[189,13139,292],{"class":1092},[189,13141,2182],{"class":195},[189,13143,8408],{"class":203},[189,13145,230],{"class":195},[189,13147,1165],{"class":210},[189,13149,214],{"class":195},[189,13151,13152,13154,13156,13158,13160,13162,13164,13166],{"class":191,"data-cue":1241,"line":601},[189,13153,1241],{"class":1092},[189,13155,2182],{"class":195},[189,13157,1203],{"class":203},[189,13159,230],{"class":195},[189,13161,1165],{"class":210},[189,13163,541],{"class":195},[189,13165,1165],{"class":210},[189,13167,214],{"class":195},[189,13169,13170,13172,13174],{"class":191,"line":618},[189,13171,997],{"class":995,"aria-hidden":996},[189,13173,1306],{"class":199},[189,13175,2572],{"class":195},[189,13177,13178,13180],{"class":191,"line":665},[189,13179,997],{"class":995,"aria-hidden":996},[189,13181,1074],{},[189,13183,13184,13186,13188,13190,13192,13194,13196,13198,13200],{"class":191,"data-cue":700,"line":676},[189,13185,700],{"class":1092},[189,13187,219],{"class":195},[189,13189,200],{"class":199},[189,13191,224],{"class":195},[189,13193,227],{"class":203},[189,13195,2593],{"class":195},[189,13197,240],{"class":239},[189,13199,200],{"class":199},[189,13201,1457],{"class":195},[189,13203,13204,13206,13208,13210,13212,13214,13216,13218,13220,13222,13224,13226,13228,13230],{"class":191,"line":681},[189,13205,997],{"class":995,"aria-hidden":996},[189,13207,254],{"class":253},[189,13209,257],{"class":195},[189,13211,260],{"class":203},[189,13213,263],{"class":195},[189,13215,1473],{"class":253},[189,13217,1476],{"class":253},[189,13219,1479],{"class":195},[189,13221,275],{"class":210},[189,13223,1484],{"class":195},[189,13225,1487],{"class":210},[189,13227,1484],{"class":195},[189,13229,1492],{"class":210},[189,13231,576],{"class":195},[189,13233,13234,13236,13238,13240,13242,13244],{"class":191,"data-cue":538,"line":687},[189,13235,538],{"class":1092},[189,13237,284],{"class":195},[189,13239,287],{"class":203},[189,13241,230],{"class":195},[189,13243,538],{"class":210},[189,13245,214],{"class":195},[189,13247,13248,13250],{"class":191,"line":705},[189,13249,997],{"class":995,"aria-hidden":996},[189,13251,1074],{},[189,13253,13254,13256,13258,13260,13262,13264,13266,13268],{"class":191,"data-cue":2685,"line":1195},[189,13255,2685],{"class":1092},[189,13257,299],{"class":195},[189,13259,200],{"class":199},[189,13261,257],{"class":195},[189,13263,306],{"class":203},[189,13265,309],{"class":195},[189,13267,312],{"class":203},[189,13269,1536],{"class":195},[189,13271,13272,13274,13276],{"class":191,"line":1216},[189,13273,997],{"class":995,"aria-hidden":996},[189,13275,1306],{"class":199},[189,13277,2676],{"class":195},[189,13279,13280,13282,13284,13286,13288,13290,13292,13294],{"class":191,"line":1227},[189,13281,997],{"class":995,"aria-hidden":996},[189,13283,560],{"class":253},[189,13285,8617],{"class":195},[189,13287,566],{"class":253},[189,13289,6743],{"class":199},[189,13291,6746],{"class":195},[189,13293,6749],{"class":203},[189,13295,6896],{"class":195},[189,13297,13298,13300,13302,13304,13306,13308,13310,13312,13314,13316,13318,13320,13322,13324,13327,13329,13331,13333,13335,13337,13339,13341,13343,13345,13347],{"class":191,"line":1234},[189,13299,997],{"class":995,"aria-hidden":996},[189,13301,6903],{"class":199},[189,13303,230],{"class":195},[189,13305,1311],{"class":253},[189,13307,1350],{"class":1314},[189,13309,1318],{"class":210},[189,13311,8644],{"class":195},[189,13313,1332],{"class":210},[189,13315,3129],{"class":1314},[189,13317,1318],{"class":210},[189,13319,2475],{"class":195},[189,13321,8655],{"class":253},[189,13323,1332],{"class":210},[189,13325,13326],{"class":210},"  {",[189,13328,8681],{"class":1314},[189,13330,659],{"class":199},[189,13332,654],{"class":195},[189,13334,8688],{"class":210},[189,13336,659],{"class":199},[189,13338,6733],{"class":195},[189,13340,8695],{"class":199},[189,13342,8698],{"class":195},[189,13344,1332],{"class":210},[189,13346,1350],{"class":1314},[189,13348,214],{"class":195},[123,13350,13351,13358,13365,13372,13378,13385],{"class":1644},[126,13352,13353,13355],{"data-cue":1089},[189,13354,1089],{"class":1092},[189,13356,13357],{"class":1651},"one qubit to compute with, one classical bit to hold what we read",[126,13359,13360,13362],{"data-cue":292},[189,13361,292],{"class":1092},[189,13363,13364],{"class":1651},"the X gate flips qubit 0 from 0 to 1",[126,13366,13367,13369],{"data-cue":1241},[189,13368,1241],{"class":1092},[189,13370,13371],{"class":1651},"read qubit 0 and store the answer in bit 0",[126,13373,13374,13376],{"data-cue":700},[189,13375,700],{"class":1092},[189,13377,2831],{"class":1651},[126,13379,13380,13382],{"data-cue":538},[189,13381,538],{"class":1092},[189,13383,13384],{"class":1651},"the simulator runs on IonQ's cloud, so we wait for it",[126,13386,13387,13389],{"data-cue":2685},[189,13388,2685],{"class":1092},[189,13390,13391],{"class":1651},"a dict: each bitstring, and how many shots read it",[111,13393,13395],{"id":13394},"sign-in-and-run-the-circuit","Sign in and run the circuit",[12,13397,13398,13399,13401],{},"Before you press anything, make a prediction. The circuit executes 1,000 times, 1,000 shots. How many of those shots will read ",[170,13400,1089],{},"? Write the number down. You will check it against the console in a minute.",[123,13403,13404,13410,13415],{},[126,13405,13406,13409],{},[16,13407,13408],{"href":64},"Sign in"," with Google or GitHub. That creates your account; Qollab then asks for a username and your name.",[126,13411,732,13412,13414],{},[16,13413,736],{"href":13050},". The code above is already in it, under the Code tab.",[126,13416,806,13417,13419],{},[129,13418,740],{},", top right.",[116,13421],{"alt":13422,"caption":13423,"no":22,"src":13424},"The project page header: the qollab breadcrumb, the Fork, Like and Run on Qollab buttons with Run on Qollab highlighted, and the Project Card, Code and Discussions tabs","The same three buttons sit on every project page. Press Run on Qollab now; Fork is the step before the first assignment.","\u002F_content\u002Fimages\u002Ffirst-circuits\u002F01-run-on-qollab.webp",[123,13426,13427],{"start":281},[126,13428,756,13429,13432,13433,809,13435,13437,13438,753],{},[129,13430,13431],{},"Run Experiment"," dialog opens and asks which compute instance to launch the project in. Under ",[129,13434,748],{},[129,13436,8002],{},": a free simulator with a noise model of Aria 1, one of IonQ's machines. IonQ lists Aria 1 as retired, so the model is the way to run against it now. Press ",[129,13439,752],{},[116,13441],{"alt":13442,"caption":13443,"no":22,"src":13444},"The Run Experiment dialog scrolled to its Remotely Run Simulators group: IonQ Aria 1 selected and highlighted, then Aria 2, Forte 1 and Forte Enterprise 1, all free, and the Run button","The rows above this group are the Locally Run Simulators, the in-browser option, which the course does not use. Every simulator in this dialog is free. The real quantum computers are a separate group below the simulators, listed when the platform reports them and marked Offline when they are unavailable; no lesson in this course needs one.","\u002F_content\u002Fimages\u002Ffirst-circuits\u002F01-run-experiment.webp",[123,13446,13447],{"start":51},[126,13448,13449,13450,13452],{},"Wait. The job is queued on IonQ's cloud, and the ",[170,13451,254],{}," loop in the code checks on it every five seconds until it is done, or has failed. Ours took under twenty seconds.",[111,13454,13456],{"id":13455},"what-came-back","What came back",[116,13458],{"alt":13459,"caption":13460,"no":22,"src":13461},"The run console: QPU IonQ Aria 1 in the header, then the circuit drawn in text, the dict {'1': 1000} and one full-length bar for 1","Our second press: the dict {'1': 1000} and its bar. The Probabilities panel, beside the console in the Playground and outside this crop, shows the same counts as shares. The code works with the dict. The console header calls your choice the QPU, short for quantum processing unit, even when it is a simulator.","\u002F_content\u002Fimages\u002Ffirst-circuits\u002F01-console.webp",[12,13463,13464,13465,13467,13468,3129,13470,13472,13473,13475,13476,13478,13479,753],{},"Compare the tally with your prediction. We pressed Run twice on 15 September 2026, on the Aria 1 noise model. The first time, 999 shots read ",[170,13466,1089],{}," and one read ",[170,13469,1165],{},[170,13471,10748],{},", which the Probabilities panel showed as 99.90% for ",[170,13474,1089],{}," and 0.10% for ",[170,13477,1165],{},". The second time, all 1,000 read ",[170,13480,1089],{},[12,13482,13483,13484,13486,13487,13489],{},"The ideal answer is ",[170,13485,1089],{}," on every shot, and if you predicted 1,000 you were right about the circuit. The stray ",[170,13488,1165],{}," the first time comes from the noise model.",[12,13491,13492],{},"A noise model is IonQ's simulator with an error model set to one of its machines, Aria 1 here; IonQ describes the models as an approximation of the named system's performance.",[12,13494,13495],{},"So a circuit with a certain answer can still come back with a tail, the few shots that read the other answer. Lesson 6 measures tails like this at 4,000 shots.",[111,13497,13499],{"id":13498},"why-the-qubit-reads-1","Why the qubit reads 1",[12,13501,13502,13503,13505,13506,3284,13508,13510,13511,13513,13514,13516],{},"A qubit starts at ",[170,13504,1165],{},". The X gate maps ",[170,13507,1165],{},[170,13509,1089],{},", so after it the qubit is ",[170,13512,1089],{}," with certainty, and measuring it gives ",[170,13515,1089],{}," every time.",[12,13518,13519,13520,3284,13522,13524,13525,13527],{},"Gates compose: two X gates in a row map ",[170,13521,1165],{},[170,13523,1089],{}," and then back to ",[170,13526,1165],{},", so the answer depends on the whole sequence.",[111,13529,13531],{"id":13530},"fork-the-project-into-your-own-copy","Fork the project into your own copy",[12,13533,13534,13535,13537,13538,753],{},"On someone else's project the code is read-only. To change the code you fork the project: press ",[129,13536,1715],{}," at the top right, keep the name the dialog suggests, and press ",[129,13539,1719],{},[12,13541,13542],{},"You land on your own copy, marked Draft: only you can open it until you publish it, which lesson 6 does. The code is editable under its Code tab. Run on Qollab works there exactly as before. Edits are saved to your copy and leave the original as it was.",[116,13544],{"alt":13545,"caption":13546,"no":22,"src":13547},"The Fork Project dialog: Create your own copy of learn-first-circuit, a Project Name field prefilled with learn-first-circuit, a Title field, and the Fork Project button","A fork is your own copy of the project, under your username. The assignments happen in your fork.","\u002F_content\u002Fimages\u002Ffirst-circuits\u002F01-fork-project.webp",[789,13549,13550,13554,13563,13600],{"check":11705},[111,13551,13553],{"id":13552},"assignment-make-every-shot-read-0-without-deleting-a-line","Assignment: make every shot read 0 without deleting a line",[12,13555,13556,13557,13559,13560,13562],{},"The circuit reads ",[170,13558,1089],{}," on every shot. Make it read ",[170,13561,1165],{}," on every shot by adding to the circuit.",[123,13564,13565,13571,13585,13588,13591],{},[126,13566,13567,13568,13570],{},"In your fork, keep ",[170,13569,12523],{}," exactly where it is.",[126,13572,13573,13574,13576,13577,13579,13580,13576,13582,13584],{},"Work out what a second X gate would do. The gate flips whatever it finds: a qubit at ",[170,13575,1165],{}," comes out at ",[170,13578,1089],{},", and a qubit at ",[170,13581,1089],{},[170,13583,1165],{},", with no memory of what came before.",[126,13586,13587],{},"Add the line that follows from that.",[126,13589,13590],{},"Write down the tally you expect.",[126,13592,806,13593,809,13595,13597,13598,753],{},[129,13594,740],{},[129,13596,8002],{}," and press ",[129,13599,752],{},[830,13601,13602,13608,13653],{"label":832},[12,13603,13604,13605,13607],{},"Add a second X gate. The second undoes the first, so the qubit is back at ",[170,13606,1165],{}," when it is measured.",[181,13609,13611],{"className":183,"code":13610,"language":185,"meta":22,"style":22},"qc.x(0)\nqc.x(0)\nqc.measure(0, 0)\n",[170,13612,13613,13625,13637],{"__ignoreMap":22},[189,13614,13615,13617,13619,13621,13623],{"class":191,"line":192},[189,13616,2182],{"class":195},[189,13618,8408],{"class":203},[189,13620,230],{"class":195},[189,13622,1165],{"class":210},[189,13624,214],{"class":195},[189,13626,13627,13629,13631,13633,13635],{"class":191,"line":23},[189,13628,2182],{"class":195},[189,13630,8408],{"class":203},[189,13632,230],{"class":195},[189,13634,1165],{"class":210},[189,13636,214],{"class":195},[189,13638,13639,13641,13643,13645,13647,13649,13651],{"class":191,"line":250},[189,13640,2182],{"class":195},[189,13642,1203],{"class":203},[189,13644,230],{"class":195},[189,13646,1165],{"class":210},[189,13648,541],{"class":195},[189,13650,1165],{"class":210},[189,13652,214],{"class":195},[12,13654,13655,13656,13659,13660,13662,13663,13665,13666,13668],{},"When you ",[170,13657,13658],{},"print(qc)"," you see two boxes on the wire. The tally is all ",[170,13661,1165],{},", or all ",[170,13664,1165],{}," but a few stray ",[170,13667,1089],{},"s: the noise model's tail is still there, now on the other side.",[111,13670,13672],{"id":13671},"reading-a-tally","Reading a tally",[12,13674,13675],{},"The bars are drawn from the counts dict, and they drop small tails: each bar is scaled to fifty characters for the full shot count, so ten shots in a thousand draw as no bar at all.",[12,13677,13678],{},"A share, written as a percentage, means the same at any shot count, so you can compare a run of 1,000 with a run of 10,000. The Probabilities panel already shows shares, but Copy output and Download give you the console, and the console shows only counts.",[789,13680,13682,13686,13726],{"check":13681},"each bar carries its share as a percentage, and the shares add up to 100.",[111,13683,13685],{"id":13684},"assignment-print-each-bars-share-as-a-percentage","Assignment: print each bar's share as a percentage",[123,13687,13688,13700,13715,13723],{},[126,13689,13690,13691,13693,13694,13696,13697,13699],{},"Find the last ",[170,13692,1306],{},", in the bar loop. It already has both numbers you need: ",[170,13695,2475],{},", how many shots read this bitstring, and ",[170,13698,240],{},", the total.",[126,13701,13702,13703,13706,13707,13709,13710,13712,13713,753],{},"The share is ",[170,13704,13705],{},"n \u002F shots",", times 100. Put that arithmetic inside the f-string's curly braces, where Python evaluates it, with the format spec ",[170,13708,5689],{}," for one decimal place, the same way ",[170,13711,8655],{}," formats ",[170,13714,2475],{},[126,13716,806,13717,809,13719,13597,13721,753],{},[129,13718,740],{},[129,13720,8002],{},[129,13722,752],{},[126,13724,13725],{},"Check that the shares next to the bars add up to 100.",[830,13727,13728,13731,13818],{"label":832},[12,13729,13730],{},"One expression added to the existing line:",[181,13732,13734],{"className":183,"code":13733,"language":185,"meta":22,"style":22},"for bits, n in sorted(counts.items()):\n    print(f\"{bits}: {n:4d}  {100 * n \u002F shots:5.1f}%  {'█' * (50 * n \u002F\u002F shots)}\")\n",[170,13735,13736,13752],{"__ignoreMap":22},[189,13737,13738,13740,13742,13744,13746,13748,13750],{"class":191,"line":192},[189,13739,560],{"class":253},[189,13741,8617],{"class":195},[189,13743,566],{"class":253},[189,13745,6743],{"class":199},[189,13747,6746],{"class":195},[189,13749,6749],{"class":203},[189,13751,6896],{"class":195},[189,13753,13754,13756,13758,13760,13762,13764,13766,13768,13770,13772,13774,13776,13778,13780,13782,13784,13786,13788,13790,13792,13794,13796,13798,13800,13802,13804,13806,13808,13810,13812,13814,13816],{"class":191,"line":23},[189,13755,6903],{"class":199},[189,13757,230],{"class":195},[189,13759,1311],{"class":253},[189,13761,1350],{"class":1314},[189,13763,1318],{"class":210},[189,13765,8644],{"class":195},[189,13767,1332],{"class":210},[189,13769,3129],{"class":1314},[189,13771,1318],{"class":210},[189,13773,2475],{"class":195},[189,13775,8655],{"class":253},[189,13777,1332],{"class":210},[189,13779,8660],{"class":210},[189,13781,659],{"class":199},[189,13783,6733],{"class":195},[189,13785,1609],{"class":199},[189,13787,1612],{"class":195},[189,13789,8671],{"class":253},[189,13791,1332],{"class":210},[189,13793,8676],{"class":1314},[189,13795,1318],{"class":210},[189,13797,8681],{"class":1314},[189,13799,659],{"class":199},[189,13801,654],{"class":195},[189,13803,8688],{"class":210},[189,13805,659],{"class":199},[189,13807,6733],{"class":195},[189,13809,8695],{"class":199},[189,13811,8698],{"class":195},[189,13813,1332],{"class":210},[189,13815,1350],{"class":1314},[189,13817,214],{"class":195},[12,13819,13820,13823,13824,753],{},[170,13821,13822],{},"5.1f"," makes the number five characters wide with one decimal, so the columns line up. A tail of 7 shots in 1,000 prints as ",[170,13825,13826],{},"  0.7%",[111,13828,13830],{"id":13829},"reading-the-dict-in-code","Reading the dict in code",[12,13832,13833,13834,13836,13837,13840],{},"Lessons 4, 5 and 6 pull numbers out of ",[170,13835,1555],{}," in code instead of reading them off the bars. The dict maps each bitstring that was read to how many shots read it, and only the bitstrings that were read: our second tally had no ",[170,13838,13839],{},"'0'"," key at all.",[12,13842,13843,13844,13847,13848,13851,13852,13854],{},"So ",[170,13845,13846],{},"counts['0']"," would have crashed on that tally. ",[170,13849,13850],{},"counts.get('0', 0)"," returns ",[170,13853,1165],{}," instead when the key is missing, which is the form to use.",[789,13856,13858,13862,13918],{"check":13857},"the console prints one number, the share of shots that read 1, and the line does not crash on your fork's tally, where no shot read 1.",[111,13859,13861],{"id":13860},"assignment-pull-one-number-out-of-the-dict","Assignment: pull one number out of the dict",[123,13863,13864,13875,13891,13905],{},[126,13865,13866,13867,13869,13870,13872,13873,753],{},"After the bar loop, add one line that prints the share of shots that read ",[170,13868,1089],{}," as a number between 0 and 1: the count for the key ",[170,13871,3369],{},", divided by ",[170,13874,240],{},[126,13876,13877,13878,13881,13882,13884,13885,13887,13888,13890],{},"Write it with ",[170,13879,13880],{},"counts.get('1', 0)"," rather than ",[170,13883,4545],{},". Your fork still has two X gates, so its tally has no ",[170,13886,3369],{}," key at all, and ",[170,13889,4545],{}," would crash on it.",[126,13892,806,13893,809,13895,13597,13897,13899,13900,13902,13903,753],{},[129,13894,740],{},[129,13896,8002],{},[129,13898,752],{},". The line prints ",[170,13901,3227],{},", or slightly above it if the noise model gave you a stray ",[170,13904,1089],{},[126,13906,13907,13908,13910,13911,1791,13914,13910,13916,753],{},"Check the line by hand against the public project's two tallies: ",[170,13909,8082],{}," gives ",[170,13912,13913],{},"1.0",[170,13915,10748],{},[170,13917,10751],{},[830,13919,13920,13948],{"label":832},[181,13921,13923],{"className":183,"code":13922,"language":185,"meta":22,"style":22},"print(counts.get('1', 0) \u002F shots)\n",[170,13924,13925],{"__ignoreMap":22},[189,13926,13927,13929,13931,13933,13935,13937,13939,13941,13943,13945],{"class":191,"line":192},[189,13928,1306],{"class":199},[189,13930,6746],{"class":195},[189,13932,1577],{"class":203},[189,13934,230],{"class":195},[189,13936,3369],{"class":1314},[189,13938,541],{"class":195},[189,13940,1165],{"class":210},[189,13942,641],{"class":195},[189,13944,1609],{"class":199},[189,13946,13947],{"class":195}," shots)\n",[12,13949,13950,13951,13953,13954,1791,13956,13958],{},"On your two-X fork this prints ",[170,13952,3227],{},"; on the public project's two tallies it would print ",[170,13955,13913],{},[170,13957,10751],{},". Lesson 4 uses the same expression to compare a measured share with the value a rotation gate should give.",[111,13960,13962],{"id":13961},"why-the-two-tallies-differ","Why the two tallies differ",[12,13964,13965,13966,13968],{},"A tally is a sample of shots, and its shares are an estimate of the circuit's odds. The noise model did not change between our two presses: a stray ",[170,13967,1165],{}," that turned up once in 1,000 shots can easily be missing from the next 1,000. More shots make the estimate tighter without changing what the circuit does. Lesson 2 swaps the X gate for the Hadamard, whose answer varies from shot to shot, and works out how many shots a given precision needs.",[884,13970,12846],{},{"title":22,"searchDepth":23,"depth":23,"links":13972},[13973,13974,13975,13976,13977,13978,13979,13980,13981,13982,13983,13984],{"id":12889,"depth":23,"text":12890},{"id":7443,"depth":23,"text":7444},{"id":13394,"depth":23,"text":13395},{"id":13455,"depth":23,"text":13456},{"id":13498,"depth":23,"text":13499},{"id":13530,"depth":23,"text":13531},{"id":13552,"depth":23,"text":13553},{"id":13671,"depth":23,"text":13672},{"id":13684,"depth":23,"text":13685},{"id":13829,"depth":23,"text":13830},{"id":13860,"depth":23,"text":13861},{"id":13961,"depth":23,"text":13962},[26,27,19,12877],[],{"username":7,"name":30,"role":31,"avatar":32},"Build a circuit with one qubit and one gate, run it on a simulator of IonQ's Aria 1 machine, and read the tally.",{"image":13990,"alt":13991},"\u002F_content\u002Fimages\u002Ffirst-circuits\u002F01-circuit-panel.webp","The Playground's Circuit panel: qubit q0 runs through an X gate into a measurement.",{},{"slug":11843,"title":13994,"desc":11833},"2 · Put a qubit in superposition","\u002Fblog\u002Flearn\u002Fprogramming-your-first-quantum-circuits\u002Fyour-first-circuit",[],{"title":13998,"description":13999},"Your first quantum circuit · Programming your first quantum circuits","Build a one-qubit circuit in Qiskit, run it on the IonQ simulator from your browser and read the tally. Lesson 1 of a free course, with a free Qollab account.","blog\u002Flearn\u002Fprogramming-your-first-quantum-circuits\u002Fyour-first-circuit",[],"3MijULfT4DW7ezWrkqDqwtXRA9miIaIKr5IMbxe8lOk",1790341756091]