You can obtain information about a Quantum Circuit by using various methods and attributes of a Quantum Circuit. In this chapter of the Qiskit tutorial, you will learn about obtaining information about a Quantum Circuit by using various methods and attributes.
Width of a Quantum Circuit
The width of a Quantum Circuit is the sum of number of Qubits and number of classical bits in a Quantum Circuit. For example, in a Quantum Circuit with 5 Qubits and 3 bits, the width of the Quantum Circuit will be 8, the sum of Qubits- 5 and bits- 3.
The width of a Quantum Circuit is also defined as the total number of wires in the diagram of the circuit. For example, in the below circuit, there are a total of 6 wires, 3 corresponding to 3 Qubits and other 3 corresponding to 3 bits. Hence the total width of the Quantum Circuit is 6.
The width of a Quantum Circuit can be known by calling the width()
method on the Quantum Circuit.
Example
In this example, we will consider that qc
is the Quantum Circuit that is shown above.
# Storing width of Quantum Circuit in depth
width = qc.width()
print(width)
# Outputs- 6
Size of a Quantum Circuit
The size of a Quantum Circuit is defined as the total number of gates(and also measurements) that are applied to the Quantum Circuit. For example, for the below circuit, a total of 2 gates and 1 measurement is performed on the first Qubit. Similarly, for second and third Qubit, a total of 3 gates and 1 gate is applied along with 1 measurement being performed on both the Qubits. This add to a total of 9. Hence the size of the Quantum Circuit is 9.
The size of a Quantum Circuit can be known by calling the size()
method on the Quantum Circuit.
Example
In this example, we will consider that qc
is the Quantum Circuit that is shown above.
# Storing size of Quantum Circuit in size
size = qc.size()
print(size)
# Outputs- 9
Depth of a Quantum Circuit
The depth of a Quantum Circuit is defined as the highest number of gates(including measurements) being applied to any Qubit in the Quantum Circuit. For example, in the circuit below, a total of 3 operations are applied to the first Qubit(2 Gates and 1 measurement). Similarly, the number of operations being applied to the second and third Qubits are 4 and 2 respectively. Hence, the depth of the Quantum Circuit is 4- the maximum among 3, 4, and 2.
The depth of a Quantum Circuit can be known by calling the depth()
method on the Quantum Circuit.
Note– The depth() function does not take into consideration the barrier operation.
Example
In this example, we will consider that qc
is the Quantum Circuit that is shown above.
# Storing depth of Quantum Circuit in depth
depth = qc.depth()
print(depth)
# Outputs- 4
Number of Classical Bits
The number of classical bits in a Quantum Circuit can be known by using the num_clbits
attribute of the Quantum Circuit.
Example
print(qc.num_clbits)
# Outputs- 3
Number of Qubits
The number of Qubits in a Quantum Circuit can be known by using the num_qubits
attribute of the Quantum Circuit.
Example
print(qc.num_qubits)
# Outputs- 3
Global Phase
The Global Phase of the Quantum Circuit can be known by using the global_phase
attribute of the Quantum Circuit.
Example
print(qc.global_phase)
# Outputs- 0
Operations on Quantum Circuit
The list of the operations that are being performed on a Quantum Circuit can be known by using the data
attribute of the Quantum Circuit.
Example
print(qc.data)
The output for this will be a list of all the operations that are being performed on the Quantum Circuit-
[(<qiskit.circuit.library.standard_gates.h.HGate object at 0x7fb723cfc5d0>, [Qubit(QuantumRegister(3, 'q'), 0)], []), (<qiskit.circuit.library.standard_gates.s.SGate object at 0x7fb723cfc690>, [Qubit(QuantumRegister(3, 'q'), 1)], []), (<qiskit.circuit.library.standard_gates.x.XGate object at 0x7fb726f05350>, [Qubit(QuantumRegister(3, 'q'), 2)], []), (<qiskit.circuit.library.standard_gates.t.TGate object at 0x7fb72635dc90>, [Qubit(QuantumRegister(3, 'q'), 0)], []), (<qiskit.circuit.library.standard_gates.z.ZGate object at 0x7fb723af0710>, [Qubit(QuantumRegister(3, 'q'), 1)], []), (<qiskit.circuit.library.standard_gates.s.SGate object at 0x7fb7278b7750>, [Qubit(QuantumRegister(3, 'q'), 1)], []), (<qiskit.circuit.measure.Measure object at 0x7fb7278b75d0>, [Qubit(QuantumRegister(3, 'q'), 0)], [Clbit(ClassicalRegister(3, 'c'), 0)]), (<qiskit.circuit.measure.Measure object at 0x7fb725c163d0>, [Qubit(QuantumRegister(3, 'q'), 1)], [Clbit(ClassicalRegister(3, 'c'), 1)]), (<qiskit.circuit.measure.Measure object at 0x7fb727ba6c50>, [Qubit(QuantumRegister(3, 'q'), 2)], [Clbit(ClassicalRegister(3, 'c'), 2)])]
Information on Bits
Information on Bits and the order in which they were added can be obtained by using the clbits
attribute of the Quantum Circuit.
Example
print(qc.clbits)
The output of this will be-
[Clbit(ClassicalRegister(3, 'c'), 0),
Clbit(ClassicalRegister(3, 'c'), 1),
Clbit(ClassicalRegister(3, 'c'), 2)]
Information on Qubits
Information on Qubits and the order in which they were added can be obtained by using the qubits
attribute of the Quantum Circuit.
Example
print(qc.qubits)
The output of this will be-
[Qubit(QuantumRegister(3, 'q'), 0),
Qubit(QuantumRegister(3, 'q'), 1),
Qubit(QuantumRegister(3, 'q'), 2)]