59 programs, each with what the reader must do with it: the language specification's 21 example programs, unchanged (those that run held to their results, the rest to the code that names the first construct the reader cannot hold exactly, or the example's own error), and a program for each construct with a reference written without it. stdgates.qasm applies every standard gate once, and its reference writes each in U and CX alone. Expectations: refused (a code), warns (every warning's code), deterministic (every shot's outcome), distribution (exact outcome probabilities), expectations (exact Pauli values), equivalent (a reference's unitary up to a global phase), exact (the bit-exact circuit takes it or refuses it with a code), outputs, timing and calibrations. bundle.json holds the cases with their text inline for builds that read no files; a test holds it equal to the files. CI: wai-quantum-lang.yml runs the reader's tests, the corpus natively, the reader built without the lowerings, and the corpus under wasm32-wasip2 by wasmtime; wai-web's wasm32 tests read every case through the page's engine (the wasm32 count goes from 8 to 9). Co-Authored-By: Claude Opus 5.5 <[email protected]>
37 lines
941 B
Text
37 lines
941 B
Text
/*
|
|
* Iterative phase estimation
|
|
*/
|
|
include "stdgates.inc";
|
|
|
|
const int[32] n = 10; // number of iterations
|
|
const float[32] theta = 3 * pi / 8; // phase angle on target qubit
|
|
|
|
qubit q; // phase estimation qubit
|
|
qubit r; // target qubit for the controlled-unitary gate
|
|
angle[n] c; // phase estimation bits
|
|
|
|
// initialize
|
|
reset q;
|
|
reset r;
|
|
|
|
// prepare uniform superposition of eigenvectors of phase
|
|
h r;
|
|
|
|
// iterative phase estimation loop
|
|
uint[n] power = 1;
|
|
for uint i in [0: n - 1] { // implicitly cast val to int
|
|
reset q;
|
|
h q;
|
|
ctrl @ pow(power) @ phase(theta) q, r;
|
|
inv @ phase(c) q;
|
|
h q;
|
|
measure q -> c[0];
|
|
// newest measurement outcome is associated to a pi/2 phase shift
|
|
// in the next iteration, so shift all bits of c left
|
|
c <<= 1;
|
|
power <<= 1;
|
|
}
|
|
|
|
// Now c contains the n-bit estimate of phi in the
|
|
// eigenvalue e^{i*phi} and qreg r is projected to an
|
|
// approximate eigenstate of the phase gate.
|