Building circuits¶
Build a circuit gate by gate with QuantumCircuit, then run it on any
simulation method.
from maestro.circuits import QuantumCircuit
qc = QuantumCircuit()
qc.h(0)
qc.cx(0, 1)
qc.rz(1, 0.25)
qc.measure([(0, 0), (1, 1)]) # (qubit, classical bit) pairs
print("qubits:", qc.num_qubits)
print(qc.execute(shots=1000)["counts"])
qubits: 2
{'00': 513, '11': 487}
There is no register size to declare. A circuit grows to cover every qubit you use, and qubits and classical bits are numbered from 0. To sample the circuit or read its counts, see Sampling and shots. To compute expectation values instead, see Expectation values and parameter sweeps.
Available gates¶
Angles are in radians.
Gate |
Method |
Parameters |
|---|---|---|
Pauli-X |
|
— |
Pauli-Y |
|
— |
Pauli-Z |
|
— |
Hadamard |
|
— |
S |
|
— |
S† |
|
— |
T |
|
— |
T† |
|
— |
√X |
|
— |
√X† |
|
— |
K |
|
— |
Phase |
|
λ |
Rx |
|
θ |
Ry |
|
θ |
Rz |
|
θ |
U |
|
3 Euler angles |
CNOT |
|
— |
CY |
|
— |
CZ |
|
— |
CH |
|
— |
CSX |
|
— |
CSX† |
|
— |
SWAP |
|
— |
CP |
|
λ |
CRx |
|
θ |
CRy |
|
θ |
CRz |
|
θ |
CU |
|
4 angles |
Toffoli |
|
— |
Fredkin |
|
— |
Delay |
|
duration in seconds |
The docs build applies every gate in this table with the listed arguments, so the table stays in step with the package:
applied 31 gate types on 3 qubits
Delays and idle time¶
qc.delay(qubit, duration) schedules idle time on a qubit, in seconds:
idle = QuantumCircuit()
idle.h(0)
idle.delay(0, 50e-6) # 50 microseconds
idle.h(0)
idle.measure([(0, 0)])
print(idle.execute(shots=1000)["counts"])
{'0': 1000}
Without noise, a delay does nothing. With a NoiseModel that sets idle noise,
it applies T1/T2 relaxation, Ornstein-Uhlenbeck phase drift and coherent
detuning for the duration; see Idle noise during delays.
From OpenQASM¶
To run an existing OpenQASM 2.0 program, pass the string to
maestro.simple_execute or maestro.simple_estimate; see
Run an OpenQASM string. OpenQASM is also the way to write classical feed-forward
(if (c==1) x q[1];), which QuantumCircuit has no method for; see
Mid-circuit measurement and reset.