random_circuit
and check the meaning of depth.from qiskit.circuit.random import random_circuit
circ_r1 = random_circuit(num_qubits=1, depth=5)
print('depth =', circ_r1.depth())
circ_r1.draw(output='mpl')
depth = 5
circ_r2 = random_circuit(num_qubits=5, depth=5)
print('depth =', circ_r2.depth())
circ_r2.draw(output='mpl')
depth = 5
circ_r3 = random_circuit(num_qubits=1, depth=10)
print('depth =', circ_r3.depth())
circ_r3.draw(output='mpl')
depth = 10
circ_r4 = random_circuit(num_qubits=5, depth=10)
print('depth =', circ_r4.depth())
circ_r4.draw(output='mpl')
depth = 10
It is difficult to intuitively understand the depth value when the number of qubits (num_qubits) is multiple, but if the number of qubits is set to 1, the number of depths will be the same as the number of gates.
`depth``` value is specified when the QV circuit is generated, but the meaning is different from the
`depth``` of a normal circuit.from qiskit.circuit.library import QuantumVolume
circ_q1 = QuantumVolume(num_qubits=5, depth=5)
print('depth =', circ_q1.depth())
circ_q1.draw('mpl')
depth = 1
The figure above shows the various gates combined into one.
If you measure `depth`
as it is, it will be "1" as it looks.
I'm not sure if this is the case, so check it by `` `decompose``` (decomposition = circuit expansion).
circ_q1_d1 = circ_q1.decompose()
print('depth =', circ_q1_d1.depth())
circ_q1_d1.draw('mpl')
depth = 5
Although it has been deployed, multiple gates are still being put together. It's a little difficult to understand, but since the gates in the second row (su4_83) and the gates in the third row (su4_767) operate on different qubits, they can be counted as "1" in the front.
The gif of the following document is easy to understand. Qiskit Document --circuit * Expand Quantum Circuit Properties and you will find a gif.
By the way, su4
is the gate of a 4x4 random unitary matrix.
From here, further decompose
to make it a normal gate unit.
circ_q1_d2 = circ_q1_d1.decompose()
print('depth =', circ_q1_d2.depth())
circ_q1_d2.draw('mpl')
depth = 35
It can be seen that su4 is composed of CNOT and U3 gates. Also, when the depth value for QV is 5, it can be seen that the depth value in the normal circuit is 35.
This time, reduce the number of qubits (5 → 3) and check.
circ_q2 = QuantumVolume(num_qubits=3, depth=5)
print('depth =', circ_q2.depth())
circ_q2.draw('mpl')
depth = 1
circ_q2_d1 = circ_q2.decompose()
print('depth =', circ_q2_d1.depth())
circ_q2_d1.draw('mpl')
depth = 5
circ_q2_d2 = circ_q2_d1.decompose()
print('depth =', circ_q2_d2.depth())
circ_q2_d2.draw('mpl')
depth = 35
It can be seen that when the depth value of QV is 5 regardless of the number of qubits, the depth value of the normal circuit is 35.
Further reduce the depth value (5 → 3) and check.
circ_q3 = QuantumVolume(num_qubits=3, depth=3)
print('depth =', circ_q3.depth())
circ_q3.draw('mpl')
depth = 1
circ_q3_d1 = circ_q3.decompose()
print('depth =', circ_q3_d1.depth())
circ_q3_d1.draw('mpl')
depth = 3
circ_q3_d2 = circ_q3_d1.decompose()
print('depth =', circ_q3_d2.depth())
circ_q3_d2.draw('mpl')
depth = 21
It can be seen that when the depth value of QV changes, the depth value of the normal circuit also changes.
QuantumVolume
, but as another generation method, qv_circuits .html) is used.import qiskit.ignis.verification.quantum_volume as qv
qubit_lists = [[0,1,3,5,7]]
ntrials = 50
qv_circs, qv_circs_nomeas = qv.qv_circuits(qubit_lists, ntrials)
There are two types of circuits to be generated: with measurement (`` qv_circs```) and without measurement (
`qv_circs_nomeas```).
First, check the circuit with measurement.
print("depth =", qv_circs[0][0].decompose().depth())
qv_circs[0][0].decompose().draw('mpl')
depth = 36
The depth value is 36. When the depth value of QV is 5, the depth value of the normal circuit is 35, but it is +1 due to the addition of the measurement operation.
Next, check the circuit without measurement.
print("depth =", qv_circs_nomeas[0][0].decompose().depth())
qv_circs_nomeas[0][0].decompose().draw('mpl')
depth = 36
The depth value is also 36, but since the last layer is a U3 gate with virtually no operation, it can be regarded as a depth value of 35.
Next, let's check the depth after converting the circuit without measurement with a transpiler.
import qiskit.compiler.transpile
qv_circs_nomeas[0] = qiskit.compiler.transpile(qv_circs_nomeas[0], basis_gates=['u1','u2','u3','cx'])
print("depth =", qv_circs_nomeas[0].depth())
qv_circs_nomeas[0].draw('mpl')
depth = 31
The depth value was 31. This is a natural result because the number of gates changed depending on the transpiler, but it can be seen that the depth value of the normal circuit is not directly related to the measurement of the QV value.
Reference
Recommended Posts