Here’s a guide to measuring the depth and 2-qubit gate count for your QASM submissions.
Step 1: Import QASM code into Qiskit
If not previously installed, install Qiskit.
Import QASM as a string or file.
String:
from qiskit import QuantumCircuit
# Paste QASM contents between three sets of quotes
qasm_str =
"""OPENQASM 2.0;
include "qelib1.inc";
qreg q[2];
creg c[2];
h q[0];
cx q[0],q[1];
measure q -> c;"""
qc = QuantumCircuit.from_qasm_str(qasm_str)
File:
from qiskit import QuantumCircuit
qc = QuantumCircuit.from_qasm_file("/path/to/file.qasm")
Step 2: (OPTIONAL) Decompose Circuit to Basis Gates As Needed
Decompose any functional blocks or multi-qubit gates into single- and two-qubit basis gates.
qc = qc.decompose()
qc = qc.decompose()
# repeat as needed, checking with draw() to see circuit status
qc.draw()
Repeat as needed until circuit fully decomposed.
Step 3: Measure Depth and 2-Qubit Gates
print(qc.depth())
print(qc.count_ops())
For the following result, submit a depth of 153 and a two-qubit gate count of 130.
153
OrderedDict([('cx', 130), ('u1', 112), ('u2', 32), ('u', 10), ('measure', 9)])