Skip to content

iniestarchen/hadamard-test

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Hadamard Test

Category: simulation  |  Difficulty: intermediate  |  Qubits: 2  |  Gates: 4  |  Depth: 4

The Hadamard test estimates the real part of the expectation value ⟨ψ|U|ψ⟩ using one ancilla qubit. The ancilla is placed in superposition, a controlled-U is applied, and a final Hadamard on the ancilla transforms the relative phase into a probability difference. For U=Z and |ψ⟩=|+⟩, Re(⟨+|Z|+⟩) = 0, so both outcomes are equally likely. The imaginary part uses an S† gate.

Expected Output

P(0) = P(1) = 0.5 (Re(⟨+|Z|+⟩) = 0)

Circuit

The OpenQASM 2.0 circuit is in circuit.qasm.

OPENQASM 2.0;
include "qelib1.inc";
// Hadamard test: estimate Re(<psi|U|psi>) for U=Z, |psi>=|+>
// q[0]: ancilla, q[1]: system qubit |psi>
qreg q[2];
creg c[1];
// Prepare |psi> = |+>
h q[1];
// Hadamard test circuit
h q[0];
cz q[0],q[1];
h q[0];
// Measure ancilla: P(0) = (1 + Re(<psi|U|psi>)) / 2 = 0.5
measure q[0] -> c[0];

Tags

hadamard-test expectation-value quantum-simulation ancilla

References

License

MIT — part of the OpenQC Algorithm Catalog.

About

Estimate Re(⟨ψ|U|ψ⟩) for U=Z gate and |ψ⟩=|+⟩ using a single ancilla qubit.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors