Build
from quantuva import Circuit, Observable qc = Circuit(2) qc.h(0) qc.cx(0, 1) qc.measure_all() obs = Observable("Z(0) @ Z(1)") result = qc.run(shots=2048) print(result.expectation(obs))
Four worked examples, from a two-qubit Bell pair to a surface-code patch. Each one shows the circuit, the state or observable it produces, and the routine that builds it. Hover a gate to light it up.
from quantuva import Circuit, Observable qc = Circuit(2) qc.h(0) qc.cx(0, 1) qc.measure_all() obs = Observable("Z(0) @ Z(1)") result = qc.run(shots=2048) print(result.expectation(obs))
qc = Circuit(3) qc.h(0) qc.cx(0, 1) qc.cx(0, 2) qc.measure_all() # both stabilizers should be +1 for obs in ["Z(0) @ Z(1)", "Z(1) @ Z(2)"]: print(qc.run(2048).expectation(Observable(obs)))
qc = Circuit(4) for i in range(4): qc.h(i) for j in range(i + 1, 4): qc.cp(2 * math.pi / 2**(j - i + 1), i, j) # un-reverse the bit order qc.swap(0, 3) qc.swap(1, 2)
# the surface code is geometry, not a gate list. # data qubits sit on vertices; ancilla qubits sit # inside each face and read out a stabilizer. from quantuva.codes import SurfaceCode code = SurfaceCode(d=3) syndrome = code.measure_round()