[{"data":1,"prerenderedAt":3433},["ShallowReactive",2],{"blog-post-quantum-measurement":3,"sibling-dives-quantum-measurement":3431,"learn-track-quantum-measurement":3432},{"id":4,"title":5,"authors":6,"body":8,"breadcrumb":3389,"builders":3393,"byline":3406,"category":3407,"categoryName":3407,"challenge":3407,"courseAuthor":3407,"courseLead":3407,"dek":3408,"description":3409,"draft":3410,"extension":3411,"eyebrow":3407,"featured":3410,"finish":3407,"fork":3412,"hero":3407,"heroAlt":3407,"heroCta":3407,"heroImage":3407,"homepageFeatured":3410,"kind":3414,"lessonCount":3407,"meta":3415,"navigation":3416,"newsItems":3407,"next":3407,"ogImage":3417,"order":3407,"outcomes":3407,"path":3418,"publishDate":3419,"readingTime":3420,"related":3421,"relatedProjects":3407,"seo":3422,"stem":3425,"tags":3426,"track":3407,"trackName":3407,"__hash__":3430},"blog\u002Fblog\u002Flearn\u002Fquantum-measurement.md","Understanding Quantum Measurement",[7],"nico",{"type":9,"value":10,"toc":3374},"minimark",[11,28,36,39,42,47,50,332,341,344,356,360,363,604,614,621,625,628,646,666,689,703,716,720,729,732,1097,1160,1166,1172,1175,1178,1187,1191,1194,1197,1204,1212,1306,1312,1315,1327,1336,1339,1342,1350,1357,1361,1364,1373,1747,1750,1753,1758,1762,1765,1770,1773,2091,2097,2103,2106,2109,2117,2124,2128,2131,2136,2139,2325,2328,2331,2334,2337,2343,2347,2350,2353,2358,2361,2579,2582,2585,2590,2593,2804,2807,2810,2823,2829,2833,2836,2839,3324,3327,3330,3333,3336,3344,3347,3351,3354,3357,3360,3370],[12,13,14,15,19,20,23,24,27],"p",{},"There is no ",[16,17,18],"code",{},"print(qubit)",". No debugger, no stepping through to watch one change. The only way to get anything out of a qubit is to measure it, and measurement does hand you a single ",[16,21,22],{},"0"," or ",[16,25,26],{},"1",".",[12,29,30,31,23,33,35],{},"The catch is where that ",[16,32,22],{},[16,34,26],{}," comes from. Measurement does not find an answer sitting in the qubit; it produces one. Before you measure there is nothing in there to print, which is why no such function exists.",[12,37,38],{},"Quantum code feels alien for that reason. You write a program, run it, get back a tally of bitstrings, and everything you actually wanted to know has to be inferred from that tally.",[12,40,41],{},"Four things follow, and each shows up the first time you write a circuit. You can sample a qubit but never read it. Which answer you get depends on which question you ask. Asking is one-way, so whatever the qubit held before is gone. And the instrument doing the asking can be wrong in its own right, separately from all of that.",[43,44,46],"h2",{"id":45},"the-smallest-measurement-you-can-make","The smallest measurement you can make",[12,48,49],{},"One qubit is enough to see the whole problem. Put it into a state that has no fixed value, read it, and count what comes back.",[51,52,56],"code-block",{"name":53,"tag":54,"run-href":55},"one_qubit.py","Python · Playground version","\u002Fu\u002Fqollab\u002Fbell-state",[57,58,63],"pre",{"className":59,"code":60,"language":61,"meta":62,"style":62},"language-python shiki shiki-themes one-dark-pro","# 'backend' is pre-created for you in the Qollab Playground.\nfrom qiskit import QuantumCircuit\n\nqc = QuantumCircuit(1, 1)\nqc.h(0)\nqc.measure(0, 0)\n\none = backend.run(qc, shots=1).result().get_counts()\nmany = backend.run(qc, shots=1000).result().get_counts()\n\nprint(one, many)\n","python","",[16,64,65,79,98,106,137,155,176,183,226,260,267,278],{"__ignoreMap":62},[66,67,70,75],"span",{"class":68,"line":69},"line",1,[66,71,74],{"class":72,"aria-hidden":73},"qg-cue qg-cue--empty","true","​",[66,76,78],{"class":77},"sV9Aq","# 'backend' is pre-created for you in the Qollab Playground.\n",[66,80,82,84,88,92,95],{"class":68,"line":81},2,[66,83,74],{"class":72,"aria-hidden":73},[66,85,87],{"class":86},"seHd6","from",[66,89,91],{"class":90},"sn6KH"," qiskit ",[66,93,94],{"class":86},"import",[66,96,97],{"class":90}," QuantumCircuit\n",[66,99,101,103],{"class":68,"line":100},3,[66,102,74],{"class":72,"aria-hidden":73},[66,104,105],{},"​\n",[66,107,109,112,115,119,123,126,129,132,134],{"class":68,"data-cue":26,"line":108},4,[66,110,26],{"class":111},"qg-cue",[66,113,114],{"class":90},"qc ",[66,116,118],{"class":117},"sjrmR","=",[66,120,122],{"class":121},"sVbv2"," QuantumCircuit",[66,124,125],{"class":90},"(",[66,127,26],{"class":128},"sVC51",[66,130,131],{"class":90},", ",[66,133,26],{"class":128},[66,135,136],{"class":90},")\n",[66,138,141,143,146,149,151,153],{"class":68,"data-cue":139,"line":140},"2",5,[66,142,139],{"class":111},[66,144,145],{"class":90},"qc.",[66,147,148],{"class":121},"h",[66,150,125],{"class":90},[66,152,22],{"class":128},[66,154,136],{"class":90},[66,156,159,161,163,166,168,170,172,174],{"class":68,"data-cue":157,"line":158},"3",6,[66,160,157],{"class":111},[66,162,145],{"class":90},[66,164,165],{"class":121},"measure",[66,167,125],{"class":90},[66,169,22],{"class":128},[66,171,131],{"class":90},[66,173,22],{"class":128},[66,175,136],{"class":90},[66,177,179,181],{"class":68,"line":178},7,[66,180,74],{"class":72,"aria-hidden":73},[66,182,105],{},[66,184,187,189,192,194,197,200,203,207,209,211,214,217,220,223],{"class":68,"data-cue":185,"line":186},"4",8,[66,188,185],{"class":111},[66,190,191],{"class":90},"one ",[66,193,118],{"class":117},[66,195,196],{"class":90}," backend.",[66,198,199],{"class":121},"run",[66,201,202],{"class":90},"(qc, ",[66,204,206],{"class":205},"s_ZVi","shots",[66,208,118],{"class":117},[66,210,26],{"class":128},[66,212,213],{"class":90},").",[66,215,216],{"class":121},"result",[66,218,219],{"class":90},"().",[66,221,222],{"class":121},"get_counts",[66,224,225],{"class":90},"()\n",[66,227,230,232,235,237,239,241,243,245,247,250,252,254,256,258],{"class":68,"data-cue":228,"line":229},"5",9,[66,231,228],{"class":111},[66,233,234],{"class":90},"many ",[66,236,118],{"class":117},[66,238,196],{"class":90},[66,240,199],{"class":121},[66,242,202],{"class":90},[66,244,206],{"class":205},[66,246,118],{"class":117},[66,248,249],{"class":128},"1000",[66,251,213],{"class":90},[66,253,216],{"class":121},[66,255,219],{"class":90},[66,257,222],{"class":121},[66,259,225],{"class":90},[66,261,263,265],{"class":68,"line":262},10,[66,264,74],{"class":72,"aria-hidden":73},[66,266,105],{},[66,268,270,272,275],{"class":68,"line":269},11,[66,271,74],{"class":72,"aria-hidden":73},[66,273,274],{"class":117},"print",[66,276,277],{"class":90},"(one, many)\n",[279,280,282,291,304,311,325],"ol",{"class":281},"qg-cues",[283,284,285,287],"li",{"data-cue":26},[66,286,26],{"class":111},[66,288,290],{"class":289},"qg-cues__text","One qubit to do the quantum work, and one ordinary bit to read the answer into.",[283,292,293,295],{"data-cue":139},[66,294,139],{"class":111},[66,296,297,298,300,301,303],{"class":289},"A Hadamard puts the qubit into superposition: not ",[16,299,22],{},", not ",[16,302,26],{},", and not secretly one of them either. It has no value to read.",[283,305,306,308],{"data-cue":157},[66,307,157],{"class":111},[66,309,310],{"class":289},"The only way to get anything out. It forces the qubit to one definite answer and writes that answer to the bit.",[283,312,313,315],{"data-cue":185},[66,314,185],{"class":111},[66,316,317,318,23,321,324],{"class":289},"Run the circuit once. You get ",[16,319,320],{},"{'0': 1}",[16,322,323],{},"{'1': 1}"," — one answer, with nothing to say whether the other was equally likely or nearly impossible.",[283,326,327,329],{"data-cue":228},[66,328,228],{"class":111},[66,330,331],{"class":289},"Run it a thousand times. Now the pattern shows: roughly 500 each. A shot is one complete run, and the odds only exist across a pile of them.",[12,333,334,335,337,338,340],{},"Eight lines, and every difficulty is in them. The qubit held something before line three, the measurement turned it into a ",[16,336,22],{}," or a ",[16,339,26],{},", and what it held cannot be recovered from what you got.",[12,342,343],{},"Run the same program twice and the thousand-shot tally comes back roughly the same, while the single shot flips between runs. Neither number is more true than the other. One is a sample and the other is a pattern in a thousand samples.",[12,345,346,350,351,337,353,355],{},[347,348,349],"strong",{},"Superposition"," is the word for what the qubit had before the measurement. It does not mean the qubit is secretly a ",[16,352,22],{},[16,354,26],{}," and we have not looked yet. There is no answer in there to find; the measurement is what produces one.",[43,357,359],{"id":358},"all-you-get-is-counts","All you get is counts",[12,361,362],{},"Every quantum program ends the same way: a dictionary mapping bitstrings to how many times each came up. Nothing else comes back.",[51,364,368],{"name":365,"tag":366,"run-href":367},"histograms.py","Python · excerpt","\u002Fu\u002Fqollab\u002Fshowcase-histograms",[57,369,371],{"className":59,"code":370,"language":61,"meta":62,"style":62},"# Counts from an ideal Bell-state experiment: only correlated outcomes,\n# roughly 50\u002F50 between 00 and 11\nideal = {\"00\": 512, \"11\": 488}\nplot_histogram(ideal, filename=\"ideal.svg\")\n\n# The same experiment on noisy hardware leaks shots into 01 and 10.\n# plot_histogram overlays multiple experiments for direct comparison.\nnoisy = {\"00\": 462, \"01\": 27, \"10\": 31, \"11\": 480}\nplot_histogram(\n    [ideal, noisy],\n    legend=[\"ideal simulator\", \"noisy device\"],\n    filename=\"ideal_vs_noisy.svg\",\n)\n",[16,372,373,380,387,422,442,448,455,462,511,520,527,550,566,573],{"__ignoreMap":62},[66,374,375,377],{"class":68,"line":69},[66,376,74],{"class":72,"aria-hidden":73},[66,378,379],{"class":77},"# Counts from an ideal Bell-state experiment: only correlated outcomes,\n",[66,381,382,384],{"class":68,"line":81},[66,383,74],{"class":72,"aria-hidden":73},[66,385,386],{"class":77},"# roughly 50\u002F50 between 00 and 11\n",[66,388,389,391,394,396,399,403,406,409,411,414,416,419],{"class":68,"data-cue":26,"line":100},[66,390,26],{"class":111},[66,392,393],{"class":90},"ideal ",[66,395,118],{"class":117},[66,397,398],{"class":90}," {",[66,400,402],{"class":401},"subq3","\"00\"",[66,404,405],{"class":90},": ",[66,407,408],{"class":128},"512",[66,410,131],{"class":90},[66,412,413],{"class":401},"\"11\"",[66,415,405],{"class":90},[66,417,418],{"class":128},"488",[66,420,421],{"class":90},"}\n",[66,423,424,426,429,432,435,437,440],{"class":68,"line":108},[66,425,74],{"class":72,"aria-hidden":73},[66,427,428],{"class":121},"plot_histogram",[66,430,431],{"class":90},"(ideal, ",[66,433,434],{"class":205},"filename",[66,436,118],{"class":117},[66,438,439],{"class":401},"\"ideal.svg\"",[66,441,136],{"class":90},[66,443,444,446],{"class":68,"line":140},[66,445,74],{"class":72,"aria-hidden":73},[66,447,105],{},[66,449,450,452],{"class":68,"line":158},[66,451,74],{"class":72,"aria-hidden":73},[66,453,454],{"class":77},"# The same experiment on noisy hardware leaks shots into 01 and 10.\n",[66,456,457,459],{"class":68,"line":178},[66,458,74],{"class":72,"aria-hidden":73},[66,460,461],{"class":77},"# plot_histogram overlays multiple experiments for direct comparison.\n",[66,463,464,466,469,471,473,475,477,480,482,485,487,490,492,495,497,500,502,504,506,509],{"class":68,"data-cue":139,"line":186},[66,465,139],{"class":111},[66,467,468],{"class":90},"noisy ",[66,470,118],{"class":117},[66,472,398],{"class":90},[66,474,402],{"class":401},[66,476,405],{"class":90},[66,478,479],{"class":128},"462",[66,481,131],{"class":90},[66,483,484],{"class":401},"\"01\"",[66,486,405],{"class":90},[66,488,489],{"class":128},"27",[66,491,131],{"class":90},[66,493,494],{"class":401},"\"10\"",[66,496,405],{"class":90},[66,498,499],{"class":128},"31",[66,501,131],{"class":90},[66,503,413],{"class":401},[66,505,405],{"class":90},[66,507,508],{"class":128},"480",[66,510,421],{"class":90},[66,512,513,515,517],{"class":68,"line":229},[66,514,74],{"class":72,"aria-hidden":73},[66,516,428],{"class":121},[66,518,519],{"class":90},"(\n",[66,521,522,524],{"class":68,"line":262},[66,523,74],{"class":72,"aria-hidden":73},[66,525,526],{"class":90},"    [ideal, noisy],\n",[66,528,529,531,534,536,539,542,544,547],{"class":68,"line":269},[66,530,74],{"class":72,"aria-hidden":73},[66,532,533],{"class":205},"    legend",[66,535,118],{"class":117},[66,537,538],{"class":90},"[",[66,540,541],{"class":401},"\"ideal simulator\"",[66,543,131],{"class":90},[66,545,546],{"class":401},"\"noisy device\"",[66,548,549],{"class":90},"],\n",[66,551,553,555,558,560,563],{"class":68,"line":552},12,[66,554,74],{"class":72,"aria-hidden":73},[66,556,557],{"class":205},"    filename",[66,559,118],{"class":117},[66,561,562],{"class":401},"\"ideal_vs_noisy.svg\"",[66,564,565],{"class":90},",\n",[66,567,569,571],{"class":68,"data-cue":157,"line":568},13,[66,570,157],{"class":111},[66,572,136],{"class":90},[279,574,575,582,597],{"class":281},[283,576,577,579],{"data-cue":26},[66,578,26],{"class":111},[66,580,581],{"class":289},"A thousand shots of a Bell pair. Not a state, not amplitudes: a tally.",[283,583,584,586],{"data-cue":139},[66,585,139],{"class":111},[66,587,588,589,592,593,596],{"class":289},"The same circuit on real hardware. ",[16,590,591],{},"01"," and ",[16,594,595],{},"10"," should be impossible for this state, and 58 shots out of a thousand landed there anyway.",[283,598,599,601],{"data-cue":157},[66,600,157],{"class":111},[66,602,603],{"class":289},"Two runs on one chart. Comparing distributions is most of what reading quantum results consists of.",[12,605,606,607,23,610,613],{},"Notice what a single shot would have told you here: one bitstring, ",[16,608,609],{},"00",[16,611,612],{},"11",", with no way to know whether the other was equally likely or nearly impossible. Only a pile of a thousand has a pattern in it at all.",[615,616],"project-card",{"description":617,"framework":618,"owner":619,"title":620,"to":367},"Every quantum program ends the same way: a dictionary of measurement counts. plot_histogram from Qiskit's visualization module is the one-liner that turns those counts into a picture.","Python + Qiskit","qollab","Histograms",[43,622,624],{"id":623},"the-gates-in-these-circuits","The gates in these circuits",[12,626,627],{},"Four gates and one instruction cover every excerpt below.",[629,630,632,643],"gate",{"token":148,"name":631},"Hadamard",[12,633,634,635,637,638,23,640,642],{},"Takes a qubit sitting at ",[16,636,22],{}," and leaves it with no fixed value: measure it and you get ",[16,639,22],{},[16,641,26],{}," with equal probability.",[12,644,645],{},"The Hadamard is also its own undo. Two of them in a row put the qubit back exactly where it started, which is the trick the next section is built on.",[629,647,649,660],{"token":648},"z",[12,650,651,652,23,654,656,657,659],{},"Leaves a qubit exactly as likely to read ",[16,653,22],{},[16,655,26],{}," as it already was, and flips the sign in front of the ",[16,658,26],{}," half of the state.",[12,661,662,663,665],{},"A sign is not something a measurement reports, so a ",[16,664,648],{}," is invisible in the counts. The change is real all the same, and the next section is about how to see it.",[629,667,669,677],{"token":668},"ry",[12,670,671,672,674,675,27],{},"A rotation. The angle comes before the qubit and sets how likely a qubit starting at ",[16,673,22],{}," is to read ",[16,676,26],{},[12,678,679,680,682,683,685,686,688],{},"At ",[16,681,22],{}," it is certain to read ",[16,684,22],{},", at π certain to read ",[16,687,26],{},", and at π\u002F2 it gives the same even split the Hadamard does. Anything in between is a bias you pick, which is how a circuit gets odds other than fifty-fifty.",[629,690,692,700],{"token":691},"rzz",[12,693,694,695,23,697,699],{},"Couples two qubits by an angle. Unlike the others it does not change how often either qubit reads ",[16,696,22],{},[16,698,26],{}," on its own.",[12,701,702],{},"The coupling changes the relationship between the two instead, which is why Entangled Body's couplings entangle the state and still leave no trace in its counts.",[629,704,705,713],{"token":165},[12,706,707,708,23,710,712],{},"Reads a qubit into an ordinary bit and forces it to a definite ",[16,709,22],{},[16,711,26],{},". It is the one irreversible step: whatever the qubit held before is gone once you look.",[12,714,715],{},"So a single run tells you one outcome and nothing about the odds behind it, which is why every circuit here is run many times over.",[43,717,719],{"id":718},"which-question-you-ask","Which question you ask",[12,721,722,723,725,726,728],{},"Measuring is not reading a value off a dial. It is putting a question to the qubit, and ",[16,724,22],{},"-or-",[16,727,26],{}," is only one of the questions available.",[12,730,731],{},"The cheapest way to see that is to build two qubits that give the same counts, and then ask them something else.",[51,733,735],{"name":734,"tag":54,"run-href":55},"two_questions.py",[57,736,738],{"className":59,"code":737,"language":61,"meta":62,"style":62},"# 'backend' is pre-created for you in the Qollab Playground.\nfrom qiskit import QuantumCircuit\n\ndef counts(add_z, ask_after_h):\n    qc = QuantumCircuit(1, 1)\n    qc.h(0)\n    if add_z:\n        qc.z(0)\n    if ask_after_h:\n        qc.h(0)\n    qc.measure(0, 0)\n    return backend.run(qc, shots=1000).result().get_counts()\n\nprint(\"h     asked directly  :\", counts(False, False))\nprint(\"h,z   asked directly  :\", counts(True, False))\nprint(\"h     asked after an h:\", counts(False, True))\nprint(\"h,z   asked after an h:\", counts(True, True))\n",[16,739,740,746,758,764,788,809,824,834,849,858,872,890,919,925,954,981,1008,1035],{"__ignoreMap":62},[66,741,742,744],{"class":68,"line":69},[66,743,74],{"class":72,"aria-hidden":73},[66,745,78],{"class":77},[66,747,748,750,752,754,756],{"class":68,"line":81},[66,749,74],{"class":72,"aria-hidden":73},[66,751,87],{"class":86},[66,753,91],{"class":90},[66,755,94],{"class":86},[66,757,97],{"class":90},[66,759,760,762],{"class":68,"line":100},[66,761,74],{"class":72,"aria-hidden":73},[66,763,105],{},[66,765,766,768,771,774,776,780,782,785],{"class":68,"line":108},[66,767,74],{"class":72,"aria-hidden":73},[66,769,770],{"class":86},"def",[66,772,773],{"class":121}," counts",[66,775,125],{"class":90},[66,777,779],{"class":778},"sb9H8","add_z",[66,781,131],{"class":90},[66,783,784],{"class":778},"ask_after_h",[66,786,787],{"class":90},"):\n",[66,789,790,792,795,797,799,801,803,805,807],{"class":68,"line":140},[66,791,74],{"class":72,"aria-hidden":73},[66,793,794],{"class":90},"    qc ",[66,796,118],{"class":117},[66,798,122],{"class":121},[66,800,125],{"class":90},[66,802,26],{"class":128},[66,804,131],{"class":90},[66,806,26],{"class":128},[66,808,136],{"class":90},[66,810,811,813,816,818,820,822],{"class":68,"data-cue":26,"line":158},[66,812,26],{"class":111},[66,814,815],{"class":90},"    qc.",[66,817,148],{"class":121},[66,819,125],{"class":90},[66,821,22],{"class":128},[66,823,136],{"class":90},[66,825,826,828,831],{"class":68,"line":178},[66,827,74],{"class":72,"aria-hidden":73},[66,829,830],{"class":86},"    if",[66,832,833],{"class":90}," add_z:\n",[66,835,836,838,841,843,845,847],{"class":68,"data-cue":139,"line":186},[66,837,139],{"class":111},[66,839,840],{"class":90},"        qc.",[66,842,648],{"class":121},[66,844,125],{"class":90},[66,846,22],{"class":128},[66,848,136],{"class":90},[66,850,851,853,855],{"class":68,"line":229},[66,852,74],{"class":72,"aria-hidden":73},[66,854,830],{"class":86},[66,856,857],{"class":90}," ask_after_h:\n",[66,859,860,862,864,866,868,870],{"class":68,"data-cue":157,"line":262},[66,861,157],{"class":111},[66,863,840],{"class":90},[66,865,148],{"class":121},[66,867,125],{"class":90},[66,869,22],{"class":128},[66,871,136],{"class":90},[66,873,874,876,878,880,882,884,886,888],{"class":68,"line":269},[66,875,74],{"class":72,"aria-hidden":73},[66,877,815],{"class":90},[66,879,165],{"class":121},[66,881,125],{"class":90},[66,883,22],{"class":128},[66,885,131],{"class":90},[66,887,22],{"class":128},[66,889,136],{"class":90},[66,891,892,894,897,899,901,903,905,907,909,911,913,915,917],{"class":68,"line":552},[66,893,74],{"class":72,"aria-hidden":73},[66,895,896],{"class":86},"    return",[66,898,196],{"class":90},[66,900,199],{"class":121},[66,902,202],{"class":90},[66,904,206],{"class":205},[66,906,118],{"class":117},[66,908,249],{"class":128},[66,910,213],{"class":90},[66,912,216],{"class":121},[66,914,219],{"class":90},[66,916,222],{"class":121},[66,918,225],{"class":90},[66,920,921,923],{"class":68,"line":568},[66,922,74],{"class":72,"aria-hidden":73},[66,924,105],{},[66,926,928,930,932,934,937,939,942,944,947,949,951],{"class":68,"data-cue":185,"line":927},14,[66,929,185],{"class":111},[66,931,274],{"class":117},[66,933,125],{"class":90},[66,935,936],{"class":401},"\"h     asked directly  :\"",[66,938,131],{"class":90},[66,940,941],{"class":121},"counts",[66,943,125],{"class":90},[66,945,946],{"class":128},"False",[66,948,131],{"class":90},[66,950,946],{"class":128},[66,952,953],{"class":90},"))\n",[66,955,957,959,961,963,966,968,970,972,975,977,979],{"class":68,"data-cue":228,"line":956},15,[66,958,228],{"class":111},[66,960,274],{"class":117},[66,962,125],{"class":90},[66,964,965],{"class":401},"\"h,z   asked directly  :\"",[66,967,131],{"class":90},[66,969,941],{"class":121},[66,971,125],{"class":90},[66,973,974],{"class":128},"True",[66,976,131],{"class":90},[66,978,946],{"class":128},[66,980,953],{"class":90},[66,982,985,987,989,991,994,996,998,1000,1002,1004,1006],{"class":68,"data-cue":983,"line":984},"6",16,[66,986,983],{"class":111},[66,988,274],{"class":117},[66,990,125],{"class":90},[66,992,993],{"class":401},"\"h     asked after an h:\"",[66,995,131],{"class":90},[66,997,941],{"class":121},[66,999,125],{"class":90},[66,1001,946],{"class":128},[66,1003,131],{"class":90},[66,1005,974],{"class":128},[66,1007,953],{"class":90},[66,1009,1012,1014,1016,1018,1021,1023,1025,1027,1029,1031,1033],{"class":68,"data-cue":1010,"line":1011},"7",17,[66,1013,1010],{"class":111},[66,1015,274],{"class":117},[66,1017,125],{"class":90},[66,1019,1020],{"class":401},"\"h,z   asked after an h:\"",[66,1022,131],{"class":90},[66,1024,941],{"class":121},[66,1026,125],{"class":90},[66,1028,974],{"class":128},[66,1030,131],{"class":90},[66,1032,974],{"class":128},[66,1034,953],{"class":90},[279,1036,1037,1044,1057,1064,1071,1078,1088],{"class":281},[283,1038,1039,1041],{"data-cue":26},[66,1040,26],{"class":111},[66,1042,1043],{"class":289},"Both states start the same way, with the Hadamard from the first listing.",[283,1045,1046,1048],{"data-cue":139},[66,1047,139],{"class":111},[66,1049,1050,1051,1053,1054,1056],{"class":289},"The only difference between the two states. A ",[16,1052,648],{}," leaves the qubit just as undecided as it was; all it does is flip the sign in front of the ",[16,1055,26],{}," half of it.",[283,1058,1059,1061],{"data-cue":157},[66,1060,157],{"class":111},[66,1062,1063],{"class":289},"This one is not part of the state. It lands after the state is finished and just before the measurement, and switching it on is what changes the question.",[283,1065,1066,1068],{"data-cue":185},[66,1067,185],{"class":111},[66,1069,1070],{"class":289},"Roughly 500 each, the same even split as the first listing.",[283,1072,1073,1075],{"data-cue":228},[66,1074,228],{"class":111},[66,1076,1077],{"class":289},"Roughly 500 each again. Nothing in this tally can tell the two states apart.",[283,1079,1080,1082],{"data-cue":983},[66,1081,983],{"class":111},[66,1083,1084,1085,1087],{"class":289},"Every shot reads ",[16,1086,22],{},". Two Hadamards cancel, so the qubit is back where it started.",[283,1089,1090,1092],{"data-cue":1010},[66,1091,1010],{"class":111},[66,1093,1084,1094,1096],{"class":289},[16,1095,26],{},". The same two states as the rows above, and now the answers are opposites.",[1098,1099,1100,1118],"table",{},[1101,1102,1103],"thead",{},[1104,1105,1106,1110,1113],"tr",{},[1107,1108,1109],"th",{},"prepared with",[1107,1111,1112],{},"asked directly",[1107,1114,1115,1116],{},"asked after an ",[16,1117,148],{},[1119,1120,1121,1141],"tbody",{},[1104,1122,1123,1128,1136],{},[1124,1125,1126],"td",{},[16,1127,148],{},[1124,1129,1130,1131,1133,1134],{},"~500 ",[16,1132,22],{},", ~500 ",[16,1135,26],{},[1124,1137,1138,1139],{},"1000 ",[16,1140,22],{},[1104,1142,1143,1150,1156],{},[1124,1144,1145,1147,1148],{},[16,1146,148],{}," then ",[16,1149,648],{},[1124,1151,1130,1152,1133,1154],{},[16,1153,22],{},[16,1155,26],{},[1124,1157,1138,1158],{},[16,1159,26],{},[12,1161,1162,1163,1165],{},"Read the table down the first column and the two states are identical. Read it down the second and they are opposites. The ",[16,1164,648],{}," did something real to the qubit, and the first question had no way to report it.",[12,1167,1168,1171],{},[347,1169,1170],{},"A basis is the question."," Measuring straight away asks one; putting a Hadamard in front of the measurement asks a different one. Nothing about the qubit changed between the two columns, only what you asked it.",[12,1173,1174],{},"A quantum state carries more than any single measurement can hand back. Ask the wrong question and the interesting half of your circuit is not in the output, and nothing about the output says so.",[12,1176,1177],{},"Each of those four rows needed its own run and its own fresh qubit. The measurement is the last line of the function every time, because there is no version of this where you ask one question, look, and then ask the other. That is the one-way part: you get one question per qubit, and the state is gone after it.",[12,1179,1180,1181,1186],{},"On real hardware the right-hand column will not come back as a clean 1000 and 0. A few dozen shots land in the wrong row, from gate and readout errors that ",[1182,1183,1185],"a",{"href":1184},"#when-the-instrument-is-wrong","a section below"," is about. Either way the pattern is unmistakable.",[43,1188,1190],{"id":1189},"when-the-odds-are-not-fifty-fifty","When the odds are not fifty-fifty",[12,1192,1193],{},"Every circuit so far has aimed at an even split or a certainty. Real circuits mostly want neither, and Entangled Body is a good place to see why that matters.",[12,1195,1196],{},"Entangled Body is a 3D human figure whose fourteen regions are fourteen qubits. Touch one and the figure responds around it, strongly nearby and less further away.",[1198,1199],"blog-figure",{"alt":1200,"caption":1201,"no":62,"poster":1202,"video":1203},"Entangled Body: a point-cloud figure whose regions react to each other across distance","Touch one region and the figure responds around it. Press play.","\u002F_content\u002Fimages\u002Fentangled-body\u002Fhero.webp","https:\u002F\u002Fapi.cms.qollab.xyz\u002Fassets\u002F960a7fe3-a278-4e61-8478-cc142d11f9a9",[12,1205,1206,1207,1211],{},"Nothing in that description is a coin flip. Each region needs its own probability of lighting up, and the piece has a two-line function that turns a probability into an ",[1182,1208,1210],{"href":1209},"#the-gates-in-these-circuits","Ry"," angle.",[51,1213,1216],{"name":1214,"tag":366,"run-href":1215},"entangled_body_demo.py","\u002Fu\u002Flukeshim\u002Fentangled-body",[57,1217,1219],{"className":59,"code":1218,"language":61,"meta":62,"style":62},"def _prob_to_ry(prob):\n    p = max(0.0, min(1.0, prob))\n    return 2.0 * asin(sqrt(p))\n",[16,1220,1221,1237,1267,1290],{"__ignoreMap":62},[66,1222,1223,1225,1227,1230,1232,1235],{"class":68,"line":69},[66,1224,74],{"class":72,"aria-hidden":73},[66,1226,770],{"class":86},[66,1228,1229],{"class":121}," _prob_to_ry",[66,1231,125],{"class":90},[66,1233,1234],{"class":778},"prob",[66,1236,787],{"class":90},[66,1238,1239,1241,1244,1246,1249,1251,1254,1256,1259,1261,1264],{"class":68,"data-cue":26,"line":81},[66,1240,26],{"class":111},[66,1242,1243],{"class":90},"    p ",[66,1245,118],{"class":117},[66,1247,1248],{"class":117}," max",[66,1250,125],{"class":90},[66,1252,1253],{"class":128},"0.0",[66,1255,131],{"class":90},[66,1257,1258],{"class":117},"min",[66,1260,125],{"class":90},[66,1262,1263],{"class":128},"1.0",[66,1265,1266],{"class":90},", prob))\n",[66,1268,1269,1271,1273,1276,1279,1282,1284,1287],{"class":68,"data-cue":139,"line":100},[66,1270,139],{"class":111},[66,1272,896],{"class":86},[66,1274,1275],{"class":128}," 2.0",[66,1277,1278],{"class":117}," *",[66,1280,1281],{"class":121}," asin",[66,1283,125],{"class":90},[66,1285,1286],{"class":121},"sqrt",[66,1288,1289],{"class":90},"(p))\n",[279,1291,1292,1299],{"class":281},[283,1293,1294,1296],{"data-cue":26},[66,1295,26],{"class":111},[66,1297,1298],{"class":289},"Hold the requested probability between 0 and 1, so a rounding error upstream cannot ask for odds that do not exist.",[283,1300,1301,1303],{"data-cue":139},[66,1302,139],{"class":111},[66,1304,1305],{"class":289},"Turn it into an Ry angle. You name the odds you want and this hands back the rotation that produces them, which is the whole bridge between \"how likely\" and \"which gate\".",[12,1307,1308,1309,1311],{},"That conversion is exact rather than an approximation. Ask for 0.84 and the odds of reading ",[16,1310,26],{}," are 0.84, not 0.839 or 0.841.",[12,1313,1314],{},"Entangled Body uses that to draw its ripple. A hover sets the region you touched to a certainty, its nearest neighbours to just under 0.995, and the furthest region to 0.90.",[12,1316,1317,1318,1320,1321,1323,1324,1326],{},"All three are close to ",[16,1319,26],{}," and they are still very different. In a single shot every region reads ",[16,1322,26],{}," and the figure tells you nothing at all. Across the 1024 shots the project runs, the nearest region reads ",[16,1325,22],{}," about five times and the furthest about a hundred. No single run contains the ripple. It lives in the difference between five and a hundred.",[12,1328,1329,1330,1332,1333,1335],{},"On top of the rotations, the anatomical links between regions get an ",[16,1331,691],{}," coupling, and those entangle the state. They also leave no trace in the counts, for the reason the last section demonstrated. An ",[16,1334,691],{}," only moves signs around, and the circuit measures in the one question where signs do not show.",[12,1337,1338],{},"So the entanglement is there and the measurement cannot see it. Nothing is broken and nothing is hidden. You asked the one question this coupling does not answer.",[12,1340,1341],{},"Fork it and put a Hadamard on every region just before the measurement, the same move as the right-hand column of the table above. The couplings then reach the counts instead of hiding in the signs.",[12,1343,1344,1345,1349],{},"Measuring one qubit of an entangled group also changes what the rest will do, which is a subject of its own: ",[1182,1346,1348],{"href":1347},"\u002Flearn\u002Fquantum-entanglement","Understanding Quantum Entanglement"," is the article about that.",[615,1351],{"description":1352,"framework":618,"owner":1353,"title":1354,"to":1215,"builder":1355,"thumb":1356},"Entangled Body is an interactive 3D artwork that treats the body as a network of 14 quantum nodes, each mapped to a specific body region.","lukeshim","Entangled Body","Chanhyuk Park & Luke Shim","\u002F_content\u002Fimages\u002Fentangled-body\u002Fscreenshot.webp",[43,1358,1360],{"id":1359},"when-the-instrument-is-wrong","When the instrument is wrong",[12,1362,1363],{},"A second thing can go wrong, and it is a different thing from the first.",[12,1365,1366,1367,1369,1370,1372],{},"The state can be fine and the reading still wrong. A detector that reports ",[16,1368,26],{}," when the qubit was ",[16,1371,22],{}," has not disturbed any physics; it has mistyped. And because that error happens after the quantum part is over, ordinary arithmetic can undo it.",[51,1374,1378],{"name":1375,"tag":1376,"run-href":1377},"readout.js","JavaScript · excerpt","\u002Fu\u002Fqollab\u002Freadout-mitigation-showcase-fi",[57,1379,1383],{"className":1380,"code":1381,"language":1382,"meta":62,"style":62},"language-javascript shiki shiki-themes one-dark-pro","function qubitMatrix(q){\n  let p10=state.p10, p01=state.p01;\n  if(state.hotQubit && q===2){p10=Math.min(0.25,p10*4); p01=Math.min(0.25,p01*4);}   \u002F\u002F1 One qubit can be worse than the others. Real devices are like this: readout quality is per-qubit and it drifts.\n  return [[1-p10,p01],[p10,1-p01]];   \u002F\u002F2 The whole error model for one qubit, as four numbers: how often a 0 is read as 0 or 1, and the same for a 1.\n}\nfunction Aentry(i,j){let p=1;\n  for(let q=0;q\u003CN;q++){const bi=(i>>q)&1, bj=(j>>q)&1; p*=qubitMatrix(q)[bi][bj];}   \u002F\u002F3 Multiply the per-qubit numbers together to get the chance that the true bitstring j was recorded as i. Do that for every pair and you have a matrix describing the whole readout.\n  return p;}\n","javascript",[16,1384,1385,1403,1441,1525,1562,1568,1601,1713,1724],{"__ignoreMap":62},[66,1386,1387,1389,1392,1395,1397,1400],{"class":68,"line":69},[66,1388,74],{"class":72,"aria-hidden":73},[66,1390,1391],{"class":86},"function",[66,1393,1394],{"class":121}," qubitMatrix",[66,1396,125],{"class":90},[66,1398,1399],{"class":205},"q",[66,1401,1402],{"class":90},"){\n",[66,1404,1405,1407,1410,1414,1416,1420,1422,1425,1427,1430,1432,1434,1436,1438],{"class":68,"line":81},[66,1406,74],{"class":72,"aria-hidden":73},[66,1408,1409],{"class":86},"  let",[66,1411,1413],{"class":1412},"sVyAn"," p10",[66,1415,118],{"class":117},[66,1417,1419],{"class":1418},"sU0A5","state",[66,1421,27],{"class":90},[66,1423,1424],{"class":1412},"p10",[66,1426,131],{"class":90},[66,1428,1429],{"class":1412},"p01",[66,1431,118],{"class":117},[66,1433,1419],{"class":1418},[66,1435,27],{"class":90},[66,1437,1429],{"class":1412},[66,1439,1440],{"class":90},";\n",[66,1442,1443,1445,1448,1450,1452,1454,1457,1460,1463,1466,1468,1471,1473,1475,1478,1480,1482,1484,1487,1490,1492,1495,1497,1500,1502,1504,1506,1508,1510,1512,1514,1516,1518,1520,1522],{"class":68,"data-cue":26,"line":100},[66,1444,26],{"class":111},[66,1446,1447],{"class":86},"  if",[66,1449,125],{"class":90},[66,1451,1419],{"class":1418},[66,1453,27],{"class":90},[66,1455,1456],{"class":1412},"hotQubit",[66,1458,1459],{"class":117}," &&",[66,1461,1462],{"class":1412}," q",[66,1464,1465],{"class":117},"===",[66,1467,139],{"class":128},[66,1469,1470],{"class":90},"){",[66,1472,1424],{"class":1412},[66,1474,118],{"class":117},[66,1476,1477],{"class":1418},"Math",[66,1479,27],{"class":90},[66,1481,1258],{"class":121},[66,1483,125],{"class":90},[66,1485,1486],{"class":128},"0.25",[66,1488,1489],{"class":90},",",[66,1491,1424],{"class":1412},[66,1493,1494],{"class":117},"*",[66,1496,185],{"class":128},[66,1498,1499],{"class":90},"); ",[66,1501,1429],{"class":1412},[66,1503,118],{"class":117},[66,1505,1477],{"class":1418},[66,1507,27],{"class":90},[66,1509,1258],{"class":121},[66,1511,125],{"class":90},[66,1513,1486],{"class":128},[66,1515,1489],{"class":90},[66,1517,1429],{"class":1412},[66,1519,1494],{"class":117},[66,1521,185],{"class":128},[66,1523,1524],{"class":90},");}\n",[66,1526,1527,1529,1532,1535,1537,1540,1542,1544,1546,1549,1551,1553,1555,1557,1559],{"class":68,"data-cue":139,"line":108},[66,1528,139],{"class":111},[66,1530,1531],{"class":86},"  return",[66,1533,1534],{"class":90}," [[",[66,1536,26],{"class":128},[66,1538,1539],{"class":117},"-",[66,1541,1424],{"class":1412},[66,1543,1489],{"class":90},[66,1545,1429],{"class":1412},[66,1547,1548],{"class":90},"],[",[66,1550,1424],{"class":1412},[66,1552,1489],{"class":90},[66,1554,26],{"class":128},[66,1556,1539],{"class":117},[66,1558,1429],{"class":1412},[66,1560,1561],{"class":90},"]];\n",[66,1563,1564,1566],{"class":68,"line":140},[66,1565,74],{"class":72,"aria-hidden":73},[66,1567,421],{"class":90},[66,1569,1570,1572,1574,1577,1579,1582,1584,1587,1589,1592,1595,1597,1599],{"class":68,"line":158},[66,1571,74],{"class":72,"aria-hidden":73},[66,1573,1391],{"class":86},[66,1575,1576],{"class":121}," Aentry",[66,1578,125],{"class":90},[66,1580,1581],{"class":205},"i",[66,1583,1489],{"class":90},[66,1585,1586],{"class":205},"j",[66,1588,1470],{"class":90},[66,1590,1591],{"class":86},"let",[66,1593,1594],{"class":1412}," p",[66,1596,118],{"class":117},[66,1598,26],{"class":128},[66,1600,1440],{"class":90},[66,1602,1603,1605,1608,1610,1612,1614,1616,1618,1621,1623,1626,1629,1631,1633,1636,1638,1641,1644,1646,1648,1650,1653,1655,1658,1661,1663,1665,1668,1670,1672,1674,1676,1678,1680,1682,1684,1687,1689,1692,1695,1697,1699,1702,1705,1708,1710],{"class":68,"data-cue":157,"line":178},[66,1604,157],{"class":111},[66,1606,1607],{"class":86},"  for",[66,1609,125],{"class":90},[66,1611,1591],{"class":86},[66,1613,1462],{"class":1412},[66,1615,118],{"class":117},[66,1617,22],{"class":128},[66,1619,1620],{"class":90},";",[66,1622,1399],{"class":1412},[66,1624,1625],{"class":117},"\u003C",[66,1627,1628],{"class":1418},"N",[66,1630,1620],{"class":90},[66,1632,1399],{"class":1412},[66,1634,1635],{"class":117},"++",[66,1637,1470],{"class":90},[66,1639,1640],{"class":86},"const",[66,1642,1643],{"class":1418}," bi",[66,1645,118],{"class":117},[66,1647,125],{"class":90},[66,1649,1581],{"class":1412},[66,1651,1652],{"class":117},">>",[66,1654,1399],{"class":1412},[66,1656,1657],{"class":90},")",[66,1659,1660],{"class":117},"&",[66,1662,26],{"class":128},[66,1664,131],{"class":90},[66,1666,1667],{"class":1418},"bj",[66,1669,118],{"class":117},[66,1671,125],{"class":90},[66,1673,1586],{"class":1412},[66,1675,1652],{"class":117},[66,1677,1399],{"class":1412},[66,1679,1657],{"class":90},[66,1681,1660],{"class":117},[66,1683,26],{"class":128},[66,1685,1686],{"class":90},"; ",[66,1688,12],{"class":1412},[66,1690,1691],{"class":117},"*=",[66,1693,1694],{"class":121},"qubitMatrix",[66,1696,125],{"class":90},[66,1698,1399],{"class":1412},[66,1700,1701],{"class":90},")[",[66,1703,1704],{"class":1412},"bi",[66,1706,1707],{"class":90},"][",[66,1709,1667],{"class":1412},[66,1711,1712],{"class":90},"];}\n",[66,1714,1715,1717,1719,1721],{"class":68,"line":186},[66,1716,74],{"class":72,"aria-hidden":73},[66,1718,1531],{"class":86},[66,1720,1594],{"class":1412},[66,1722,1723],{"class":90},";}\n",[279,1725,1726,1733,1740],{"class":281},[283,1727,1728,1730],{"data-cue":26},[66,1729,26],{"class":111},[66,1731,1732],{"class":289},"One qubit can be worse than the others. Real devices are like this: readout quality is per-qubit and it drifts.",[283,1734,1735,1737],{"data-cue":139},[66,1736,139],{"class":111},[66,1738,1739],{"class":289},"The whole error model for one qubit, as four numbers: how often a 0 is read as 0 or 1, and the same for a 1.",[283,1741,1742,1744],{"data-cue":157},[66,1743,157],{"class":111},[66,1745,1746],{"class":289},"Multiply the per-qubit numbers together to get the chance that the true bitstring j was recorded as i. Do that for every pair and you have a matrix describing the whole readout.",[12,1748,1749],{},"Build that matrix, and correcting the results is a linear algebra problem: you have the corrupted counts and the matrix that corrupted them, so you solve for what went in. The project does exactly that and shows three histograms side by side, ideal, raw and corrected.",[12,1751,1752],{},"This repairs the record, not the run. Nothing recovers a state the measurement already destroyed.",[615,1754],{"description":1755,"framework":1756,"owner":619,"title":1757,"to":1377},"Readout error corrupts the measurement, not the quantum state - so classical math can undo it. Drag the error sliders on a GHZ-5 and watch three histograms (ideal, raw, corrected) update instantly.","JS + Qiskit","Readout mitigation",[43,1759,1761],{"id":1760},"hearing-the-distribution","Hearing the distribution",[12,1763,1764],{},"Musiq turns a circuit's output into sound. Because the output is a distribution, so is the music: run the same circuit again and you get a variation rather than a repeat.",[1198,1766],{"alt":1767,"caption":1768,"no":62,"src":1769},"Musiq, a browser-based quantum sonification platform","A circuit's measured outcomes, mapped to pitch and texture.","\u002F_content\u002Fimages\u002Fmusiq\u002Fscreenshot.webp",[12,1771,1772],{},"Its mapper offers two ways to do that, and the choice between them is the difference between probabilities and shots, in one function.",[51,1774,1777],{"name":1775,"tag":1776},"musiq\u002Futils\u002Faudio_mapper.py","Python · from the Musiq repository",[57,1778,1780],{"className":59,"code":1779,"language":61,"meta":62,"style":62},"        if method == \"weighted_sum\":\n            for bitstring, prob in probability_dist.items():\n                if prob > 0.01:\n                    amp = self.map_bitstring_to_amplitude(bitstring)\n                    waveform += prob * amp\n\n        elif method == \"stochastic\":\n            # Probabilistic sampling from quantum outcome distribution\n            bitstrings = list(probability_dist.keys())\n            probs = np.array(list(probability_dist.values()))\n            probs = probs \u002F np.sum(probs)\n\n            # Sample based on probability at each time point\n            for i in range(self.samples):\n                selected = np.random.choice(bitstrings, p=probs)\n                amp = self.map_bitstring_to_amplitude(selected)\n                waveform[i] = amp[i]\n",[16,1781,1782,1801,1823,1841,1861,1878,1884,1900,1907,1928,1956,1978,1984,1991,2013,2038,2056,2068],{"__ignoreMap":62},[66,1783,1784,1786,1789,1792,1795,1798],{"class":68,"line":69},[66,1785,74],{"class":72,"aria-hidden":73},[66,1787,1788],{"class":86},"        if",[66,1790,1791],{"class":90}," method ",[66,1793,1794],{"class":117},"==",[66,1796,1797],{"class":401}," \"weighted_sum\"",[66,1799,1800],{"class":90},":\n",[66,1802,1803,1805,1808,1811,1814,1817,1820],{"class":68,"line":81},[66,1804,74],{"class":72,"aria-hidden":73},[66,1806,1807],{"class":86},"            for",[66,1809,1810],{"class":90}," bitstring, prob ",[66,1812,1813],{"class":86},"in",[66,1815,1816],{"class":90}," probability_dist.",[66,1818,1819],{"class":121},"items",[66,1821,1822],{"class":90},"():\n",[66,1824,1825,1827,1830,1833,1836,1839],{"class":68,"data-cue":26,"line":100},[66,1826,26],{"class":111},[66,1828,1829],{"class":86},"                if",[66,1831,1832],{"class":90}," prob ",[66,1834,1835],{"class":117},">",[66,1837,1838],{"class":128}," 0.01",[66,1840,1800],{"class":90},[66,1842,1843,1845,1848,1850,1853,1855,1858],{"class":68,"line":108},[66,1844,74],{"class":72,"aria-hidden":73},[66,1846,1847],{"class":90},"                    amp ",[66,1849,118],{"class":117},[66,1851,1852],{"class":1418}," self",[66,1854,27],{"class":90},[66,1856,1857],{"class":121},"map_bitstring_to_amplitude",[66,1859,1860],{"class":90},"(bitstring)\n",[66,1862,1863,1865,1868,1871,1873,1875],{"class":68,"data-cue":139,"line":140},[66,1864,139],{"class":111},[66,1866,1867],{"class":90},"                    waveform ",[66,1869,1870],{"class":117},"+=",[66,1872,1832],{"class":90},[66,1874,1494],{"class":117},[66,1876,1877],{"class":90}," amp\n",[66,1879,1880,1882],{"class":68,"line":158},[66,1881,74],{"class":72,"aria-hidden":73},[66,1883,105],{},[66,1885,1886,1888,1891,1893,1895,1898],{"class":68,"line":178},[66,1887,74],{"class":72,"aria-hidden":73},[66,1889,1890],{"class":86},"        elif",[66,1892,1791],{"class":90},[66,1894,1794],{"class":117},[66,1896,1897],{"class":401}," \"stochastic\"",[66,1899,1800],{"class":90},[66,1901,1902,1904],{"class":68,"line":186},[66,1903,74],{"class":72,"aria-hidden":73},[66,1905,1906],{"class":77},"            # Probabilistic sampling from quantum outcome distribution\n",[66,1908,1909,1911,1914,1916,1919,1922,1925],{"class":68,"line":229},[66,1910,74],{"class":72,"aria-hidden":73},[66,1912,1913],{"class":90},"            bitstrings ",[66,1915,118],{"class":117},[66,1917,1918],{"class":117}," list",[66,1920,1921],{"class":90},"(probability_dist.",[66,1923,1924],{"class":121},"keys",[66,1926,1927],{"class":90},"())\n",[66,1929,1930,1932,1935,1937,1940,1943,1945,1948,1950,1953],{"class":68,"line":262},[66,1931,74],{"class":72,"aria-hidden":73},[66,1933,1934],{"class":90},"            probs ",[66,1936,118],{"class":117},[66,1938,1939],{"class":90}," np.",[66,1941,1942],{"class":121},"array",[66,1944,125],{"class":90},[66,1946,1947],{"class":117},"list",[66,1949,1921],{"class":90},[66,1951,1952],{"class":121},"values",[66,1954,1955],{"class":90},"()))\n",[66,1957,1958,1960,1962,1964,1967,1970,1972,1975],{"class":68,"line":269},[66,1959,74],{"class":72,"aria-hidden":73},[66,1961,1934],{"class":90},[66,1963,118],{"class":117},[66,1965,1966],{"class":90}," probs ",[66,1968,1969],{"class":117},"\u002F",[66,1971,1939],{"class":90},[66,1973,1974],{"class":121},"sum",[66,1976,1977],{"class":90},"(probs)\n",[66,1979,1980,1982],{"class":68,"line":552},[66,1981,74],{"class":72,"aria-hidden":73},[66,1983,105],{},[66,1985,1986,1988],{"class":68,"line":568},[66,1987,74],{"class":72,"aria-hidden":73},[66,1989,1990],{"class":77},"            # Sample based on probability at each time point\n",[66,1992,1993,1995,1997,2000,2002,2005,2007,2010],{"class":68,"line":927},[66,1994,74],{"class":72,"aria-hidden":73},[66,1996,1807],{"class":86},[66,1998,1999],{"class":90}," i ",[66,2001,1813],{"class":86},[66,2003,2004],{"class":117}," range",[66,2006,125],{"class":90},[66,2008,2009],{"class":1418},"self",[66,2011,2012],{"class":90},".samples):\n",[66,2014,2015,2017,2020,2022,2025,2028,2031,2033,2035],{"class":68,"data-cue":157,"line":956},[66,2016,157],{"class":111},[66,2018,2019],{"class":90},"                selected ",[66,2021,118],{"class":117},[66,2023,2024],{"class":90}," np.random.",[66,2026,2027],{"class":121},"choice",[66,2029,2030],{"class":90},"(bitstrings, ",[66,2032,12],{"class":205},[66,2034,118],{"class":117},[66,2036,2037],{"class":90},"probs)\n",[66,2039,2040,2042,2045,2047,2049,2051,2053],{"class":68,"line":984},[66,2041,74],{"class":72,"aria-hidden":73},[66,2043,2044],{"class":90},"                amp ",[66,2046,118],{"class":117},[66,2048,1852],{"class":1418},[66,2050,27],{"class":90},[66,2052,1857],{"class":121},[66,2054,2055],{"class":90},"(selected)\n",[66,2057,2058,2060,2063,2065],{"class":68,"line":1011},[66,2059,74],{"class":72,"aria-hidden":73},[66,2061,2062],{"class":90},"                waveform[i] ",[66,2064,118],{"class":117},[66,2066,2067],{"class":90}," amp[i]\n",[279,2069,2070,2077,2084],{"class":281},[283,2071,2072,2074],{"data-cue":26},[66,2073,26],{"class":111},[66,2075,2076],{"class":289},"A threshold, and this one is Musiq's own. Any outcome under one per cent never reaches the chord at all.",[283,2078,2079,2081],{"data-cue":139},[66,2080,139],{"class":111},[66,2082,2083],{"class":289},"Every surviving outcome added in, scaled by how likely it is. You hear the whole tally at once, and the same circuit sounds identical every time.",[283,2085,2086,2088],{"data-cue":157},[66,2087,157],{"class":111},[66,2089,2090],{"class":289},"The other route. Draw one outcome, then another, weighted by those same probabilities. That is shots rather than the distribution, and it comes out different on every run.",[12,2092,2093,2096],{},[16,2094,2095],{},"weighted_sum"," sounds the entire distribution at once. Every outcome contributes in proportion to its probability, so what you hear is the tally as a chord, and the same circuit gives the same chord every time.",[12,2098,2099,2102],{},[16,2100,2101],{},"stochastic"," draws a single outcome per sample instead, which is shots made audible: a sequence of individual answers, different on every run. Tomoya Hatanaka's docstring is careful about the distinction, calling it sampling from \"the quantum outcome distribution (not classical random generation)\".",[12,2104,2105],{},"Two honest renderings of one measurement. The probabilities are what the state says will happen. The shots are what happened.",[12,2107,2108],{},"Look again at the threshold on the first branch. A rare outcome and a noise blip look identical in a distribution, and no line of code can separate them. Dropping everything under one per cent is a judgement, and every quantum program makes one somewhere.",[12,2110,2111,2112,2116],{},"This listing comes from ",[1182,2113,2115],{"href":2114},"https:\u002F\u002Fgithub.com\u002Fdorakingx\u002Fmusiq","the project's repository"," rather than its Qollab page, which still carries the starter circuit.",[615,2118],{"description":2119,"framework":618,"owner":2120,"title":2121,"to":2122,"builder":2123,"thumb":1769},"Musiq is a browser-based quantum sonification platform that transforms quantum-circuit outputs into generative audio.","doraking","Musiq","\u002Fu\u002Fdoraking\u002Fmusiq","Tomoya Hatanaka & Emmanuella Adams",[43,2125,2127],{"id":2126},"measured-once-and-fixed-from-then-on","Measured once, and fixed from then on",[12,2129,2130],{},"Quantum Garden grows each plant from a real quantum measurement, and it shows the one-way part plainly.",[1198,2132],{"alt":2133,"caption":2134,"no":62,"src":2135},"Quantum Garden, a generative garden grown from real quantum measurements","Every plant's traits come from a measurement that already happened.","\u002F_content\u002Fimages\u002Fquantum-garden\u002Fscreenshot.webp",[12,2137,2138],{},"The circuit behind a plant is completely fixed. Each plant derives a seed from its own ID, and the same seed always builds the same five-qubit circuit.",[51,2140,2143],{"name":2141,"tag":366,"run-href":2142},"plant_circuit.py","\u002Fu\u002FAmberPincar\u002Fquantum-garden",[57,2144,2146],{"className":59,"code":2145,"language":61,"meta":62,"style":62},"seed = 42  # Each plant gets a deterministic seed from its ID hash\n\ncircuit = QuantumCircuit(5, 5)\n\n# Layer 1: Full superposition — all 32 outcomes initially possible\nfor i in range(5):\n    circuit.h(i)\n# ...\n# Measure all qubits\ncircuit.measure([0, 1, 2, 3, 4], [0, 1, 2, 3, 4])\n",[16,2147,2148,2163,2169,2190,2196,2203,2222,2234,2241,2248,2302],{"__ignoreMap":62},[66,2149,2150,2152,2155,2157,2160],{"class":68,"line":69},[66,2151,74],{"class":72,"aria-hidden":73},[66,2153,2154],{"class":90},"seed ",[66,2156,118],{"class":117},[66,2158,2159],{"class":128}," 42",[66,2161,2162],{"class":77},"  # Each plant gets a deterministic seed from its ID hash\n",[66,2164,2165,2167],{"class":68,"line":81},[66,2166,74],{"class":72,"aria-hidden":73},[66,2168,105],{},[66,2170,2171,2173,2176,2178,2180,2182,2184,2186,2188],{"class":68,"data-cue":26,"line":100},[66,2172,26],{"class":111},[66,2174,2175],{"class":90},"circuit ",[66,2177,118],{"class":117},[66,2179,122],{"class":121},[66,2181,125],{"class":90},[66,2183,228],{"class":128},[66,2185,131],{"class":90},[66,2187,228],{"class":128},[66,2189,136],{"class":90},[66,2191,2192,2194],{"class":68,"line":108},[66,2193,74],{"class":72,"aria-hidden":73},[66,2195,105],{},[66,2197,2198,2200],{"class":68,"line":140},[66,2199,74],{"class":72,"aria-hidden":73},[66,2201,2202],{"class":77},"# Layer 1: Full superposition — all 32 outcomes initially possible\n",[66,2204,2205,2207,2210,2212,2214,2216,2218,2220],{"class":68,"line":158},[66,2206,74],{"class":72,"aria-hidden":73},[66,2208,2209],{"class":86},"for",[66,2211,1999],{"class":90},[66,2213,1813],{"class":86},[66,2215,2004],{"class":117},[66,2217,125],{"class":90},[66,2219,228],{"class":128},[66,2221,787],{"class":90},[66,2223,2224,2226,2229,2231],{"class":68,"data-cue":139,"line":178},[66,2225,139],{"class":111},[66,2227,2228],{"class":90},"    circuit.",[66,2230,148],{"class":121},[66,2232,2233],{"class":90},"(i)\n",[66,2235,2236,2238],{"class":68,"line":186},[66,2237,74],{"class":72,"aria-hidden":73},[66,2239,2240],{"class":77},"# ...\n",[66,2242,2243,2245],{"class":68,"line":229},[66,2244,74],{"class":72,"aria-hidden":73},[66,2246,2247],{"class":77},"# Measure all qubits\n",[66,2249,2250,2252,2255,2257,2260,2262,2264,2266,2268,2270,2272,2274,2276,2278,2281,2283,2285,2287,2289,2291,2293,2295,2297,2299],{"class":68,"data-cue":157,"line":262},[66,2251,157],{"class":111},[66,2253,2254],{"class":90},"circuit.",[66,2256,165],{"class":121},[66,2258,2259],{"class":90},"([",[66,2261,22],{"class":128},[66,2263,131],{"class":90},[66,2265,26],{"class":128},[66,2267,131],{"class":90},[66,2269,139],{"class":128},[66,2271,131],{"class":90},[66,2273,157],{"class":128},[66,2275,131],{"class":90},[66,2277,185],{"class":128},[66,2279,2280],{"class":90},"], [",[66,2282,22],{"class":128},[66,2284,131],{"class":90},[66,2286,26],{"class":128},[66,2288,131],{"class":90},[66,2290,139],{"class":128},[66,2292,131],{"class":90},[66,2294,157],{"class":128},[66,2296,131],{"class":90},[66,2298,185],{"class":128},[66,2300,2301],{"class":90},"])\n",[279,2303,2304,2311,2318],{"class":281},[283,2305,2306,2308],{"data-cue":26},[66,2307,26],{"class":111},[66,2309,2310],{"class":289},"Five qubits to do the work, and five ordinary bits waiting to receive the answers. Five bits is thirty-two possible results.",[283,2312,2313,2315],{"data-cue":139},[66,2314,139],{"class":111},[66,2316,2317],{"class":289},"A Hadamard on each one, so all thirty-two start out equally likely. The five layers this excerpt skips then bend the odds between them, without ever closing any of them off.",[283,2319,2320,2322],{"data-cue":157},[66,2321,157],{"class":111},[66,2323,2324],{"class":289},"One draw from those odds. Five bits come out, and every trait the plant shows is read off them.",[12,2326,2327],{},"What the seed fixes is the odds, never the answer. Simulate the finished circuit and all thirty-two outcomes still carry some probability, the likeliest of them only 22%. Run that identical circuit twice and about seven times in eight the second run gives you a different plant.",[12,2329,2330],{},"A plant's identity, then, sits not in its circuit but in the one draw that happened, and no amount of re-running gets that particular draw back.",[12,2332,2333],{},"Which is why the garden keeps it rather than recomputing it. None of this runs while you watch. Its circuits went to IonQ ahead of time, and their results sit in a pool of 500. Hovering a plant assigns it one and fixes its traits from then on. Hover again and nothing changes, because there is nothing left to decide.",[12,2335,2336],{},"The randomness happened once, at the moment of measuring. Everything after it is a record.",[615,2338],{"description":2339,"framework":618,"owner":2340,"title":2341,"to":2142,"builder":2342,"thumb":2135},"Quantum Garden is an interactive generative art installation where digital plants exist in quantum superposition until observed.","AmberPincar","Quantum Garden","Amber Wang & Justin Pincar",[43,2344,2346],{"id":2345},"you-cannot-print-a-qubit","You cannot print a qubit",[12,2348,2349],{},"Every section above has been about inferring something from a tally. So the obvious question is what was actually in there. There is exactly one way to look, and the thing you have to do first says everything.",[12,2351,2352],{},"QAVE takes a Qiskit circuit and turns it into a deterministic trace: a frame-by-frame record of how the state evolves, which it then renders as an animation. To do that it has to get at the state, and the state is precisely the thing a measurement destroys.",[1198,2354],{"alt":2355,"caption":2356,"no":62,"src":2357},"QAVE rendering a quantum circuit as an animated trace","QAVE traces a circuit's evolution frame by frame.","\u002F_content\u002Fimages\u002Fqave\u002Fscreenshot.webp",[12,2359,2360],{},"Its solution is the only one available.",[51,2362,2365],{"name":2363,"tag":366,"run-href":2364},"ghz3_trace.py","\u002Fu\u002Fq-inho\u002Fqave",[57,2366,2368],{"className":59,"code":2367,"language":61,"meta":62,"style":62},"# Inspect the pre-measurement statevector\npre_measurement = circuit.remove_final_measurements(inplace=False)\npsi = Statevector.from_instruction(pre_measurement)\n\nprint(\"Non-zero amplitudes before measurement (bitstring is |q2 q1 q0>):\")\nfor basis, amp in sorted(psi.to_dict().items()):  # Keep output order stable.\n    if abs(amp) \u003C 1e-12:\n        continue\n    print(f\"  |{basis}>: {amp.real:+.6f}{amp.imag:+.6f}j\")\n",[16,2369,2370,2377,2403,2421,2427,2440,2470,2489,2496,2546],{"__ignoreMap":62},[66,2371,2372,2374],{"class":68,"line":69},[66,2373,74],{"class":72,"aria-hidden":73},[66,2375,2376],{"class":77},"# Inspect the pre-measurement statevector\n",[66,2378,2379,2381,2384,2386,2389,2392,2394,2397,2399,2401],{"class":68,"data-cue":26,"line":81},[66,2380,26],{"class":111},[66,2382,2383],{"class":90},"pre_measurement ",[66,2385,118],{"class":117},[66,2387,2388],{"class":90}," circuit.",[66,2390,2391],{"class":121},"remove_final_measurements",[66,2393,125],{"class":90},[66,2395,2396],{"class":205},"inplace",[66,2398,118],{"class":117},[66,2400,946],{"class":128},[66,2402,136],{"class":90},[66,2404,2405,2407,2410,2412,2415,2418],{"class":68,"data-cue":139,"line":100},[66,2406,139],{"class":111},[66,2408,2409],{"class":90},"psi ",[66,2411,118],{"class":117},[66,2413,2414],{"class":90}," Statevector.",[66,2416,2417],{"class":121},"from_instruction",[66,2419,2420],{"class":90},"(pre_measurement)\n",[66,2422,2423,2425],{"class":68,"line":108},[66,2424,74],{"class":72,"aria-hidden":73},[66,2426,105],{},[66,2428,2429,2431,2433,2435,2438],{"class":68,"line":140},[66,2430,74],{"class":72,"aria-hidden":73},[66,2432,274],{"class":117},[66,2434,125],{"class":90},[66,2436,2437],{"class":401},"\"Non-zero amplitudes before measurement (bitstring is |q2 q1 q0>):\"",[66,2439,136],{"class":90},[66,2441,2442,2444,2446,2449,2451,2454,2457,2460,2462,2464,2467],{"class":68,"line":158},[66,2443,74],{"class":72,"aria-hidden":73},[66,2445,2209],{"class":86},[66,2447,2448],{"class":90}," basis, amp ",[66,2450,1813],{"class":86},[66,2452,2453],{"class":117}," sorted",[66,2455,2456],{"class":90},"(psi.",[66,2458,2459],{"class":121},"to_dict",[66,2461,219],{"class":90},[66,2463,1819],{"class":121},[66,2465,2466],{"class":90},"()):  ",[66,2468,2469],{"class":77},"# Keep output order stable.\n",[66,2471,2472,2474,2476,2479,2482,2484,2487],{"class":68,"line":178},[66,2473,74],{"class":72,"aria-hidden":73},[66,2475,830],{"class":86},[66,2477,2478],{"class":117}," abs",[66,2480,2481],{"class":90},"(amp) ",[66,2483,1625],{"class":117},[66,2485,2486],{"class":128}," 1e-12",[66,2488,1800],{"class":90},[66,2490,2491,2493],{"class":68,"line":186},[66,2492,74],{"class":72,"aria-hidden":73},[66,2494,2495],{"class":86},"        continue\n",[66,2497,2498,2500,2503,2505,2508,2511,2514,2517,2520,2523,2525,2528,2531,2534,2537,2539,2541,2544],{"class":68,"data-cue":157,"line":229},[66,2499,157],{"class":111},[66,2501,2502],{"class":117},"    print",[66,2504,125],{"class":90},[66,2506,2507],{"class":86},"f",[66,2509,2510],{"class":401},"\"  |",[66,2512,2513],{"class":128},"{",[66,2515,2516],{"class":90},"basis",[66,2518,2519],{"class":128},"}",[66,2521,2522],{"class":401},">: ",[66,2524,2513],{"class":128},[66,2526,2527],{"class":90},"amp.real",[66,2529,2530],{"class":86},":+.6f",[66,2532,2533],{"class":128},"}{",[66,2535,2536],{"class":90},"amp.imag",[66,2538,2530],{"class":86},[66,2540,2519],{"class":128},[66,2542,2543],{"class":401},"j\"",[66,2545,136],{"class":90},[279,2547,2548,2555,2565],{"class":281},[283,2549,2550,2552],{"data-cue":26},[66,2551,26],{"class":111},[66,2553,2554],{"class":289},"To look at the state, you first delete the measurement. Not a trick of this project: a circuit that has measured has no state left to inspect.",[283,2556,2557,2559],{"data-cue":139},[66,2558,139],{"class":111},[66,2560,2561,2564],{"class":289},[16,2562,2563],{},"Statevector"," does not read the qubits. It recomputes, from the gates alone, what the state must be. That is simulation, not observation.",[283,2566,2567,2569],{"data-cue":157},[66,2568,157],{"class":111},[66,2570,2571,2572,592,2575,2578],{"class":289},"An amplitude per outcome. Eight are possible for three qubits; a GHZ state puts weight on just ",[16,2573,2574],{},"000",[16,2576,2577],{},"111"," and leaves the other six at zero.",[12,2580,2581],{},"The amplitudes are the full description, and nothing on real hardware will hand them to you. There is no slow API behind which they hide and no flag that turns them on. A device gives you bitstrings.",[12,2583,2584],{},"So this listing is not a way of reading a quantum computer. It is a simulator being asked to predict what the hardware would have had, on a circuit small enough that a laptop can work it out.",[2586,2587,2589],"h3",{"id":2588},"the-randomness-is-seeded","The randomness is seeded",[12,2591,2592],{},"The second half of QAVE's measurement handling makes a point the first half sets up. Because the trace is deterministic, the shots are reproducible.",[51,2594,2595],{"name":2363,"tag":366,"run-href":2364},[57,2596,2598],{"className":59,"code":2597,"language":61,"meta":62,"style":62},"# Require deterministic shot replay for terminal measurements.\nreplay = result.require_measurement_shot_replay()\n\nprint(f\"measurement_shot_replay.shots_total: {replay.shots_total}\")\nprint(f\"measurement_shot_replay.sampling_seed: {replay.sampling_seed}\")\n\n# Print outcomes sorted by probability.\nprint(\"Top outcomes from measurement_shot_replay.outcomes:\")\nfor outcome in sorted(replay.outcomes, key=lambda item: item.probability, reverse=True):\n    print(f\"  {outcome.label}: p={outcome.probability:.6f}\")\n",[16,2599,2600,2607,2624,2630,2655,2679,2685,2692,2705,2744,2781],{"__ignoreMap":62},[66,2601,2602,2604],{"class":68,"line":69},[66,2603,74],{"class":72,"aria-hidden":73},[66,2605,2606],{"class":77},"# Require deterministic shot replay for terminal measurements.\n",[66,2608,2609,2611,2614,2616,2619,2622],{"class":68,"data-cue":26,"line":81},[66,2610,26],{"class":111},[66,2612,2613],{"class":90},"replay ",[66,2615,118],{"class":117},[66,2617,2618],{"class":90}," result.",[66,2620,2621],{"class":121},"require_measurement_shot_replay",[66,2623,225],{"class":90},[66,2625,2626,2628],{"class":68,"line":100},[66,2627,74],{"class":72,"aria-hidden":73},[66,2629,105],{},[66,2631,2632,2634,2636,2638,2640,2643,2645,2648,2650,2653],{"class":68,"line":108},[66,2633,74],{"class":72,"aria-hidden":73},[66,2635,274],{"class":117},[66,2637,125],{"class":90},[66,2639,2507],{"class":86},[66,2641,2642],{"class":401},"\"measurement_shot_replay.shots_total: ",[66,2644,2513],{"class":128},[66,2646,2647],{"class":90},"replay.shots_total",[66,2649,2519],{"class":128},[66,2651,2652],{"class":401},"\"",[66,2654,136],{"class":90},[66,2656,2657,2659,2661,2663,2665,2668,2670,2673,2675,2677],{"class":68,"data-cue":139,"line":140},[66,2658,139],{"class":111},[66,2660,274],{"class":117},[66,2662,125],{"class":90},[66,2664,2507],{"class":86},[66,2666,2667],{"class":401},"\"measurement_shot_replay.sampling_seed: ",[66,2669,2513],{"class":128},[66,2671,2672],{"class":90},"replay.sampling_seed",[66,2674,2519],{"class":128},[66,2676,2652],{"class":401},[66,2678,136],{"class":90},[66,2680,2681,2683],{"class":68,"line":158},[66,2682,74],{"class":72,"aria-hidden":73},[66,2684,105],{},[66,2686,2687,2689],{"class":68,"line":178},[66,2688,74],{"class":72,"aria-hidden":73},[66,2690,2691],{"class":77},"# Print outcomes sorted by probability.\n",[66,2693,2694,2696,2698,2700,2703],{"class":68,"line":186},[66,2695,74],{"class":72,"aria-hidden":73},[66,2697,274],{"class":117},[66,2699,125],{"class":90},[66,2701,2702],{"class":401},"\"Top outcomes from measurement_shot_replay.outcomes:\"",[66,2704,136],{"class":90},[66,2706,2707,2709,2711,2714,2716,2718,2721,2724,2726,2729,2732,2735,2738,2740,2742],{"class":68,"line":229},[66,2708,74],{"class":72,"aria-hidden":73},[66,2710,2209],{"class":86},[66,2712,2713],{"class":90}," outcome ",[66,2715,1813],{"class":86},[66,2717,2453],{"class":117},[66,2719,2720],{"class":90},"(replay.outcomes, ",[66,2722,2723],{"class":205},"key",[66,2725,118],{"class":117},[66,2727,2728],{"class":86},"lambda",[66,2730,2731],{"class":778}," item",[66,2733,2734],{"class":90},": item.probability, ",[66,2736,2737],{"class":205},"reverse",[66,2739,118],{"class":117},[66,2741,974],{"class":128},[66,2743,787],{"class":90},[66,2745,2746,2748,2750,2752,2754,2757,2759,2762,2764,2767,2769,2772,2775,2777,2779],{"class":68,"data-cue":157,"line":262},[66,2747,157],{"class":111},[66,2749,2502],{"class":117},[66,2751,125],{"class":90},[66,2753,2507],{"class":86},[66,2755,2756],{"class":401},"\"  ",[66,2758,2513],{"class":128},[66,2760,2761],{"class":90},"outcome.label",[66,2763,2519],{"class":128},[66,2765,2766],{"class":401},": p=",[66,2768,2513],{"class":128},[66,2770,2771],{"class":90},"outcome.probability",[66,2773,2774],{"class":86},":.6f",[66,2776,2519],{"class":128},[66,2778,2652],{"class":401},[66,2780,136],{"class":90},[279,2782,2783,2790,2797],{"class":281},[283,2784,2785,2787],{"data-cue":26},[66,2786,26],{"class":111},[66,2788,2789],{"class":289},"The individual draws, not just the summary. Every shot the trace generated, in order.",[283,2791,2792,2794],{"data-cue":139},[66,2793,139],{"class":111},[66,2795,2796],{"class":289},"A seed. Run the trace again with the same one and you get the same hundred shots back, which no real device would ever give you.",[283,2798,2799,2801],{"data-cue":157},[66,2800,157],{"class":111},[66,2802,2803],{"class":289},"The odds themselves, straight from the maths, to six decimal places. Hardware never prints this line: it only ever gives you draws you have to infer the odds from.",[12,2805,2806],{},"Those two listings carry the distinction. The probabilities are what the state says will happen. The shots are what happened.",[12,2808,2809],{},"A simulator can show you both. A quantum computer shows you only the second, and everything you want to know about the first has to be reconstructed from a pile of them.",[12,2811,2812,2815,2816,592,2819,2822],{},[347,2813,2814],{},"Try this when you fork it."," The trace is configured with ",[16,2817,2818],{},"seed=24",[16,2820,2821],{},"shot_count=100",". Change the seed and re-run: the outcome probabilities printed above are identical, because the state has not changed, while the hundred individual shots are different. Then raise the shot count and watch the tally converge on those probabilities it never had access to.",[615,2824],{"description":2825,"framework":618,"owner":2826,"title":2827,"to":2364,"builder":2828,"thumb":2357},"Quantum Algorithm Visualization Engine turns Qiskit\u002FOpenQASM quantum circuits into deterministic traces and synchronized animations, making quantum algorithms easier to teach and understand.","q-inho","QAVE","Inho Choi",[43,2830,2832],{"id":2831},"where-the-circuit-actually-runs","Where the circuit actually runs",[12,2834,2835],{},"Every listing above assumes you can just run the circuit. You can, and the same circuit has more than one place to go.",[12,2837,2838],{},"Entangled Body settles the question in the open, and its answer is a fallback chain.",[51,2840,2841],{"name":1214,"tag":366,"run-href":1215},[57,2842,2844],{"className":59,"code":2843,"language":61,"meta":62,"style":62},"def run_measurement(ops, shots, seed=None):\n    \"\"\"Run the circuit and return (counts, backend_label).\"\"\"\n    # 1. hosted runtime backend (e.g. IonQ \u002F IBM \u002F Aer provided as `backend`)\n    bk = globals().get(\"backend\", None)\n    if HAVE_QISKIT and bk is not None:\n        try:\n            tqc = transpile(build_circuit(ops, measure=True), backend=bk, optimization_level=1)\n            counts = bk.run(tqc, shots=shots).result().get_counts()\n            label = \"backend: %s\" % getattr(bk, \"name\", getattr(type(bk), \"__name__\", \"provided\"))\n            return dict(counts), label\n        except Exception as exc:\n            print(\"    (provided backend failed: %s -- falling back)\" % exc)\n\n    # 2. qiskit Statevector sampler (no qiskit_aer required)\n    if HAVE_QISKIT:\n        sv = Statevector(build_circuit(ops, measure=False))\n        counts = sv.sample_counts(shots)\n        return {k: int(v) for k, v in counts.items()}, \"qiskit Statevector\"\n\n    # 3. pure-Python fallback\n    return _py_run(ops, shots, seed), \"pure-Python state vector\"\n",[16,2845,2846,2876,2883,2890,2918,2944,2953,2999,3031,3083,3096,3112,3134,3140,3147,3157,3183,3201,3236,3243,3251,3267],{"__ignoreMap":62},[66,2847,2848,2850,2852,2855,2857,2860,2862,2864,2866,2869,2871,2874],{"class":68,"line":69},[66,2849,74],{"class":72,"aria-hidden":73},[66,2851,770],{"class":86},[66,2853,2854],{"class":121}," run_measurement",[66,2856,125],{"class":90},[66,2858,2859],{"class":778},"ops",[66,2861,131],{"class":90},[66,2863,206],{"class":778},[66,2865,131],{"class":90},[66,2867,2868],{"class":778},"seed",[66,2870,118],{"class":90},[66,2872,2873],{"class":128},"None",[66,2875,787],{"class":90},[66,2877,2878,2880],{"class":68,"line":81},[66,2879,74],{"class":72,"aria-hidden":73},[66,2881,2882],{"class":401},"    \"\"\"Run the circuit and return (counts, backend_label).\"\"\"\n",[66,2884,2885,2887],{"class":68,"line":100},[66,2886,74],{"class":72,"aria-hidden":73},[66,2888,2889],{"class":77},"    # 1. hosted runtime backend (e.g. IonQ \u002F IBM \u002F Aer provided as `backend`)\n",[66,2891,2892,2894,2897,2899,2902,2904,2907,2909,2912,2914,2916],{"class":68,"line":108},[66,2893,74],{"class":72,"aria-hidden":73},[66,2895,2896],{"class":90},"    bk ",[66,2898,118],{"class":117},[66,2900,2901],{"class":117}," globals",[66,2903,219],{"class":90},[66,2905,2906],{"class":121},"get",[66,2908,125],{"class":90},[66,2910,2911],{"class":401},"\"backend\"",[66,2913,131],{"class":90},[66,2915,2873],{"class":128},[66,2917,136],{"class":90},[66,2919,2920,2922,2924,2927,2930,2933,2936,2939,2942],{"class":68,"line":140},[66,2921,74],{"class":72,"aria-hidden":73},[66,2923,830],{"class":86},[66,2925,2926],{"class":128}," HAVE_QISKIT",[66,2928,2929],{"class":86}," and",[66,2931,2932],{"class":90}," bk ",[66,2934,2935],{"class":86},"is",[66,2937,2938],{"class":86}," not",[66,2940,2941],{"class":128}," None",[66,2943,1800],{"class":90},[66,2945,2946,2948,2951],{"class":68,"line":158},[66,2947,74],{"class":72,"aria-hidden":73},[66,2949,2950],{"class":86},"        try",[66,2952,1800],{"class":90},[66,2954,2955,2957,2960,2962,2965,2967,2970,2973,2975,2977,2979,2982,2985,2987,2990,2993,2995,2997],{"class":68,"data-cue":26,"line":178},[66,2956,26],{"class":111},[66,2958,2959],{"class":90},"            tqc ",[66,2961,118],{"class":117},[66,2963,2964],{"class":121}," transpile",[66,2966,125],{"class":90},[66,2968,2969],{"class":121},"build_circuit",[66,2971,2972],{"class":90},"(ops, ",[66,2974,165],{"class":205},[66,2976,118],{"class":117},[66,2978,974],{"class":128},[66,2980,2981],{"class":90},"), ",[66,2983,2984],{"class":205},"backend",[66,2986,118],{"class":117},[66,2988,2989],{"class":90},"bk, ",[66,2991,2992],{"class":205},"optimization_level",[66,2994,118],{"class":117},[66,2996,26],{"class":128},[66,2998,136],{"class":90},[66,3000,3001,3003,3006,3008,3011,3013,3016,3018,3020,3023,3025,3027,3029],{"class":68,"data-cue":139,"line":186},[66,3002,139],{"class":111},[66,3004,3005],{"class":90},"            counts ",[66,3007,118],{"class":117},[66,3009,3010],{"class":90}," bk.",[66,3012,199],{"class":121},[66,3014,3015],{"class":90},"(tqc, ",[66,3017,206],{"class":205},[66,3019,118],{"class":117},[66,3021,3022],{"class":90},"shots).",[66,3024,216],{"class":121},[66,3026,219],{"class":90},[66,3028,222],{"class":121},[66,3030,225],{"class":90},[66,3032,3033,3035,3038,3040,3043,3046,3048,3051,3054,3057,3060,3062,3065,3067,3070,3073,3076,3078,3081],{"class":68,"line":229},[66,3034,74],{"class":72,"aria-hidden":73},[66,3036,3037],{"class":90},"            label ",[66,3039,118],{"class":117},[66,3041,3042],{"class":401}," \"backend: ",[66,3044,3045],{"class":128},"%s",[66,3047,2652],{"class":401},[66,3049,3050],{"class":117}," %",[66,3052,3053],{"class":117}," getattr",[66,3055,3056],{"class":90},"(bk, ",[66,3058,3059],{"class":401},"\"name\"",[66,3061,131],{"class":90},[66,3063,3064],{"class":117},"getattr",[66,3066,125],{"class":90},[66,3068,3069],{"class":117},"type",[66,3071,3072],{"class":90},"(bk), ",[66,3074,3075],{"class":401},"\"__name__\"",[66,3077,131],{"class":90},[66,3079,3080],{"class":401},"\"provided\"",[66,3082,953],{"class":90},[66,3084,3085,3087,3090,3093],{"class":68,"line":262},[66,3086,74],{"class":72,"aria-hidden":73},[66,3088,3089],{"class":86},"            return",[66,3091,3092],{"class":117}," dict",[66,3094,3095],{"class":90},"(counts), label\n",[66,3097,3098,3100,3103,3106,3109],{"class":68,"line":269},[66,3099,74],{"class":72,"aria-hidden":73},[66,3101,3102],{"class":86},"        except",[66,3104,3105],{"class":90}," Exception ",[66,3107,3108],{"class":86},"as",[66,3110,3111],{"class":90}," exc:\n",[66,3113,3114,3116,3119,3121,3124,3126,3129,3131],{"class":68,"data-cue":157,"line":552},[66,3115,157],{"class":111},[66,3117,3118],{"class":117},"            print",[66,3120,125],{"class":90},[66,3122,3123],{"class":401},"\"    (provided backend failed: ",[66,3125,3045],{"class":128},[66,3127,3128],{"class":401}," -- falling back)\"",[66,3130,3050],{"class":117},[66,3132,3133],{"class":90}," exc)\n",[66,3135,3136,3138],{"class":68,"line":568},[66,3137,74],{"class":72,"aria-hidden":73},[66,3139,105],{},[66,3141,3142,3144],{"class":68,"line":927},[66,3143,74],{"class":72,"aria-hidden":73},[66,3145,3146],{"class":77},"    # 2. qiskit Statevector sampler (no qiskit_aer required)\n",[66,3148,3149,3151,3153,3155],{"class":68,"line":956},[66,3150,74],{"class":72,"aria-hidden":73},[66,3152,830],{"class":86},[66,3154,2926],{"class":128},[66,3156,1800],{"class":90},[66,3158,3159,3161,3164,3166,3169,3171,3173,3175,3177,3179,3181],{"class":68,"data-cue":185,"line":984},[66,3160,185],{"class":111},[66,3162,3163],{"class":90},"        sv ",[66,3165,118],{"class":117},[66,3167,3168],{"class":121}," Statevector",[66,3170,125],{"class":90},[66,3172,2969],{"class":121},[66,3174,2972],{"class":90},[66,3176,165],{"class":205},[66,3178,118],{"class":117},[66,3180,946],{"class":128},[66,3182,953],{"class":90},[66,3184,3185,3187,3190,3192,3195,3198],{"class":68,"data-cue":228,"line":1011},[66,3186,228],{"class":111},[66,3188,3189],{"class":90},"        counts ",[66,3191,118],{"class":117},[66,3193,3194],{"class":90}," sv.",[66,3196,3197],{"class":121},"sample_counts",[66,3199,3200],{"class":90},"(shots)\n",[66,3202,3204,3206,3209,3212,3215,3218,3220,3223,3225,3228,3230,3233],{"class":68,"line":3203},18,[66,3205,74],{"class":72,"aria-hidden":73},[66,3207,3208],{"class":86},"        return",[66,3210,3211],{"class":90}," {k: ",[66,3213,3214],{"class":117},"int",[66,3216,3217],{"class":90},"(v) ",[66,3219,2209],{"class":86},[66,3221,3222],{"class":90}," k, v ",[66,3224,1813],{"class":86},[66,3226,3227],{"class":90}," counts.",[66,3229,1819],{"class":121},[66,3231,3232],{"class":90},"()}, ",[66,3234,3235],{"class":401},"\"qiskit Statevector\"\n",[66,3237,3239,3241],{"class":68,"line":3238},19,[66,3240,74],{"class":72,"aria-hidden":73},[66,3242,105],{},[66,3244,3246,3248],{"class":68,"line":3245},20,[66,3247,74],{"class":72,"aria-hidden":73},[66,3249,3250],{"class":77},"    # 3. pure-Python fallback\n",[66,3252,3254,3256,3258,3261,3264],{"class":68,"data-cue":983,"line":3253},21,[66,3255,983],{"class":111},[66,3257,896],{"class":86},[66,3259,3260],{"class":121}," _py_run",[66,3262,3263],{"class":90},"(ops, shots, seed), ",[66,3265,3266],{"class":401},"\"pure-Python state vector\"\n",[279,3268,3269,3281,3288,3299,3310,3317],{"class":281},[283,3270,3271,3273],{"data-cue":26},[66,3272,26],{"class":111},[66,3274,3275,3276,592,3278,3280],{"class":289},"Rewrite the circuit into the gates this particular machine actually has. Hardware does not run ",[16,3277,668],{},[16,3279,691],{}," directly, it runs its own small set, and this is the translation. It is also where a circuit can get longer, and longer means noisier.",[283,3282,3283,3285],{"data-cue":139},[66,3284,139],{"class":111},[66,3286,3287],{"class":289},"The only line on this page that touches a quantum computer. Everything else here, including every listing above, is arithmetic about one.",[283,3289,3290,3292],{"data-cue":157},[66,3291,157],{"class":111},[66,3293,3294,3295,3298],{"class":289},"And it sits inside a ",[16,3296,3297],{},"try",", because a hardware run is a network call to a shared machine with a queue in front of it. It can fail, and this project would rather draw something than stop.",[283,3300,3301,3303],{"data-cue":185},[66,3302,185],{"class":111},[66,3304,3305,3306,3309],{"class":289},"Fallback one: work out the state from the gates alone. Note ",[16,3307,3308],{},"measure=False",", the same move QAVE had to make above. A circuit that measures has no state left to compute.",[283,3311,3312,3314],{"data-cue":228},[66,3313,228],{"class":111},[66,3315,3316],{"class":289},"Then draw shots from it. You get the same shot-to-shot randomness as hardware and none of the hardware's errors, which is either the point or the problem depending on what you are testing.",[283,3318,3319,3321],{"data-cue":983},[66,3320,983],{"class":111},[66,3322,3323],{"class":289},"Fallback two: the same maths again with no Qiskit at all, so the piece still runs on a machine with nothing installed.",[12,3325,3326],{},"Three ways to get a tally, and only the first is a quantum computer. Both fallbacks work out what the hardware should have produced and draw shots from that.",[12,3328,3329],{},"The simulator wins on nearly everything a developer cares about day to day. Runs are fast, free, exactly repeatable and never queued. At fourteen qubits it is also perfectly honest: it holds the same state the hardware would.",[12,3331,3332],{},"What it cannot do is keep up. Every qubit you add doubles the state a simulator has to track. Fourteen qubits is 16,384 amplitudes and fits in a quarter of a megabyte.",[12,3334,3335],{},"Fifty qubits is about 1.1 quadrillion amplitudes, which is eighteen petabytes and no longer a laptop problem. A fifty-qubit device holds that state anyway, because it stores nothing. It is the thing.",[12,3337,3338,3339,592,3341,3343],{},"Errors are the other half of the trade. A simulator gives you the distribution the maths predicts; hardware gives you the distribution a physical device produces, which is the one your results will actually have. Those 58 shots in ",[16,3340,591],{},[16,3342,595],{}," in the very first histogram are what a real machine looks like, not a flaw in the example.",[12,3345,3346],{},"So the rule of thumb is unglamorous. Develop against the simulator, where a run takes a second and you can change one line and go again. Move to hardware when the question is whether the circuit survives contact with a real device, because that is the one question a simulator is guaranteed not to answer.",[43,3348,3350],{"id":3349},"start-with-the-counts","Start with the counts",[12,3352,3353],{},"Every project here ends in the same place: a dictionary of bitstrings and how often each one came up. That tally is the whole output of a quantum computer.",[12,3355,3356],{},"Which comes down to four habits. Read a pattern, never a value, because a single shot says nothing about the odds behind it. Choose the question before you run, because the same state answers different questions differently. Keep a corrupted reading separate from a destroyed state, because only one of those can be repaired. And know which of your runs was a machine and which was a prediction of one.",[12,3358,3359],{},"Fork the histogram example first. The listing needs no hardware and no setup, and once you have put two distributions side by side, everything above is about what you are allowed to conclude from them.",[3361,3362,3364],"make-it-yours",{"fork-href":367,"title":3363},"Run it, then change the question.",[12,3365,3366,3367],{},"Fork the histograms example and change the counts by hand until you can predict the chart. Then open any project above and find the line where its measurement happens. ",[347,3368,3369],{},"Everything here is open and yours to build on.",[3371,3372,3373],"style",{},"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 .sVbv2, html code.shiki .sVbv2{--shiki-default:#61AFEF}html pre.shiki code .sVC51, html code.shiki .sVC51{--shiki-default:#D19A66}html pre.shiki code .s_ZVi, html code.shiki .s_ZVi{--shiki-default:#E06C75;--shiki-default-font-style:italic}html .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 .subq3, html code.shiki .subq3{--shiki-default:#98C379}html pre.shiki code .sb9H8, html code.shiki .sb9H8{--shiki-default:#D19A66;--shiki-default-font-style:italic}html pre.shiki code .sU0A5, html code.shiki .sU0A5{--shiki-default:#E5C07B}html pre.shiki code .sVyAn, html code.shiki .sVyAn{--shiki-default:#E06C75}",{"title":62,"searchDepth":81,"depth":81,"links":3375},[3376,3377,3378,3379,3380,3381,3382,3383,3384,3387,3388],{"id":45,"depth":81,"text":46},{"id":358,"depth":81,"text":359},{"id":623,"depth":81,"text":624},{"id":718,"depth":81,"text":719},{"id":1189,"depth":81,"text":1190},{"id":1359,"depth":81,"text":1360},{"id":1760,"depth":81,"text":1761},{"id":2126,"depth":81,"text":2127},{"id":2345,"depth":81,"text":2346,"children":3385},[3386],{"id":2588,"depth":100,"text":2589},{"id":2831,"depth":81,"text":2832},{"id":3349,"depth":81,"text":3350},[3390,3391,3392],"Qollab","Learn","Quantum measurement",[3394],{"username":7,"name":3395,"role":3396,"avatar":3397,"bio":3398,"links":3399},"Nicolaas Spijker","Community manager, Qollab","\u002F_content\u002Fimages\u002Fbuilders\u002Fnicolaas-spijker.webp","Nico runs the builder community at Qollab. These concept articles come out of that work: forking the projects people publish and running them. And talking with authors to learn more about their projects.",[3400,3403],{"label":3401,"href":3402},"Qollab ↗","https:\u002F\u002Fqollab.xyz\u002Fu\u002Fnico",{"label":3404,"href":3405},"GitHub ↗","https:\u002F\u002Fgithub.com\u002Fnicolaasspijker",{"username":7,"name":3395,"role":3396,"avatar":3397},null,"Measurement does not read a value off a qubit, it produces one. Why a single run tells you nothing, and why the question you ask changes the answer.","Measurement does not read a value off a qubit, it produces one. What that means for your code, and real projects you can run and fork to see it.",false,"md",{"href":367,"label":3413},"Fork the histogram example","article",{},true,"\u002F_content\u002Fimages\u002Fmeasurement\u002Fog.png","\u002Fblog\u002Flearn\u002Fquantum-measurement","2026-09-09","14 min read",[],{"title":3423,"description":3424},"Quantum Measurement, Explained with Code You Can Run","What quantum measurement actually does: why one run tells you nothing, and why the question you ask changes the answer. With real projects to run and fork.","blog\u002Flearn\u002Fquantum-measurement",[3427,3428,3429],"measurement","education","quantum","FiSxZUZvH_Zyg8ac4zu456hu6mYwbltbZNhfWR4B8Fs",[],[],1788974865914]