[{"data":1,"prerenderedAt":7729},["ShallowReactive",2],{"blog-post-programming-your-first-quantum-circuits\u002Fyour-first-circuit":3,"sibling-dives-programming-your-first-quantum-circuits\u002Fyour-first-circuit":1293,"learn-track-programming-your-first-quantum-circuits\u002Fyour-first-circuit":1294},{"id":4,"title":5,"authors":6,"body":8,"breadcrumb":1259,"builders":1263,"byline":1264,"category":1268,"categoryName":1268,"challenge":1268,"courseAuthor":1268,"courseLead":1268,"dek":1269,"description":1269,"draft":1270,"extension":1271,"eyebrow":1268,"featured":1270,"finish":1268,"fork":1268,"hero":1272,"heroAlt":1268,"heroCta":1268,"heroImage":1268,"homepageFeatured":1270,"kind":1275,"lessonCount":282,"meta":1276,"navigation":1277,"newsItems":1268,"next":1278,"ogImage":1268,"order":128,"outcomes":1268,"path":1282,"publishDate":1283,"readingTime":1284,"related":1285,"relatedProjects":1268,"seo":1286,"stem":1289,"tags":1290,"track":1291,"trackName":1262,"__hash__":1292},"blog\u002Fblog\u002Flearn\u002Fprogramming-your-first-quantum-circuits\u002Fyour-first-circuit.md","Your first circuit",[7],"nico",{"type":9,"value":10,"toc":1245},"minimark",[11,15,18,23,26,47,63,76,92,99,103,106,113,116,198,204,210,653,657,663,687,692,712,717,725,729,734,748,757,760,763,767,791,802,806,816,819,824,941,945,948,951,1097,1101,1112,1126,1231,1235,1238,1241],[12,13,14],"p",{},"A quantum circuit is a program with an unusual kind of output. Instead of a value, a circuit returns a tally: how many times each possible answer came up when the circuit was run over and over.",[12,16,17],{},"This lesson builds one, runs it on a simulator of IonQ's Aria 1 machine from your browser, reads the tally, then changes the circuit once and the printout twice. Nothing to install. Running it needs a free account; signing in with Google or GitHub takes a minute and is the first step of the run.",[19,20,22],"h2",{"id":21},"what-a-circuit-is","What a circuit is",[12,24,25],{},"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 is what produces a bit you can print.",[12,27,28,29,34,35,39,40,42,43,46],{},"A ",[30,31,33],"a",{"href":32},"\u002Flearn\u002Fquantum-foundations\u002Fqubits","qubit"," starts every run at ",[36,37,38],"code",{},"0",". Gates change it, in order. A measurement reads it and copies the answer, ",[36,41,38],{}," or ",[36,44,45],{},"1",", into an ordinary bit, and the bits are what come back to you. In code, those are four words:",[48,49,51],"gate",{"name":50,"token":33},"The qubit",[12,52,53,54,56,57,59,60,62],{},"The thing the gates act on. It starts at ",[36,55,38],{}," on every run. In code it is a position number, qubit ",[36,58,38],{},", and the ordinary bit that stores what was read of it is a second position number, bit ",[36,61,38],{},".",[48,64,67],{"name":65,"token":66},"The X gate","x",[12,68,69,70,72,73,75],{},"The flip. A qubit that reads ",[36,71,38],{}," comes out reading ",[36,74,45],{},", and the other way round. It is the quantum version of NOT, and the only gate in this lesson.",[48,77,80],{"name":78,"token":79},"Measurement","measure",[12,81,82,83,42,85,87,88,62],{},"Reads a qubit and writes the answer, ",[36,84,38],{},[36,86,45],{},", into an ordinary bit. In this circuit it is the last step. Everything a run hands back to you comes through a ",[30,89,91],{"href":90},"\u002Flearn\u002Fquantum-measurement","measurement",[48,93,96],{"name":94,"token":95},"Shots","shots",[12,97,98],{},"How many times the whole circuit is executed, start to finish, in one press of Run. One shot gives one answer. A thousand shots give a tally, and the tally is what a quantum program actually returns.",[19,100,102],{"id":101},"the-circuit-then-the-code","The circuit, then the code",[12,104,105],{},"A circuit is drawn like a timeline. 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.",[107,108],"blog-figure",{"alt":109,"caption":110,"no":111,"src":112},"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","Circuits are drawn the way they run, left to right. 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,114,115],{},"In Qiskit, the Python library this course uses, that picture is three lines:",[117,118,122],"pre",{"className":119,"code":120,"language":121,"meta":111,"style":111},"language-python shiki shiki-themes one-dark-pro","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","python",[36,123,124,159,177],{"__ignoreMap":111},[125,126,129,133,137,141,144,147,150,152,155],"span",{"class":127,"line":128},"line",1,[125,130,132],{"class":131},"sn6KH","qc ",[125,134,136],{"class":135},"sjrmR","=",[125,138,140],{"class":139},"sVbv2"," QuantumCircuit",[125,142,143],{"class":131},"(",[125,145,45],{"class":146},"sVC51",[125,148,149],{"class":131},", ",[125,151,45],{"class":146},[125,153,154],{"class":131},")   ",[125,156,158],{"class":157},"sV9Aq","# one qubit, one ordinary bit\n",[125,160,162,165,167,169,171,174],{"class":127,"line":161},2,[125,163,164],{"class":131},"qc.",[125,166,66],{"class":139},[125,168,143],{"class":131},[125,170,38],{"class":146},[125,172,173],{"class":131},")                     ",[125,175,176],{"class":157},"# the X gate on qubit 0\n",[125,178,180,182,184,186,188,190,192,195],{"class":127,"line":179},3,[125,181,164],{"class":131},[125,183,79],{"class":139},[125,185,143],{"class":131},[125,187,38],{"class":146},[125,189,149],{"class":131},[125,191,38],{"class":146},[125,193,194],{"class":131},")            ",[125,196,197],{"class":157},"# read qubit 0 into bit 0\n",[12,199,200,201,62],{},"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 is not defined anywhere in the file: ",[36,202,203],{},"backend",[12,205,206,207,209],{},"The Playground creates ",[36,208,203],{}," before your code runs. It holds whatever you choose when you press Run: a simulator in your browser, a model of an IonQ machine on IonQ's cloud, or the machine itself. Same code for all three.",[211,212,216],"code-block",{"name":213,"no-picker":111,"run-href":214,"tag":215},"first_circuit.py","\u002Fu\u002Fqollab\u002Flearn-first-circuit","Python · Playground",[117,217,219],{"className":119,"code":218,"language":121,"meta":111,"style":111},"# '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",[36,220,221,231,248,262,272,280,293,300,323,339,359,370,377,405,448,466,473,498,508,534,605],{"__ignoreMap":111},[125,222,223,228],{"class":127,"line":128},[125,224,227],{"class":225,"aria-hidden":226},"qg-cue qg-cue--empty","true","​",[125,229,230],{"class":157},"# 'backend' already exists when this runs: it is whatever you pick in the Run Experiment dialog.\n",[125,232,233,235,239,242,245],{"class":127,"line":161},[125,234,227],{"class":225,"aria-hidden":226},[125,236,238],{"class":237},"seHd6","from",[125,240,241],{"class":131}," qiskit ",[125,243,244],{"class":237},"import",[125,246,247],{"class":131}," QuantumCircuit\n",[125,249,250,252,254,257,259],{"class":127,"line":179},[125,251,227],{"class":225,"aria-hidden":226},[125,253,238],{"class":237},[125,255,256],{"class":131}," qiskit.providers.jobstatus ",[125,258,244],{"class":237},[125,260,261],{"class":131}," JobStatus\n",[125,263,265,267,269],{"class":127,"line":264},4,[125,266,227],{"class":225,"aria-hidden":226},[125,268,244],{"class":237},[125,270,271],{"class":131}," time\n",[125,273,275,277],{"class":127,"line":274},5,[125,276,227],{"class":225,"aria-hidden":226},[125,278,279],{},"​\n",[125,281,283,285,288,290],{"class":127,"line":282},6,[125,284,227],{"class":225,"aria-hidden":226},[125,286,287],{"class":131},"shots ",[125,289,136],{"class":135},[125,291,292],{"class":146}," 1000\n",[125,294,296,298],{"class":127,"line":295},7,[125,297,227],{"class":225,"aria-hidden":226},[125,299,279],{},[125,301,303,306,308,310,312,314,316,318,320],{"class":127,"data-cue":45,"line":302},8,[125,304,45],{"class":305},"qg-cue",[125,307,132],{"class":131},[125,309,136],{"class":135},[125,311,140],{"class":139},[125,313,143],{"class":131},[125,315,45],{"class":146},[125,317,149],{"class":131},[125,319,45],{"class":146},[125,321,322],{"class":131},")\n",[125,324,327,329,331,333,335,337],{"class":127,"data-cue":325,"line":326},"2",9,[125,328,325],{"class":305},[125,330,164],{"class":131},[125,332,66],{"class":139},[125,334,143],{"class":131},[125,336,38],{"class":146},[125,338,322],{"class":131},[125,340,343,345,347,349,351,353,355,357],{"class":127,"data-cue":341,"line":342},"3",10,[125,344,341],{"class":305},[125,346,164],{"class":131},[125,348,79],{"class":139},[125,350,143],{"class":131},[125,352,38],{"class":146},[125,354,149],{"class":131},[125,356,38],{"class":146},[125,358,322],{"class":131},[125,360,362,364,367],{"class":127,"line":361},11,[125,363,227],{"class":225,"aria-hidden":226},[125,365,366],{"class":135},"print",[125,368,369],{"class":131},"(qc)\n",[125,371,373,375],{"class":127,"line":372},12,[125,374,227],{"class":225,"aria-hidden":226},[125,376,279],{},[125,378,381,383,386,388,391,394,397,400,402],{"class":127,"data-cue":379,"line":380},"4",13,[125,382,379],{"class":305},[125,384,385],{"class":131},"job ",[125,387,136],{"class":135},[125,389,390],{"class":131}," backend.",[125,392,393],{"class":139},"run",[125,395,396],{"class":131},"(qc, ",[125,398,95],{"class":399},"s_ZVi",[125,401,136],{"class":135},[125,403,404],{"class":131},"shots)\n",[125,406,408,410,413,416,419,422,425,428,431,434,437,440,442,445],{"class":127,"line":407},14,[125,409,227],{"class":225,"aria-hidden":226},[125,411,412],{"class":237},"while",[125,414,415],{"class":131}," job.",[125,417,418],{"class":139},"status",[125,420,421],{"class":131},"() ",[125,423,424],{"class":237},"not",[125,426,427],{"class":237}," in",[125,429,430],{"class":131}," (JobStatus.",[125,432,433],{"class":146},"DONE",[125,435,436],{"class":131},", JobStatus.",[125,438,439],{"class":146},"ERROR",[125,441,436],{"class":131},[125,443,444],{"class":146},"CANCELLED",[125,446,447],{"class":131},"):\n",[125,449,452,454,457,460,462,464],{"class":127,"data-cue":450,"line":451},"5",15,[125,453,450],{"class":305},[125,455,456],{"class":131},"    time.",[125,458,459],{"class":139},"sleep",[125,461,143],{"class":131},[125,463,450],{"class":146},[125,465,322],{"class":131},[125,467,469,471],{"class":127,"line":468},16,[125,470,227],{"class":225,"aria-hidden":226},[125,472,279],{},[125,474,477,479,482,484,486,489,492,495],{"class":127,"data-cue":475,"line":476},"6",17,[125,478,475],{"class":305},[125,480,481],{"class":131},"counts ",[125,483,136],{"class":135},[125,485,415],{"class":131},[125,487,488],{"class":139},"result",[125,490,491],{"class":131},"().",[125,493,494],{"class":139},"get_counts",[125,496,497],{"class":131},"()\n",[125,499,501,503,505],{"class":127,"line":500},18,[125,502,227],{"class":225,"aria-hidden":226},[125,504,366],{"class":135},[125,506,507],{"class":131},"(counts)\n",[125,509,511,513,516,519,522,525,528,531],{"class":127,"line":510},19,[125,512,227],{"class":225,"aria-hidden":226},[125,514,515],{"class":237},"for",[125,517,518],{"class":131}," bits, n ",[125,520,521],{"class":237},"in",[125,523,524],{"class":135}," sorted",[125,526,527],{"class":131},"(counts.",[125,529,530],{"class":139},"items",[125,532,533],{"class":131},"()):\n",[125,535,537,539,542,544,547,551,554,557,560,563,565,568,571,573,576,579,582,585,588,590,593,596,599,601,603],{"class":127,"line":536},20,[125,538,227],{"class":225,"aria-hidden":226},[125,540,541],{"class":135},"    print",[125,543,143],{"class":131},[125,545,546],{"class":237},"f",[125,548,550],{"class":549},"subq3","\"",[125,552,553],{"class":146},"{",[125,555,556],{"class":131},"bits",[125,558,559],{"class":146},"}",[125,561,562],{"class":549},": ",[125,564,553],{"class":146},[125,566,567],{"class":131},"n",[125,569,570],{"class":237},":4d",[125,572,559],{"class":146},[125,574,575],{"class":146},"  {",[125,577,578],{"class":549},"'█'",[125,580,581],{"class":135}," *",[125,583,584],{"class":131}," (",[125,586,587],{"class":146},"50",[125,589,581],{"class":135},[125,591,592],{"class":131}," n ",[125,594,595],{"class":135},"\u002F\u002F",[125,597,598],{"class":131}," shots)",[125,600,559],{"class":146},[125,602,550],{"class":549},[125,604,322],{"class":131},[606,607,609,618,625,632,639,646],"ol",{"class":608},"qg-cues",[610,611,612,614],"li",{"data-cue":45},[125,613,45],{"class":305},[125,615,617],{"class":616},"qg-cues__text","one qubit to compute with, one classical bit to hold what we read",[610,619,620,622],{"data-cue":325},[125,621,325],{"class":305},[125,623,624],{"class":616},"the X gate flips qubit 0 from 0 to 1",[610,626,627,629],{"data-cue":341},[125,628,341],{"class":305},[125,630,631],{"class":616},"read qubit 0 and store the answer in bit 0",[610,633,634,636],{"data-cue":379},[125,635,379],{"class":305},[125,637,638],{"class":616},"one job, the circuit run 1,000 times",[610,640,641,643],{"data-cue":450},[125,642,450],{"class":305},[125,644,645],{"class":616},"the simulator runs on IonQ's cloud, so we wait for it",[610,647,648,650],{"data-cue":475},[125,649,475],{"class":305},[125,651,652],{"class":616},"a dict: each bitstring, and how many shots read it",[19,654,656],{"id":655},"run-the-circuit-from-nothing-to-a-tally","Run the circuit, from nothing to a tally",[12,658,659,660,662],{},"Before you press anything, make a prediction. The circuit executes 1,000 times, 1,000 shots. How many of those shots will read ",[36,661,45],{},"? Write the number down. You will check it against the console in a minute.",[606,664,665,672,679],{},[610,666,667,671],{},[30,668,670],{"href":669},"\u002Flogin","Sign in"," with Google or GitHub. That creates your account; Qollab then asks for a username and your name, and nothing else.",[610,673,674,675,678],{},"Open ",[30,676,677],{"href":214},"the project",". The code above is already in it, under the Code tab.",[610,680,681,682,686],{},"Press ",[683,684,685],"strong",{},"Run on Qollab",", top right.",[107,688],{"alt":689,"caption":690,"no":111,"src":691},"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. Fork comes back later in this lesson; Run on Qollab is the one to press now.","\u002F_content\u002Fimages\u002Ffirst-circuits\u002F01-run-on-qollab.webp",[606,693,694],{"start":264},[610,695,696,697,700,701,704,705,708,709,62],{},"The ",[683,698,699],{},"Run Experiment"," dialog opens and asks which compute instance to launch the project in. Under ",[683,702,703],{},"Remotely Run Simulators",", choose ",[683,706,707],{},"IonQ Aria 1",": a free simulator with a noise model of Aria 1, a machine IonQ has since retired. Press ",[683,710,711],{},"Run",[107,713],{"alt":714,"caption":715,"no":111,"src":716},"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","Every simulator in this dialog is free. The real quantum computers are a separate group below these, listed when the platform reports them and marked Offline when they are not available; nothing in this course needs one.","\u002F_content\u002Fimages\u002Ffirst-circuits\u002F01-run-experiment.webp",[606,718,719],{"start":274},[610,720,721,722,724],{},"Wait. The job is queued on IonQ's cloud, and the ",[36,723,412],{}," loop in the code checks on it every five seconds until it is done, or has failed. Ours took under twenty seconds.",[19,726,728],{"id":727},"what-came-back","What came back",[107,730],{"alt":731,"caption":732,"no":111,"src":733},"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","Three views of one result. The dict is the tally itself, the bars are the dict drawn, and the Probabilities panel, beside the console in the Playground, is the dict as shares. The dict is the one the code works with. The header labels the choice QPU, quantum processing unit, simulator or not.","\u002F_content\u002Fimages\u002Ffirst-circuits\u002F01-console.webp",[12,735,736,737,739,740,562,742,745,746,62],{},"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 ",[36,738,45],{}," and one read ",[36,741,38],{},[36,743,744],{},"{'0': 1, '1': 999}",", which the Probabilities panel showed as 99.90% and 0.10%. The second time, all 1,000 read ",[36,747,45],{},[12,749,750,751,753,754,756],{},"The ideal answer is ",[36,752,45],{}," on every shot, and if you predicted 1,000 you were right about the circuit. The stray ",[36,755,38],{}," in the first press is the noise model at work.",[12,758,759],{},"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 representative of the named system.",[12,761,762],{},"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.",[19,764,766],{"id":765},"why-the-qubit-reads-1","Why the qubit reads 1",[12,768,769,770,772,773,775,776,778,779,781,782,784,785,787,788,790],{},"A qubit starts at ",[36,771,38],{},". The X gate maps ",[36,774,38],{}," to ",[36,777,45],{},", so after it the qubit is exactly ",[36,780,45],{},", not probably ",[36,783,45],{},". Measuring a qubit that is exactly ",[36,786,45],{}," gives ",[36,789,45],{}," every time. Nothing in this circuit is uncertain. Lesson 2 builds one that is.",[12,792,793,794,775,796,798,799,801],{},"Gates compose. Two X gates in a row map ",[36,795,38],{},[36,797,45],{}," and then back to ",[36,800,38],{},", so the answer depends on the whole sequence, not on any one gate.",[19,803,805],{"id":804},"make-it-yours-fork-the-project","Make it yours: fork the project",[12,807,808,809,812,813,62],{},"On someone else's project the code is read-only. To change it you fork it: press ",[683,810,811],{},"Fork"," at the top right, keep the name the dialog suggests, and press ",[683,814,815],{},"Fork Project",[12,817,818],{},"You land on your own copy, marked Draft, with the code editable under its Code tab. Run on Qollab works there exactly as before. Every edit is saved to your copy; the original stays as it was.",[107,820],{"alt":821,"caption":822,"no":111,"src":823},"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 copy, under your name. It is where the assignments happen, and where anything you build later starts.","\u002F_content\u002Fimages\u002Ffirst-circuits\u002F01-fork-project.webp",[825,826,828,832,841,870],"assignment",{"check":827},"the tally is all 0, or all 0 but a few stray 1s.",[19,829,831],{"id":830},"assignment-make-every-shot-read-0-without-deleting-a-line","Assignment: make every shot read 0 without deleting a line",[12,833,834,835,837,838,840],{},"The circuit reads ",[36,836,45],{}," on every shot. Your job is to make it read ",[36,839,38],{}," on every shot, by adding to the circuit rather than removing from it.",[606,842,843,850,864,867],{},[610,844,845,846,849],{},"In your fork, keep ",[36,847,848],{},"qc.x(0)"," exactly where it is. Nothing gets deleted.",[610,851,852,853,855,856,858,859,855,861,863],{},"Work out what a second X gate would do. The gate flips whatever it finds: a qubit at ",[36,854,38],{}," comes out at ",[36,857,45],{},", and a qubit at ",[36,860,45],{},[36,862,38],{},", with no memory of what came before.",[610,865,866],{},"Add the line that follows from that.",[610,868,869],{},"Write down the tally you expect, then press Run.",[871,872,874,880,925],"hint",{"label":873},"Solution",[12,875,876,877,879],{},"Two X gates in a row. The second undoes the first, so the qubit is back at ",[36,878,38],{}," when it is measured.",[117,881,883],{"className":119,"code":882,"language":121,"meta":111,"style":111},"qc.x(0)\nqc.x(0)\nqc.measure(0, 0)\n",[36,884,885,897,909],{"__ignoreMap":111},[125,886,887,889,891,893,895],{"class":127,"line":128},[125,888,164],{"class":131},[125,890,66],{"class":139},[125,892,143],{"class":131},[125,894,38],{"class":146},[125,896,322],{"class":131},[125,898,899,901,903,905,907],{"class":127,"line":161},[125,900,164],{"class":131},[125,902,66],{"class":139},[125,904,143],{"class":131},[125,906,38],{"class":146},[125,908,322],{"class":131},[125,910,911,913,915,917,919,921,923],{"class":127,"line":179},[125,912,164],{"class":131},[125,914,79],{"class":139},[125,916,143],{"class":131},[125,918,38],{"class":146},[125,920,149],{"class":131},[125,922,38],{"class":146},[125,924,322],{"class":131},[12,926,927,928,931,932,934,935,937,938,940],{},"When you ",[36,929,930],{},"print(qc)"," you see two boxes on the wire. The tally is all ",[36,933,38],{},", or all ",[36,936,38],{}," but a few stray ",[36,939,45],{},"s: the noise model's tail is still there, now on the other side.",[19,942,944],{"id":943},"reading-a-tally","Reading a tally",[12,946,947],{},"The counts dict is the whole result; the bars are only a picture of it, and the picture drops 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,949,950],{},"A share, written as a percentage, survives any shot count. It is also what lets you compare a run of 1,000 with a run of 10,000. The Probabilities panel already shows shares, but the console is what Copy output and Download give you, and the console does not.",[825,952,954,958,991],{"check":953},"each bar carries its share as a percentage, and the shares add up to 100.",[19,955,957],{"id":956},"assignment-print-the-tail-as-a-percentage","Assignment: print the tail as a percentage",[606,959,960,972,988],{},[610,961,962,963,965,966,968,969,971],{},"Find the last ",[36,964,366],{},", in the bar loop. It already has both numbers you need: ",[36,967,567],{},", how many shots read this bitstring, and ",[36,970,95],{},", the total.",[610,973,974,975,978,979,982,983,985,986,62],{},"The share is ",[36,976,977],{},"n \u002F shots",", times 100. Put that arithmetic inside the f-string's curly braces, where Python evaluates it, with the format spec ",[36,980,981],{},":.1f"," for one decimal place, the same way ",[36,984,570],{}," formats ",[36,987,567],{},[610,989,990],{},"Run, and check that the shares next to the bars add up to 100.",[871,992,993,996,1088],{"label":873},[12,994,995],{},"One expression added to the existing line:",[117,997,999],{"className":119,"code":998,"language":121,"meta":111,"style":111},"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",[36,1000,1001,1017],{"__ignoreMap":111},[125,1002,1003,1005,1007,1009,1011,1013,1015],{"class":127,"line":128},[125,1004,515],{"class":237},[125,1006,518],{"class":131},[125,1008,521],{"class":237},[125,1010,524],{"class":135},[125,1012,527],{"class":131},[125,1014,530],{"class":139},[125,1016,533],{"class":131},[125,1018,1019,1021,1023,1025,1027,1029,1031,1033,1035,1037,1039,1041,1043,1046,1048,1050,1053,1056,1059,1061,1064,1066,1068,1070,1072,1074,1076,1078,1080,1082,1084,1086],{"class":127,"line":161},[125,1020,541],{"class":135},[125,1022,143],{"class":131},[125,1024,546],{"class":237},[125,1026,550],{"class":549},[125,1028,553],{"class":146},[125,1030,556],{"class":131},[125,1032,559],{"class":146},[125,1034,562],{"class":549},[125,1036,553],{"class":146},[125,1038,567],{"class":131},[125,1040,570],{"class":237},[125,1042,559],{"class":146},[125,1044,1045],{"class":146},"  {100",[125,1047,581],{"class":135},[125,1049,592],{"class":131},[125,1051,1052],{"class":135},"\u002F",[125,1054,1055],{"class":131}," shots",[125,1057,1058],{"class":237},":5.1f",[125,1060,559],{"class":146},[125,1062,1063],{"class":549},"%  ",[125,1065,553],{"class":146},[125,1067,578],{"class":549},[125,1069,581],{"class":135},[125,1071,584],{"class":131},[125,1073,587],{"class":146},[125,1075,581],{"class":135},[125,1077,592],{"class":131},[125,1079,595],{"class":135},[125,1081,598],{"class":131},[125,1083,559],{"class":146},[125,1085,550],{"class":549},[125,1087,322],{"class":131},[12,1089,1090,1093,1094,62],{},[36,1091,1092],{},"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 ",[36,1095,1096],{},"  0.7%",[19,1098,1100],{"id":1099},"the-dict-is-the-result","The dict is the result",[12,1102,1103,1104,1107,1108,1111],{},"Every later lesson pulls numbers out of ",[36,1105,1106],{},"counts"," in code rather than 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 press had no ",[36,1109,1110],{},"'0'"," key at all.",[12,1113,1114,1115,1118,1119,1122,1123,1125],{},"So ",[36,1116,1117],{},"counts['0']"," would have crashed on that press. ",[36,1120,1121],{},"counts.get('0', 0)"," returns ",[36,1124,38],{}," instead when the key is missing, which is the form to use.",[825,1127,1129,1133,1188],{"check":1128},"the console prints one number, the share of shots that read 1, and it does not crash on your fork's tally, where no shot read 1.",[19,1130,1132],{"id":1131},"assignment-pull-one-number-out-of-the-dict","Assignment: pull one number out of the dict",[606,1134,1135,1147,1164,1173],{},[610,1136,1137,1138,1140,1141,1144,1145,62],{},"After the bar loop, add one line that prints the share of shots that read ",[36,1139,45],{}," as a number between 0 and 1: the count for the key ",[36,1142,1143],{},"'1'",", divided by ",[36,1146,95],{},[610,1148,1149,1150,1153,1154,1157,1158,1160,1161,1163],{},"Write it with ",[36,1151,1152],{},"counts.get('1', 0)"," rather than ",[36,1155,1156],{},"counts['1']",". Your fork still has two X gates, so its tally has no ",[36,1159,1143],{}," key at all, and ",[36,1162,1156],{}," would crash on it.",[610,1165,1166,1167,1170,1171,62],{},"Run. The line prints ",[36,1168,1169],{},"0.0",", or a hair above it if the noise model gave you a stray ",[36,1172,45],{},[610,1174,1175,1176,787,1179,1182,1183,787,1185,62],{},"Check the line by hand against the public project's two tallies: ",[36,1177,1178],{},"{'1': 1000}",[36,1180,1181],{},"1.0"," and ",[36,1184,744],{},[36,1186,1187],{},"0.999",[871,1189,1190,1220],{"label":873},[117,1191,1193],{"className":119,"code":1192,"language":121,"meta":111,"style":111},"print(counts.get('1', 0) \u002F shots)\n",[36,1194,1195],{"__ignoreMap":111},[125,1196,1197,1199,1201,1204,1206,1208,1210,1212,1215,1217],{"class":127,"line":128},[125,1198,366],{"class":135},[125,1200,527],{"class":131},[125,1202,1203],{"class":139},"get",[125,1205,143],{"class":131},[125,1207,1143],{"class":549},[125,1209,149],{"class":131},[125,1211,38],{"class":146},[125,1213,1214],{"class":131},") ",[125,1216,1052],{"class":135},[125,1218,1219],{"class":131}," shots)\n",[12,1221,1222,1223,1225,1226,1182,1228,1230],{},"On your two-X fork this prints ",[36,1224,1169],{},"; on the public project's two presses it would print ",[36,1227,1181],{},[36,1229,1187],{},". Lesson 4 uses exactly this line to compare a measured share with the value a rotation gate should give.",[19,1232,1234],{"id":1233},"how-many-shots-is-enough","How many shots is enough",[12,1236,1237],{},"A tally is a sample, and a sample is an estimate. The noise model did not change between our two runs; the second sample was small for such a rare event and missed it. More shots sharpen the estimate. They never change what the circuit does.",[12,1239,1240],{},"This gate gave a certain answer. Lesson 2's gate, the Hadamard, gives an uncertain one, and the tally of many runs is the only way to read it.",[1242,1243,1244],"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 .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":111,"searchDepth":161,"depth":161,"links":1246},[1247,1248,1249,1250,1251,1252,1253,1254,1255,1256,1257,1258],{"id":21,"depth":161,"text":22},{"id":101,"depth":161,"text":102},{"id":655,"depth":161,"text":656},{"id":727,"depth":161,"text":728},{"id":765,"depth":161,"text":766},{"id":804,"depth":161,"text":805},{"id":830,"depth":161,"text":831},{"id":943,"depth":161,"text":944},{"id":956,"depth":161,"text":957},{"id":1099,"depth":161,"text":1100},{"id":1131,"depth":161,"text":1132},{"id":1233,"depth":161,"text":1234},[1260,1261,1262,5],"Qollab","Learn","Programming your first quantum circuits",[],{"username":7,"name":1265,"role":1266,"avatar":1267},"Nicolaas Spijker","Community manager, Qollab","\u002F_content\u002Fimages\u002Fbuilders\u002Fnicolaas-spijker.webp",null,"One qubit, one gate, one measurement: build a circuit, run it on the IonQ simulator from your browser, and read the tally that comes back.",false,"md",{"image":1273,"alt":1274},"\u002F_content\u002Fimages\u002Ffirst-circuits\u002F01-circuit-panel.webp","The Playground's Circuit panel: qubit q0 runs through an X gate into a measurement.","lesson",{},true,{"slug":1279,"title":1280,"desc":1281},"\u002Fblog\u002Flearn\u002Fprogramming-your-first-quantum-circuits\u002Fsuperposition","2 · Put a qubit in superposition","The Hadamard gate, and why 1,000 shots almost never split exactly 500\u002F500.","\u002Fblog\u002Flearn\u002Fprogramming-your-first-quantum-circuits\u002Fyour-first-circuit","2026-09-15","9 min read",[],{"title":1287,"description":1288},"Your first quantum circuit · Programming your first quantum circuits","Build a one-qubit circuit in Qiskit, run it on the IonQ simulator in your browser and read the tally. Lesson 1 of a free course; no account needed to start.","blog\u002Flearn\u002Fprogramming-your-first-quantum-circuits\u002Fyour-first-circuit",[],"programming-your-first-quantum-circuits","FtzeEzvfQhawcb7WyG-64FvvUjDv37qz-hcr_GhRgqs",[],[1295,2202,2943,3997,5068,6767],{"id":4,"title":5,"authors":1296,"body":1297,"breadcrumb":2193,"builders":2194,"byline":2195,"category":1268,"categoryName":1268,"challenge":1268,"courseAuthor":1268,"courseLead":1268,"dek":1269,"description":1269,"draft":1270,"extension":1271,"eyebrow":1268,"featured":1270,"finish":1268,"fork":1268,"hero":2196,"heroAlt":1268,"heroCta":1268,"heroImage":1268,"homepageFeatured":1270,"kind":1275,"lessonCount":282,"meta":2197,"navigation":1277,"newsItems":1268,"next":2198,"ogImage":1268,"order":128,"outcomes":1268,"path":1282,"publishDate":1283,"readingTime":1284,"related":2199,"relatedProjects":1268,"seo":2200,"stem":1289,"tags":2201,"track":1291,"trackName":1262,"__hash__":1292},[7],{"type":9,"value":1298,"toc":2179},[1299,1301,1303,1305,1307,1317,1327,1335,1345,1349,1351,1353,1355,1357,1413,1417,1421,1757,1759,1763,1777,1779,1791,1793,1799,1801,1803,1813,1819,1821,1823,1825,1841,1849,1851,1857,1859,1861,1951,1953,1955,1957,2079,2081,2087,2095,2171,2173,2175,2177],[12,1300,14],{},[12,1302,17],{},[19,1304,22],{"id":21},[12,1306,25],{},[12,1308,28,1309,34,1311,39,1313,42,1315,46],{},[30,1310,33],{"href":32},[36,1312,38],{},[36,1314,38],{},[36,1316,45],{},[48,1318,1319],{"name":50,"token":33},[12,1320,53,1321,56,1323,59,1325,62],{},[36,1322,38],{},[36,1324,38],{},[36,1326,38],{},[48,1328,1329],{"name":65,"token":66},[12,1330,69,1331,72,1333,75],{},[36,1332,38],{},[36,1334,45],{},[48,1336,1337],{"name":78,"token":79},[12,1338,82,1339,42,1341,87,1343,62],{},[36,1340,38],{},[36,1342,45],{},[30,1344,91],{"href":90},[48,1346,1347],{"name":94,"token":95},[12,1348,98],{},[19,1350,102],{"id":101},[12,1352,105],{},[107,1354],{"alt":109,"caption":110,"no":111,"src":112},[12,1356,115],{},[117,1358,1359],{"className":119,"code":120,"language":121,"meta":111,"style":111},[36,1360,1361,1381,1395],{"__ignoreMap":111},[125,1362,1363,1365,1367,1369,1371,1373,1375,1377,1379],{"class":127,"line":128},[125,1364,132],{"class":131},[125,1366,136],{"class":135},[125,1368,140],{"class":139},[125,1370,143],{"class":131},[125,1372,45],{"class":146},[125,1374,149],{"class":131},[125,1376,45],{"class":146},[125,1378,154],{"class":131},[125,1380,158],{"class":157},[125,1382,1383,1385,1387,1389,1391,1393],{"class":127,"line":161},[125,1384,164],{"class":131},[125,1386,66],{"class":139},[125,1388,143],{"class":131},[125,1390,38],{"class":146},[125,1392,173],{"class":131},[125,1394,176],{"class":157},[125,1396,1397,1399,1401,1403,1405,1407,1409,1411],{"class":127,"line":179},[125,1398,164],{"class":131},[125,1400,79],{"class":139},[125,1402,143],{"class":131},[125,1404,38],{"class":146},[125,1406,149],{"class":131},[125,1408,38],{"class":146},[125,1410,194],{"class":131},[125,1412,197],{"class":157},[12,1414,200,1415,62],{},[36,1416,203],{},[12,1418,206,1419,209],{},[36,1420,203],{},[211,1422,1423],{"name":213,"no-picker":111,"run-href":214,"tag":215},[117,1424,1425],{"className":119,"code":218,"language":121,"meta":111,"style":111},[36,1426,1427,1433,1445,1457,1465,1471,1481,1487,1507,1521,1539,1547,1553,1573,1603,1617,1623,1641,1649,1667,1719],{"__ignoreMap":111},[125,1428,1429,1431],{"class":127,"line":128},[125,1430,227],{"class":225,"aria-hidden":226},[125,1432,230],{"class":157},[125,1434,1435,1437,1439,1441,1443],{"class":127,"line":161},[125,1436,227],{"class":225,"aria-hidden":226},[125,1438,238],{"class":237},[125,1440,241],{"class":131},[125,1442,244],{"class":237},[125,1444,247],{"class":131},[125,1446,1447,1449,1451,1453,1455],{"class":127,"line":179},[125,1448,227],{"class":225,"aria-hidden":226},[125,1450,238],{"class":237},[125,1452,256],{"class":131},[125,1454,244],{"class":237},[125,1456,261],{"class":131},[125,1458,1459,1461,1463],{"class":127,"line":264},[125,1460,227],{"class":225,"aria-hidden":226},[125,1462,244],{"class":237},[125,1464,271],{"class":131},[125,1466,1467,1469],{"class":127,"line":274},[125,1468,227],{"class":225,"aria-hidden":226},[125,1470,279],{},[125,1472,1473,1475,1477,1479],{"class":127,"line":282},[125,1474,227],{"class":225,"aria-hidden":226},[125,1476,287],{"class":131},[125,1478,136],{"class":135},[125,1480,292],{"class":146},[125,1482,1483,1485],{"class":127,"line":295},[125,1484,227],{"class":225,"aria-hidden":226},[125,1486,279],{},[125,1488,1489,1491,1493,1495,1497,1499,1501,1503,1505],{"class":127,"data-cue":45,"line":302},[125,1490,45],{"class":305},[125,1492,132],{"class":131},[125,1494,136],{"class":135},[125,1496,140],{"class":139},[125,1498,143],{"class":131},[125,1500,45],{"class":146},[125,1502,149],{"class":131},[125,1504,45],{"class":146},[125,1506,322],{"class":131},[125,1508,1509,1511,1513,1515,1517,1519],{"class":127,"data-cue":325,"line":326},[125,1510,325],{"class":305},[125,1512,164],{"class":131},[125,1514,66],{"class":139},[125,1516,143],{"class":131},[125,1518,38],{"class":146},[125,1520,322],{"class":131},[125,1522,1523,1525,1527,1529,1531,1533,1535,1537],{"class":127,"data-cue":341,"line":342},[125,1524,341],{"class":305},[125,1526,164],{"class":131},[125,1528,79],{"class":139},[125,1530,143],{"class":131},[125,1532,38],{"class":146},[125,1534,149],{"class":131},[125,1536,38],{"class":146},[125,1538,322],{"class":131},[125,1540,1541,1543,1545],{"class":127,"line":361},[125,1542,227],{"class":225,"aria-hidden":226},[125,1544,366],{"class":135},[125,1546,369],{"class":131},[125,1548,1549,1551],{"class":127,"line":372},[125,1550,227],{"class":225,"aria-hidden":226},[125,1552,279],{},[125,1554,1555,1557,1559,1561,1563,1565,1567,1569,1571],{"class":127,"data-cue":379,"line":380},[125,1556,379],{"class":305},[125,1558,385],{"class":131},[125,1560,136],{"class":135},[125,1562,390],{"class":131},[125,1564,393],{"class":139},[125,1566,396],{"class":131},[125,1568,95],{"class":399},[125,1570,136],{"class":135},[125,1572,404],{"class":131},[125,1574,1575,1577,1579,1581,1583,1585,1587,1589,1591,1593,1595,1597,1599,1601],{"class":127,"line":407},[125,1576,227],{"class":225,"aria-hidden":226},[125,1578,412],{"class":237},[125,1580,415],{"class":131},[125,1582,418],{"class":139},[125,1584,421],{"class":131},[125,1586,424],{"class":237},[125,1588,427],{"class":237},[125,1590,430],{"class":131},[125,1592,433],{"class":146},[125,1594,436],{"class":131},[125,1596,439],{"class":146},[125,1598,436],{"class":131},[125,1600,444],{"class":146},[125,1602,447],{"class":131},[125,1604,1605,1607,1609,1611,1613,1615],{"class":127,"data-cue":450,"line":451},[125,1606,450],{"class":305},[125,1608,456],{"class":131},[125,1610,459],{"class":139},[125,1612,143],{"class":131},[125,1614,450],{"class":146},[125,1616,322],{"class":131},[125,1618,1619,1621],{"class":127,"line":468},[125,1620,227],{"class":225,"aria-hidden":226},[125,1622,279],{},[125,1624,1625,1627,1629,1631,1633,1635,1637,1639],{"class":127,"data-cue":475,"line":476},[125,1626,475],{"class":305},[125,1628,481],{"class":131},[125,1630,136],{"class":135},[125,1632,415],{"class":131},[125,1634,488],{"class":139},[125,1636,491],{"class":131},[125,1638,494],{"class":139},[125,1640,497],{"class":131},[125,1642,1643,1645,1647],{"class":127,"line":500},[125,1644,227],{"class":225,"aria-hidden":226},[125,1646,366],{"class":135},[125,1648,507],{"class":131},[125,1650,1651,1653,1655,1657,1659,1661,1663,1665],{"class":127,"line":510},[125,1652,227],{"class":225,"aria-hidden":226},[125,1654,515],{"class":237},[125,1656,518],{"class":131},[125,1658,521],{"class":237},[125,1660,524],{"class":135},[125,1662,527],{"class":131},[125,1664,530],{"class":139},[125,1666,533],{"class":131},[125,1668,1669,1671,1673,1675,1677,1679,1681,1683,1685,1687,1689,1691,1693,1695,1697,1699,1701,1703,1705,1707,1709,1711,1713,1715,1717],{"class":127,"line":536},[125,1670,227],{"class":225,"aria-hidden":226},[125,1672,541],{"class":135},[125,1674,143],{"class":131},[125,1676,546],{"class":237},[125,1678,550],{"class":549},[125,1680,553],{"class":146},[125,1682,556],{"class":131},[125,1684,559],{"class":146},[125,1686,562],{"class":549},[125,1688,553],{"class":146},[125,1690,567],{"class":131},[125,1692,570],{"class":237},[125,1694,559],{"class":146},[125,1696,575],{"class":146},[125,1698,578],{"class":549},[125,1700,581],{"class":135},[125,1702,584],{"class":131},[125,1704,587],{"class":146},[125,1706,581],{"class":135},[125,1708,592],{"class":131},[125,1710,595],{"class":135},[125,1712,598],{"class":131},[125,1714,559],{"class":146},[125,1716,550],{"class":549},[125,1718,322],{"class":131},[606,1720,1721,1727,1733,1739,1745,1751],{"class":608},[610,1722,1723,1725],{"data-cue":45},[125,1724,45],{"class":305},[125,1726,617],{"class":616},[610,1728,1729,1731],{"data-cue":325},[125,1730,325],{"class":305},[125,1732,624],{"class":616},[610,1734,1735,1737],{"data-cue":341},[125,1736,341],{"class":305},[125,1738,631],{"class":616},[610,1740,1741,1743],{"data-cue":379},[125,1742,379],{"class":305},[125,1744,638],{"class":616},[610,1746,1747,1749],{"data-cue":450},[125,1748,450],{"class":305},[125,1750,645],{"class":616},[610,1752,1753,1755],{"data-cue":475},[125,1754,475],{"class":305},[125,1756,652],{"class":616},[19,1758,656],{"id":655},[12,1760,659,1761,662],{},[36,1762,45],{},[606,1764,1765,1769,1773],{},[610,1766,1767,671],{},[30,1768,670],{"href":669},[610,1770,674,1771,678],{},[30,1772,677],{"href":214},[610,1774,681,1775,686],{},[683,1776,685],{},[107,1778],{"alt":689,"caption":690,"no":111,"src":691},[606,1780,1781],{"start":264},[610,1782,696,1783,700,1785,704,1787,708,1789,62],{},[683,1784,699],{},[683,1786,703],{},[683,1788,707],{},[683,1790,711],{},[107,1792],{"alt":714,"caption":715,"no":111,"src":716},[606,1794,1795],{"start":274},[610,1796,721,1797,724],{},[36,1798,412],{},[19,1800,728],{"id":727},[107,1802],{"alt":731,"caption":732,"no":111,"src":733},[12,1804,736,1805,739,1807,562,1809,745,1811,62],{},[36,1806,45],{},[36,1808,38],{},[36,1810,744],{},[36,1812,45],{},[12,1814,750,1815,753,1817,756],{},[36,1816,45],{},[36,1818,38],{},[12,1820,759],{},[12,1822,762],{},[19,1824,766],{"id":765},[12,1826,769,1827,772,1829,775,1831,778,1833,781,1835,784,1837,787,1839,790],{},[36,1828,38],{},[36,1830,38],{},[36,1832,45],{},[36,1834,45],{},[36,1836,45],{},[36,1838,45],{},[36,1840,45],{},[12,1842,793,1843,775,1845,798,1847,801],{},[36,1844,38],{},[36,1846,45],{},[36,1848,38],{},[19,1850,805],{"id":804},[12,1852,808,1853,812,1855,62],{},[683,1854,811],{},[683,1856,815],{},[12,1858,818],{},[107,1860],{"alt":821,"caption":822,"no":111,"src":823},[825,1862,1863,1865,1871,1891],{"check":827},[19,1864,831],{"id":830},[12,1866,834,1867,837,1869,840],{},[36,1868,45],{},[36,1870,38],{},[606,1872,1873,1877,1887,1889],{},[610,1874,845,1875,849],{},[36,1876,848],{},[610,1878,852,1879,855,1881,858,1883,855,1885,863],{},[36,1880,38],{},[36,1882,45],{},[36,1884,45],{},[36,1886,38],{},[610,1888,866],{},[610,1890,869],{},[871,1892,1893,1897,1941],{"label":873},[12,1894,876,1895,879],{},[36,1896,38],{},[117,1898,1899],{"className":119,"code":882,"language":121,"meta":111,"style":111},[36,1900,1901,1913,1925],{"__ignoreMap":111},[125,1902,1903,1905,1907,1909,1911],{"class":127,"line":128},[125,1904,164],{"class":131},[125,1906,66],{"class":139},[125,1908,143],{"class":131},[125,1910,38],{"class":146},[125,1912,322],{"class":131},[125,1914,1915,1917,1919,1921,1923],{"class":127,"line":161},[125,1916,164],{"class":131},[125,1918,66],{"class":139},[125,1920,143],{"class":131},[125,1922,38],{"class":146},[125,1924,322],{"class":131},[125,1926,1927,1929,1931,1933,1935,1937,1939],{"class":127,"line":179},[125,1928,164],{"class":131},[125,1930,79],{"class":139},[125,1932,143],{"class":131},[125,1934,38],{"class":146},[125,1936,149],{"class":131},[125,1938,38],{"class":146},[125,1940,322],{"class":131},[12,1942,927,1943,931,1945,934,1947,937,1949,940],{},[36,1944,930],{},[36,1946,38],{},[36,1948,38],{},[36,1950,45],{},[19,1952,944],{"id":943},[12,1954,947],{},[12,1956,950],{},[825,1958,1959,1961,1983],{"check":953},[19,1960,957],{"id":956},[606,1962,1963,1971,1981],{},[610,1964,962,1965,965,1967,968,1969,971],{},[36,1966,366],{},[36,1968,567],{},[36,1970,95],{},[610,1972,974,1973,978,1975,982,1977,985,1979,62],{},[36,1974,977],{},[36,1976,981],{},[36,1978,570],{},[36,1980,567],{},[610,1982,990],{},[871,1984,1985,1987,2073],{"label":873},[12,1986,995],{},[117,1988,1989],{"className":119,"code":998,"language":121,"meta":111,"style":111},[36,1990,1991,2007],{"__ignoreMap":111},[125,1992,1993,1995,1997,1999,2001,2003,2005],{"class":127,"line":128},[125,1994,515],{"class":237},[125,1996,518],{"class":131},[125,1998,521],{"class":237},[125,2000,524],{"class":135},[125,2002,527],{"class":131},[125,2004,530],{"class":139},[125,2006,533],{"class":131},[125,2008,2009,2011,2013,2015,2017,2019,2021,2023,2025,2027,2029,2031,2033,2035,2037,2039,2041,2043,2045,2047,2049,2051,2053,2055,2057,2059,2061,2063,2065,2067,2069,2071],{"class":127,"line":161},[125,2010,541],{"class":135},[125,2012,143],{"class":131},[125,2014,546],{"class":237},[125,2016,550],{"class":549},[125,2018,553],{"class":146},[125,2020,556],{"class":131},[125,2022,559],{"class":146},[125,2024,562],{"class":549},[125,2026,553],{"class":146},[125,2028,567],{"class":131},[125,2030,570],{"class":237},[125,2032,559],{"class":146},[125,2034,1045],{"class":146},[125,2036,581],{"class":135},[125,2038,592],{"class":131},[125,2040,1052],{"class":135},[125,2042,1055],{"class":131},[125,2044,1058],{"class":237},[125,2046,559],{"class":146},[125,2048,1063],{"class":549},[125,2050,553],{"class":146},[125,2052,578],{"class":549},[125,2054,581],{"class":135},[125,2056,584],{"class":131},[125,2058,587],{"class":146},[125,2060,581],{"class":135},[125,2062,592],{"class":131},[125,2064,595],{"class":135},[125,2066,598],{"class":131},[125,2068,559],{"class":146},[125,2070,550],{"class":549},[125,2072,322],{"class":131},[12,2074,2075,1093,2077,62],{},[36,2076,1092],{},[36,2078,1096],{},[19,2080,1100],{"id":1099},[12,2082,1103,2083,1107,2085,1111],{},[36,2084,1106],{},[36,2086,1110],{},[12,2088,1114,2089,1118,2091,1122,2093,1125],{},[36,2090,1117],{},[36,2092,1121],{},[36,2094,38],{},[825,2096,2097,2099,2135],{"check":1128},[19,2098,1132],{"id":1131},[606,2100,2101,2109,2119,2125],{},[610,2102,1137,2103,1140,2105,1144,2107,62],{},[36,2104,45],{},[36,2106,1143],{},[36,2108,95],{},[610,2110,1149,2111,1153,2113,1157,2115,1160,2117,1163],{},[36,2112,1152],{},[36,2114,1156],{},[36,2116,1143],{},[36,2118,1156],{},[610,2120,1166,2121,1170,2123,62],{},[36,2122,1169],{},[36,2124,45],{},[610,2126,1175,2127,787,2129,1182,2131,787,2133,62],{},[36,2128,1178],{},[36,2130,1181],{},[36,2132,744],{},[36,2134,1187],{},[871,2136,2137,2163],{"label":873},[117,2138,2139],{"className":119,"code":1192,"language":121,"meta":111,"style":111},[36,2140,2141],{"__ignoreMap":111},[125,2142,2143,2145,2147,2149,2151,2153,2155,2157,2159,2161],{"class":127,"line":128},[125,2144,366],{"class":135},[125,2146,527],{"class":131},[125,2148,1203],{"class":139},[125,2150,143],{"class":131},[125,2152,1143],{"class":549},[125,2154,149],{"class":131},[125,2156,38],{"class":146},[125,2158,1214],{"class":131},[125,2160,1052],{"class":135},[125,2162,1219],{"class":131},[12,2164,1222,2165,1225,2167,1182,2169,1230],{},[36,2166,1169],{},[36,2168,1181],{},[36,2170,1187],{},[19,2172,1234],{"id":1233},[12,2174,1237],{},[12,2176,1240],{},[1242,2178,1244],{},{"title":111,"searchDepth":161,"depth":161,"links":2180},[2181,2182,2183,2184,2185,2186,2187,2188,2189,2190,2191,2192],{"id":21,"depth":161,"text":22},{"id":101,"depth":161,"text":102},{"id":655,"depth":161,"text":656},{"id":727,"depth":161,"text":728},{"id":765,"depth":161,"text":766},{"id":804,"depth":161,"text":805},{"id":830,"depth":161,"text":831},{"id":943,"depth":161,"text":944},{"id":956,"depth":161,"text":957},{"id":1099,"depth":161,"text":1100},{"id":1131,"depth":161,"text":1132},{"id":1233,"depth":161,"text":1234},[1260,1261,1262,5],[],{"username":7,"name":1265,"role":1266,"avatar":1267},{"image":1273,"alt":1274},{},{"slug":1279,"title":1280,"desc":1281},[],{"title":1287,"description":1288},[],{"id":2203,"title":2204,"authors":2205,"body":2206,"breadcrumb":2923,"builders":2924,"byline":2925,"category":1268,"categoryName":1268,"challenge":1268,"courseAuthor":1268,"courseLead":1268,"dek":1281,"description":2926,"draft":1270,"extension":1271,"eyebrow":1268,"featured":1270,"finish":1268,"fork":1268,"hero":2927,"heroAlt":1268,"heroCta":1268,"heroImage":1268,"homepageFeatured":1270,"kind":1275,"lessonCount":282,"meta":2930,"navigation":1277,"newsItems":1268,"next":2931,"ogImage":1268,"order":161,"outcomes":1268,"path":1279,"publishDate":1283,"readingTime":2935,"related":2936,"relatedProjects":1268,"seo":2937,"stem":2940,"tags":2941,"track":1291,"trackName":1262,"__hash__":2942},"blog\u002Fblog\u002Flearn\u002Fprogramming-your-first-quantum-circuits\u002Fsuperposition.md","Put a qubit in superposition",[7],{"type":9,"value":2207,"toc":2913},[2208,2211,2218,2222,2231,2238,2241,2244,2247,2250,2267,2269,2274,2614,2626,2630,2633,2647,2652,2666,2669,2672,2709,2713,2719,2722,2725,2728,2770,2774,2783,2792,2907,2910],[12,2209,2210],{},"A qubit in superposition carries weights on both answers instead of holding one of them, and its answer is not fixed until the moment it is measured. Lesson 1 built a circuit with a certain answer; this one builds a circuit of that uncertain kind, and reads it 1,000 times at a go to see what that means.",[12,2212,2213,2214,2217],{},"The gate that does it is the Hadamard, ",[36,2215,2216],{},"h"," in Qiskit: one line of code and one idea.",[19,2219,2221],{"id":2220},"half-and-half-until-you-look","Half and half, until you look",[12,2223,2224,2225,2227,2228,2230],{},"Start with an ordinary bit. It holds a ",[36,2226,38],{}," or a ",[36,2229,45],{},". If you have not looked at it you do not know which, but it is already one or the other, and looking only tells you which one it was.",[12,2232,2233,2234,62],{},"A qubit after a Hadamard gate is not a bit you have not looked at. Before the measurement there is no value in it to find. What it carries instead is a weight on each outcome, equal here, so each answer is equally likely. That state, weights on both answers at once, is a ",[30,2235,2237],{"href":2236},"\u002Flearn\u002Fquantum-superposition","superposition",[12,2239,2240],{},"The measurement is the step that turns those weights into one answer. Run the circuit again and the answer can come out the other way. A quantum program returns a tally for that reason: one answer cannot pin the weights down, and a thousand answers can.",[12,2242,2243],{},"Weights are more than odds. 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.",[12,2245,2246],{},"A weight also has a sign, which never shows in a tally on its own.",[12,2248,2249],{},"It shows when another gate acts on the weights before the measurement, because gates transform the weights, sign included. The last assignment in this lesson is the first place it matters.",[48,2251,2253],{"name":2252,"token":2216},"The Hadamard gate",[12,2254,2255,2256,2258,2259,1182,2261,2263,2264,2266],{},"Takes a qubit at ",[36,2257,38],{}," and leaves it weighted evenly between ",[36,2260,38],{},[36,2262,45],{},"; takes a qubit at ",[36,2265,45],{}," and does the same with the sign of one weight flipped. Measure either and each answer is equally likely. Its own inverse: twice in a row and the qubit is back where it started.",[19,2268,102],{"id":101},[107,2270],{"alt":2271,"caption":2272,"no":111,"src":2273},"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 is not 0 and not 1. The half-strength chips are the two weights; the diagram cannot show their signs, and neither can a tally.","\u002F_content\u002Fimages\u002Ffirst-circuits\u002Fone-qubit-h-circuit.svg",[211,2275,2278],{"name":2276,"no-picker":111,"run-href":2277,"tag":215},"superposition.py","\u002Fu\u002Fqollab\u002Flearn-superposition",[117,2279,2281],{"className":119,"code":2280,"language":121,"meta":111,"style":111},"# '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",[36,2282,2283,2289,2301,2313,2321,2327,2337,2343,2363,2377,2395,2403,2409,2429,2459,2473,2479,2497,2505,2523,2591],{"__ignoreMap":111},[125,2284,2285,2287],{"class":127,"line":128},[125,2286,227],{"class":225,"aria-hidden":226},[125,2288,230],{"class":157},[125,2290,2291,2293,2295,2297,2299],{"class":127,"line":161},[125,2292,227],{"class":225,"aria-hidden":226},[125,2294,238],{"class":237},[125,2296,241],{"class":131},[125,2298,244],{"class":237},[125,2300,247],{"class":131},[125,2302,2303,2305,2307,2309,2311],{"class":127,"line":179},[125,2304,227],{"class":225,"aria-hidden":226},[125,2306,238],{"class":237},[125,2308,256],{"class":131},[125,2310,244],{"class":237},[125,2312,261],{"class":131},[125,2314,2315,2317,2319],{"class":127,"line":264},[125,2316,227],{"class":225,"aria-hidden":226},[125,2318,244],{"class":237},[125,2320,271],{"class":131},[125,2322,2323,2325],{"class":127,"line":274},[125,2324,227],{"class":225,"aria-hidden":226},[125,2326,279],{},[125,2328,2329,2331,2333,2335],{"class":127,"line":282},[125,2330,227],{"class":225,"aria-hidden":226},[125,2332,287],{"class":131},[125,2334,136],{"class":135},[125,2336,292],{"class":146},[125,2338,2339,2341],{"class":127,"line":295},[125,2340,227],{"class":225,"aria-hidden":226},[125,2342,279],{},[125,2344,2345,2347,2349,2351,2353,2355,2357,2359,2361],{"class":127,"line":302},[125,2346,227],{"class":225,"aria-hidden":226},[125,2348,132],{"class":131},[125,2350,136],{"class":135},[125,2352,140],{"class":139},[125,2354,143],{"class":131},[125,2356,45],{"class":146},[125,2358,149],{"class":131},[125,2360,45],{"class":146},[125,2362,322],{"class":131},[125,2364,2365,2367,2369,2371,2373,2375],{"class":127,"data-cue":45,"line":326},[125,2366,45],{"class":305},[125,2368,164],{"class":131},[125,2370,2216],{"class":139},[125,2372,143],{"class":131},[125,2374,38],{"class":146},[125,2376,322],{"class":131},[125,2378,2379,2381,2383,2385,2387,2389,2391,2393],{"class":127,"line":342},[125,2380,227],{"class":225,"aria-hidden":226},[125,2382,164],{"class":131},[125,2384,79],{"class":139},[125,2386,143],{"class":131},[125,2388,38],{"class":146},[125,2390,149],{"class":131},[125,2392,38],{"class":146},[125,2394,322],{"class":131},[125,2396,2397,2399,2401],{"class":127,"line":361},[125,2398,227],{"class":225,"aria-hidden":226},[125,2400,366],{"class":135},[125,2402,369],{"class":131},[125,2404,2405,2407],{"class":127,"line":372},[125,2406,227],{"class":225,"aria-hidden":226},[125,2408,279],{},[125,2410,2411,2413,2415,2417,2419,2421,2423,2425,2427],{"class":127,"data-cue":325,"line":380},[125,2412,325],{"class":305},[125,2414,385],{"class":131},[125,2416,136],{"class":135},[125,2418,390],{"class":131},[125,2420,393],{"class":139},[125,2422,396],{"class":131},[125,2424,95],{"class":399},[125,2426,136],{"class":135},[125,2428,404],{"class":131},[125,2430,2431,2433,2435,2437,2439,2441,2443,2445,2447,2449,2451,2453,2455,2457],{"class":127,"line":407},[125,2432,227],{"class":225,"aria-hidden":226},[125,2434,412],{"class":237},[125,2436,415],{"class":131},[125,2438,418],{"class":139},[125,2440,421],{"class":131},[125,2442,424],{"class":237},[125,2444,427],{"class":237},[125,2446,430],{"class":131},[125,2448,433],{"class":146},[125,2450,436],{"class":131},[125,2452,439],{"class":146},[125,2454,436],{"class":131},[125,2456,444],{"class":146},[125,2458,447],{"class":131},[125,2460,2461,2463,2465,2467,2469,2471],{"class":127,"line":451},[125,2462,227],{"class":225,"aria-hidden":226},[125,2464,456],{"class":131},[125,2466,459],{"class":139},[125,2468,143],{"class":131},[125,2470,450],{"class":146},[125,2472,322],{"class":131},[125,2474,2475,2477],{"class":127,"line":468},[125,2476,227],{"class":225,"aria-hidden":226},[125,2478,279],{},[125,2480,2481,2483,2485,2487,2489,2491,2493,2495],{"class":127,"line":476},[125,2482,227],{"class":225,"aria-hidden":226},[125,2484,481],{"class":131},[125,2486,136],{"class":135},[125,2488,415],{"class":131},[125,2490,488],{"class":139},[125,2492,491],{"class":131},[125,2494,494],{"class":139},[125,2496,497],{"class":131},[125,2498,2499,2501,2503],{"class":127,"line":500},[125,2500,227],{"class":225,"aria-hidden":226},[125,2502,366],{"class":135},[125,2504,507],{"class":131},[125,2506,2507,2509,2511,2513,2515,2517,2519,2521],{"class":127,"line":510},[125,2508,227],{"class":225,"aria-hidden":226},[125,2510,515],{"class":237},[125,2512,518],{"class":131},[125,2514,521],{"class":237},[125,2516,524],{"class":135},[125,2518,527],{"class":131},[125,2520,530],{"class":139},[125,2522,533],{"class":131},[125,2524,2525,2527,2529,2531,2533,2535,2537,2539,2541,2543,2545,2547,2549,2551,2553,2555,2557,2559,2561,2563,2565,2567,2569,2571,2573,2575,2577,2579,2581,2583,2585,2587,2589],{"class":127,"data-cue":341,"line":536},[125,2526,341],{"class":305},[125,2528,541],{"class":135},[125,2530,143],{"class":131},[125,2532,546],{"class":237},[125,2534,550],{"class":549},[125,2536,553],{"class":146},[125,2538,556],{"class":131},[125,2540,559],{"class":146},[125,2542,562],{"class":549},[125,2544,553],{"class":146},[125,2546,567],{"class":131},[125,2548,570],{"class":237},[125,2550,559],{"class":146},[125,2552,1045],{"class":146},[125,2554,581],{"class":135},[125,2556,592],{"class":131},[125,2558,1052],{"class":135},[125,2560,1055],{"class":131},[125,2562,1058],{"class":237},[125,2564,559],{"class":146},[125,2566,1063],{"class":549},[125,2568,553],{"class":146},[125,2570,578],{"class":549},[125,2572,581],{"class":135},[125,2574,584],{"class":131},[125,2576,587],{"class":146},[125,2578,581],{"class":135},[125,2580,592],{"class":131},[125,2582,595],{"class":135},[125,2584,598],{"class":131},[125,2586,559],{"class":146},[125,2588,550],{"class":549},[125,2590,322],{"class":131},[606,2592,2593,2600,2607],{"class":608},[610,2594,2595,2597],{"data-cue":45},[125,2596,45],{"class":305},[125,2598,2599],{"class":616},"the Hadamard gate: half 0, half 1, and no value at all until it is measured",[610,2601,2602,2604],{"data-cue":325},[125,2603,325],{"class":305},[125,2605,2606],{"class":616},"one job per press of Run: press it again for another tally",[610,2608,2609,2611],{"data-cue":341},[125,2610,341],{"class":305},[125,2612,2613],{"class":616},"the share next to each bar, from lesson 1's second assignment",[12,2615,2616,2617,2619,2620,2622,2623,2625],{},"Two things changed in what the code does since lesson 1. The gate is ",[36,2618,2216],{}," instead of ",[36,2621,66],{},", and the bar loop prints each bar's share next to it, which was lesson 1's second assignment. Everything else, the qubit, the bit, the measurement, the job and ",[36,2624,203],{},", does the same as before.",[19,2627,2629],{"id":2628},"run-the-circuit-three-presses","Run the circuit, three presses",[12,2631,2632],{},"Three levels to keep apart. A shot is one execution of the circuit, start to finish. A job is one press: Run on Qollab, a choice in the dialog, then 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,2634,2635,2636,2638,2639,704,2641,2643,2644,2646],{},"Predict the tally. Then open ",[30,2637,677],{"href":2277},", press ",[683,2640,685],{},[683,2642,707],{}," under Remotely Run Simulators, and press ",[683,2645,711],{},". When the tally is in, note it and press twice more, choosing Aria 1 each time. Our first press took 17.9 seconds.",[107,2648],{"alt":2649,"caption":2650,"no":111,"src":2651},"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, and the next press lands somewhere else again. That is a fair split sampled a thousand times.","\u002F_content\u002Fimages\u002Ffirst-circuits\u002F02-superposition.webp",[12,2653,2654,2655,2658,2659,2658,2662,2665],{},"Our three presses on 15 September 2026, on the Aria 1 noise model, came back ",[36,2656,2657],{},"{'0': 487, '1': 513}",", then ",[36,2660,2661],{},"{'0': 505, '1': 495}",[36,2663,2664],{},"{'0': 511, '1': 489}",". Three different splits from one circuit, none of them 500\u002F500.",[12,2667,2668],{},"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 run in forty.",[12,2670,2671],{},"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.",[825,2673,2675,2679,2701],{"check":2674},"you have three single-shot tallies from three presses, each with one key and a count of 1, and an answer to the question.",[19,2676,2678],{"id":2677},"assignment-one-shot-at-a-time","Assignment: one shot at a time",[606,2680,2681,2688,2698],{},[610,2682,2683,2684,2687],{},"In your fork, set ",[36,2685,2686],{},"shots = 1"," and press three times, noting each tally.",[610,2689,2690,2691,42,2694,2697],{},"Each dict can only be ",[36,2692,2693],{},"{'0': 1}",[36,2695,2696],{},"{'1': 1}",". Try to reconstruct the 50\u002F50 split from your three dicts.",[610,2699,2700],{},"Write one sentence: what does one shot tell you about the weights inside the qubit?",[871,2702,2703],{"label":873},[12,2704,2705,2706,2708],{},"One shot tells you which answer came out this time, not how likely it was. A single ",[36,2707,2696],{}," is consistent with odds of 50\u002F50 and with 99\u002F1; it cannot tell them apart. The weights only appear across many shots, which is why a quantum program returns the tally rather than one answer.",[19,2710,2712],{"id":2711},"why-the-split-is-hardly-ever-exactly-half","Why the split is hardly ever exactly half",[12,2714,2715,2716,2718],{},"A fair split measured 1,000 times is a sample, and samples scatter. The expected count of ",[36,2717,45],{},"s is 500. The typical distance from it, the standard deviation, is the square root of 1,000 times one half times one half, about 16 shots. Nineteen runs in twenty land within twice that, between about 468 and 532.",[12,2720,2721],{},"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,2723,2724],{},"Multiplying the shots by a hundred divides the scatter, as a share, by ten. Precision grows with the square root of the shot count, not with the count.",[12,2726,2727],{},"The weights inside the qubit never change between presses. What changes is the sample, and a bigger sample estimates the same weights more tightly. Lesson 1's noise tail was the same lesson from the other side. There the rare event was noise; here the scatter is built into a fair split.",[825,2729,2731,2735,2759,2762],{"check":2730},"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.",[19,2732,2734],{"id":2733},"assignment-make-the-split-move","Assignment: make the split move",[606,2736,2737,2747,2750,2756],{},[610,2738,2739,2740,2743,2744,2746],{},"Set ",[36,2741,2742],{},"shots = 100",". Before you run, write down the band you expect the count of ",[36,2745,45],{},"s to land in: the expected count, 50, plus or minus twice the scatter, where the scatter is the square root of the shot count times one half. That gives 40 to 60.",[610,2748,2749],{},"Run, and note whether the count landed inside the band. Read the dict for the count and the Probabilities panel for the share.",[610,2751,2739,2752,2755],{},[36,2753,2754],{},"shots = 10000"," and work out its band the same way.",[610,2757,2758],{},"Run, and note whether the count landed inside it.",[12,2760,2761],{},"One press cannot prove the rule. It can only land inside or outside the band it predicts, and nineteen presses in twenty land inside.",[871,2763,2764,2767],{"label":873},[12,2765,2766],{},"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; a miss is not a contradiction, it is the one in twenty.",[12,2768,2769],{},"The rule to keep is the shape of the bands: a hundred times the shots buys ten times the precision, never a hundred.",[19,2771,2773],{"id":2772},"a-superposition-is-not-a-hidden-coin","A superposition is not a hidden coin",[12,2775,2776,2777,2779,2780,2782],{},"Everything in the tally so far looks like a coin: one press, one answer, and no way to predict it. Suppose the qubit after one Hadamard were secretly a ",[36,2778,38],{}," or secretly a ",[36,2781,45],{},", and the measurement merely revealed it.",[12,2784,2785,2786,2788,2789,2791],{},"The gate row gives the test. The Hadamard spreads a qubit at ",[36,2787,38],{}," evenly, and it spreads a qubit at ",[36,2790,45],{}," 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.",[825,2793,2794,2798,2821],{"check":827},[19,2795,2797],{"id":2796},"assignment-two-hadamards-in-a-row","Assignment: two Hadamards in a row",[606,2799,2800,2808,2815,2818],{},[610,2801,2739,2802,2804,2805,62],{},[36,2803,95],{}," back to ",[36,2806,2807],{},"1000",[610,2809,2810,2811,2814],{},"Add a second ",[36,2812,2813],{},"qc.h(0)"," directly under the first, before the measurement.",[610,2816,2817],{},"Write down two predictions: half and half, from the hidden-coin argument above, and the gate row's answer, its own inverse.",[610,2819,2820],{},"Decide which you believe, then run.",[871,2822,2823,2832,2895,2901],{"label":873},[12,2824,2825,2826,2828,2829,2831],{},"Every shot reads ",[36,2827,38],{},", bar a few stray ",[36,2830,45],{},"s from the noise model. The hidden coin predicted half and half and was wrong.",[117,2833,2835],{"className":119,"code":2834,"language":121,"meta":111,"style":111},"qc = QuantumCircuit(1, 1)\nqc.h(0)\nqc.h(0)\nqc.measure(0, 0)\n",[36,2836,2837,2855,2867,2879],{"__ignoreMap":111},[125,2838,2839,2841,2843,2845,2847,2849,2851,2853],{"class":127,"line":128},[125,2840,132],{"class":131},[125,2842,136],{"class":135},[125,2844,140],{"class":139},[125,2846,143],{"class":131},[125,2848,45],{"class":146},[125,2850,149],{"class":131},[125,2852,45],{"class":146},[125,2854,322],{"class":131},[125,2856,2857,2859,2861,2863,2865],{"class":127,"line":161},[125,2858,164],{"class":131},[125,2860,2216],{"class":139},[125,2862,143],{"class":131},[125,2864,38],{"class":146},[125,2866,322],{"class":131},[125,2868,2869,2871,2873,2875,2877],{"class":127,"line":179},[125,2870,164],{"class":131},[125,2872,2216],{"class":139},[125,2874,143],{"class":131},[125,2876,38],{"class":146},[125,2878,322],{"class":131},[125,2880,2881,2883,2885,2887,2889,2891,2893],{"class":127,"line":264},[125,2882,164],{"class":131},[125,2884,79],{"class":139},[125,2886,143],{"class":131},[125,2888,38],{"class":146},[125,2890,149],{"class":131},[125,2892,38],{"class":146},[125,2894,322],{"class":131},[12,2896,2897,2898,2900],{},"The Hadamard is its own inverse because the weights carry signs. After one Hadamard the two weights are equal in size and share a sign. A hidden ",[36,2899,45],{}," would have given equal sizes with opposite signs: the same tally, a different state.",[12,2902,2903,2904,2906],{},"The second Hadamard reads the signs. It adds the weights that agree and cancels the ones that disagree, and for the shared-sign state everything collects on ",[36,2905,38],{},". Lesson 5 is built on that step.",[12,2908,2909],{},"The Hadamard gave one qubit two possible answers. The next lesson adds a second qubit and a gate that acts on both, and the answers stop being independent of each other.",[1242,2911,2912],{},"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":111,"searchDepth":161,"depth":161,"links":2914},[2915,2916,2917,2918,2919,2920,2921,2922],{"id":2220,"depth":161,"text":2221},{"id":101,"depth":161,"text":102},{"id":2628,"depth":161,"text":2629},{"id":2677,"depth":161,"text":2678},{"id":2711,"depth":161,"text":2712},{"id":2733,"depth":161,"text":2734},{"id":2772,"depth":161,"text":2773},{"id":2796,"depth":161,"text":2797},[1260,1261,1262,2204],[],{"username":7,"name":1265,"role":1266,"avatar":1267},"The Hadamard gate takes a fresh qubit and leaves it with no value until it is measured. Run it 1,000 times, three presses over, and read what a tally can and cannot tell you.",{"image":2928,"alt":2929},"\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":2932,"title":2933,"desc":2934},"\u002Fblog\u002Flearn\u002Fprogramming-your-first-quantum-circuits\u002Ftwo-qubits","3 · Two qubits and the Bell pair","The CNOT gate as a controlled flip, then the Bell pair, and how to read a two-bit string in Qiskit.","10 min read",[],{"title":2938,"description":2939},"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",[],"ZQbHba1CpV-nXIEFhHFH8Www1bwRY19vK59jqhv0o0I",{"id":2944,"title":2945,"authors":2946,"body":2947,"breadcrumb":3978,"builders":3979,"byline":3980,"category":1268,"categoryName":1268,"challenge":1268,"courseAuthor":1268,"courseLead":1268,"dek":2934,"description":3981,"draft":1270,"extension":1271,"eyebrow":1268,"featured":1270,"finish":1268,"fork":1268,"hero":3982,"heroAlt":1268,"heroCta":1268,"heroImage":1268,"homepageFeatured":1270,"kind":1275,"lessonCount":282,"meta":3985,"navigation":1277,"newsItems":1268,"next":3986,"ogImage":1268,"order":179,"outcomes":1268,"path":2932,"publishDate":1283,"readingTime":1284,"related":3990,"relatedProjects":1268,"seo":3991,"stem":3994,"tags":3995,"track":1291,"trackName":1262,"__hash__":3996},"blog\u002Fblog\u002Flearn\u002Fprogramming-your-first-quantum-circuits\u002Ftwo-qubits.md","Two qubits and the Bell pair",[7],{"type":9,"value":2948,"toc":3967},[2949,2952,2955,2959,2968,2978,2992,3001,3033,3052,3054,3059,3062,3155,3158,3540,3544,3566,3571,3584,3598,3602,3612,3626,3643,3765,3769,3777,3835,3839,3844,3962,3965],[12,2950,2951],{},"One qubit gave answers that were uncertain. Two qubits give answers that can be uncertain and still agree with each other, every time. This lesson builds the smallest circuit that does that, the Bell pair, and along the way teaches the one gate that makes qubits act together.",[12,2953,2954],{},"The answer now has two characters instead of one, and Qiskit writes them in an order that catches most people out the first time. This lesson covers it before the first tally arrives.",[19,2956,2958],{"id":2957},"a-gate-that-acts-on-two-qubits","A gate that acts on two qubits",[12,2960,2961,2962,2964,2965,2967],{},"Every gate so far acted on one qubit. The CNOT acts on two: a control and a target. It looks at the control and flips the target only if the control is ",[36,2963,45],{},". With the control at ",[36,2966,38],{}," it does nothing at all.",[12,2969,2970,2971,2974,2975,2977],{},"On its own that is a plain conditional, the kind of thing an ordinary program does with an ",[36,2972,2973],{},"if",". The difference from an ",[36,2976,2973],{}," shows when the control is in superposition.",[12,2979,2980,2981,2983,2984,2986,2987,2989,2990,62],{},"The CNOT does not pick one of the control's two options and act on that. It applies its rule to each option separately, inside the superposition: where the control is ",[36,2982,38],{}," the target stays ",[36,2985,38],{},", and where the control is ",[36,2988,45],{}," the target flips to ",[36,2991,45],{},[12,2993,2994,2995,2997,2998,3000],{},"So the target's options become tied to the control's: both ",[36,2996,38],{}," together, or both ",[36,2999,45],{}," together, and never one of each.",[48,3002,3005],{"name":3003,"token":3004},"The CNOT gate","cx",[12,3006,3007,3010,3011,3013,3014,3016,3017,3019,3020,42,3023,3026,3027,42,3030,62],{},[36,3008,3009],{},"cx(control, target)",". Flips the target if the control is ",[36,3012,45],{},", leaves it alone if the control is ",[36,3015,38],{},". Applied to a target at ",[36,3018,38],{}," while the control is in superposition, it makes the two qubits agree: measure them and you get ",[36,3021,3022],{},"00",[36,3024,3025],{},"11",", never ",[36,3028,3029],{},"01",[36,3031,3032],{},"10",[48,3034,3036],{"name":3035,"token":3022},"Two-character answers",[12,3037,3038,3039,3042,3043,3045,3046,3048,3049,3051],{},"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 ",[683,3040,3041],{},"right",": the string ",[36,3044,3032],{}," means qubit 1 read ",[36,3047,45],{}," and qubit 0 read ",[36,3050,38],{},". Read the string from the right to read it in qubit order.",[19,3053,102],{"id":101},[107,3055],{"alt":3056,"caption":3057,"no":111,"src":3058},"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, the two wires carry the same two options, together.","\u002F_content\u002Fimages\u002Ffirst-circuits\u002Ftwo-qubit-bell-circuit.svg",[12,3060,3061],{},"The circuit is three gates and two measurements:",[117,3063,3065],{"className":119,"code":3064,"language":121,"meta":111,"style":111},"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",[36,3066,3067,3089,3105,3125],{"__ignoreMap":111},[125,3068,3069,3071,3073,3075,3077,3079,3081,3083,3086],{"class":127,"line":128},[125,3070,132],{"class":131},[125,3072,136],{"class":135},[125,3074,140],{"class":139},[125,3076,143],{"class":131},[125,3078,325],{"class":146},[125,3080,149],{"class":131},[125,3082,325],{"class":146},[125,3084,3085],{"class":131},")     ",[125,3087,3088],{"class":157},"# two qubits, two ordinary bits\n",[125,3090,3091,3093,3095,3097,3099,3102],{"class":127,"line":161},[125,3092,164],{"class":131},[125,3094,2216],{"class":139},[125,3096,143],{"class":131},[125,3098,38],{"class":146},[125,3100,3101],{"class":131},")                       ",[125,3103,3104],{"class":157},"# qubit 0 into superposition\n",[125,3106,3107,3109,3111,3113,3115,3117,3119,3122],{"class":127,"line":179},[125,3108,164],{"class":131},[125,3110,3004],{"class":139},[125,3112,143],{"class":131},[125,3114,38],{"class":146},[125,3116,149],{"class":131},[125,3118,45],{"class":146},[125,3120,3121],{"class":131},")                   ",[125,3123,3124],{"class":157},"# CNOT: control qubit 0, target qubit 1\n",[125,3126,3127,3129,3131,3134,3136,3138,3140,3143,3145,3147,3149,3152],{"class":127,"line":264},[125,3128,164],{"class":131},[125,3130,79],{"class":139},[125,3132,3133],{"class":131},"([",[125,3135,38],{"class":146},[125,3137,149],{"class":131},[125,3139,45],{"class":146},[125,3141,3142],{"class":131},"], [",[125,3144,38],{"class":146},[125,3146,149],{"class":131},[125,3148,45],{"class":146},[125,3150,3151],{"class":131},"])    ",[125,3153,3154],{"class":157},"# qubit 0 into bit 0, qubit 1 into bit 1\n",[12,3156,3157],{},"The plumbing is lesson 1's, unchanged. The keys of the counts dict are two characters now, and the bar loop prints one line per string that was read.",[211,3159,3162],{"name":3160,"no-picker":111,"run-href":3161,"tag":215},"two_qubits.py","\u002Fu\u002Fqollab\u002Flearn-two-qubits",[117,3163,3165],{"className":119,"code":3164,"language":121,"meta":111,"style":111},"# '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",[36,3166,3167,3173,3185,3197,3205,3211,3221,3227,3247,3261,3279,3306,3314,3320,3340,3370,3384,3390,3408,3416,3434,3503],{"__ignoreMap":111},[125,3168,3169,3171],{"class":127,"line":128},[125,3170,227],{"class":225,"aria-hidden":226},[125,3172,230],{"class":157},[125,3174,3175,3177,3179,3181,3183],{"class":127,"line":161},[125,3176,227],{"class":225,"aria-hidden":226},[125,3178,238],{"class":237},[125,3180,241],{"class":131},[125,3182,244],{"class":237},[125,3184,247],{"class":131},[125,3186,3187,3189,3191,3193,3195],{"class":127,"line":179},[125,3188,227],{"class":225,"aria-hidden":226},[125,3190,238],{"class":237},[125,3192,256],{"class":131},[125,3194,244],{"class":237},[125,3196,261],{"class":131},[125,3198,3199,3201,3203],{"class":127,"line":264},[125,3200,227],{"class":225,"aria-hidden":226},[125,3202,244],{"class":237},[125,3204,271],{"class":131},[125,3206,3207,3209],{"class":127,"line":274},[125,3208,227],{"class":225,"aria-hidden":226},[125,3210,279],{},[125,3212,3213,3215,3217,3219],{"class":127,"line":282},[125,3214,227],{"class":225,"aria-hidden":226},[125,3216,287],{"class":131},[125,3218,136],{"class":135},[125,3220,292],{"class":146},[125,3222,3223,3225],{"class":127,"line":295},[125,3224,227],{"class":225,"aria-hidden":226},[125,3226,279],{},[125,3228,3229,3231,3233,3235,3237,3239,3241,3243,3245],{"class":127,"data-cue":45,"line":302},[125,3230,45],{"class":305},[125,3232,132],{"class":131},[125,3234,136],{"class":135},[125,3236,140],{"class":139},[125,3238,143],{"class":131},[125,3240,325],{"class":146},[125,3242,149],{"class":131},[125,3244,325],{"class":146},[125,3246,322],{"class":131},[125,3248,3249,3251,3253,3255,3257,3259],{"class":127,"data-cue":325,"line":326},[125,3250,325],{"class":305},[125,3252,164],{"class":131},[125,3254,2216],{"class":139},[125,3256,143],{"class":131},[125,3258,38],{"class":146},[125,3260,322],{"class":131},[125,3262,3263,3265,3267,3269,3271,3273,3275,3277],{"class":127,"data-cue":341,"line":342},[125,3264,341],{"class":305},[125,3266,164],{"class":131},[125,3268,3004],{"class":139},[125,3270,143],{"class":131},[125,3272,38],{"class":146},[125,3274,149],{"class":131},[125,3276,45],{"class":146},[125,3278,322],{"class":131},[125,3280,3281,3283,3285,3287,3289,3291,3293,3295,3297,3299,3301,3303],{"class":127,"data-cue":379,"line":361},[125,3282,379],{"class":305},[125,3284,164],{"class":131},[125,3286,79],{"class":139},[125,3288,3133],{"class":131},[125,3290,38],{"class":146},[125,3292,149],{"class":131},[125,3294,45],{"class":146},[125,3296,3142],{"class":131},[125,3298,38],{"class":146},[125,3300,149],{"class":131},[125,3302,45],{"class":146},[125,3304,3305],{"class":131},"])\n",[125,3307,3308,3310,3312],{"class":127,"line":372},[125,3309,227],{"class":225,"aria-hidden":226},[125,3311,366],{"class":135},[125,3313,369],{"class":131},[125,3315,3316,3318],{"class":127,"line":380},[125,3317,227],{"class":225,"aria-hidden":226},[125,3319,279],{},[125,3321,3322,3324,3326,3328,3330,3332,3334,3336,3338],{"class":127,"line":407},[125,3323,227],{"class":225,"aria-hidden":226},[125,3325,385],{"class":131},[125,3327,136],{"class":135},[125,3329,390],{"class":131},[125,3331,393],{"class":139},[125,3333,396],{"class":131},[125,3335,95],{"class":399},[125,3337,136],{"class":135},[125,3339,404],{"class":131},[125,3341,3342,3344,3346,3348,3350,3352,3354,3356,3358,3360,3362,3364,3366,3368],{"class":127,"line":451},[125,3343,227],{"class":225,"aria-hidden":226},[125,3345,412],{"class":237},[125,3347,415],{"class":131},[125,3349,418],{"class":139},[125,3351,421],{"class":131},[125,3353,424],{"class":237},[125,3355,427],{"class":237},[125,3357,430],{"class":131},[125,3359,433],{"class":146},[125,3361,436],{"class":131},[125,3363,439],{"class":146},[125,3365,436],{"class":131},[125,3367,444],{"class":146},[125,3369,447],{"class":131},[125,3371,3372,3374,3376,3378,3380,3382],{"class":127,"line":468},[125,3373,227],{"class":225,"aria-hidden":226},[125,3375,456],{"class":131},[125,3377,459],{"class":139},[125,3379,143],{"class":131},[125,3381,450],{"class":146},[125,3383,322],{"class":131},[125,3385,3386,3388],{"class":127,"line":476},[125,3387,227],{"class":225,"aria-hidden":226},[125,3389,279],{},[125,3391,3392,3394,3396,3398,3400,3402,3404,3406],{"class":127,"line":500},[125,3393,227],{"class":225,"aria-hidden":226},[125,3395,481],{"class":131},[125,3397,136],{"class":135},[125,3399,415],{"class":131},[125,3401,488],{"class":139},[125,3403,491],{"class":131},[125,3405,494],{"class":139},[125,3407,497],{"class":131},[125,3409,3410,3412,3414],{"class":127,"line":510},[125,3411,227],{"class":225,"aria-hidden":226},[125,3413,366],{"class":135},[125,3415,507],{"class":131},[125,3417,3418,3420,3422,3424,3426,3428,3430,3432],{"class":127,"data-cue":450,"line":536},[125,3419,450],{"class":305},[125,3421,515],{"class":237},[125,3423,518],{"class":131},[125,3425,521],{"class":237},[125,3427,524],{"class":135},[125,3429,527],{"class":131},[125,3431,530],{"class":139},[125,3433,533],{"class":131},[125,3435,3437,3439,3441,3443,3445,3447,3449,3451,3453,3455,3457,3459,3461,3463,3465,3467,3469,3471,3473,3475,3477,3479,3481,3483,3485,3487,3489,3491,3493,3495,3497,3499,3501],{"class":127,"line":3436},21,[125,3438,227],{"class":225,"aria-hidden":226},[125,3440,541],{"class":135},[125,3442,143],{"class":131},[125,3444,546],{"class":237},[125,3446,550],{"class":549},[125,3448,553],{"class":146},[125,3450,556],{"class":131},[125,3452,559],{"class":146},[125,3454,562],{"class":549},[125,3456,553],{"class":146},[125,3458,567],{"class":131},[125,3460,570],{"class":237},[125,3462,559],{"class":146},[125,3464,1045],{"class":146},[125,3466,581],{"class":135},[125,3468,592],{"class":131},[125,3470,1052],{"class":135},[125,3472,1055],{"class":131},[125,3474,1058],{"class":237},[125,3476,559],{"class":146},[125,3478,1063],{"class":549},[125,3480,553],{"class":146},[125,3482,578],{"class":549},[125,3484,581],{"class":135},[125,3486,584],{"class":131},[125,3488,587],{"class":146},[125,3490,581],{"class":135},[125,3492,592],{"class":131},[125,3494,595],{"class":135},[125,3496,598],{"class":131},[125,3498,559],{"class":146},[125,3500,550],{"class":549},[125,3502,322],{"class":131},[606,3504,3505,3512,3519,3526,3533],{"class":608},[610,3506,3507,3509],{"data-cue":45},[125,3508,45],{"class":305},[125,3510,3511],{"class":616},"two qubits, two ordinary bits",[610,3513,3514,3516],{"data-cue":325},[125,3515,325],{"class":305},[125,3517,3518],{"class":616},"qubit 0 into superposition, as in lesson 2",[610,3520,3521,3523],{"data-cue":341},[125,3522,341],{"class":305},[125,3524,3525],{"class":616},"the CNOT: flip qubit 1 if qubit 0 is 1, and it acts inside the superposition",[610,3527,3528,3530],{"data-cue":379},[125,3529,379],{"class":305},[125,3531,3532],{"class":616},"read both: qubit 0 into bit 0, qubit 1 into bit 1",[610,3534,3535,3537],{"data-cue":450},[125,3536,450],{"class":305},[125,3538,3539],{"class":616},"each key is now two characters: bit 1 on the left, bit 0 on the right",[19,3541,3543],{"id":3542},"run-the-circuit","Run the circuit",[12,3545,3546,3547,149,3549,149,3551,1182,3553,3555,3556,2638,3558,704,3560,3562,3563,3565],{},"Predict the tally first. Four strings are possible, ",[36,3548,3022],{},[36,3550,3029],{},[36,3552,3032],{},[36,3554,3025],{},". Which of them will you see, and in what shares? Then open ",[30,3557,677],{"href":3161},[683,3559,685],{},[683,3561,707],{},", and press ",[683,3564,711],{},". Then fork it, the way lesson 1 showed, so the edits below land in your own copy.",[107,3567],{"alt":3568,"caption":3569,"no":111,"src":3570},"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 everything. 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. Those four are the noise model, not the circuit.","\u002F_content\u002Fimages\u002Ffirst-circuits\u002F03-two-qubits.webp",[12,3572,3573,3574,3577,3578,3580,3581,3583],{},"Our run on 15 September 2026, on the Aria 1 noise model, came back ",[36,3575,3576],{},"{'00': 512, '01': 3, '10': 1, '11': 484}",": 51.2% ",[36,3579,3022],{},", 48.4% ",[36,3582,3025],{},", and four shots in a thousand where the two qubits disagreed.",[12,3585,3586,3587,3589,3590,3592,3593,1182,3595,3597],{},"Half ",[36,3588,3022],{},", half ",[36,3591,3025],{},", and a sliver of ",[36,3594,3029],{},[36,3596,3032],{},". The sliver is the noise model; on a perfect simulator the pair never disagrees. If you predicted four strings at a quarter each, the reading below is for you.",[19,3599,3601],{"id":3600},"why-the-pair-always-agrees","Why the pair always agrees",[12,3603,3604,3605,1182,3607,3609,3610,62],{},"Follow the circuit in order. After the Hadamard, qubit 0 carries two options, ",[36,3606,38],{},[36,3608,45],{},", with no value chosen. The CNOT then says: flip qubit 1 wherever qubit 0 is ",[36,3611,45],{},[12,3613,3614,3615,3617,3618,3620,3621,3623,3624,62],{},"It applies that rule to both options at once. Where qubit 0 is ",[36,3616,38],{},", qubit 1 stays ",[36,3619,38],{},"; where qubit 0 is ",[36,3622,45],{},", qubit 1 becomes ",[36,3625,45],{},[12,3627,3628,3629,42,3631,3633,3634,42,3636,3638,3639,62],{},"So the circuit never holds ",[36,3630,3029],{},[36,3632,3032],{}," as an option, and measuring cannot produce them. What it holds is ",[36,3635,3022],{},[36,3637,3025],{},", weighted half and half, and the measurement picks one of those. Two qubits in that state are called a Bell pair, the smallest case of ",[30,3640,3642],{"href":3641},"\u002Flearn\u002Fquantum-entanglement","entanglement",[825,3644,3646,3650,3673],{"check":3645},"every shot reads 11, bar a stray 01 or 10 from the noise model.",[19,3647,3649],{"id":3648},"assignment-make-the-cnot-copy-a-plain-1","Assignment: make the CNOT copy a plain 1",[606,3651,3652,3664,3670],{},[610,3653,3654,3655,3657,3658,3660,3661,3663],{},"In your fork, replace ",[36,3656,2813],{}," with ",[36,3659,848],{},", so qubit 0 is a definite ",[36,3662,45],{}," when the CNOT sees it. There is no superposition now, so the CNOT has one case to handle.",[610,3665,3666,3667,3669],{},"Apply the gate row's rule, flip the target if the control is ",[36,3668,45],{},", and work out what each of the two measurements reads. Write the answer as a string with qubit 0 on the right.",[610,3671,3672],{},"Run and compare.",[871,3674,3675,3750],{"label":873},[117,3676,3678],{"className":119,"code":3677,"language":121,"meta":111,"style":111},"qc = QuantumCircuit(2, 2)\nqc.x(0)\nqc.cx(0, 1)\nqc.measure([0, 1], [0, 1])\n",[36,3679,3680,3698,3710,3726],{"__ignoreMap":111},[125,3681,3682,3684,3686,3688,3690,3692,3694,3696],{"class":127,"line":128},[125,3683,132],{"class":131},[125,3685,136],{"class":135},[125,3687,140],{"class":139},[125,3689,143],{"class":131},[125,3691,325],{"class":146},[125,3693,149],{"class":131},[125,3695,325],{"class":146},[125,3697,322],{"class":131},[125,3699,3700,3702,3704,3706,3708],{"class":127,"line":161},[125,3701,164],{"class":131},[125,3703,66],{"class":139},[125,3705,143],{"class":131},[125,3707,38],{"class":146},[125,3709,322],{"class":131},[125,3711,3712,3714,3716,3718,3720,3722,3724],{"class":127,"line":179},[125,3713,164],{"class":131},[125,3715,3004],{"class":139},[125,3717,143],{"class":131},[125,3719,38],{"class":146},[125,3721,149],{"class":131},[125,3723,45],{"class":146},[125,3725,322],{"class":131},[125,3727,3728,3730,3732,3734,3736,3738,3740,3742,3744,3746,3748],{"class":127,"line":264},[125,3729,164],{"class":131},[125,3731,79],{"class":139},[125,3733,3133],{"class":131},[125,3735,38],{"class":146},[125,3737,149],{"class":131},[125,3739,45],{"class":146},[125,3741,3142],{"class":131},[125,3743,38],{"class":146},[125,3745,149],{"class":131},[125,3747,45],{"class":146},[125,3749,3305],{"class":131},[12,3751,3752,3753,3755,3756,3758,3759,3761,3762,3764],{},"Qubit 0 is ",[36,3754,45],{},", so the CNOT flips qubit 1 to ",[36,3757,45],{},". Both read ",[36,3760,45],{}," and every shot is ",[36,3763,3025],{},". This is the CNOT as an ordinary conditional; the previous run was the same gate with a control that had not decided.",[19,3766,3768],{"id":3767},"which-character-is-which-qubit","Which character is which qubit",[12,3770,3771,3772,1182,3774,3776],{},"The Bell pair hides the bit order, because ",[36,3773,3022],{},[36,3775,3025],{}," read the same either way. The next task does not: it produces a string where the order matters, and asks you to call it before you see it.",[825,3778,3780,3784,3810],{"check":3779},"you predicted one of 01 and 10, and the tally shows the string you predicted, bar the noise.",[19,3781,3783],{"id":3782},"assignment-find-qubit-0-in-the-string","Assignment: find qubit 0 in the string",[606,3785,3786,3796,3802],{},[610,3787,3788,3789,3791,3792,3795],{},"Starting from the version with ",[36,3790,848],{},", change that line to ",[36,3793,3794],{},"qc.x(1)"," and leave the CNOT in.",[610,3797,3798,3799,3801],{},"Work out two things before you run: whether the CNOT changes its target at all, now that its control, qubit 0, is never flipped; and which character the qubit that reads ",[36,3800,45],{}," is written in, by the gate row on two-character answers.",[610,3803,3804,3805,42,3807,3809],{},"Write down ",[36,3806,3029],{},[36,3808,3032],{},", then run.",[871,3811,3812,3829],{"label":873},[12,3813,3814,3815,3817,3818,3820,3821,3823,3824,3826,3827,62],{},"Qubit 0 stays ",[36,3816,38],{},", so the CNOT does nothing to qubit 1, which keeps the ",[36,3819,45],{}," the X gate gave it. Qubit 1 is ",[36,3822,45],{}," and qubit 0 is ",[36,3825,38],{},", and Qiskit writes qubit 0 on the right: the string is ",[36,3828,3032],{},[12,3830,3831,3832,3834],{},"If you expected ",[36,3833,3029],{},", you read the string left to right in qubit order. Read the tally from the right, qubit 0 first.",[19,3836,3838],{"id":3837},"measuring-is-per-qubit","Measuring is per qubit",[12,3840,3841,3842,62],{},"The pair agrees when both qubits are measured. Measuring only one of them is a legal circuit too, and the tally still shows two characters, because there are still two bits. A bit that no measurement writes to stays at ",[36,3843,38],{},[825,3845,3847,3851,3877],{"check":3846},"the tally shows two strings, 00 and 01, about half each, and nothing else.",[19,3848,3850],{"id":3849},"assignment-read-only-one-qubit-of-the-pair","Assignment: read only one qubit of the pair",[606,3852,3853,3864,3871,3874],{},[610,3854,3855,3856,2804,3858,3860,3861,3863],{},"Change ",[36,3857,3794],{},[36,3859,2813],{},", so the circuit is the Bell pair again: ",[36,3862,2813],{},", then the CNOT.",[610,3865,3866,3867,3870],{},"Replace the measurement line with ",[36,3868,3869],{},"qc.measure(0, 0)",", so only qubit 0 is read.",[610,3872,3873],{},"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.",[610,3875,3876],{},"Put the two together into two-character strings, qubit 0 on the right, then run.",[871,3878,3879,3946],{"label":873},[117,3880,3882],{"className":119,"code":3881,"language":121,"meta":111,"style":111},"qc = QuantumCircuit(2, 2)\nqc.h(0)\nqc.cx(0, 1)\nqc.measure(0, 0)\n",[36,3883,3884,3902,3914,3930],{"__ignoreMap":111},[125,3885,3886,3888,3890,3892,3894,3896,3898,3900],{"class":127,"line":128},[125,3887,132],{"class":131},[125,3889,136],{"class":135},[125,3891,140],{"class":139},[125,3893,143],{"class":131},[125,3895,325],{"class":146},[125,3897,149],{"class":131},[125,3899,325],{"class":146},[125,3901,322],{"class":131},[125,3903,3904,3906,3908,3910,3912],{"class":127,"line":161},[125,3905,164],{"class":131},[125,3907,2216],{"class":139},[125,3909,143],{"class":131},[125,3911,38],{"class":146},[125,3913,322],{"class":131},[125,3915,3916,3918,3920,3922,3924,3926,3928],{"class":127,"line":179},[125,3917,164],{"class":131},[125,3919,3004],{"class":139},[125,3921,143],{"class":131},[125,3923,38],{"class":146},[125,3925,149],{"class":131},[125,3927,45],{"class":146},[125,3929,322],{"class":131},[125,3931,3932,3934,3936,3938,3940,3942,3944],{"class":127,"line":264},[125,3933,164],{"class":131},[125,3935,79],{"class":139},[125,3937,143],{"class":131},[125,3939,38],{"class":146},[125,3941,149],{"class":131},[125,3943,38],{"class":146},[125,3945,322],{"class":131},[12,3947,3948,3949,42,3951,3953,3954,3956,3957,1182,3959,3961],{},"Qubit 0 reads ",[36,3950,38],{},[36,3952,45],{},", half each. Bit 1 stays ",[36,3955,38],{},". So the tally is ",[36,3958,3022],{},[36,3960,3029],{},", about half each. Qubit 1 was in the pair the whole time; you simply did not ask it. Ask both again and the agreement comes back.",[12,3963,3964],{},"Every gate so far was all or nothing: a full flip, a full spread, a full copy. The next lesson turns the gate into a dial.",[1242,3966,1244],{},{"title":111,"searchDepth":161,"depth":161,"links":3968},[3969,3970,3971,3972,3973,3974,3975,3976,3977],{"id":2957,"depth":161,"text":2958},{"id":101,"depth":161,"text":102},{"id":3542,"depth":161,"text":3543},{"id":3600,"depth":161,"text":3601},{"id":3648,"depth":161,"text":3649},{"id":3767,"depth":161,"text":3768},{"id":3782,"depth":161,"text":3783},{"id":3837,"depth":161,"text":3838},{"id":3849,"depth":161,"text":3850},[1260,1261,1262,2945],[],{"username":7,"name":1265,"role":1266,"avatar":1267},"Add a second qubit and a gate that acts on both. The CNOT as a controlled flip, then the Bell pair, and how to read a two-character answer in Qiskit.",{"image":3983,"alt":3984},"\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":3987,"title":3988,"desc":3989},"\u002Fblog\u002Flearn\u002Fprogramming-your-first-quantum-circuits\u002Frotations","4 · Rotate a qubit by any angle","RY and RZ: a gate can be partial, the Bloch sphere is its picture, and a phase alone is invisible.",[],{"title":3992,"description":3993},"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",[],"-79jcLB2VwNxJjm0IjE5xeaDD9lxCyeVawI4ZRTo-8k",{"id":3998,"title":3999,"authors":4000,"body":4001,"breadcrumb":5049,"builders":5050,"byline":5051,"category":1268,"categoryName":1268,"challenge":1268,"courseAuthor":1268,"courseLead":1268,"dek":3989,"description":5052,"draft":1270,"extension":1271,"eyebrow":1268,"featured":1270,"finish":1268,"fork":1268,"hero":5053,"heroAlt":1268,"heroCta":1268,"heroImage":1268,"homepageFeatured":1270,"kind":1275,"lessonCount":282,"meta":5056,"navigation":1277,"newsItems":1268,"next":5057,"ogImage":1268,"order":264,"outcomes":1268,"path":3987,"publishDate":1283,"readingTime":1284,"related":5061,"relatedProjects":1268,"seo":5062,"stem":5065,"tags":5066,"track":1291,"trackName":1262,"__hash__":5067},"blog\u002Fblog\u002Flearn\u002Fprogramming-your-first-quantum-circuits\u002Frotations.md","Rotate a qubit by any angle",[7],{"type":9,"value":4002,"toc":5039},[4003,4006,4009,4013,4036,4043,4053,4056,4061,4086,4088,4091,4167,4173,4573,4577,4595,4610,4615,4618,4728,4742,4799,4803,4814,4817,4832,4835,4914,4918,4936,4939,4945,4948,4962,4965,4968,5033,5036],[12,4004,4005],{},"The X gate flipped a qubit all the way. The Hadamard spread it exactly in half. In what they do to a fresh qubit, both are stops on one dial: a gate that takes an angle and moves the qubit part of the way.",[12,4007,4008],{},"With it, a circuit stops being a list of yes-or-no operations and becomes something you tune. That is what a rotation gate is for, and it is how a circuit gets odds other than all-or-nothing.",[19,4010,4012],{"id":4011},"a-gate-with-a-dial","A gate with a dial",[12,4014,4015,4018,4019,4022,4023,4025,4026,4028,4029,4032,4033,4035],{},[36,4016,4017],{},"ry(theta, 0)"," rotates qubit 0 by the angle ",[36,4020,4021],{},"theta",", in radians. At ",[36,4024,38],{}," it does nothing and the qubit stays at ",[36,4027,38],{},". At ",[36,4030,4031],{},"pi"," it flips a fresh qubit all the way to ",[36,4034,45],{},", the same tally the X gate gave in lesson 1.",[12,4037,4038,4039,4042],{},"At ",[36,4040,4041],{},"pi \u002F 2",", halfway, it gives the same even split the Hadamard gave in lesson 2. In between, it sets the odds anywhere you like.",[12,4044,4045,4046,4049,4050,4052],{},"The rule is short. After ",[36,4047,4048],{},"ry(theta)"," on a fresh qubit, the share of shots that read ",[36,4051,45],{}," is sin²(θ\u002F2): take the sine of half the angle and square it.",[12,4054,4055],{},"The foundations course derives it from the geometry of the qubit. Here it is the thing to check against real runs, in code, one press per angle.",[107,4057],{"alt":4058,"caption":4059,"no":111,"src":4060},"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.","The dial and the rule. The share of 1 is not proportional to the angle: it climbs slowly near the ends and fast through the middle, which is what sin²(θ\u002F2) looks like.","\u002F_content\u002Fimages\u002Ffirst-circuits\u002Fry-dial.svg",[48,4062,4065],{"name":4063,"token":4064},"Rotation around Y","ry",[12,4066,4067,4068,4071,4072,4074,4075,149,4077,4079,4080,4082,4083,4085],{},"The dial. ",[36,4069,4070],{},"ry(theta, qubit)"," rotates the qubit by an angle in radians: ",[36,4073,38],{}," leaves it at ",[36,4076,38],{},[36,4078,4031],{}," flips it, ",[36,4081,4041],{}," is the even split. The share of ",[36,4084,45],{}," after it is sin²(θ\u002F2), and two rotations in a row add their angles. The Y is the axis it turns around.",[19,4087,102],{"id":101},[12,4089,4090],{},"One qubit, one rotation, one measurement. The angle sits at the top of the file so it can be changed without touching the circuit:",[117,4092,4094],{"className":119,"code":4093,"language":121,"meta":111,"style":111},"theta = pi \u002F 4\n\nqc = QuantumCircuit(1, 1)\nqc.ry(theta, 0)               # rotate qubit 0 by theta\nqc.measure(0, 0)\n",[36,4095,4096,4111,4116,4134,4151],{"__ignoreMap":111},[125,4097,4098,4101,4103,4106,4108],{"class":127,"line":128},[125,4099,4100],{"class":131},"theta ",[125,4102,136],{"class":135},[125,4104,4105],{"class":131}," pi ",[125,4107,1052],{"class":135},[125,4109,4110],{"class":146}," 4\n",[125,4112,4113],{"class":127,"line":161},[125,4114,4115],{"emptyLinePlaceholder":1277},"\n",[125,4117,4118,4120,4122,4124,4126,4128,4130,4132],{"class":127,"line":179},[125,4119,132],{"class":131},[125,4121,136],{"class":135},[125,4123,140],{"class":139},[125,4125,143],{"class":131},[125,4127,45],{"class":146},[125,4129,149],{"class":131},[125,4131,45],{"class":146},[125,4133,322],{"class":131},[125,4135,4136,4138,4140,4143,4145,4148],{"class":127,"line":264},[125,4137,164],{"class":131},[125,4139,4064],{"class":139},[125,4141,4142],{"class":131},"(theta, ",[125,4144,38],{"class":146},[125,4146,4147],{"class":131},")               ",[125,4149,4150],{"class":157},"# rotate qubit 0 by theta\n",[125,4152,4153,4155,4157,4159,4161,4163,4165],{"class":127,"line":274},[125,4154,164],{"class":131},[125,4156,79],{"class":139},[125,4158,143],{"class":131},[125,4160,38],{"class":146},[125,4162,149],{"class":131},[125,4164,38],{"class":146},[125,4166,322],{"class":131},[12,4168,4169,4170,4172],{},"The plumbing gains two lines at the end. One pulls the measured share of ",[36,4171,45],{}," 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.",[211,4174,4177],{"name":4175,"no-picker":111,"run-href":4176,"tag":215},"rotations.py","\u002Fu\u002Fqollab\u002Flearn-rotations",[117,4178,4180],{"className":119,"code":4179,"language":121,"meta":111,"style":111},"# '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",[36,4181,4182,4188,4202,4214,4226,4234,4240,4250,4264,4270,4290,4304,4322,4330,4336,4356,4386,4400,4406,4424,4432,4462,4491,4543],{"__ignoreMap":111},[125,4183,4184,4186],{"class":127,"line":128},[125,4185,227],{"class":225,"aria-hidden":226},[125,4187,230],{"class":157},[125,4189,4190,4192,4194,4197,4199],{"class":127,"line":161},[125,4191,227],{"class":225,"aria-hidden":226},[125,4193,238],{"class":237},[125,4195,4196],{"class":131}," math ",[125,4198,244],{"class":237},[125,4200,4201],{"class":131}," pi, sin\n",[125,4203,4204,4206,4208,4210,4212],{"class":127,"line":179},[125,4205,227],{"class":225,"aria-hidden":226},[125,4207,238],{"class":237},[125,4209,241],{"class":131},[125,4211,244],{"class":237},[125,4213,247],{"class":131},[125,4215,4216,4218,4220,4222,4224],{"class":127,"line":264},[125,4217,227],{"class":225,"aria-hidden":226},[125,4219,238],{"class":237},[125,4221,256],{"class":131},[125,4223,244],{"class":237},[125,4225,261],{"class":131},[125,4227,4228,4230,4232],{"class":127,"line":274},[125,4229,227],{"class":225,"aria-hidden":226},[125,4231,244],{"class":237},[125,4233,271],{"class":131},[125,4235,4236,4238],{"class":127,"line":282},[125,4237,227],{"class":225,"aria-hidden":226},[125,4239,279],{},[125,4241,4242,4244,4246,4248],{"class":127,"line":295},[125,4243,227],{"class":225,"aria-hidden":226},[125,4245,287],{"class":131},[125,4247,136],{"class":135},[125,4249,292],{"class":146},[125,4251,4252,4254,4256,4258,4260,4262],{"class":127,"data-cue":45,"line":302},[125,4253,45],{"class":305},[125,4255,4100],{"class":131},[125,4257,136],{"class":135},[125,4259,4105],{"class":131},[125,4261,1052],{"class":135},[125,4263,4110],{"class":146},[125,4265,4266,4268],{"class":127,"line":326},[125,4267,227],{"class":225,"aria-hidden":226},[125,4269,279],{},[125,4271,4272,4274,4276,4278,4280,4282,4284,4286,4288],{"class":127,"line":342},[125,4273,227],{"class":225,"aria-hidden":226},[125,4275,132],{"class":131},[125,4277,136],{"class":135},[125,4279,140],{"class":139},[125,4281,143],{"class":131},[125,4283,45],{"class":146},[125,4285,149],{"class":131},[125,4287,45],{"class":146},[125,4289,322],{"class":131},[125,4291,4292,4294,4296,4298,4300,4302],{"class":127,"data-cue":325,"line":361},[125,4293,325],{"class":305},[125,4295,164],{"class":131},[125,4297,4064],{"class":139},[125,4299,4142],{"class":131},[125,4301,38],{"class":146},[125,4303,322],{"class":131},[125,4305,4306,4308,4310,4312,4314,4316,4318,4320],{"class":127,"line":372},[125,4307,227],{"class":225,"aria-hidden":226},[125,4309,164],{"class":131},[125,4311,79],{"class":139},[125,4313,143],{"class":131},[125,4315,38],{"class":146},[125,4317,149],{"class":131},[125,4319,38],{"class":146},[125,4321,322],{"class":131},[125,4323,4324,4326,4328],{"class":127,"line":380},[125,4325,227],{"class":225,"aria-hidden":226},[125,4327,366],{"class":135},[125,4329,369],{"class":131},[125,4331,4332,4334],{"class":127,"line":407},[125,4333,227],{"class":225,"aria-hidden":226},[125,4335,279],{},[125,4337,4338,4340,4342,4344,4346,4348,4350,4352,4354],{"class":127,"line":451},[125,4339,227],{"class":225,"aria-hidden":226},[125,4341,385],{"class":131},[125,4343,136],{"class":135},[125,4345,390],{"class":131},[125,4347,393],{"class":139},[125,4349,396],{"class":131},[125,4351,95],{"class":399},[125,4353,136],{"class":135},[125,4355,404],{"class":131},[125,4357,4358,4360,4362,4364,4366,4368,4370,4372,4374,4376,4378,4380,4382,4384],{"class":127,"line":468},[125,4359,227],{"class":225,"aria-hidden":226},[125,4361,412],{"class":237},[125,4363,415],{"class":131},[125,4365,418],{"class":139},[125,4367,421],{"class":131},[125,4369,424],{"class":237},[125,4371,427],{"class":237},[125,4373,430],{"class":131},[125,4375,433],{"class":146},[125,4377,436],{"class":131},[125,4379,439],{"class":146},[125,4381,436],{"class":131},[125,4383,444],{"class":146},[125,4385,447],{"class":131},[125,4387,4388,4390,4392,4394,4396,4398],{"class":127,"line":476},[125,4389,227],{"class":225,"aria-hidden":226},[125,4391,456],{"class":131},[125,4393,459],{"class":139},[125,4395,143],{"class":131},[125,4397,450],{"class":146},[125,4399,322],{"class":131},[125,4401,4402,4404],{"class":127,"line":500},[125,4403,227],{"class":225,"aria-hidden":226},[125,4405,279],{},[125,4407,4408,4410,4412,4414,4416,4418,4420,4422],{"class":127,"line":510},[125,4409,227],{"class":225,"aria-hidden":226},[125,4411,481],{"class":131},[125,4413,136],{"class":135},[125,4415,415],{"class":131},[125,4417,488],{"class":139},[125,4419,491],{"class":131},[125,4421,494],{"class":139},[125,4423,497],{"class":131},[125,4425,4426,4428,4430],{"class":127,"line":536},[125,4427,227],{"class":225,"aria-hidden":226},[125,4429,366],{"class":135},[125,4431,507],{"class":131},[125,4433,4434,4436,4439,4441,4444,4446,4448,4451,4453,4455,4457,4459],{"class":127,"data-cue":341,"line":3436},[125,4435,341],{"class":305},[125,4437,4438],{"class":131},"measured ",[125,4440,136],{"class":135},[125,4442,4443],{"class":131}," counts.",[125,4445,1203],{"class":139},[125,4447,143],{"class":131},[125,4449,4450],{"class":549},"\"1\"",[125,4452,149],{"class":131},[125,4454,38],{"class":146},[125,4456,1214],{"class":131},[125,4458,1052],{"class":135},[125,4460,4461],{"class":131}," shots\n",[125,4463,4465,4467,4470,4472,4475,4478,4480,4483,4485,4488],{"class":127,"data-cue":379,"line":4464},22,[125,4466,379],{"class":305},[125,4468,4469],{"class":131},"expected ",[125,4471,136],{"class":135},[125,4473,4474],{"class":139}," sin",[125,4476,4477],{"class":131},"(theta ",[125,4479,1052],{"class":135},[125,4481,4482],{"class":146}," 2",[125,4484,1214],{"class":131},[125,4486,4487],{"class":135},"**",[125,4489,4490],{"class":146}," 2\n",[125,4492,4494,4496,4498,4500,4502,4505,4507,4509,4512,4514,4517,4519,4522,4525,4527,4530,4532,4535,4537,4539,4541],{"class":127,"line":4493},23,[125,4495,227],{"class":225,"aria-hidden":226},[125,4497,366],{"class":135},[125,4499,143],{"class":131},[125,4501,546],{"class":237},[125,4503,4504],{"class":549},"\"theta = ",[125,4506,553],{"class":146},[125,4508,4021],{"class":131},[125,4510,4511],{"class":237},":.4f",[125,4513,559],{"class":146},[125,4515,4516],{"class":549},"   share of 1: measured ",[125,4518,553],{"class":146},[125,4520,4521],{"class":131},"measured",[125,4523,4524],{"class":237},":.3f",[125,4526,559],{"class":146},[125,4528,4529],{"class":549},"   rule says ",[125,4531,553],{"class":146},[125,4533,4534],{"class":131},"expected",[125,4536,4524],{"class":237},[125,4538,559],{"class":146},[125,4540,550],{"class":549},[125,4542,322],{"class":131},[606,4544,4545,4552,4559,4566],{"class":608},[610,4546,4547,4549],{"data-cue":45},[125,4548,45],{"class":305},[125,4550,4551],{"class":616},"the dial: change this, press Run, compare. 0 is no rotation, pi is a full flip",[610,4553,4554,4556],{"data-cue":325},[125,4555,325],{"class":305},[125,4557,4558],{"class":616},"rotate qubit 0 by theta around the Y axis",[610,4560,4561,4563],{"data-cue":341},[125,4562,341],{"class":305},[125,4564,4565],{"class":616},"the share of shots that read 1, from lesson 1's last task",[610,4567,4568,4570],{"data-cue":379},[125,4569,379],{"class":305},[125,4571,4572],{"class":616},"the rule this lesson is about",[19,4574,4576],{"id":4575},"run-the-circuit-five-times","Run the circuit, five times",[12,4578,4579,4580,4582,4583,4586,4587,2638,4589,704,4591,3562,4593,62],{},"The listing runs one angle per press. Predict the share of ",[36,4581,45],{}," for ",[36,4584,4585],{},"pi \u002F 4"," first, then open ",[30,4588,677],{"href":4176},[683,4590,685],{},[683,4592,707],{},[683,4594,711],{},[12,4596,4597,4598,775,4600,149,4602,149,4604,1182,4607,4609],{},"Then fork the project, as in lesson 1, and in your fork set ",[36,4599,4021],{},[36,4601,38],{},[36,4603,4041],{},[36,4605,4606],{},"3 * pi \u002F 4",[36,4608,4031],{},", one press each.",[107,4611],{"alt":4612,"caption":4613,"no":111,"src":4614},"The run console after RY by pi over 4: the counts dict and the line theta = 0.7854, share of 1: measured, rule says 0.146","One press, one angle. The last line puts the measured share beside the rule's value for that angle.","\u002F_content\u002Fimages\u002Ffirst-circuits\u002F04-rotations.webp",[12,4616,4617],{},"Our five presses on 15 September 2026, on the Aria 1 noise model:",[4619,4620,4621,4642],"table",{},[4622,4623,4624],"thead",{},[4625,4626,4627,4632,4634,4639],"tr",{},[4628,4629,4630],"th",{},[36,4631,4021],{},[4628,4633,1106],{},[4628,4635,4636,4637],{},"measured share of ",[36,4638,45],{},[4628,4640,4641],{},"rule says",[4643,4644,4645,4662,4679,4696,4713],"tbody",{},[4625,4646,4647,4652,4657,4660],{},[4648,4649,4650],"td",{},[36,4651,38],{},[4648,4653,4654],{},[36,4655,4656],{},"{'0': 1000}",[4648,4658,4659],{},"0.000",[4648,4661,4659],{},[4625,4663,4664,4668,4673,4676],{},[4648,4665,4666],{},[36,4667,4585],{},[4648,4669,4670],{},[36,4671,4672],{},"{'0': 851, '1': 149}",[4648,4674,4675],{},"0.149",[4648,4677,4678],{},"0.146",[4625,4680,4681,4685,4690,4693],{},[4648,4682,4683],{},[36,4684,4041],{},[4648,4686,4687],{},[36,4688,4689],{},"{'0': 507, '1': 493}",[4648,4691,4692],{},"0.493",[4648,4694,4695],{},"0.500",[4625,4697,4698,4702,4707,4710],{},[4648,4699,4700],{},[36,4701,4606],{},[4648,4703,4704],{},[36,4705,4706],{},"{'0': 123, '1': 877}",[4648,4708,4709],{},"0.877",[4648,4711,4712],{},"0.854",[4625,4714,4715,4719,4723,4725],{},[4648,4716,4717],{},[36,4718,4031],{},[4648,4720,4721],{},[36,4722,744],{},[4648,4724,1187],{},[4648,4726,4727],{},"1.000",[12,4729,4730,4731,42,4733,4735,4736,4738,4739,4741],{},"The measured shares track the rule to within a few hundredths, which is lesson 2's scatter at 1,000 shots. At the two ends, where the ideal share is exactly ",[36,4732,38],{},[36,4734,45],{},", the noise model adds its small tail: one stray shot at ",[36,4737,4031],{},", none at ",[36,4740,38],{}," this time.",[825,4743,4745,4749,4769],{"check":4744},"the console shows a measured share of 1 near 0.25, and the rule line agrees with it.",[19,4746,4748],{"id":4747},"assignment-hit-a-quarter","Assignment: hit a quarter",[606,4750,4751,4754,4766],{},[610,4752,4753],{},"Invert the rule. You want sin²(θ\u002F2) = 0.25, so sin(θ\u002F2) = 0.5. The angle whose sine is one half is π\u002F6, thirty degrees, and that angle is θ\u002F2, not θ.",[610,4755,2739,4756,4758,4759,4761,4762,4765],{},[36,4757,4021],{}," to the angle that follows, written as a fraction of ",[36,4760,4031],{},"; ",[36,4763,4764],{},"from math import pi"," is already at the top of the file.",[610,4767,4768],{},"Run and compare the measured share with the rule line.",[871,4770,4771,4774,4792],{"label":873},[12,4772,4773],{},"sin(θ\u002F2) = 0.5 when θ\u002F2 = π\u002F6, so θ = π\u002F3.",[117,4775,4777],{"className":119,"code":4776,"language":121,"meta":111,"style":111},"theta = pi \u002F 3\n",[36,4778,4779],{"__ignoreMap":111},[125,4780,4781,4783,4785,4787,4789],{"class":127,"line":128},[125,4782,4100],{"class":131},[125,4784,136],{"class":135},[125,4786,4105],{"class":131},[125,4788,1052],{"class":135},[125,4790,4791],{"class":146}," 3\n",[12,4793,4794,4795,4798],{},"The rule line prints ",[36,4796,4797],{},"0.250",", and the measured share lands near it: within about 0.03 at 1,000 shots, by lesson 2's scatter.",[19,4800,4802],{"id":4801},"rotations-add","Rotations add",[12,4804,4805,4806,4809,4810,4813],{},"Two rotations in a row rotate by the sum of their angles. ",[36,4807,4808],{},"ry(pi \u002F 2)"," twice is ",[36,4811,4812],{},"ry(pi)",", a full flip, even though each half on its own would give an even split.",[12,4815,4816],{},"This is the same fact as lesson 1's two X gates, with a dial: gates compose, and the answer depends on the whole sequence.",[12,4818,4819,4820,4822,4823,4825,4826,4828,4829,4831],{},"It is also why the Hadamard and ",[36,4821,4808],{}," give the same tally but are not the same gate. Two Hadamards in a row gave every shot ",[36,4824,38],{}," in lesson 2; two ",[36,4827,4808],{}," in a row give every shot ",[36,4830,45],{},", in the assignment below. Same first step, different second step.",[12,4833,4834],{},"The share after one gate is not the whole state, only the part a measurement can see.",[825,4836,4838,4842,4865],{"check":4837},"every shot reads 1, bar the noise model's tail.",[19,4839,4841],{"id":4840},"assignment-two-half-turns","Assignment: two half turns",[606,4843,4844,4850,4856],{},[610,4845,2739,4846,2804,4848,62],{},[36,4847,4021],{},[36,4849,4041],{},[610,4851,2810,4852,4855],{},[36,4853,4854],{},"qc.ry(theta, 0)"," directly under the first.",[610,4857,4858,4859,4861,4862,4864],{},"Predict from the angle, not from two even splits: add the two rotations and find that stop on the dial. Then run. The console's rule line only knows about one ",[36,4860,4021],{},", so it will keep saying ",[36,4863,4695],{},"; compare the measured share with the rule for the summed angle instead.",[871,4866,4867,4876,4905],{"label":873},[12,4868,4869,4870,4872,4873,4875],{},"π\u002F2 + π\u002F2 = π, a full flip: every shot reads ",[36,4871,45],{},", and the measured share prints as ",[36,4874,4727],{}," or a hair under it.",[117,4877,4879],{"className":119,"code":4878,"language":121,"meta":111,"style":111},"qc.ry(theta, 0)\nqc.ry(theta, 0)\n",[36,4880,4881,4893],{"__ignoreMap":111},[125,4882,4883,4885,4887,4889,4891],{"class":127,"line":128},[125,4884,164],{"class":131},[125,4886,4064],{"class":139},[125,4888,4142],{"class":131},[125,4890,38],{"class":146},[125,4892,322],{"class":131},[125,4894,4895,4897,4899,4901,4903],{"class":127,"line":161},[125,4896,164],{"class":131},[125,4898,4064],{"class":139},[125,4900,4142],{"class":131},[125,4902,38],{"class":146},[125,4904,322],{"class":131},[12,4906,4907,4908,4910,4911,4913],{},"The console's rule line says ",[36,4909,4695],{},", because it only knows about one ",[36,4912,4021],{},". The rule applies to the total angle, not to each gate on its own, which is why the line and the tally disagree.",[19,4915,4917],{"id":4916},"a-rotation-you-cannot-see","A rotation you cannot see",[12,4919,4920,4921,4923,4924,4926,4927,4930,4931,4935],{},"Picture the qubit as an arrow from the centre of a globe: fresh, it points at the north pole, ",[36,4922,38],{},", and the south pole is ",[36,4925,45],{},". That globe has a name, the ",[30,4928,4929],{"href":32},"Bloch sphere",", and you can ",[30,4932,4934],{"href":4933},"\u002Fu\u002Fqollab\u002Finteractive-bloch-sphere","drag the arrow around one"," on Qollab.",[12,4937,4938],{},"RY tilts the arrow south, and the measurement reads how far it tilted.",[12,4940,4941,4942,4944],{},"RZ spins the arrow around the pole instead. The north-south position does not change, so the share of ",[36,4943,45],{}," does not change either. The spin changes only the arrow's position around the pole, and that position is the qubit's phase.",[12,4946,4947],{},"In lesson 2 a weight carried a sign, plus or minus. A phase is that sign made continuous: any angle rather than two. Two paths with the same phase add up, two with opposite phases cancel, and anything between does part of each. Lesson 5 turns that into a tally.",[48,4949,4952],{"name":4950,"token":4951},"Rotation around Z","rz",[12,4953,4954,4955,4958,4959,4961],{},"The same dial, turned around the axis the measurement reads along. ",[36,4956,4957],{},"rz(phi, qubit)"," changes the qubit's phase and leaves the share of ",[36,4960,45],{}," exactly where it was.",[12,4963,4964],{},"On a fresh qubit that spin changes nothing at all, not even in principle: there is only one path, and turning it leaves nothing to compare it with.",[12,4966,4967],{},"Lesson 5 puts a Hadamard before the spin, so there are two paths and the spin becomes a difference between them. A Hadamard after it turns that difference into odds you can read.",[825,4969,4971,4975,4998],{"check":4970},"every shot reads 0, bar the noise model's tail, whatever angle you chose.",[19,4972,4974],{"id":4973},"assignment-turn-the-dial-where-measurement-cannot-see","Assignment: turn the dial where measurement cannot see",[606,4976,4977,4980,4992,4995],{},[610,4978,4979],{},"Remove the second RY again, so the circuit is back to one rotation.",[610,4981,4982,4983,3657,4985,4988,4989,4991],{},"Replace ",[36,4984,4854],{},[36,4986,4987],{},"qc.rz(theta, 0)",", with any ",[36,4990,4021],{}," you like.",[610,4993,4994],{},"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.",[610,4996,4997],{},"Run. 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.",[871,4999,5000,5010,5027],{"label":873},[12,5001,2825,5002,5004,5005,5007,5008,62],{},[36,5003,38],{},", for any angle. The arrow started at the pole, and spinning around the pole leaves it there; the share of ",[36,5006,45],{}," stays at ",[36,5009,38],{},[117,5011,5013],{"className":119,"code":5012,"language":121,"meta":111,"style":111},"qc.rz(theta, 0)\n",[36,5014,5015],{"__ignoreMap":111},[125,5016,5017,5019,5021,5023,5025],{"class":127,"line":128},[125,5018,164],{"class":131},[125,5020,4951],{"class":139},[125,5022,4142],{"class":131},[125,5024,38],{"class":146},[125,5026,322],{"class":131},[12,5028,5029,5030,5032],{},"The rule is for RY. RZ has a different one, and its answer for the share of ",[36,5031,45],{}," is always the share you started with.",[12,5034,5035],{},"A spin around the pole showed nothing on a fresh qubit. The next lesson gives the qubit two paths first, and the same spin becomes something you can read, and then a search.",[1242,5037,5038],{},"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":111,"searchDepth":161,"depth":161,"links":5040},[5041,5042,5043,5044,5045,5046,5047,5048],{"id":4011,"depth":161,"text":4012},{"id":101,"depth":161,"text":102},{"id":4575,"depth":161,"text":4576},{"id":4747,"depth":161,"text":4748},{"id":4801,"depth":161,"text":4802},{"id":4840,"depth":161,"text":4841},{"id":4916,"depth":161,"text":4917},{"id":4973,"depth":161,"text":4974},[1260,1261,1262,3999],[],{"username":7,"name":1265,"role":1266,"avatar":1267},"Every gate so far was all or nothing. RY is a dial: set an angle, and the share of shots that read 1 follows a rule you can check in code. RZ turns the same dial where measurement cannot see it.",{"image":5054,"alt":5055},"\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":5058,"title":5059,"desc":5060},"\u002Fblog\u002Flearn\u002Fprogramming-your-first-quantum-circuits\u002Finterference","5 · Interference and your first algorithm","Make a hidden phase visible, then run a two-qubit Grover search.",[],{"title":5063,"description":5064},"Rotation gates RY and RZ · Programming your first quantum circuits","Use the RY gate as a dial in Qiskit, check sin²(θ\u002F2) against real runs on the IonQ simulator, and see why RZ alone is invisible. Lesson 4 of a free course.","blog\u002Flearn\u002Fprogramming-your-first-quantum-circuits\u002Frotations",[],"AQQf4F3xyuhwiXqlynrm7Uyq3Kf_y1TrBIcWAzDCz_0",{"id":5069,"title":5070,"authors":5071,"body":5072,"breadcrumb":6747,"builders":6748,"byline":6749,"category":1268,"categoryName":1268,"challenge":1268,"courseAuthor":1268,"courseLead":1268,"dek":5060,"description":6750,"draft":1270,"extension":1271,"eyebrow":1268,"featured":1270,"finish":1268,"fork":1268,"hero":6751,"heroAlt":1268,"heroCta":1268,"heroImage":1268,"homepageFeatured":1270,"kind":1275,"lessonCount":282,"meta":6754,"navigation":1277,"newsItems":1268,"next":6755,"ogImage":1268,"order":274,"outcomes":1268,"path":5058,"publishDate":1283,"readingTime":6759,"related":6760,"relatedProjects":1268,"seo":6761,"stem":6764,"tags":6765,"track":1291,"trackName":1262,"__hash__":6766},"blog\u002Fblog\u002Flearn\u002Fprogramming-your-first-quantum-circuits\u002Finterference.md","Interference and your first algorithm",[7],{"type":9,"value":5073,"toc":6737},[5074,5081,5084,5088,5102,5105,5108,5113,5126,5144,5154,5156,5159,5262,5268,5686,5690,5714,5717,5781,5793,5888,5892,5904,5910,5923,5926,5929,5932,5935,5938,5943,6404,6414,6419,6425,6429,6444,6447,6455,6635,6732,6735],[12,5075,5076,5080],{},[30,5077,5079],{"href":5078},"\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 lone path has nothing to differ from.",[12,5082,5083],{},"Put a Hadamard before the spin and there are two paths; the spin becomes a phase difference between them. A second Hadamard brings them back together and turns that difference into odds you can read. Grover's search, later in this lesson, runs on the same effect.",[19,5085,5087],{"id":5086},"two-paths-and-whether-they-agree","Two paths, and whether they agree",[12,5089,5090,5091,5093,5094,1182,5096,5098,5099,62],{},"The first Hadamard spreads a qubit at ",[36,5092,38],{}," over two paths: the two weighted options of lesson 2, ",[36,5095,38],{},[36,5097,45],{},", not routes anything travels. The RZ gate turns the phase of one path by ",[36,5100,5101],{},"phi",[12,5103,5104],{},"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,5106,5107],{},"The second Hadamard brings the two paths back together, and here the phase matters: paths that agree add up, and paths that disagree cancel.",[107,5109],{"alt":5110,"caption":5111,"no":111,"src":5112},"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.","Same circuit, one number changed. 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,5114,5115,5116,149,5118,149,5121,4049,5123,5125],{},"The rule is the one from lesson 4 with a new driver. After ",[36,5117,2216],{},[36,5119,5120],{},"rz(phi)",[36,5122,2216],{},[36,5124,45],{}," is sin²(φ\u002F2).",[12,5127,4038,5128,5131,5132,5134,5135,5138,5139,5134,5141,5143],{},[36,5129,5130],{},"phi = 0"," nothing is turned and every shot reads ",[36,5133,38],{},"; at ",[36,5136,5137],{},"phi = pi"," every shot reads ",[36,5140,45],{},[36,5142,4041],{}," it is the even split.",[48,5145,5148],{"name":5146,"token":5147},"A phase, made visible","h · rz · h",[12,5149,5150,5151,5153],{},"Hadamard, phase rotation, Hadamard. The first H opens two paths, RZ turns one of them, the second H closes them and lets them add or cancel. The share of ",[36,5152,45],{}," after it is sin²(φ\u002F2), the RY rule with the phase as the dial.",[19,5155,102],{"id":101},[12,5157,5158],{},"One qubit, three gates, the phase at the top of the file:",[117,5160,5162],{"className":119,"code":5161,"language":121,"meta":111,"style":111},"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",[36,5163,5164,5177,5181,5199,5214,5231,5246],{"__ignoreMap":111},[125,5165,5166,5169,5171,5173,5175],{"class":127,"line":128},[125,5167,5168],{"class":131},"phi ",[125,5170,136],{"class":135},[125,5172,4105],{"class":131},[125,5174,1052],{"class":135},[125,5176,4490],{"class":146},[125,5178,5179],{"class":127,"line":161},[125,5180,4115],{"emptyLinePlaceholder":1277},[125,5182,5183,5185,5187,5189,5191,5193,5195,5197],{"class":127,"line":179},[125,5184,132],{"class":131},[125,5186,136],{"class":135},[125,5188,140],{"class":139},[125,5190,143],{"class":131},[125,5192,45],{"class":146},[125,5194,149],{"class":131},[125,5196,45],{"class":146},[125,5198,322],{"class":131},[125,5200,5201,5203,5205,5207,5209,5211],{"class":127,"line":264},[125,5202,164],{"class":131},[125,5204,2216],{"class":139},[125,5206,143],{"class":131},[125,5208,38],{"class":146},[125,5210,3101],{"class":131},[125,5212,5213],{"class":157},"# two paths\n",[125,5215,5216,5218,5220,5223,5225,5228],{"class":127,"line":274},[125,5217,164],{"class":131},[125,5219,4951],{"class":139},[125,5221,5222],{"class":131},"(phi, ",[125,5224,38],{"class":146},[125,5226,5227],{"class":131},")                 ",[125,5229,5230],{"class":157},"# turn one of them\n",[125,5232,5233,5235,5237,5239,5241,5243],{"class":127,"line":282},[125,5234,164],{"class":131},[125,5236,2216],{"class":139},[125,5238,143],{"class":131},[125,5240,38],{"class":146},[125,5242,3101],{"class":131},[125,5244,5245],{"class":157},"# bring them back together\n",[125,5247,5248,5250,5252,5254,5256,5258,5260],{"class":127,"line":295},[125,5249,164],{"class":131},[125,5251,79],{"class":139},[125,5253,143],{"class":131},[125,5255,38],{"class":146},[125,5257,149],{"class":131},[125,5259,38],{"class":146},[125,5261,322],{"class":131},[12,5263,5264,5265,5267],{},"The plumbing is lesson 4's: the measured share of ",[36,5266,45],{}," beside what the rule says.",[211,5269,5272],{"name":5270,"no-picker":111,"run-href":5271,"tag":215},"interference.py","\u002Fu\u002Fqollab\u002Flearn-interference",[117,5273,5275],{"className":119,"code":5274,"language":121,"meta":111,"style":111},"# '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",[36,5276,5277,5283,5295,5307,5319,5327,5333,5343,5357,5363,5383,5397,5411,5425,5443,5451,5457,5477,5507,5521,5527,5545,5553,5579,5603,5649],{"__ignoreMap":111},[125,5278,5279,5281],{"class":127,"line":128},[125,5280,227],{"class":225,"aria-hidden":226},[125,5282,230],{"class":157},[125,5284,5285,5287,5289,5291,5293],{"class":127,"line":161},[125,5286,227],{"class":225,"aria-hidden":226},[125,5288,238],{"class":237},[125,5290,4196],{"class":131},[125,5292,244],{"class":237},[125,5294,4201],{"class":131},[125,5296,5297,5299,5301,5303,5305],{"class":127,"line":179},[125,5298,227],{"class":225,"aria-hidden":226},[125,5300,238],{"class":237},[125,5302,241],{"class":131},[125,5304,244],{"class":237},[125,5306,247],{"class":131},[125,5308,5309,5311,5313,5315,5317],{"class":127,"line":264},[125,5310,227],{"class":225,"aria-hidden":226},[125,5312,238],{"class":237},[125,5314,256],{"class":131},[125,5316,244],{"class":237},[125,5318,261],{"class":131},[125,5320,5321,5323,5325],{"class":127,"line":274},[125,5322,227],{"class":225,"aria-hidden":226},[125,5324,244],{"class":237},[125,5326,271],{"class":131},[125,5328,5329,5331],{"class":127,"line":282},[125,5330,227],{"class":225,"aria-hidden":226},[125,5332,279],{},[125,5334,5335,5337,5339,5341],{"class":127,"line":295},[125,5336,227],{"class":225,"aria-hidden":226},[125,5338,287],{"class":131},[125,5340,136],{"class":135},[125,5342,292],{"class":146},[125,5344,5345,5347,5349,5351,5353,5355],{"class":127,"data-cue":45,"line":302},[125,5346,45],{"class":305},[125,5348,5168],{"class":131},[125,5350,136],{"class":135},[125,5352,4105],{"class":131},[125,5354,1052],{"class":135},[125,5356,4490],{"class":146},[125,5358,5359,5361],{"class":127,"line":326},[125,5360,227],{"class":225,"aria-hidden":226},[125,5362,279],{},[125,5364,5365,5367,5369,5371,5373,5375,5377,5379,5381],{"class":127,"line":342},[125,5366,227],{"class":225,"aria-hidden":226},[125,5368,132],{"class":131},[125,5370,136],{"class":135},[125,5372,140],{"class":139},[125,5374,143],{"class":131},[125,5376,45],{"class":146},[125,5378,149],{"class":131},[125,5380,45],{"class":146},[125,5382,322],{"class":131},[125,5384,5385,5387,5389,5391,5393,5395],{"class":127,"data-cue":325,"line":361},[125,5386,325],{"class":305},[125,5388,164],{"class":131},[125,5390,2216],{"class":139},[125,5392,143],{"class":131},[125,5394,38],{"class":146},[125,5396,322],{"class":131},[125,5398,5399,5401,5403,5405,5407,5409],{"class":127,"data-cue":341,"line":372},[125,5400,341],{"class":305},[125,5402,164],{"class":131},[125,5404,4951],{"class":139},[125,5406,5222],{"class":131},[125,5408,38],{"class":146},[125,5410,322],{"class":131},[125,5412,5413,5415,5417,5419,5421,5423],{"class":127,"data-cue":379,"line":380},[125,5414,379],{"class":305},[125,5416,164],{"class":131},[125,5418,2216],{"class":139},[125,5420,143],{"class":131},[125,5422,38],{"class":146},[125,5424,322],{"class":131},[125,5426,5427,5429,5431,5433,5435,5437,5439,5441],{"class":127,"line":407},[125,5428,227],{"class":225,"aria-hidden":226},[125,5430,164],{"class":131},[125,5432,79],{"class":139},[125,5434,143],{"class":131},[125,5436,38],{"class":146},[125,5438,149],{"class":131},[125,5440,38],{"class":146},[125,5442,322],{"class":131},[125,5444,5445,5447,5449],{"class":127,"line":451},[125,5446,227],{"class":225,"aria-hidden":226},[125,5448,366],{"class":135},[125,5450,369],{"class":131},[125,5452,5453,5455],{"class":127,"line":468},[125,5454,227],{"class":225,"aria-hidden":226},[125,5456,279],{},[125,5458,5459,5461,5463,5465,5467,5469,5471,5473,5475],{"class":127,"line":476},[125,5460,227],{"class":225,"aria-hidden":226},[125,5462,385],{"class":131},[125,5464,136],{"class":135},[125,5466,390],{"class":131},[125,5468,393],{"class":139},[125,5470,396],{"class":131},[125,5472,95],{"class":399},[125,5474,136],{"class":135},[125,5476,404],{"class":131},[125,5478,5479,5481,5483,5485,5487,5489,5491,5493,5495,5497,5499,5501,5503,5505],{"class":127,"line":500},[125,5480,227],{"class":225,"aria-hidden":226},[125,5482,412],{"class":237},[125,5484,415],{"class":131},[125,5486,418],{"class":139},[125,5488,421],{"class":131},[125,5490,424],{"class":237},[125,5492,427],{"class":237},[125,5494,430],{"class":131},[125,5496,433],{"class":146},[125,5498,436],{"class":131},[125,5500,439],{"class":146},[125,5502,436],{"class":131},[125,5504,444],{"class":146},[125,5506,447],{"class":131},[125,5508,5509,5511,5513,5515,5517,5519],{"class":127,"line":510},[125,5510,227],{"class":225,"aria-hidden":226},[125,5512,456],{"class":131},[125,5514,459],{"class":139},[125,5516,143],{"class":131},[125,5518,450],{"class":146},[125,5520,322],{"class":131},[125,5522,5523,5525],{"class":127,"line":536},[125,5524,227],{"class":225,"aria-hidden":226},[125,5526,279],{},[125,5528,5529,5531,5533,5535,5537,5539,5541,5543],{"class":127,"line":3436},[125,5530,227],{"class":225,"aria-hidden":226},[125,5532,481],{"class":131},[125,5534,136],{"class":135},[125,5536,415],{"class":131},[125,5538,488],{"class":139},[125,5540,491],{"class":131},[125,5542,494],{"class":139},[125,5544,497],{"class":131},[125,5546,5547,5549,5551],{"class":127,"line":4464},[125,5548,227],{"class":225,"aria-hidden":226},[125,5550,366],{"class":135},[125,5552,507],{"class":131},[125,5554,5555,5557,5559,5561,5563,5565,5567,5569,5571,5573,5575,5577],{"class":127,"line":4493},[125,5556,227],{"class":225,"aria-hidden":226},[125,5558,4438],{"class":131},[125,5560,136],{"class":135},[125,5562,4443],{"class":131},[125,5564,1203],{"class":139},[125,5566,143],{"class":131},[125,5568,4450],{"class":549},[125,5570,149],{"class":131},[125,5572,38],{"class":146},[125,5574,1214],{"class":131},[125,5576,1052],{"class":135},[125,5578,4461],{"class":131},[125,5580,5582,5584,5586,5588,5590,5593,5595,5597,5599,5601],{"class":127,"data-cue":450,"line":5581},24,[125,5583,450],{"class":305},[125,5585,4469],{"class":131},[125,5587,136],{"class":135},[125,5589,4474],{"class":139},[125,5591,5592],{"class":131},"(phi ",[125,5594,1052],{"class":135},[125,5596,4482],{"class":146},[125,5598,1214],{"class":131},[125,5600,4487],{"class":135},[125,5602,4490],{"class":146},[125,5604,5606,5608,5610,5612,5614,5617,5619,5621,5623,5625,5627,5629,5631,5633,5635,5637,5639,5641,5643,5645,5647],{"class":127,"line":5605},25,[125,5607,227],{"class":225,"aria-hidden":226},[125,5609,366],{"class":135},[125,5611,143],{"class":131},[125,5613,546],{"class":237},[125,5615,5616],{"class":549},"\"phi = ",[125,5618,553],{"class":146},[125,5620,5101],{"class":131},[125,5622,4511],{"class":237},[125,5624,559],{"class":146},[125,5626,4516],{"class":549},[125,5628,553],{"class":146},[125,5630,4521],{"class":131},[125,5632,4524],{"class":237},[125,5634,559],{"class":146},[125,5636,4529],{"class":549},[125,5638,553],{"class":146},[125,5640,4534],{"class":131},[125,5642,4524],{"class":237},[125,5644,559],{"class":146},[125,5646,550],{"class":549},[125,5648,322],{"class":131},[606,5650,5651,5658,5665,5672,5679],{"class":608},[610,5652,5653,5655],{"data-cue":45},[125,5654,45],{"class":305},[125,5656,5657],{"class":616},"the phase RZ sets. On its own it is invisible; change it and press Run",[610,5659,5660,5662],{"data-cue":325},[125,5661,325],{"class":305},[125,5663,5664],{"class":616},"spread the qubit over 0 and 1, two paths",[610,5666,5667,5669],{"data-cue":341},[125,5668,341],{"class":305},[125,5670,5671],{"class":616},"turn the invisible dial on one of them",[610,5673,5674,5676],{"data-cue":379},[125,5675,379],{"class":305},[125,5677,5678],{"class":616},"fold the two paths back together: they add, or they cancel",[610,5680,5681,5683],{"data-cue":450},[125,5682,450],{"class":305},[125,5684,5685],{"class":616},"the same rule as RY, now driven by a phase",[19,5687,5689],{"id":5688},"run-the-circuit-three-times","Run the circuit, three times",[12,5691,5692,5693,4582,5695,5697,5698,2638,5700,704,5702,3562,5704,5706,5707,775,5709,5711,5712,4609],{},"Predict the share of ",[36,5694,45],{},[36,5696,4041],{}," first. Then open ",[30,5699,677],{"href":5271},[683,5701,685],{},[683,5703,707],{},[683,5705,711],{},". Then fork it, as in lesson 1, and in your fork set ",[36,5708,5101],{},[36,5710,38],{}," and to ",[36,5713,4031],{},[12,5715,5716],{},"Our three presses on 15 September 2026, on the Aria 1 noise model:",[4619,5718,5719,5735],{},[4622,5720,5721],{},[4625,5722,5723,5727,5729,5733],{},[4628,5724,5725],{},[36,5726,5101],{},[4628,5728,1106],{},[4628,5730,4636,5731],{},[36,5732,45],{},[4628,5734,4641],{},[4643,5736,5737,5751,5767],{},[4625,5738,5739,5743,5747,5749],{},[4648,5740,5741],{},[36,5742,38],{},[4648,5744,5745],{},[36,5746,4656],{},[4648,5748,4659],{},[4648,5750,4659],{},[4625,5752,5753,5757,5762,5765],{},[4648,5754,5755],{},[36,5756,4041],{},[4648,5758,5759],{},[36,5760,5761],{},"{'0': 474, '1': 526}",[4648,5763,5764],{},"0.526",[4648,5766,4695],{},[4625,5768,5769,5773,5777,5779],{},[4648,5770,5771],{},[36,5772,4031],{},[4648,5774,5775],{},[36,5776,1178],{},[4648,5778,4727],{},[4648,5780,4727],{},[12,5782,5783,5784,5786,5787,5789,5790,5792],{},"Lesson 4 ended with ",[36,5785,4951],{}," doing nothing visible. The same gate, between two Hadamards, now moves the share from all ",[36,5788,38],{}," to all ",[36,5791,45],{},". The phase was there all along; the second Hadamard is what makes it count.",[825,5794,5796,5800,5822],{"check":5795},"the tally splits about half and half at phi = pi, and still does at the second phi you tried.",[19,5797,5799],{"id":5798},"assignment-take-the-second-hadamard-away","Assignment: take the second Hadamard away",[606,5801,5802,5811,5817],{},[610,5803,5804,5805,5807,5808,5810],{},"Keep ",[36,5806,5137],{}," and delete the second ",[36,5809,2813],{},". What is left is a Hadamard, then a phase, then a measurement.",[610,5812,5813,5814,5816],{},"Predict the tally: lesson 4 showed that a phase on its own leaves the share of ",[36,5815,45],{}," where it was, so ask where the first Hadamard left it. Then run.",[610,5818,3855,5819,5821],{},[36,5820,5101],{}," to anything else and run again. The rule line keeps printing sin²(φ\u002F2), which no longer applies to this circuit; the tally is the answer.",[871,5823,5824,5834,5879],{"label":873},[12,5825,5826,5827,5829,5830,5833],{},"The circuit is ",[36,5828,2216],{}," then ",[36,5831,5832],{},"rz(pi)"," then measure: an even split with a phase on one path and nothing to make the phase count.",[117,5835,5837],{"className":119,"code":5836,"language":121,"meta":111,"style":111},"qc.h(0)\nqc.rz(phi, 0)\nqc.measure(0, 0)\n",[36,5838,5839,5851,5863],{"__ignoreMap":111},[125,5840,5841,5843,5845,5847,5849],{"class":127,"line":128},[125,5842,164],{"class":131},[125,5844,2216],{"class":139},[125,5846,143],{"class":131},[125,5848,38],{"class":146},[125,5850,322],{"class":131},[125,5852,5853,5855,5857,5859,5861],{"class":127,"line":161},[125,5854,164],{"class":131},[125,5856,4951],{"class":139},[125,5858,5222],{"class":131},[125,5860,38],{"class":146},[125,5862,322],{"class":131},[125,5864,5865,5867,5869,5871,5873,5875,5877],{"class":127,"line":179},[125,5866,164],{"class":131},[125,5868,79],{"class":139},[125,5870,143],{"class":131},[125,5872,38],{"class":146},[125,5874,149],{"class":131},[125,5876,38],{"class":146},[125,5878,322],{"class":131},[12,5880,5881,5882,5884,5885,5887],{},"The share of ",[36,5883,45],{}," is one half, whatever ",[36,5886,5101],{}," is, because the measurement reads the split the first Hadamard made and cannot see the phase. The second Hadamard was the whole mechanism.",[19,5889,5891],{"id":5890},"from-a-phase-to-a-search","From a phase to a search",[12,5893,5894,5895,149,5897,149,5899,1182,5901,5903],{},"Now two qubits. Two Hadamards put four candidates in play, ",[36,5896,3022],{},[36,5898,3029],{},[36,5900,3032],{},[36,5902,3025],{},", a quarter each: four weights of one half, since a share is a weight's size squared.",[12,5905,5906,5907,5909],{},"Then an oracle: the part of a search that checks the condition and marks whatever passes it. Here the condition is fixed, \"both qubits are ",[36,5908,45],{},"\", and the marking is a CZ gate.",[48,5911,5914],{"name":5912,"token":5913},"The controlled-Z gate","cz",[12,5915,5916,5919,5920,5922],{},[36,5917,5918],{},"cz(a, b)",". Flips the sign of the weight on the state where both qubits are ",[36,5921,45],{},", 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, and the mark cannot be seen.",[12,5924,5925],{},"The diffusion step is what makes the mark count, and it is the second Hadamard's job done for four candidates instead of two paths. It reflects every weight about their average.",[12,5927,5928],{},"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,5930,5931],{},"Reflecting about it sends each unmarked weight to zero and the marked one to a full one, with a minus sign in front in this circuit that measurement cannot see. One round, oracle then diffusion, and the marked answer is the only one left.",[12,5933,5934],{},"The five lines below are that reflection written in gates. The two Hadamards on both qubits change to a frame where the average is a single state; X on both qubits and a CZ flip the sign of that one state and leave the other three alone; the Hadamards change back.",[12,5936,5937],{},"The five lines are the same for any oracle on two qubits, so you can reuse them without re-deriving them.",[12,5939,5940,5941,62],{},"The oracle holds the problem and the diffusion step never changes, so the same five lines find whatever a different oracle marks. That is what makes it a search rather than a circuit that happens to output ",[36,5942,3025],{},[211,5944,5947],{"name":5945,"no-picker":111,"run-href":5946,"tag":215},"grover.py","\u002Fu\u002Fqollab\u002Flearn-grover",[117,5948,5950],{"className":119,"code":5949,"language":121,"meta":111,"style":111},"# '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",[36,5951,5952,5958,5970,5982,5990,5996,6006,6012,6032,6050,6068,6086,6104,6122,6140,6158,6184,6192,6198,6218,6248,6262,6268,6286,6294,6312,6381],{"__ignoreMap":111},[125,5953,5954,5956],{"class":127,"line":128},[125,5955,227],{"class":225,"aria-hidden":226},[125,5957,230],{"class":157},[125,5959,5960,5962,5964,5966,5968],{"class":127,"line":161},[125,5961,227],{"class":225,"aria-hidden":226},[125,5963,238],{"class":237},[125,5965,241],{"class":131},[125,5967,244],{"class":237},[125,5969,247],{"class":131},[125,5971,5972,5974,5976,5978,5980],{"class":127,"line":179},[125,5973,227],{"class":225,"aria-hidden":226},[125,5975,238],{"class":237},[125,5977,256],{"class":131},[125,5979,244],{"class":237},[125,5981,261],{"class":131},[125,5983,5984,5986,5988],{"class":127,"line":264},[125,5985,227],{"class":225,"aria-hidden":226},[125,5987,244],{"class":237},[125,5989,271],{"class":131},[125,5991,5992,5994],{"class":127,"line":274},[125,5993,227],{"class":225,"aria-hidden":226},[125,5995,279],{},[125,5997,5998,6000,6002,6004],{"class":127,"line":282},[125,5999,227],{"class":225,"aria-hidden":226},[125,6001,287],{"class":131},[125,6003,136],{"class":135},[125,6005,292],{"class":146},[125,6007,6008,6010],{"class":127,"line":295},[125,6009,227],{"class":225,"aria-hidden":226},[125,6011,279],{},[125,6013,6014,6016,6018,6020,6022,6024,6026,6028,6030],{"class":127,"line":302},[125,6015,227],{"class":225,"aria-hidden":226},[125,6017,132],{"class":131},[125,6019,136],{"class":135},[125,6021,140],{"class":139},[125,6023,143],{"class":131},[125,6025,325],{"class":146},[125,6027,149],{"class":131},[125,6029,325],{"class":146},[125,6031,322],{"class":131},[125,6033,6034,6036,6038,6040,6042,6044,6046,6048],{"class":127,"data-cue":45,"line":326},[125,6035,45],{"class":305},[125,6037,164],{"class":131},[125,6039,2216],{"class":139},[125,6041,3133],{"class":131},[125,6043,38],{"class":146},[125,6045,149],{"class":131},[125,6047,45],{"class":146},[125,6049,3305],{"class":131},[125,6051,6052,6054,6056,6058,6060,6062,6064,6066],{"class":127,"data-cue":325,"line":342},[125,6053,325],{"class":305},[125,6055,164],{"class":131},[125,6057,5913],{"class":139},[125,6059,143],{"class":131},[125,6061,38],{"class":146},[125,6063,149],{"class":131},[125,6065,45],{"class":146},[125,6067,322],{"class":131},[125,6069,6070,6072,6074,6076,6078,6080,6082,6084],{"class":127,"data-cue":341,"line":361},[125,6071,341],{"class":305},[125,6073,164],{"class":131},[125,6075,2216],{"class":139},[125,6077,3133],{"class":131},[125,6079,38],{"class":146},[125,6081,149],{"class":131},[125,6083,45],{"class":146},[125,6085,3305],{"class":131},[125,6087,6088,6090,6092,6094,6096,6098,6100,6102],{"class":127,"line":372},[125,6089,227],{"class":225,"aria-hidden":226},[125,6091,164],{"class":131},[125,6093,66],{"class":139},[125,6095,3133],{"class":131},[125,6097,38],{"class":146},[125,6099,149],{"class":131},[125,6101,45],{"class":146},[125,6103,3305],{"class":131},[125,6105,6106,6108,6110,6112,6114,6116,6118,6120],{"class":127,"line":380},[125,6107,227],{"class":225,"aria-hidden":226},[125,6109,164],{"class":131},[125,6111,5913],{"class":139},[125,6113,143],{"class":131},[125,6115,38],{"class":146},[125,6117,149],{"class":131},[125,6119,45],{"class":146},[125,6121,322],{"class":131},[125,6123,6124,6126,6128,6130,6132,6134,6136,6138],{"class":127,"line":407},[125,6125,227],{"class":225,"aria-hidden":226},[125,6127,164],{"class":131},[125,6129,66],{"class":139},[125,6131,3133],{"class":131},[125,6133,38],{"class":146},[125,6135,149],{"class":131},[125,6137,45],{"class":146},[125,6139,3305],{"class":131},[125,6141,6142,6144,6146,6148,6150,6152,6154,6156],{"class":127,"line":451},[125,6143,227],{"class":225,"aria-hidden":226},[125,6145,164],{"class":131},[125,6147,2216],{"class":139},[125,6149,3133],{"class":131},[125,6151,38],{"class":146},[125,6153,149],{"class":131},[125,6155,45],{"class":146},[125,6157,3305],{"class":131},[125,6159,6160,6162,6164,6166,6168,6170,6172,6174,6176,6178,6180,6182],{"class":127,"line":468},[125,6161,227],{"class":225,"aria-hidden":226},[125,6163,164],{"class":131},[125,6165,79],{"class":139},[125,6167,3133],{"class":131},[125,6169,38],{"class":146},[125,6171,149],{"class":131},[125,6173,45],{"class":146},[125,6175,3142],{"class":131},[125,6177,38],{"class":146},[125,6179,149],{"class":131},[125,6181,45],{"class":146},[125,6183,3305],{"class":131},[125,6185,6186,6188,6190],{"class":127,"line":476},[125,6187,227],{"class":225,"aria-hidden":226},[125,6189,366],{"class":135},[125,6191,369],{"class":131},[125,6193,6194,6196],{"class":127,"line":500},[125,6195,227],{"class":225,"aria-hidden":226},[125,6197,279],{},[125,6199,6200,6202,6204,6206,6208,6210,6212,6214,6216],{"class":127,"line":510},[125,6201,227],{"class":225,"aria-hidden":226},[125,6203,385],{"class":131},[125,6205,136],{"class":135},[125,6207,390],{"class":131},[125,6209,393],{"class":139},[125,6211,396],{"class":131},[125,6213,95],{"class":399},[125,6215,136],{"class":135},[125,6217,404],{"class":131},[125,6219,6220,6222,6224,6226,6228,6230,6232,6234,6236,6238,6240,6242,6244,6246],{"class":127,"line":536},[125,6221,227],{"class":225,"aria-hidden":226},[125,6223,412],{"class":237},[125,6225,415],{"class":131},[125,6227,418],{"class":139},[125,6229,421],{"class":131},[125,6231,424],{"class":237},[125,6233,427],{"class":237},[125,6235,430],{"class":131},[125,6237,433],{"class":146},[125,6239,436],{"class":131},[125,6241,439],{"class":146},[125,6243,436],{"class":131},[125,6245,444],{"class":146},[125,6247,447],{"class":131},[125,6249,6250,6252,6254,6256,6258,6260],{"class":127,"line":3436},[125,6251,227],{"class":225,"aria-hidden":226},[125,6253,456],{"class":131},[125,6255,459],{"class":139},[125,6257,143],{"class":131},[125,6259,450],{"class":146},[125,6261,322],{"class":131},[125,6263,6264,6266],{"class":127,"line":4464},[125,6265,227],{"class":225,"aria-hidden":226},[125,6267,279],{},[125,6269,6270,6272,6274,6276,6278,6280,6282,6284],{"class":127,"line":4493},[125,6271,227],{"class":225,"aria-hidden":226},[125,6273,481],{"class":131},[125,6275,136],{"class":135},[125,6277,415],{"class":131},[125,6279,488],{"class":139},[125,6281,491],{"class":131},[125,6283,494],{"class":139},[125,6285,497],{"class":131},[125,6287,6288,6290,6292],{"class":127,"line":5581},[125,6289,227],{"class":225,"aria-hidden":226},[125,6291,366],{"class":135},[125,6293,507],{"class":131},[125,6295,6296,6298,6300,6302,6304,6306,6308,6310],{"class":127,"line":5605},[125,6297,227],{"class":225,"aria-hidden":226},[125,6299,515],{"class":237},[125,6301,518],{"class":131},[125,6303,521],{"class":237},[125,6305,524],{"class":135},[125,6307,527],{"class":131},[125,6309,530],{"class":139},[125,6311,533],{"class":131},[125,6313,6315,6317,6319,6321,6323,6325,6327,6329,6331,6333,6335,6337,6339,6341,6343,6345,6347,6349,6351,6353,6355,6357,6359,6361,6363,6365,6367,6369,6371,6373,6375,6377,6379],{"class":127,"line":6314},26,[125,6316,227],{"class":225,"aria-hidden":226},[125,6318,541],{"class":135},[125,6320,143],{"class":131},[125,6322,546],{"class":237},[125,6324,550],{"class":549},[125,6326,553],{"class":146},[125,6328,556],{"class":131},[125,6330,559],{"class":146},[125,6332,562],{"class":549},[125,6334,553],{"class":146},[125,6336,567],{"class":131},[125,6338,570],{"class":237},[125,6340,559],{"class":146},[125,6342,1045],{"class":146},[125,6344,581],{"class":135},[125,6346,592],{"class":131},[125,6348,1052],{"class":135},[125,6350,1055],{"class":131},[125,6352,1058],{"class":237},[125,6354,559],{"class":146},[125,6356,1063],{"class":549},[125,6358,553],{"class":146},[125,6360,578],{"class":549},[125,6362,581],{"class":135},[125,6364,584],{"class":131},[125,6366,587],{"class":146},[125,6368,581],{"class":135},[125,6370,592],{"class":131},[125,6372,595],{"class":135},[125,6374,598],{"class":131},[125,6376,559],{"class":146},[125,6378,550],{"class":549},[125,6380,322],{"class":131},[606,6382,6383,6390,6397],{"class":608},[610,6384,6385,6387],{"data-cue":45},[125,6386,45],{"class":305},[125,6388,6389],{"class":616},"all four answers at once, a quarter each",[610,6391,6392,6394],{"data-cue":325},[125,6393,325],{"class":305},[125,6395,6396],{"class":616},"the oracle: flip the sign of 11 and nothing else. Invisible on its own",[610,6398,6399,6401],{"data-cue":341},[125,6400,341],{"class":305},[125,6402,6403],{"class":616},"the diffusion step, five lines: it turns that hidden sign into probability",[12,6405,6406,6407,6410,6411,6413],{},"Predict the tally, then open ",[30,6408,6409],{"href":5946},"the search project"," and run it on ",[683,6412,707],{},". Fork it too; the last two assignments edit it.",[107,6415],{"alt":6416,"caption":6417,"no":111,"src":6418},"The run console after the Grover search: the counts dict {'11': 1000} and one full-length bar at 11","One round, one answer. In the text drawing the first pair of H gates and the CZ are the oracle side; the block after them is the diffusion step. On a perfect simulator the search never misses; on this press the noise model did not touch it either.","\u002F_content\u002Fimages\u002Ffirst-circuits\u002F05-grover.webp",[12,6420,3573,6421,6424],{},[36,6422,6423],{},"{'11': 1000}",": the marked answer on all 1,000 shots, and not a single miss. The noise model can put a few shots elsewhere on another press; the ideal is exactly this.",[19,6426,6428],{"id":6427},"changing-the-oracle","Changing the oracle",[12,6430,6431,6432,6434,6435,6437,6438,6440,6441,6443],{},"The CZ fires on ",[36,6433,3025],{},". To mark a different string, surround it with X gates on the qubits that should read ",[36,6436,38],{}," in that string. An X before the CZ turns that qubit's ",[36,6439,38],{}," into a ",[36,6442,45],{}," for the CZ to see, and an X after it turns it back.",[12,6445,6446],{},"The diffusion step stays exactly as it is.",[12,6448,6449,6450,6454],{},"With exactly four candidates one round lands the marked answer on 100%. With more candidates it takes more rounds, about the square root of their number, which is where Grover's speed-up comes from; ",[30,6451,6453],{"href":6452},"\u002Fu\u002Fqollab\u002Fgrovers-search","Grover's search on Qollab"," runs it at a size where the rounds matter.",[825,6456,6458,6462,6483],{"check":6457},"the tally shows 10 on almost every shot.",[19,6459,6461],{"id":6460},"assignment-mark-a-different-answer","Assignment: mark a different answer",[606,6463,6464,6473,6480],{},[610,6465,6466,6467,6469,6470,6472],{},"In your fork of the search, work out which qubit reads ",[36,6468,38],{}," in the string ",[36,6471,3032],{},". Remember which character is qubit 0.",[610,6474,6475,6476,6479],{},"Put an X gate on that qubit immediately before the first ",[36,6477,6478],{},"qc.cz(0, 1)"," and another immediately after it, as the section above describes. Do not touch the diffusion step.",[610,6481,6482],{},"Predict the tally, then run.",[871,6484,6485,6626],{"label":873},[117,6486,6488],{"className":119,"code":6487,"language":121,"meta":111,"style":111},"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",[36,6489,6490,6506,6518,6534,6546,6562,6578,6594,6610],{"__ignoreMap":111},[125,6491,6492,6494,6496,6498,6500,6502,6504],{"class":127,"line":128},[125,6493,164],{"class":131},[125,6495,2216],{"class":139},[125,6497,3133],{"class":131},[125,6499,38],{"class":146},[125,6501,149],{"class":131},[125,6503,45],{"class":146},[125,6505,3305],{"class":131},[125,6507,6508,6510,6512,6514,6516],{"class":127,"line":161},[125,6509,164],{"class":131},[125,6511,66],{"class":139},[125,6513,143],{"class":131},[125,6515,38],{"class":146},[125,6517,322],{"class":131},[125,6519,6520,6522,6524,6526,6528,6530,6532],{"class":127,"line":179},[125,6521,164],{"class":131},[125,6523,5913],{"class":139},[125,6525,143],{"class":131},[125,6527,38],{"class":146},[125,6529,149],{"class":131},[125,6531,45],{"class":146},[125,6533,322],{"class":131},[125,6535,6536,6538,6540,6542,6544],{"class":127,"line":264},[125,6537,164],{"class":131},[125,6539,66],{"class":139},[125,6541,143],{"class":131},[125,6543,38],{"class":146},[125,6545,322],{"class":131},[125,6547,6548,6550,6552,6554,6556,6558,6560],{"class":127,"line":274},[125,6549,164],{"class":131},[125,6551,2216],{"class":139},[125,6553,3133],{"class":131},[125,6555,38],{"class":146},[125,6557,149],{"class":131},[125,6559,45],{"class":146},[125,6561,3305],{"class":131},[125,6563,6564,6566,6568,6570,6572,6574,6576],{"class":127,"line":282},[125,6565,164],{"class":131},[125,6567,66],{"class":139},[125,6569,3133],{"class":131},[125,6571,38],{"class":146},[125,6573,149],{"class":131},[125,6575,45],{"class":146},[125,6577,3305],{"class":131},[125,6579,6580,6582,6584,6586,6588,6590,6592],{"class":127,"line":295},[125,6581,164],{"class":131},[125,6583,5913],{"class":139},[125,6585,143],{"class":131},[125,6587,38],{"class":146},[125,6589,149],{"class":131},[125,6591,45],{"class":146},[125,6593,322],{"class":131},[125,6595,6596,6598,6600,6602,6604,6606,6608],{"class":127,"line":302},[125,6597,164],{"class":131},[125,6599,66],{"class":139},[125,6601,3133],{"class":131},[125,6603,38],{"class":146},[125,6605,149],{"class":131},[125,6607,45],{"class":146},[125,6609,3305],{"class":131},[125,6611,6612,6614,6616,6618,6620,6622,6624],{"class":127,"line":326},[125,6613,164],{"class":131},[125,6615,2216],{"class":139},[125,6617,3133],{"class":131},[125,6619,38],{"class":146},[125,6621,149],{"class":131},[125,6623,45],{"class":146},[125,6625,3305],{"class":131},[12,6627,6628,6629,6631,6632,6634],{},"The oracle now marks ",[36,6630,3032],{},", and the unchanged diffusion step finds it: ",[36,6633,3032],{}," on every shot, bar the tail. The diffusion step did not know which answer was marked; it never does.",[825,6636,6638,6642,6660],{"check":6637},"the tally shows all four strings at about a quarter each.",[19,6639,6641],{"id":6640},"assignment-search-without-the-diffusion-step","Assignment: search without the diffusion step",[606,6643,6644,6650,6657],{},[610,6645,6646,6647,6649],{},"Put the oracle back to ",[36,6648,3025],{}," by removing the two X lines you added around the first CZ.",[610,6651,6652,6653,6656],{},"Delete the five diffusion lines, the block from the second ",[36,6654,6655],{},"qc.h([0, 1])"," down to the last one, so only the opening Hadamards, the CZ and the measurements remain.",[610,6658,6659],{},"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 nothing follows the phase to make it count. Then run.",[871,6661,6662,6668,6729],{"label":873},[12,6663,6664,6665,6667],{},"Four strings, a quarter each, bar the tail. The oracle did its job and marked ",[36,6666,3025],{},", and without the diffusion step the mark stays invisible.",[117,6669,6671],{"className":119,"code":6670,"language":121,"meta":111,"style":111},"qc.h([0, 1])\nqc.cz(0, 1)\nqc.measure([0, 1], [0, 1])\n",[36,6672,6673,6689,6705],{"__ignoreMap":111},[125,6674,6675,6677,6679,6681,6683,6685,6687],{"class":127,"line":128},[125,6676,164],{"class":131},[125,6678,2216],{"class":139},[125,6680,3133],{"class":131},[125,6682,38],{"class":146},[125,6684,149],{"class":131},[125,6686,45],{"class":146},[125,6688,3305],{"class":131},[125,6690,6691,6693,6695,6697,6699,6701,6703],{"class":127,"line":161},[125,6692,164],{"class":131},[125,6694,5913],{"class":139},[125,6696,143],{"class":131},[125,6698,38],{"class":146},[125,6700,149],{"class":131},[125,6702,45],{"class":146},[125,6704,322],{"class":131},[125,6706,6707,6709,6711,6713,6715,6717,6719,6721,6723,6725,6727],{"class":127,"line":179},[125,6708,164],{"class":131},[125,6710,79],{"class":139},[125,6712,3133],{"class":131},[125,6714,38],{"class":146},[125,6716,149],{"class":131},[125,6718,45],{"class":146},[125,6720,3142],{"class":131},[125,6722,38],{"class":146},[125,6724,149],{"class":131},[125,6726,45],{"class":146},[125,6728,3305],{"class":131},[12,6730,6731],{},"Interference is not the oracle and not the mark. It is the step that turns a phase into something a measurement can read.",[12,6733,6734],{},"Some runs in this course came back with a small tail of wrong answers, and each time the lesson called it the noise model and moved on. The last lesson stops and measures it, on four machines' models, and then looks at the real machines behind them.",[1242,6736,5038],{},{"title":111,"searchDepth":161,"depth":161,"links":6738},[6739,6740,6741,6742,6743,6744,6745,6746],{"id":5086,"depth":161,"text":5087},{"id":101,"depth":161,"text":102},{"id":5688,"depth":161,"text":5689},{"id":5798,"depth":161,"text":5799},{"id":5890,"depth":161,"text":5891},{"id":6427,"depth":161,"text":6428},{"id":6460,"depth":161,"text":6461},{"id":6640,"depth":161,"text":6641},[1260,1261,1262,5070],[],{"username":7,"name":1265,"role":1266,"avatar":1267},"A phase that measurement cannot see becomes a share you can read, once two Hadamards sit around it. The same trick, on two qubits, is a search that finds a marked answer on every shot.",{"image":6752,"alt":6753},"\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":6756,"title":6757,"desc":6758},"\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 a real quantum computer changes, and how to give your circuit a public home.","11 min read",[],{"title":6762,"description":6763},"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 watch it find the marked answer. Lesson 5, free.","blog\u002Flearn\u002Fprogramming-your-first-quantum-circuits\u002Finterference",[],"p5Y_5fw-5Mcj-DTo2LCcahB4vJnvNo_gXnMbyFyeP4A",{"id":6768,"title":6769,"authors":6770,"body":6771,"breadcrumb":7713,"builders":7714,"byline":7715,"category":1268,"categoryName":1268,"challenge":1268,"courseAuthor":1268,"courseLead":1268,"dek":6758,"description":7716,"draft":1270,"extension":1271,"eyebrow":1268,"featured":1270,"finish":7717,"fork":1268,"hero":7718,"heroAlt":1268,"heroCta":1268,"heroImage":1268,"homepageFeatured":1270,"kind":1275,"lessonCount":282,"meta":7721,"navigation":1277,"newsItems":1268,"next":1268,"ogImage":1268,"order":282,"outcomes":1268,"path":6756,"publishDate":1283,"readingTime":6759,"related":7722,"relatedProjects":1268,"seo":7723,"stem":7726,"tags":7727,"track":1291,"trackName":1262,"__hash__":7728},"blog\u002Fblog\u002Flearn\u002Fprogramming-your-first-quantum-circuits\u002Fnoise-and-the-real-machine.md","Noise, and the real machine",[7],{"type":9,"value":6772,"toc":7702},[6773,6785,6788,6792,6799,6802,6805,6825,6827,6830,7308,7312,7323,7330,7335,7338,7382,7385,7388,7444,7448,7451,7459,7587,7591,7598,7603,7609,7624,7636,7640,7643,7649,7660,7673,7699],[12,6774,6775,6776,6778,6779,6781,6782,6784],{},"Some tallies in this course carried a small tail: a stray ",[36,6777,38],{}," under an X gate, a few ",[36,6780,3029],{},"s and ",[36,6783,3032],{},"s from a pair that should always agree. Each time the lesson named it the noise model and moved on. This one stops and measures it.",[12,6786,6787],{},"The measuring instrument is the Bell pair from lesson 3 at four times the shots, so a one-percent tail shows up as about forty shots rather than ten. You will run it on the models of four IonQ machines, compare them, and then look at where the real machines sit in the same dialog.",[19,6789,6791],{"id":6790},"what-a-noise-model-is","What a noise model is",[12,6793,6794,6795,6798],{},"The simulators under Remotely Run Simulators are not four copies of the same thing. Each is IonQ's simulator with a ",[36,6796,6797],{},"noise_model"," option set to one of IonQ's machines, which the Playground passes along when you pick one.",[12,6800,6801],{},"IonQ describes these as error models representative of the named system and does not publish what is inside one, so this lesson treats each model as a box and measures its effect.",[12,6803,6804],{},"The circuit is the same on every model here, so running it on several and counting compares the models.",[48,6806,6809],{"name":6807,"token":6808},"The tail, counted","disagree",[12,6810,6811,6812,1182,6814,6816,6817,42,6819,6821,6822,6824],{},"The ideal Bell tally is ",[36,6813,3022],{},[36,6815,3025],{}," only, so every ",[36,6818,3029],{},[36,6820,3032],{}," is a wrong answer. The listing adds them up as ",[36,6823,6808],{}," and prints the share. That is one measure of the noise, the errors that made the pair disagree; an error in a phase does not show in it.",[19,6826,102],{"id":101},[12,6828,6829],{},"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.",[211,6831,6834],{"name":6832,"no-picker":111,"run-href":6833,"tag":215},"noise.py","\u002Fu\u002Fqollab\u002Flearn-noise",[117,6835,6837],{"className":119,"code":6836,"language":121,"meta":111,"style":111},"# '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",[36,6838,6839,6845,6857,6869,6877,6883,6894,6900,6935,6941,6961,6975,6993,7019,7025,7045,7075,7089,7095,7113,7121,7163,7181,7229,7271],{"__ignoreMap":111},[125,6840,6841,6843],{"class":127,"line":128},[125,6842,227],{"class":225,"aria-hidden":226},[125,6844,230],{"class":157},[125,6846,6847,6849,6851,6853,6855],{"class":127,"line":161},[125,6848,227],{"class":225,"aria-hidden":226},[125,6850,238],{"class":237},[125,6852,241],{"class":131},[125,6854,244],{"class":237},[125,6856,247],{"class":131},[125,6858,6859,6861,6863,6865,6867],{"class":127,"line":179},[125,6860,227],{"class":225,"aria-hidden":226},[125,6862,238],{"class":237},[125,6864,256],{"class":131},[125,6866,244],{"class":237},[125,6868,261],{"class":131},[125,6870,6871,6873,6875],{"class":127,"line":264},[125,6872,227],{"class":225,"aria-hidden":226},[125,6874,244],{"class":237},[125,6876,271],{"class":131},[125,6878,6879,6881],{"class":127,"line":274},[125,6880,227],{"class":225,"aria-hidden":226},[125,6882,279],{},[125,6884,6885,6887,6889,6891],{"class":127,"data-cue":45,"line":282},[125,6886,45],{"class":305},[125,6888,287],{"class":131},[125,6890,136],{"class":135},[125,6892,6893],{"class":146}," 4000\n",[125,6895,6896,6898],{"class":127,"line":295},[125,6897,227],{"class":225,"aria-hidden":226},[125,6899,279],{},[125,6901,6902,6904,6906,6908,6911,6914,6917,6920,6922,6924,6927,6929,6932],{"class":127,"data-cue":325,"line":302},[125,6903,325],{"class":305},[125,6905,366],{"class":135},[125,6907,143],{"class":131},[125,6909,6910],{"class":549},"\"backend:\"",[125,6912,6913],{"class":131},", backend.name, ",[125,6915,6916],{"class":549},"\"| noise model:\"",[125,6918,6919],{"class":131},", backend.options.",[125,6921,1203],{"class":139},[125,6923,143],{"class":131},[125,6925,6926],{"class":549},"\"noise_model\"",[125,6928,149],{"class":131},[125,6930,6931],{"class":549},"\"none\"",[125,6933,6934],{"class":131},"))\n",[125,6936,6937,6939],{"class":127,"line":326},[125,6938,227],{"class":225,"aria-hidden":226},[125,6940,279],{},[125,6942,6943,6945,6947,6949,6951,6953,6955,6957,6959],{"class":127,"line":342},[125,6944,227],{"class":225,"aria-hidden":226},[125,6946,132],{"class":131},[125,6948,136],{"class":135},[125,6950,140],{"class":139},[125,6952,143],{"class":131},[125,6954,325],{"class":146},[125,6956,149],{"class":131},[125,6958,325],{"class":146},[125,6960,322],{"class":131},[125,6962,6963,6965,6967,6969,6971,6973],{"class":127,"line":361},[125,6964,227],{"class":225,"aria-hidden":226},[125,6966,164],{"class":131},[125,6968,2216],{"class":139},[125,6970,143],{"class":131},[125,6972,38],{"class":146},[125,6974,322],{"class":131},[125,6976,6977,6979,6981,6983,6985,6987,6989,6991],{"class":127,"data-cue":341,"line":372},[125,6978,341],{"class":305},[125,6980,164],{"class":131},[125,6982,3004],{"class":139},[125,6984,143],{"class":131},[125,6986,38],{"class":146},[125,6988,149],{"class":131},[125,6990,45],{"class":146},[125,6992,322],{"class":131},[125,6994,6995,6997,6999,7001,7003,7005,7007,7009,7011,7013,7015,7017],{"class":127,"line":380},[125,6996,227],{"class":225,"aria-hidden":226},[125,6998,164],{"class":131},[125,7000,79],{"class":139},[125,7002,3133],{"class":131},[125,7004,38],{"class":146},[125,7006,149],{"class":131},[125,7008,45],{"class":146},[125,7010,3142],{"class":131},[125,7012,38],{"class":146},[125,7014,149],{"class":131},[125,7016,45],{"class":146},[125,7018,3305],{"class":131},[125,7020,7021,7023],{"class":127,"line":407},[125,7022,227],{"class":225,"aria-hidden":226},[125,7024,279],{},[125,7026,7027,7029,7031,7033,7035,7037,7039,7041,7043],{"class":127,"line":451},[125,7028,227],{"class":225,"aria-hidden":226},[125,7030,385],{"class":131},[125,7032,136],{"class":135},[125,7034,390],{"class":131},[125,7036,393],{"class":139},[125,7038,396],{"class":131},[125,7040,95],{"class":399},[125,7042,136],{"class":135},[125,7044,404],{"class":131},[125,7046,7047,7049,7051,7053,7055,7057,7059,7061,7063,7065,7067,7069,7071,7073],{"class":127,"line":468},[125,7048,227],{"class":225,"aria-hidden":226},[125,7050,412],{"class":237},[125,7052,415],{"class":131},[125,7054,418],{"class":139},[125,7056,421],{"class":131},[125,7058,424],{"class":237},[125,7060,427],{"class":237},[125,7062,430],{"class":131},[125,7064,433],{"class":146},[125,7066,436],{"class":131},[125,7068,439],{"class":146},[125,7070,436],{"class":131},[125,7072,444],{"class":146},[125,7074,447],{"class":131},[125,7076,7077,7079,7081,7083,7085,7087],{"class":127,"line":476},[125,7078,227],{"class":225,"aria-hidden":226},[125,7080,456],{"class":131},[125,7082,459],{"class":139},[125,7084,143],{"class":131},[125,7086,450],{"class":146},[125,7088,322],{"class":131},[125,7090,7091,7093],{"class":127,"line":500},[125,7092,227],{"class":225,"aria-hidden":226},[125,7094,279],{},[125,7096,7097,7099,7101,7103,7105,7107,7109,7111],{"class":127,"line":510},[125,7098,227],{"class":225,"aria-hidden":226},[125,7100,481],{"class":131},[125,7102,136],{"class":135},[125,7104,415],{"class":131},[125,7106,488],{"class":139},[125,7108,491],{"class":131},[125,7110,494],{"class":139},[125,7112,497],{"class":131},[125,7114,7115,7117,7119],{"class":127,"line":536},[125,7116,227],{"class":225,"aria-hidden":226},[125,7118,366],{"class":135},[125,7120,507],{"class":131},[125,7122,7123,7125,7128,7130,7132,7134,7136,7139,7141,7143,7145,7148,7150,7152,7154,7157,7159,7161],{"class":127,"data-cue":379,"line":3436},[125,7124,379],{"class":305},[125,7126,7127],{"class":131},"agree ",[125,7129,136],{"class":135},[125,7131,4443],{"class":131},[125,7133,1203],{"class":139},[125,7135,143],{"class":131},[125,7137,7138],{"class":549},"\"00\"",[125,7140,149],{"class":131},[125,7142,38],{"class":146},[125,7144,1214],{"class":131},[125,7146,7147],{"class":135},"+",[125,7149,4443],{"class":131},[125,7151,1203],{"class":139},[125,7153,143],{"class":131},[125,7155,7156],{"class":549},"\"11\"",[125,7158,149],{"class":131},[125,7160,38],{"class":146},[125,7162,322],{"class":131},[125,7164,7165,7167,7170,7172,7175,7178],{"class":127,"data-cue":450,"line":4464},[125,7166,450],{"class":305},[125,7168,7169],{"class":131},"disagree ",[125,7171,136],{"class":135},[125,7173,7174],{"class":131}," shots ",[125,7176,7177],{"class":135},"-",[125,7179,7180],{"class":131}," agree\n",[125,7182,7183,7185,7187,7189,7191,7194,7196,7199,7202,7204,7207,7210,7212,7215,7217,7219,7222,7224,7227],{"class":127,"line":4493},[125,7184,227],{"class":225,"aria-hidden":226},[125,7186,366],{"class":135},[125,7188,143],{"class":131},[125,7190,546],{"class":237},[125,7192,7193],{"class":549},"\"agree:    ",[125,7195,553],{"class":146},[125,7197,7198],{"class":131},"agree",[125,7200,7201],{"class":237},":5d",[125,7203,559],{"class":146},[125,7205,7206],{"class":549},"  (",[125,7208,7209],{"class":146},"{100",[125,7211,581],{"class":135},[125,7213,7214],{"class":131}," agree ",[125,7216,1052],{"class":135},[125,7218,1055],{"class":131},[125,7220,7221],{"class":237},":5.2f",[125,7223,559],{"class":146},[125,7225,7226],{"class":549},"%)\"",[125,7228,322],{"class":131},[125,7230,7231,7233,7235,7237,7239,7242,7244,7246,7248,7250,7252,7254,7256,7259,7261,7263,7265,7267,7269],{"class":127,"line":5581},[125,7232,227],{"class":225,"aria-hidden":226},[125,7234,366],{"class":135},[125,7236,143],{"class":131},[125,7238,546],{"class":237},[125,7240,7241],{"class":549},"\"disagree: ",[125,7243,553],{"class":146},[125,7245,6808],{"class":131},[125,7247,7201],{"class":237},[125,7249,559],{"class":146},[125,7251,7206],{"class":549},[125,7253,7209],{"class":146},[125,7255,581],{"class":135},[125,7257,7258],{"class":131}," disagree ",[125,7260,1052],{"class":135},[125,7262,1055],{"class":131},[125,7264,7221],{"class":237},[125,7266,559],{"class":146},[125,7268,7226],{"class":549},[125,7270,322],{"class":131},[606,7272,7273,7280,7287,7294,7301],{"class":608},[610,7274,7275,7277],{"data-cue":45},[125,7276,45],{"class":305},[125,7278,7279],{"class":616},"more shots than before, so a small tail is measured rather than guessed",[610,7281,7282,7284],{"data-cue":325},[125,7283,325],{"class":305},[125,7285,7286],{"class":616},"which backend ran it, and which machine the model imitates",[610,7288,7289,7291],{"data-cue":341},[125,7290,341],{"class":305},[125,7292,7293],{"class":616},"the Bell pair from lesson 3: the two qubits should always agree",[610,7295,7296,7298],{"data-cue":379},[125,7297,379],{"class":305},[125,7299,7300],{"class":616},"the pair's signal",[610,7302,7303,7305],{"data-cue":450},[125,7304,450],{"class":305},[125,7306,7307],{"class":616},"the tail: every shot where the pair disagreed",[19,7309,7311],{"id":7310},"run-it-on-two-models","Run it on two models",[12,7313,674,7314,2638,7316,704,7318,3562,7320,7322],{},[30,7315,677],{"href":6833},[683,7317,685],{},[683,7319,707],{},[683,7321,711],{},". 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 guess is there to be checked.",[12,7324,7325,7326,7329],{},"Then press Run on Qollab again and choose ",[683,7327,7328],{},"IonQ Forte 1",". Same code, different model; the first printed line tells you which.",[107,7331],{"alt":7332,"caption":7333,"no":111,"src":7334},"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 change with every press, model or no model.","\u002F_content\u002Fimages\u002Ffirst-circuits\u002F06-noise-aria-1.webp",[12,7336,7337],{},"Our two presses on 15 September 2026:",[4619,7339,7340,7351],{},[4622,7341,7342],{},[4625,7343,7344,7347,7349],{},[4628,7345,7346],{},"noise model",[4628,7348,1106],{},[4628,7350,6808],{},[4643,7352,7353,7368],{},[4625,7354,7355,7360,7365],{},[4648,7356,7357],{},[36,7358,7359],{},"aria-1",[4648,7361,7362],{},[36,7363,7364],{},"{'00': 2033, '01': 25, '10': 13, '11': 1929}",[4648,7366,7367],{},"38 (0.95%)",[4625,7369,7370,7375,7380],{},[4648,7371,7372],{},[36,7373,7374],{},"forte-1",[4648,7376,7377],{},[36,7378,7379],{},"{'00': 1922, '01': 14, '10': 24, '11': 2040}",[4648,7381,7367],{},[12,7383,7384],{},"The same number twice. Before reading anything into that, work out how much one press can wander. 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,7386,7387],{},"Two presses on the same model can therefore differ by close to 20 shots before anything real has changed.",[825,7389,7391,7395,7423],{"check":7390},"you have four disagree lines, one per model, and a sentence saying whether any two of them differ by more than about 20 shots.",[19,7392,7394],{"id":7393},"assignment-complete-the-table","Assignment: complete the table",[606,7396,7397,7407,7417,7420],{},[610,7398,7399,7400,7403,7404,7406],{},"Run the listing on ",[683,7401,7402],{},"IonQ Aria 2"," and copy the console's ",[36,7405,6808],{}," line; the first line of each console names the model.",[610,7408,7409,7410,7413,7414,7416],{},"Run it on ",[683,7411,7412],{},"IonQ Forte Enterprise 1"," and copy that ",[36,7415,6808],{}," line too, before the next press replaces it. You now have all four models from your own presses.",[610,7418,7419],{},"Compare your four numbers against the 20-shot bar above: two numbers 8 apart are the same number, two numbers 40 apart are not.",[610,7421,7422],{},"Write one sentence saying whether any two models differ.",[871,7424,7425,7435,7438,7441],{"label":873},[12,7426,7427,7428,7431,7432,62],{},"Our four presses gave 38, 38, 36 and 44 shots. Aria 2 came back ",[36,7429,7430],{},"{'00': 2018, '01': 19, '10': 17, '11': 1946}"," and Forte Enterprise 1 ",[36,7433,7434],{},"{'00': 2007, '01': 22, '10': 22, '11': 1949}",[12,7436,7437],{},"The largest gap is 8, well under 20, so no pair of models differs by more than a fresh press of the same model would.",[12,7439,7440],{},"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. Whatever separates an Aria from a Forte does not show in this measurement.",[12,7442,7443],{},"Your four numbers will differ from ours and, by the 20-shot bar, will most likely say the same thing.",[19,7445,7447],{"id":7446},"does-the-model-charge-for-depth","Does the model charge for depth?",[12,7449,7450],{},"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. That is a reason algorithms are counted in gates.",[12,7452,7453,7454,7458],{},"Whether the model does the same is a question you can try to put to it directly: make the circuit deeper without changing what it computes, and watch the tail. One catch to keep in mind: IonQ ",[30,7455,7457],{"href":7456},"\u002Flearn\u002Fdocs\u002Fhow-your-circuit-is-compiled","compiles"," what you submit before it runs, and gates that cancel can be removed on the way.",[825,7460,7462,7466,7487],{"check":7461},"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.",[19,7463,7465],{"id":7464},"assignment-pad-the-circuit-and-watch-the-tail","Assignment: pad the circuit and watch the tail",[606,7467,7468,7471,7478,7481],{},[610,7469,7470],{},"Fork the project, as in lesson 1.",[610,7472,7473,7474,7477],{},"In your fork, add ",[36,7475,7476],{},"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.",[610,7479,7480],{},"Write down what you expect from a model that charges per gate, and from one that does not.",[610,7482,7483,7484,7486],{},"Run on the same model as your plain-circuit press, and compare the two ",[36,7485,6808],{}," lines against the 20-shot bar before you call a difference real.",[871,7488,7489,7578,7581,7584],{"label":873},[117,7490,7492],{"className":119,"code":7491,"language":121,"meta":111,"style":111},"qc.h(0)\nqc.cx(0, 1)\nqc.cx(0, 1)\nqc.cx(0, 1)\nqc.measure([0, 1], [0, 1])\n",[36,7493,7494,7506,7522,7538,7554],{"__ignoreMap":111},[125,7495,7496,7498,7500,7502,7504],{"class":127,"line":128},[125,7497,164],{"class":131},[125,7499,2216],{"class":139},[125,7501,143],{"class":131},[125,7503,38],{"class":146},[125,7505,322],{"class":131},[125,7507,7508,7510,7512,7514,7516,7518,7520],{"class":127,"line":161},[125,7509,164],{"class":131},[125,7511,3004],{"class":139},[125,7513,143],{"class":131},[125,7515,38],{"class":146},[125,7517,149],{"class":131},[125,7519,45],{"class":146},[125,7521,322],{"class":131},[125,7523,7524,7526,7528,7530,7532,7534,7536],{"class":127,"line":179},[125,7525,164],{"class":131},[125,7527,3004],{"class":139},[125,7529,143],{"class":131},[125,7531,38],{"class":146},[125,7533,149],{"class":131},[125,7535,45],{"class":146},[125,7537,322],{"class":131},[125,7539,7540,7542,7544,7546,7548,7550,7552],{"class":127,"line":264},[125,7541,164],{"class":131},[125,7543,3004],{"class":139},[125,7545,143],{"class":131},[125,7547,38],{"class":146},[125,7549,149],{"class":131},[125,7551,45],{"class":146},[125,7553,322],{"class":131},[125,7555,7556,7558,7560,7562,7564,7566,7568,7570,7572,7574,7576],{"class":127,"line":274},[125,7557,164],{"class":131},[125,7559,79],{"class":139},[125,7561,3133],{"class":131},[125,7563,38],{"class":146},[125,7565,149],{"class":131},[125,7567,45],{"class":146},[125,7569,3142],{"class":131},[125,7571,38],{"class":146},[125,7573,149],{"class":131},[125,7575,45],{"class":146},[125,7577,3305],{"class":131},[12,7579,7580],{},"On our presses the padded circuit's tail was 32 shots against 38 for the plain one: no growth beyond the scatter.",[12,7582,7583],{},"The likely reason is that the padding never ran. IonQ compiles what you submit, and 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,7585,7586],{},"So this experiment cannot tell a model that does not charge for depth from extra gates that were compiled away. A circuit that is deeper in the editor is not always deeper on the machine, and the tally alone cannot say which.",[19,7588,7590],{"id":7589},"where-the-real-machines-sit","Where the real machines sit",[12,7592,7593,7594,7597],{},"Scroll to the bottom of the Run Experiment dialog and the last group is ",[683,7595,7596],{},"Quantum Computer",": the physical IonQ machines, in the same list as their models.",[107,7599],{"alt":7600,"caption":7601,"no":111,"src":7602},"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, shown before you confirm. 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,7604,7605,7606,7608],{},"The code does not change at all. The ",[36,7607,203],{}," global from lesson 1 is what allows that: the same listing runs on a local simulator, on a machine's model, or on the machine.",[12,7610,7611,7612,7615,7616,7619,7620,7623],{},"On the machine the first line names a different backend, ",[36,7613,7614],{},"ionq_qpu.forte-1"," in place of ",[36,7617,7618],{},"ionq_simulator",", and the model field shows its default, ",[36,7621,7622],{},"ideal",", because on the machine there is no model to set. The tail is then the machine's own, made of every gate that actually ran.",[12,7625,7626,7627,7631,7632,62],{},"Nothing in this course needs a paid run. When you want one, Course 2 walks through ",[30,7628,7630],{"href":7629},"\u002Flearn\u002Fquantum-computing-with-python\u002Fionq-hardware","the account, the estimate and the queue",", and every option in the dialog is listed with its qubit count and cost under ",[30,7633,7635],{"href":7634},"\u002Flearn\u002Fdocs\u002Fcompute-backends","compute backends",[19,7637,7639],{"id":7638},"give-your-work-a-public-home","Give your work a public home",[12,7641,7642],{},"Seven circuits, each one you have run, changed and run again. The last step is to make one of them yours in public: a public project on Qollab is runnable by anyone, forkable by anyone, and carries a page that says what it does and how to run it.",[12,7644,7645,7646],{},"The procedure is short. In your fork, edit the circuit into something of your own. Under the Project Card tab, write what it does and how to run it, and say which licence it carries; each course project has a line reading ",[36,7647,7648],{},"MIT license. Fork it, change it, keep it.",[12,7650,7651,7652,7655,7656,7659],{},"Then press ",[683,7653,7654],{},"Publish Project"," in the header: one click, no dialog. The Draft label clears, the project is public at ",[36,7657,7658],{},"qollab.xyz\u002Fu\u002F\u003Cyour username>\u002F\u003Cyour project>",", and this first release is tagged v1.0.",[12,7661,7662,7663,7667,7668,7672],{},"How ",[30,7664,7666],{"href":7665},"\u002Flearn\u002Fdocs\u002Fpublish","later versions"," work is in the docs, and so is ",[30,7669,7671],{"href":7670},"\u002Flearn\u002Fdocs\u002Fwrite-your-project-page","the project page",", which is the part people read before they press Run.",[825,7674,7676,7680,7691],{"check":7675},"your project has a public URL under your own username, and its page says what the circuit does and how to run it.",[19,7677,7679],{"id":7678},"assignment-publish-a-circuit-of-your-own","Assignment: publish a circuit of your own",[606,7681,7682,7685,7688],{},[610,7683,7684],{},"Take any circuit from this course and change it into something that is yours. The smallest honest change is a real one: 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.",[610,7686,7687],{},"On the project page, say what you changed and what the tally shows because of it.",[610,7689,7690],{},"Publish it by the procedure above, then open the URL in a private window.",[871,7692,7693],{"label":873},[12,7694,7695,7696,7698],{},"There is no single answer here. The check is the URL: ",[36,7697,7658],{},", which opens in a private window where you are not signed in. If the page also lets a stranger predict the tally before they press Run, it is a good project page.",[1242,7700,7701],{},"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":111,"searchDepth":161,"depth":161,"links":7703},[7704,7705,7706,7707,7708,7709,7710,7711,7712],{"id":6790,"depth":161,"text":6791},{"id":101,"depth":161,"text":102},{"id":7310,"depth":161,"text":7311},{"id":7393,"depth":161,"text":7394},{"id":7446,"depth":161,"text":7447},{"id":7464,"depth":161,"text":7465},{"id":7589,"depth":161,"text":7590},{"id":7638,"depth":161,"text":7639},{"id":7678,"depth":161,"text":7679},[1260,1261,1262,6769],[],{"username":7,"name":1265,"role":1266,"avatar":1267},"Some runs in this course came back with a small tail of wrong answers. This lesson measures it on four IonQ noise models, finds where the models stop, and looks at the real machine behind them.","That is Programming your first quantum circuits, start to finish.",{"image":7719,"alt":7720},"\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":7724,"description":7725},"Noise and the real machine · Programming your first quantum circuits","Measure the noise tail of a Bell pair on four IonQ noise-model simulators, see what the models miss, and what the real quantum computer changes. Lesson 6, free.","blog\u002Flearn\u002Fprogramming-your-first-quantum-circuits\u002Fnoise-and-the-real-machine",[],"m4ZL7DeOx-PBYEoAyg63H1F6fDif2FJWjUcx_MtG59s",1789514644546]