Learn QUIPPER with Real Code Examples
Updated Nov 25, 2025
Code Sample Descriptions
1
Quipper Simple Quantum Circuit
import Quipper
main = print_simple Preview $ do
q1 <- qinit False
q2 <- qinit False
hadamard q1
controlled_not q1 q2
measure q1
measure q2
A minimal Quipper example defining a 2-qubit quantum circuit, applying Hadamard and CNOT gates.
2
Quipper Bell State Circuit
import Quipper
main = print_simple Preview $ do
q1 <- qinit False
q2 <- qinit False
hadamard q1
controlled_not q1 q2
measure q1
measure q2
Creates a Bell state using Hadamard and CNOT gates on 2 qubits.
3
Quipper GHZ State Circuit
import Quipper
main = print_simple Preview $ do
q1 <- qinit False
q2 <- qinit False
q3 <- qinit False
hadamard q1
controlled_not q1 q2
controlled_not q1 q3
measure q1
measure q2
measure q3
Generates a 3-qubit GHZ state.
4
Quipper Quantum Teleportation Circuit
import Quipper
main = print_simple Preview $ do
alice <- qinit False
bob <- qinit False
msg <- qinit True
hadamard alice
controlled_not alice bob
controlled_not msg alice
hadamard msg
c1 <- measure msg
c2 <- measure alice
if c2 then gate_X bob else return ()
if c1 then gate_Z bob else return ()
measure bob
Implements the quantum teleportation protocol with 3 qubits.
5
Quipper Toffoli Gate Circuit
import Quipper
main = print_simple Preview $ do
a <- qinit False
b <- qinit True
c <- qinit False
toffoli a b c
measure a
measure b
measure c
Applies a Toffoli (CCNOT) gate to 3 qubits.
6
Quipper Quantum Fourier Transform Circuit
import Quipper
qft3 q = do
hadamard (q!!0)
controlled_phase_shift (pi/2) (q!!1) (q!!0)
controlled_phase_shift (pi/4) (q!!2) (q!!0)
hadamard (q!!1)
controlled_phase_shift (pi/2) (q!!2) (q!!1)
hadamard (q!!2)
main = print_simple Preview $ do
qs <- qinit_list 3 False
qft3 qs
mapM_ measure qs
Implements a 3-qubit Quantum Fourier Transform.
7
Quipper Swap Gate Circuit
import Quipper
main = print_simple Preview $ do
a <- qinit False
b <- qinit True
swap a b
measure a
measure b
Swaps the states of two qubits.
8
Quipper Controlled-U Gate Circuit
import Quipper
main = print_simple Preview $ do
control <- qinit True
target <- qinit False
controlled control (gate_X target)
measure control
measure target
Applies a controlled unitary operation on a target qubit.
9
Quipper Phase Kickback Example
import Quipper
main = print_simple Preview $ do
control <- qinit True
target <- qinit False
controlled control (gate_RZ (pi/2) target)
measure control
measure target
Demonstrates phase kickback using a controlled phase gate.
10
Quipper Quantum Teleportation with Classical Communication
import Quipper
main = print_simple Preview $ do
alice <- qinit True
bob <- qinit False
msg <- qinit True
hadamard alice
controlled_not alice bob
controlled_not msg alice
hadamard msg
c1 <- measure msg
c2 <- measure alice
if c2 then gate_X bob else return ()
if c1 then gate_Z bob else return ()
measure bob
Shows teleportation with classical measurement results affecting operations.