def diffusion(qubits):
with around([H, X], qubits):
ctrl(qubits[1:], Z, qubits[0])
def qft(qubits, invert = True):
if len(qubits) == 1:
H(qubits)
else:
*head, tail = qubits
H(tail)
for i, ctrl_qubit in enumerate(reversed(head)):
with control(ctrl_qubit):
phase(pi / 2**(i + 1), tail)
qft(head, invert=False)
if invert:
size = len(qubits)
for i in range(size // 2):
swap(qubits[i], qubits[size - i - 1])
IQFT = adj(QFT)
with inverse():
QFT(qubits)
with control()
: Open a controlled-scopectrl()
: Add control-qubits to a Callablewith inverse()
: Open a inverse scopeadj()
: Inverse of a Callablewith around()
: Apply a, b, c = H(quant(3))
m_ab = measure(a+b)
m_c = measure(c)
print(m_ab.value, m_c.value)
>>> q = H(quant(2))
>>> d = dump(q)
>>> print(d.show())
|00⟩ (25.00%)
0.500000 ≅ 1/√4
|01⟩ (25.00%)
0.500000 ≅ 1/√4
|10⟩ (25.00%)
0.500000 ≅ 1/√4
|11⟩ (25.00%)
0.500000 ≅ 1/√4
quant
: Qubit reference listfuture
: Measurement result (from measure()
)dump
: Quantum state