-- Phase estimation demo -- See qiskit.org/textbook/ch-algorithms/quantum-phase-estimation.html "Phase to estimate (range 0 to 1 turns)" theta = 0.7 theta pi = float(pi) -- use numerical value of pi U(psi) = rotate(psi, P,0, 2 pi theta, P,1, 4 pi theta, P,2, 8 pi theta, P,3, 16 pi theta) psi = zero(16) psi[1] = 1 psi = rotate(psi,H,0,H,1,H,2,H,3) psi = U(psi) psi = rotate(psi,V,3) "Probability distribution" P = psi conj(psi) xrange = (0,16) yrange = (0,1) draw(P[ceiling(x)],x) "Expectation value (estimate of phase)" 1/16 sum(k,0,15,k P[k + 1])
Run