{"id":263,"date":"2026-07-21T21:39:50","date_gmt":"2026-07-22T01:39:50","guid":{"rendered":"https:\/\/wp.stgeorges.bc.ca\/vincentz\/?p=263"},"modified":"2026-07-24T21:39:22","modified_gmt":"2026-07-25T01:39:22","slug":"update-getting-quantum-amplitude-estimation-running","status":"publish","type":"post","link":"https:\/\/wp.stgeorges.bc.ca\/vincentz\/2026\/07\/21\/update-getting-quantum-amplitude-estimation-running\/","title":{"rendered":"Update: Getting Quantum Amplitude Estimation Running"},"content":{"rendered":"\n<h3 class=\"wp-block-heading\">(and a bug that taught me more than the code did)<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">7\/21\/2026<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Since the last post I got back into VSCode and Qiskit properly, and this update is less about a result and more about a mistake I almost didn&#8217;t catch<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>GETTING THE FIRST NUMBER<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The finance module of Qiskit, namely the <strong>(qiskit-finance) <\/strong>module, already contains everything you require, including a <strong>LogNormalDistribution<\/strong> circuit that encodes the probability distribution of the future price of the underlying asset, and an <strong>EuropeanCallPricingObjective<\/strong> circuit that encodes the payoff function into the amplitude of one of its qubits. By combining these components and then passing them through <strong>IterativeAmplitudeEstimation<\/strong>, you obtain the price of your option.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">As many parts of the API were new to me, I used an AI tool (Manus) to write my first draft of the script, the same way I used AI for debugging and concept clarification in the previous project. It didn\u2019t give any error, came up with the price estimate almost equal to the $10.45 baseline estimated using Black Scholes model, and even showed the ef fect of \u201cqubit gap\u201d which I hoped it would, wherein the estimates are very poor for low qubit numbers but converge to the correct value for higher numbers.<\/p>\n\n\n\n<div class=\"wp-block-media-text alignwide has-media-on-the-right is-stacked-on-mobile\"><div class=\"wp-block-media-text__content\">\n<p class=\"wp-block-paragraph\"><strong>Notable Bug I Encountered<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">I Ran that exact same script a second time, no changes at all just to confirm the number. Got an entirely different outcome &#8211; not even remotely close to the last one so clearly something was wrong<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">What I discovered was that the culprit in this case was relatively easy to pin down: there wasn&#8217;t any seeding in the script. The randomness is entirely regenerated when running each iteration of the classical Monte Carlo simulation as well as the quantum sampling simulation, making a single pass of the qubit numbers simply a random noisy data point. What the original version had generated was essentially a fluke &#8211; lucky, unlucky, doesnt matter <\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This is a sort of continuation of the &#8220;1,000 samples landed above 500 samples&#8221; issue of the previous post.<\/p>\n<\/div><figure class=\"wp-block-media-text__media\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"399\" src=\"https:\/\/wp.stgeorges.bc.ca\/vincentz\/wp-content\/uploads\/sites\/18\/2026\/07\/image-1-1024x399.png\" alt=\"\" class=\"wp-image-265 size-full\" srcset=\"https:\/\/wp.stgeorges.bc.ca\/vincentz\/wp-content\/uploads\/sites\/18\/2026\/07\/image-1-1024x399.png 1024w, https:\/\/wp.stgeorges.bc.ca\/vincentz\/wp-content\/uploads\/sites\/18\/2026\/07\/image-1-300x117.png 300w, https:\/\/wp.stgeorges.bc.ca\/vincentz\/wp-content\/uploads\/sites\/18\/2026\/07\/image-1-768x299.png 768w, https:\/\/wp.stgeorges.bc.ca\/vincentz\/wp-content\/uploads\/sites\/18\/2026\/07\/image-1.png 1208w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure><\/div>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Fixing It<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This &#8220;fix&#8221; is the same as the classical baseline idea: do not rely on single runs anymore and use the average results of many repetitions instead. Now for each qubit size, I perform 8 repetitions of the price calculation circuit with different seeds and provide an average error and spread among those repetitions, rather than a single misleading value.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><strong># before \u2014 every run draws fresh randomness, nothing is reproducible<\/strong>\nsampler = StatevectorSampler(default_shots=4096)\n\n<strong># after \u2014 seeded, and repeated across trials instead of trusting one run<\/strong>\nsampler = StatevectorSampler(seed=seed, default_shots=4096)<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Here&#8217;s what that actually looks like after alot of debugging<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>Qubits<\/th><th>Average error vs. exact price<\/th><th>Spread across trials<\/th><\/tr><\/thead><tbody><tr><td>2<\/td><td>$1.43<\/td><td>\u00b1 $0.07<\/td><\/tr><tr><td>3<\/td><td>$0.26<\/td><td>\u00b1 $0.07<\/td><\/tr><tr><td>4<\/td><td>$0.14<\/td><td>\u00b1 $0.05<\/td><\/tr><tr><td>5<\/td><td>$0.12<\/td><td>\u00b1 $0.06<\/td><\/tr><tr><td>6<\/td><td>$0.09<\/td><td>\u00b1 $0.04<\/td><\/tr><tr><td>7<\/td><td>$0.06<\/td><td>\u00b1 $0.06<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">This is the actual implementation of what I was talking about. From 2 qubits to 7 qubits, there&#8217;s a reduction of over 20 times in errors, and this time it&#8217;s a smooth, monotonically increasing function rather than a one-shot noisy result. I applied the same concepts I learned from the last project on quantum computing <\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Lesson learned<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">The real lesson here isn&#8217;t about quantum computing at all; it is the lesson of being cautious about accepting an answer when the code works without any errors and gives you a sensible number. Being error-free doesn&#8217;t mean being right, and it&#8217;s always better to constantly change and improve your methodology to produce the optimal results. I had a similar experience last year when running the code for my EAQEC project, atleast 13 versions of the main code was created.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Next up I want to put the classical Monte Carlo convergence and this QAE convergence on the same chart<\/p>\n","protected":false},"excerpt":{"rendered":"<p>(and a bug that taught me more than the code did) 7\/21\/2026 Since the last post I got back into VSCode and Qiskit properly, and this update is less about a result and more about a mistake I almost didn&#8217;t catch GETTING THE FIRST NUMBER The finance module of Qiskit, namely the (qiskit-finance) module, already [&hellip;]<\/p>\n","protected":false},"author":15,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[9],"tags":[],"class_list":["post-263","post","type-post","status-publish","format-standard","hentry","category-qubitoptions"],"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/wp.stgeorges.bc.ca\/vincentz\/wp-json\/wp\/v2\/posts\/263","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wp.stgeorges.bc.ca\/vincentz\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/wp.stgeorges.bc.ca\/vincentz\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/wp.stgeorges.bc.ca\/vincentz\/wp-json\/wp\/v2\/users\/15"}],"replies":[{"embeddable":true,"href":"https:\/\/wp.stgeorges.bc.ca\/vincentz\/wp-json\/wp\/v2\/comments?post=263"}],"version-history":[{"count":2,"href":"https:\/\/wp.stgeorges.bc.ca\/vincentz\/wp-json\/wp\/v2\/posts\/263\/revisions"}],"predecessor-version":[{"id":269,"href":"https:\/\/wp.stgeorges.bc.ca\/vincentz\/wp-json\/wp\/v2\/posts\/263\/revisions\/269"}],"wp:attachment":[{"href":"https:\/\/wp.stgeorges.bc.ca\/vincentz\/wp-json\/wp\/v2\/media?parent=263"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/wp.stgeorges.bc.ca\/vincentz\/wp-json\/wp\/v2\/categories?post=263"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/wp.stgeorges.bc.ca\/vincentz\/wp-json\/wp\/v2\/tags?post=263"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}