-
Notifications
You must be signed in to change notification settings - Fork 19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
OpenQASM 3 circuit depth function #295
Comments
@ryanhill1 , I found that the In [6]: from qbraid.interface.qbraid_qasm.tools import qasm_depth
In [7]: test_str_2 = """
...: OPENQASM 2.0;
...: include "qelib1.inc";
...: qreg q[2];
...: qreg q2[4];
...: creg c[2];
...: cx q[0], q[1];
...: cx q[0], q2[2];
...: h q[1];
...: z q[0];
...: """
In [8]: qasm_depth(test_str_2)
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
Cell In[8], line 1
----> 1 qasm_depth(test_str_2)
File ~/Desktop/college/quantum/Unitary Fund/Unitary-Hack/qBraid/qbraid/interface/qbraid_qasm/tools.py:73, in qasm_depth(qasmstr)
70 matches = set(map(int, re.findall(r"q\[(\d+)\]", s)))
72 # Calculate max depth among the qubits in the current line.
---> 73 max_depth = max(counts_dict[f"q[{i}]"] for i in matches)
75 # Update depths for all qubits in the current line.
76 for i in matches:
ValueError: max() arg is an empty sequence I feel some of the assumptions used in
|
@TheGupta2012 Thank's for pointing this out!
But there may be other edge cases where qubit names are mentioned that are not currently excluded. So we can definitely look into that more as well. |
@TheGupta2012 Following up on this, I added a new qasm3 depth test that uses an alternate qubit syntax:
It currently fails, so is being skipped. But all OpenQASM 3 generated from Amazon Braket circuits (as of v1.54.1) use this new qubit syntax. So they are a good test case. E.g. from braket.circuits.serialization import IRType
from qbraid.interface import random_circuit
from qbraid.interface.qbraid_qasm.tools import qasm3_depth
circuit = random_circuit("braket")
qasm_str = circuit.to_ir(IRType.OPENQASM).source
assert qasm3_depth(qasm_str) == circuit.depth |
@TheGupta2012 I've updated the |
Thanks @ryanhill1 for the updates! I was working on the contiguous qasm issue and will pick this up now. |
Write function that takes in OpenQASM 3 string as argument and returns the int circuit depth.
Similar to
qasm_depth()
but for qasm3 instead of qasm2, and which does not use any external libraries.The text was updated successfully, but these errors were encountered: