Meta tags:
description= Why quantum computing uses complex numbers, how quantum amplitudes work, and the role of phase in quantum interference.;
author= QuantumComputingCourses.com;
Headings (most frequently used words):
complex, quantum, in, the, numbers, and, phase, is, why, computing, amplitudes, it, for, conjugate, what, euler, formula, inner, products, from, matters, interference, reference, python, requires, forgetting, number, polar, form, real, are, not, enough, needs, bloch, sphere, probability, how, affects, computation, gates, kickback, exponentials, algorithms, measuring, state, tomography, density, matrices, worked, example, estimation, intuition, numpy, arithmetic, common, mistakes, with, code, summary, next, steps, try, yourself, playground, related, tutorials, get, one, email, week, multiplication, rotation, scaling, gate, entries, full, group, of, single, qubit, unitaries, three, parameters, born, rule, double, slit, analogy, np, abs, arrays, confusing, methods, misusing, exponentiation, expectation, values, assuming, global, always, irrelevant, ready, to, go, deeper, learn, careers, about,
Text of the page (most frequently used words):
the (223), #complex (137), quantum (90), print (89), and (79), phase (75), psi (70), sqrt (69), state (51), for (50), array (50), dtype (47), theta (47), alpha (42), phi (41), abs (40), qubit (39), beta (38), numbers (37), #amplitudes (34), with (32), real (30), are (29), conjugate (26), this (25), gate (22), computing (21), that (21), angle (21), 707 (20), conj (19), ancilla (19), you (18), exp (18), magnitude (18), from (17), probability (17), entries (17), probabilities (17), interference (16), amplitude (16), after (15), gamma (15), what (14), how (14), why (14), states (14), control (14), global (14), single (14), measurement (14), degrees (14), algorithm (13), all (13), inner (13), has (13), outcome (13), sin (13), bloch (12), sphere (12), courses (12), diagonal (12), matrix (12), but (12), apply (12), cos (12), gates (11), number (11), can (11), wrong (11), psi2 (11), 0000 (11), product (11), guide (10), one (10), read (10), not (10), full (10), coherence (10), qubits (10), imaginary (10), correct (10), amp (10), tutorials (9), python (9), example (9), density (9), algorithms (9), off (9), eigenvalue (9), relative (9), eigenphase (9), best (9), its (9), min (8), numpy (8), matrices (8), tomography (8), euler (8), formula (8), because (8), two (8), vector (8), both (8), probs (8), when (8), part (8), 0000j (8), verify (8), target (8), eigenstate (8), pz0 (8), get (7), bell (7), code (7), estimation (7), measuring (7), work (7), more (7), have (7), roots (7), rotation (7), which (7), different (7), where (7), true (7), function (7), 7071 (7), rho (7), vdot (7), each (7), rho_01 (7), psi_plus (7), px0 (7), py0 (7), after_s (7), pole (7), reference (6), paths (6), written (6), products (6), polar (6), form (6), first (6), left (6), requires (6), magnitudes (6), range (6), always (6), same (6), allclose (6), operations (6), bins (6), return (6), sum (6), def (6), unitary (6), zero (6), amp_1 (6), amp_0 (6), bloch_to_statevector (6), 2026 (5), com (5), about (5), hardware (5), framework (5), case (5), qiskit (5), arithmetic (5), kickback (5), matters (5), here (5), unity (5), unit (5), phases (5), squared (5), they (5), basis (5), unchanged (5), eye (5), only (5), becomes (5), result (5), difference (5), arrays (5), controlled (5), qft (5), superposition (5), without (5), psi_plus_i (5), pure (5), psi_i (5), angles (5), psi_true (5), measure (5), normalization (5), omega (5), final (5), initial (5), component (5), constant (5), add (5), balanced (5), lambda (5), use (4), learning (4), free (4), zeitgeist (4), donovan (4), next (4), common (4), exponentials (4), affects (4), computation (4), circuit (4), built (4), out (4), measurements (4), uses (4), plane (4), multiplication (4), cancel (4), cannot (4), before (4), computational (4), kron (4), entangled (4), expectation (4), hermitian (4), using (4), dagger (4), will (4), 5000 (4), gives (4), between (4), measured (4), 500 (4), dephasing (4), need (4), psi_recon (4), reconstruct (4), norm (4), then (4), three (4), every (4), dft (4), negative (4), hello (4), world (4), your (3), policy (3), hadamard (3), amazon (3), team (3), careers (3), glossary (3), studies (3), writes (3), cirq (3), pennylane (3), intermediate (3), any (3), point (3), test (3), entanglement (3), time (3), beginner (3), steps (3), summary (3), mistakes (3), worked (3), intuition (3), needs (3), enough (3), these (3), browse (3), tutorial (3), since (3), physics (3), other (3), mathematical (3), through (3), multiple (3), fourier (3), transform (3), ratio (3), isolated (3), group (3), scaling (3), exactly (3), their (3), points (3), after_z (3), system (3), operators (3), check (3), non (3), even (3), pauli (3), value (3), preferred (3), while (3), element (3), unitarity (3), conjugates (3), eigenphases (3), 2500 (3), inverse (3), n_ancilla (3), given (3), now (3), starts (3), 000 (3), rho_t (3), rho_plus (3), complete (3), mixed (3), directly (3), observable (3), beta_true (3), alpha_true (3), theta_true (3), im_part (3), re_part (3), abs_alpha (3), step (3), information (3), control_after (3), factor (3), most (3), after_t (3), 707j (3), converts (3), into (3), destructive (3), constructive (3), path (3), produce (3), psi1 (3), applied (3), equator (3), south (3), north (3), parameters (3), prob_1 (3), prob_0 (3), lam (3), prerequisites (3), braket (3), cookies (2), experience (2), affiliate (2), see (2), terms (2), quantumcomputingcourses (2), books (2), podcasts (2), events (2), faq (2), editorial (2), jobs (2), interview (2), certifications (2), salary (2), programming (2), timeline (2), types (2), news (2), frameworks (2), learn (2), who (2), research (2), industry (2), references (2), tools (2), quantumcomputing (2), email (2), changed (2), week (2), reaching (2), bernstein (2), vazirani (2), implementing (2), hidden (2), string (2), finder (2), inequalities (2), chsh (2), know (2), related (2), language (2), level (2), computers (2), guides (2), coursera (2), edx (2), udemy (2), brilliant (2), deeper (2), ibm (2), put (2), there (2), should (2), also (2), entirely (2), try (2), yourself (2), notation (2), bra (2), bases (2), encode (2), them (2), decoherence (2), circle (2), require (2), unobservable (2), unitaries (2), too (2), key (2), effects (2), give (2), power (2), reinforce (2), some (2), irrelevant (2), rule (2), values (2), correct3 (2), wrong3 (2), 6000 (2), correct2 (2), wrong2 (2), happens (2), results (2), forgetting (2), result1 (2), result2 (2), computes (2), operator (2), arr (2), works (2), wise (2), expect (2), outer (2), transpose (2), argument (2), import (2), bin (2), simulate_qpe (2), zeros (2), simulate (2), ideal (2), qpe (2), precision (2), distinguish (2), 125 (2), 250 (2), 375 (2), dephased_state (2), rho_initial (2), copy (2), parameter (2), interfere (2), structure (2), makes (2), rho_mixed (2), completely (2), noisy (2), rho_plus_i (2), entry (2), tells (2), meaning (2), equals (2), sum_i (2), provides (2), measurable (2), 000000 (2), overlap (2), reconstructed (2), tomography_reconstruct (2), psi_y (2), sdg (2), psi_x (2), phi_true (2), linalg (2), abs_beta (2), positive (2), p_y (2), maps (2), p_x (2), shor (2), 4x4 (2), change (2), shifted (2), minus_state (2), back (2), proj_1 (2), proj_0 (2), concrete (2), important (2), changing (2), 785 (2), rad (2), adds (2), contribute (2), sign (2), constructively (2), opposite (2), deutsch (2), consider (2), bit (2), whether (2), contributes (2), squaring (2), double (2), slit (2), reach (2), detector (2), leading (2), answers (2), grover (2), cancelled (2), would (2), combined (2), making (2), likely (2), alone (2), collapses (2), psi_minus (2), ket_1 (2), ket_0 (2), subsequent (2), correct_norm (2), wrong_norm (2), just (2), name (2), azimuthal (2), arbitrary (2), rotations (2), orthogonal (2), dimensional (2), identity_check (2), u_gate (2), general (2), necessary (2), theta1 (2), theta2 (2), role (2), wave (2), accept, decline, improve, track, performance, our, cookie, privacy, disclosure, llc, associate, earn, qualifying, purchases, contact, site, talent, pool, post, job, training, questions, cheatsheets, history, docs, compare, maintained, curated, anyone, 241, 220, 112, subscribe, address, new, worth, taking, spam, unsubscribe, anytime, qsilver, workshop, qworld, paid, jun, updated, glance, page, chemistry, basics, programs, previous, continue, structured, ready, share, yes, was, helpful, quantumzeitgeist, ran, his, 2018, subject, down, material, forced, choice, nobody, make, pop, science, hand, waving, end, phd, ramp, had, usually, stopped, working, found, run, preloaded, right, edit, execute, instantly, runs, browser, signup, install, open, screen, playground, showing, design, physicists, ket, explained, vectors, linear, algebra, recovers, destroys, transfers, enabling, parameterization, drives, restrictive, perform, remember, convenience, necessity, valued, represent, capture, dynamics, correlations, differ, means, second, larger, appears, subsystem, assuming, simple, conjugated, may, stark, dramatic, conjugating, side, omitting, produces, avoid, clarity, correctly, mathematically, equivalent, numerically, safer, universally, understood, mistake, writing, 71828, misusing, exponentiation, cleaner, method, compute, reads, clearly, confusing, methods, explicit, calls, internally, idiomatic, individual, handles, cleanly, note, radians, 7854, scalar, compact, repeatedly, resolved, align, provide, better, approximations, concentrating, around, nearest, argmax, sum_, resolution, improves, allowing, resolve, bits, outcomes, equal, perfectly, falls, neither, certain, acts, suppose, extracts, let, walk, minimal, channel, simulating, decay, exponentially, precisely, process, decaying, toward, coherent, gradually, loses, ability, error, correction, powerful, degrades, over, maximally, encodes, much, remains, own, forces, p_i, subsystems, description, demonstrates, leave, signatures, probe, fidelity, match, renormalize, else, choose, fixing, returns, sets, suffice, procedure, called, yields, lost, preserves, frequency, foundation, factoring, round, build, deg, enumerate, equally, spaced, distinct, nth, started, ended, mechanism, behind, many, extract, kicked, still, kicks, onto, setup, phenomena, occurs, applying, instead, acquires, standard, illustrate, signs, deterministic, clean, determines, query, principle, circuits, output, experiment, particle, take, total, analogy, designed, based, achieve, speedups, cancellation, renormalization, together, destructively, less, genuinely, however, joint, subtlety, essence, components, physically, meaningful, identical, overall, entire, effect, ignored, kinds, those, determine, respond, via, normalize, born, version, fixes, expected, dot, itself, could, 5000j, define, denotes, optional, definite, phi_i, within, numerical, convert, coordinates, corresponds, unique, tan, undefined, vanishes, mapping, been, factored, leaving, though, like, parts, appear, essential, evolve, satisfying, starting, restricted, 2x2, family, access, space, mechanics, allows, reason, belongs, replace, keeping, performs, specific, expressed, rotate, might, wonder, truly, purely, remain, shift, become, visible, 7071j, rotated, start, multiplies, rotates, demonstrate, multiply, multiplying, transparent, useful, identities, connects, 606, absolute, measures, distance, flips, imag, defined, property, everywhere, involve, explains, plays, along, way, concept, claim, sections, background, needed, basic, variables, functions, loops, feb, series, concepts, home, search, troubleshooting, prep, universities, career, cheat, sheets, migration, comparison, pinball, explore, ocean, tket, pyquil, rigetti, quera, azure, quantinuum, ionq, google, providers, course, platforms, skip, main, content,
Text of the page (random words):
0000 phase what it is and why it matters the phase of a complex amplitude is its angle in the complex plane two states can have the same measurement probabilities but different phases and those phases determine how the states respond to gates there are two kinds of phase to distinguish global phase is an overall factor e i theta applied to the entire state it has no observable effect and can always be ignored psi1 np array 1 np sqrt 2 1 np sqrt 2 dtype complex psi2 np exp 1 j np pi 4 psi1 global phase applied probabilities are identical print abs psi1 2 0 5 0 5 print abs psi2 2 0 5 0 5 relative phase is a phase difference between components of a superposition relative phase is physically meaningful because it affects interference state both amplitudes in phase psi_plus np array 1 np sqrt 2 1 np sqrt 2 dtype complex state amplitudes out of phase by pi psi_minus np array 1 np sqrt 2 1 np sqrt 2 dtype complex apply hadamard to both h 1 np sqrt 2 np array 1 1 1 1 dtype complex print h psi_plus 1 0 j 0 0 j collapses to 0 print h psi_minus 0 0 j 1 0 j collapses to 1 the hadamard gate converts relative phase into a difference in measurement probabilities this is the essence of quantum interference important subtlety global phase is genuinely unobservable for isolated qubits however relative phase between qubits in an entangled state is observable when qubit a is entangled with qubit b a global phase on qubit a alone becomes a relative phase of the joint system and can produce measurable effects interference how phase affects computation quantum interference happens when probability amplitudes add together amplitudes with the same phase add constructively making the outcome more likely amplitudes with opposite phases cancel destructively making the outcome less likely constructive interference a 1 np sqrt 2 b 1 np sqrt 2 combined a b amplitudes add up print abs combined 2 2 0 but this would need renormalization destructive interference c 1 np sqrt 2 d 1 np sqrt 2 cancelled c d print abs cancelled 2 0 0 complete cancellation in a real quantum algorithm the circuit is designed so that amplitudes leading to wrong answers cancel and amplitudes leading to correct answers reinforce this is how grover s algorithm and quantum fourier transform based algorithms achieve their speedups interference in the double slit analogy in a double slit experiment a particle can take two paths to reach a detector each path contributes a complex amplitude the total amplitude at the detector is the sum of both path amplitudes and the probability is the squared magnitude of that sum this is the same principle at work in quantum circuits each computational path through a circuit contributes a complex amplitude to a given output the amplitudes from all paths sum before squaring to get a probability the deutsch algorithm provides a clean example consider a function f that maps one bit to one bit the algorithm determines whether f is constant f 0 f 1 or balanced f 0 f 1 with a single query h 1 np sqrt 2 np array 1 1 1 1 dtype complex after the deutsch circuit the amplitude of measuring 0 on the first qubit is 1 f 0 1 f 1 2 case 1 constant function f 0 0 f 1 0 f0 f1 0 0 amp_0 1 f0 1 f1 2 amp_1 1 f0 1 f1 2 print f constant amp 0 amp_0 2f amp 1 amp_1 2f print f p 0 abs amp_0 2 2f p 1 abs amp_1 2 2f constant amp 0 1 00 amp 1 0 00 constructive interference on 0 destructive on 1 case 2 balanced function f 0 0 f 1 1 f0 f1 0 1 amp_0 1 f0 1 f1 2 amp_1 1 f0 1 f1 2 print f balanced amp 0 amp_0 2f amp 1 amp_1 2f print f p 0 abs amp_0 2 2f p 1 abs amp_1 2 2f balanced amp 0 0 00 amp 1 1 00 destructive interference on 0 constructive on 1 for the constant function both paths contribute the same sign so they add constructively for the balanced function the paths contribute opposite signs and cancel interference converts a phase difference into a deterministic measurement outcome complex numbers in quantum gates all standard quantum gates have complex entries the y gate and the s gate illustrate this y np array 0 1 j 1 j 0 dtype complex s np array 1 0 0 1 j dtype complex s gate adds a phase of i to the 1 component psi np array 1 np sqrt 2 1 np sqrt 2 dtype complex after_s s psi print after_s 0 707 0 j 0 0 707j the 1 component now has a phase of i e i pi 2 the t gate pi 8 gate adds a phase of e i pi 4 to the 1 component t np array 1 0 0 np exp 1 j np pi 4 dtype complex after_t t psi print after_t 0 707 0 j 0 5 0 5j print np angle after_t 1 0 785 rad pi 4 phase kickback phase kickback is one of the most important phenomena in quantum algorithms it occurs when applying a controlled u gate and the target qubit is an eigenstate of u instead of the target qubit changing the control qubit acquires a phase here is the setup u is a unitary with eigenstate u and eigenvalue e i phi that is u u e i phi u when we apply controlled u with the control qubit in superposition and the target in u cu 0 1 sqrt 2 u 0 u e i phi 1 u sqrt 2 0 e i phi 1 sqrt 2 u the phase kicks back onto the control qubit the target qubit is unchanged concrete example cz gate target in 1 eigenstate of z with eigenvalue 1 z gate z np array 1 0 0 1 dtype complex 1 is an eigenstate of z with eigenvalue 1 e i pi eigenstate np array 0 1 dtype complex print f z 1 z eigenstate 0 1 1 1 e i pi 1 control qubit starts in control np array 1 np sqrt 2 1 np sqrt 2 dtype complex cz gate as a 4x4 matrix cz 0 0 x i 1 1 x z i np eye 2 dtype complex proj_0 np array 1 0 0 0 dtype complex 0 0 proj_1 np array 0 0 0 1 dtype complex 1 1 cz np kron proj_0 i np kron proj_1 z full initial state control x target initial np kron control eigenstate print f initial state initial 0 0 707 0 0 707 apply cz final cz initial print f final state final 0 0 707 0 0 707 factor out the target it s still 1 the control qubit is now 0 1 sqrt 2 phase e i pi 1 has kicked back to the control qubit control_after np array final 1 final 3 extract control amplitudes print f control after control_after 0 707 0 707 verify this is up to normalization minus_state np array 1 np sqrt 2 1 np sqrt 2 dtype complex print f is np allclose control_after minus_state true the control qubit started in and ended in the z eigenvalue of 1 e i pi shifted the relative phase of the control qubit by pi this is the mechanism behind quantum phase estimation and many other quantum algorithms complex exponentials in quantum algorithms the quantum fourier transform qft is built from roots of unity the nth roots of unity are the n complex numbers omega k e 2 pi i k n for k 0 1 n 1 these n points are equally spaced on the unit circle each has magnitude 1 pure phase no amplitude change and a distinct angle roots of unity for n 8 n 8 roots np exp 2 j np pi k n for k in range n print n 8 roots of unity for k w in enumerate roots print f omega k w 4f f magnitude abs w 4f angle np degrees np angle w 7 1f deg the dft matrix has entries f j k omega jk sqrt n for n 4 n 4 omega np exp 2 j np pi n i build the 4x4 dft matrix f np zeros n n dtype complex for j in range n for k in range n f j k omega j k np sqrt n print dft matrix n 4 print np round f 3 0 5 0 j 0 5 0 j 0 5 0 j 0 5 0 j 0 5 0 j 0 0 5j 0 5 0 j 0 0 5j 0 5 0 j 0 5 0 j 0 5 0 j 0 5 0 j 0 5 0 j 0 0 5j 0 5 0 j 0 0 5j verify unitarity f f i print n f f i np allclose f conj t f np eye n true verify all entries have magnitude 1 sqrt n print all entries magnitude 1 sqrt n np allclose np abs f 1 np sqrt n true because every entry of the dft matrix has the same magnitude 1 sqrt n the qft preserves normalization the complex phases are what encode the frequency information this is the mathematical foundation of shor s factoring algorithm and quantum phase estimation measuring complex amplitudes quantum state tomography you cannot directly measure the complex amplitudes of a quantum state a measurement in the computational basis yields only probabilities which are the squared magnitudes alpha 2 and beta 2 all phase information is lost to reconstruct the full complex state you need to measure in multiple bases this procedure is called quantum state tomography for a single qubit psi alpha 0 beta 1 three sets of measurements suffice step 1 measure in the z basis to get alpha 2 and beta 2 step 2 apply h then measure in z to get information about re alpha beta after h the state becomes alpha beta alpha beta sqrt 2 the probability of outcome 0 is p_x 0 alpha beta 2 2 alpha 2 beta 2 2 re alpha beta 2 so re alpha beta p_x 0 1 2 step 3 apply s dagger then h then measure in z to get im alpha beta s dagger maps 1 to i 1 so after s dagger beta becomes i beta then h gives the probability p_y 0 alpha i beta 2 2 alpha 2 beta 2 2 re alpha i beta 2 1 2 im alpha beta 2 so im alpha beta p_y 0 1 2 def tomography_reconstruct pz0 px0 py0 reconstruct a single qubit state from tomography probabilities pz0 probability of 0 in z measurement px0 probability of 0 after h x measurement py0 probability of 0 after s h y measurement returns the reconstructed state vector up to global phase from z measurement abs_alpha np sqrt pz0 abs_beta np sqrt 1 pz0 choose alpha real and positive fixing global phase alpha abs_alpha from x and y measurements re_part px0 0 5 re alpha beta im_part py0 0 5 im alpha beta if abs_alpha 1e 10 alpha beta alpha beta since alpha is real so beta re_part i im_part alpha beta re_part 1 j im_part alpha else alpha is 0 state is 1 phase of beta is global phase beta abs_beta state np array alpha beta dtype complex state state np linalg norm state renormalize return state test reconstruct the state psi cos pi 8 0 e i pi 3 sin pi 8 1 theta_true np pi 4 phi_true np pi 3 alpha_true np cos theta_true 2 beta_true np exp 1 j phi_true np sin theta_true 2 psi_true np array alpha_true beta_true dtype complex print f true state alpha alpha_true 4f beta beta_true 4f simulate ideal tomography measurements h 1 np sqrt 2 np array 1 1 1 1 dtype complex sdg np array 1 0 0 1 j dtype complex z measurement pz0 np abs psi_true 0 2 x measurement apply h first psi_x h psi_true px0 np abs psi_x 0 2 y measurement apply s h first psi_y h sdg psi_true py0 np abs psi_y 0 2 print f tomography probabilities pz0 pz0 4f px0 px0 4f py0 py0 4f reconstruct psi_recon tomography_reconstruct pz0 px0 py0 print f reconstructed alpha psi_recon 0 4f beta psi_recon 1 4f check states should match up to global phase overlap np abs np vdot psi_true psi_recon 2 print f fidelity overlap 6f 1 000000 this demonstrates that complex amplitudes while not directly observable leave measurable signatures when you probe the state from different angles complex numbers in density matrices for mixed states noisy qubits or subsystems of entangled states the density matrix provides a complete description rho sum_i p_i psi_i psi_i a density matrix is hermitian rho rho meaning it equals its own conjugate transpose this forces the diagonal entries to be real and the off diagonal entries to be complex conjugates of each other pure state 0 1 sqrt 2 psi_plus np array 1 np sqrt 2 1 np sqrt 2 dtype complex rho_plus psi_plus psi_plus conj t print density matrix for print rho_plus 0 5 0 5 0 5 0 5 off diagonal entries are 0 5 full coherence the off diagonal entry rho_01 0 rho 1 encodes the coherence between 0 and 1 its magnitude tells you how much quantum superposition remains and its phase tells you which superposition pure state i 0 i 1 sqrt 2 psi_plus_i np array 1 np sqrt 2 1 j np sqrt 2 dtype complex rho_plus_i psi_plus_i psi_plus_i conj t print density matrix for i print rho_plus_i 0 5 0 5j 0 5j 0 5 off diagonal entries are imaginary the phase is pi 2 completely mixed state maximally noisy rho_mixed np array 0 5 0 0 0 5 dtype complex print n completely mixed state print rho_mixed 0 5 0 0 0 5 off diagonal entries are zero no coherence decoherence is precisely the process of the off diagonal entries decaying toward zero a qubit that starts in a coherent superposition gradually loses its complex off diagonal entries and with them its ability to interfere this is why quantum computers need error correction without it the complex structure that makes quantum computation powerful degrades over time simulating dephasing off diagonal entries decay exponentially def dephased_state rho gamma apply dephasing channel with parameter gamma in 0 1 gamma 0 no dephasing gamma 1 complete dephasing result rho copy result 0 1 1 gamma result 1 0 1 gamma return result rho_initial rho_plus copy for gamma in 0 0 25 0 5 0 75 1 0 rho_t dephased_state rho_initial gamma print f gamma gamma 2f rho_01 rho_t 0 1 3f f coherence abs rho_t 0 1 3f gamma 0 00 rho_01 0 500 coherence 0 500 gamma 0 25 rho_01 0 375 coherence 0 375 gamma 0 50 rho_01 0 250 coherence 0 250 gamma 0 75 rho_01 0 125 coherence 0 125 gamma 1 00 rho_01 0 000 coherence 0 000 worked example phase estimation intuition quantum phase estimation qpe extracts the eigenvalue phase of a unitary operator let us walk through a minimal example with a single ancilla qubit suppose u has eigenvalue e i pi 2 i eigenphase 1 4 since pi 2 2 pi 1 4 the ancilla starts in and the target is in the eigenstate of u after controlled u the ancilla state is 0 e i pi 2 1 sqrt 2 0 i 1 sqrt 2 now we apply h which acts as a 1 qubit inverse qft to the ancilla ancilla state after controlled u ancilla np array 1 np sqrt 2 1 j np sqrt 2 dtype complex apply h inverse qft for 1 qubit h 1 np sqrt 2 np array 1 1 1 1 dtype complex measured h ancilla print f after h measured after h 0 5 0 5j 0 5 0 5j measurement probabilities p0 np abs measured 0 2 p1 np abs measured 1 2 print f p 0 p0 4f 0 5000 print f p 1 p1 4f 0 5000 with a single ancilla qubit both outcomes have equal probability the single ancilla can only distinguish eigenphases of 0 and 1 2 perfectly the eigenphase 1 4 falls between these so neither outcome is certain with more ancilla qubits the resolution improves using n ancilla qubits gives 2 n bins for the phase allowing you to resolve eigenphases to n bits of precision def simulate_qpe eigenphase n_ancilla simulate ideal qpe outcome probabilities for a given eigenphase eigenphase the phase phi where eigenvalue e 2 pi i phi in 0 1 n_ancilla number of ancilla qubits n 2 n_ancilla after controlled u operations and inverse qft the probability of measuring outcome m is p m sum_ k 0 n 1 e 2 pi i k phi m n n 2 probs np zeros n for m in range n amp sum np exp 2 j np pi k eigenphase m n for k in range n n probs m np abs amp 2 return probs eigenphase 0 25 eigenvalue e i pi 2 i for n in 1 2 3 4 probs simulate_qpe eigenphase n n 2 n best np argmax probs print f n n ancilla n 2d bins f best outcome best n best n 4f f p probs best 4f n 1 ancilla 2 bins best outcome 0 2 0 0000 p 0 5000 n 2 ancilla 4 bins best outcome 1 4 0 2500 p 1 0000 n 3 ancilla 8 bins best outcome 2 8 0 2500 p 1 0000 n 4 ancilla 16 bins best outcome 4 16 0 2500 p 1 0000 with 2 or more ancilla qubits the eigenphase 1 4 is resolved exactly because 1 4 is a multiple of 1 n for n 4 for eigenphases that do not align with a bin more ancilla qubits provide better approximat...
|