Skip to content

[BUG] Depth mismatch with QASM3 gates #201

@TheGupta2012

Description

@TheGupta2012

Environment

  • PyQASM version: 0.3.2
  • Python version: 3.11.6
  • Operating system: MacOS 15.5

What happened?

Depth calculation for the following program is inconsistent -

In [1]: import pyqasm

In [2]: qasm_str = """
   ...: OPENQASM 3.0;
   ...: include "stdgates.inc";
   ...: qreg q[3];
   ...: creg c[3];
   ...: 
   ...: crx (0.1) q[0], q[1];
   ...: """

In [3]: mod = pyqasm.loads(qasm_str)

In [4]: mod.unroll()

In [5]: mod
Out[5]: <pyqasm.modules.qasm3.Qasm3Module at 0x1042d7210>

In [6]: print(mod)
OPENQASM 3.0;
include "stdgates.inc";
qubit[3] q;
bit[3] c;
rz(1.5707963267948966) q[1];
rx(1.5707963267948966) q[1];
rz(3.141592653589793) q[1];
rx(1.5707963267948966) q[1];
rz(3.141592653589793) q[1];
cx q[0], q[1];
rz(0) q[1];
rx(1.5707963267948966) q[1];
rz(3.0915926535897933) q[1];
rx(1.5707963267948966) q[1];
rz(3.141592653589793) q[1];
cx q[0], q[1];
rz(0) q[1];
rx(1.5707963267948966) q[1];
rz(3.191592653589793) q[1];
rx(1.5707963267948966) q[1];
rz(1.5707963267948966) q[1];


In [7]: mod.depth()
Out[7]: 1

In [8]: unrolled_qasm = pyqasm.dumps(mod)

In [9]: unrolled_mod = pyqasm.loads(unrolled_qasm)

In [10]: unrolled_mod.depth()
Out[10]: 17

Suggestions (Optional)

The depth calculation should be exactly the same for the module before and after unrolling. The problem seems to be in the way we update the depths inside the _visit_basic_gate_operation method. Looks like we treat crx (and other decomposable gates) as an atomic gate rather than considering the complete decomposition during depth calculation

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingqasm3Related to openqasm3

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions