QFT, QPE, and LCU
This page describes the quantum Fourier transform, phase estimation, and linear combinations of unitary operators. All three can be embedded in larger quantum circuits.
Recommended imports
from unitarylab import Circuit
from unitarylab.library import QFT, IQFT, QPE, LCU
from unitarylab.library._lcu import recover_lcu_operatorThe first four entries construct circuits. recover_lcu_operator() recovers the equivalent operator represented by an LCU circuit.
QFT and IQFT
from unitarylab import Circuit
from unitarylab.library import QFT, IQFT
qft = QFT(3)
inverse = IQFT(3)
circuit = Circuit(3)
circuit.append(qft, target=[0, 1, 2])The signatures are QFT(n) and IQFT(n); both return Circuit. n must be a positive integer. IQFT(n) is the adjoint of a QFT of the same width. Constructing a circuit does not execute it.
QPE
from unitarylab import Circuit
from unitarylab.library import QPE
unitary = Circuit(1)
unitary.z(0)
target = Circuit(1)
target.x(0)
circuit, phase, probability = QPE(
U=unitary, d=3, prepare_target=target,
backend="torch", device="cpu",
)
print(phase, probability)QPE(U, d, prepare_target=None, return_circuit=False,
backend="torch", device="cpu", dtype=np.complex128)| Parameter | Description |
|---|---|
U | Target-register Circuit |
d | Number of phase-register qubits; phase-grid resolution is |
prepare_target | Optional target-state preparation circuit; its width must match U |
return_circuit | If True, return the QPE circuit without execution |
backend, device, dtype | Backend, device, and complex precision used during execution |
When return_circuit=False, the result is (circuit, phase, probability). phase is the most probable phase estimate and probability is its probability. Increasing d increases the number of controlled-unitary operations and simulation cost.
LCU
from unitarylab import Circuit
from unitarylab.library import LCU
x_term = Circuit(1)
x_term.x(0)
z_term = Circuit(1)
z_term.z(0)
lcu = LCU([(x_term, 0.6), (z_term, 0.8)])LCU(decompositions) accepts a sequence of (Circuit, coefficient) pairs and returns a Circuit containing an ancilla register. All nonzero-coefficient terms must have the same width. Coefficients must be finite and nonnegative, and their sum must be positive. Empty decompositions, negative coefficients, and inconsistent widths raise exceptions.
To recover the matrix represented by the LCU circuit, call:
operator = recover_lcu_operator(
lcu, [(x_term, 0.6), (z_term, 0.8)],
backend="torch", device="cpu",
)Matrix recovery executes the full circuit and uses memory exponential in the qubit count.