Description
_visit_external_gate_operation calls _visit_basic_gate_operation(operation) "just for validation" (src/pyqasm/visitor.py:1351), and that call still runs _update_qubit_depth_for_gate over the decomposition. So a gate that is not decomposed because it is external still contributes the depth of the decomposition that was skipped.
The _recording_ext_gate_depth suppression on the neighbouring line guards only the custom-gate path, not the basic-gate path.
Reproduction
from pyqasm import loads
qasm = """OPENQASM 3.0;
include "stdgates.inc";
qubit[2] q;
crz(0.5) q[0], q[1];
"""
m = loads(qasm)
m.unroll(external_gates=["crz"])
print(m.depth()) # 12, but exactly one crz statement is emitted
Only gates with a decomposition rule are affected — unroll(external_gates=["ccx"]) reports 1 correctly, as does a body of rx + cz (2).
Why it matters more now
Before #341 this required opting in per gate name via external_gates. #341 routes every gate inside a #pragma braket verbatim box through the same path, so any Braket verbatim program containing a decomposable gate silently reports an inflated depth without the user naming anything:
#pragma braket verbatim
box { crz(0.5) q[0], q[1]; }
emits one instruction and reports depth == 12.
Suggested fix
Suppress depth recording around the validation-only _visit_basic_gate_operation call, the same way _recording_ext_gate_depth already does for the custom-gate path, and record the external gate's own depth instead.
Found in review of #341 (M1).
Description
_visit_external_gate_operationcalls_visit_basic_gate_operation(operation)"just for validation" (src/pyqasm/visitor.py:1351), and that call still runs_update_qubit_depth_for_gateover the decomposition. So a gate that is not decomposed because it is external still contributes the depth of the decomposition that was skipped.The
_recording_ext_gate_depthsuppression on the neighbouring line guards only the custom-gate path, not the basic-gate path.Reproduction
Only gates with a decomposition rule are affected —
unroll(external_gates=["ccx"])reports 1 correctly, as does a body ofrx+cz(2).Why it matters more now
Before #341 this required opting in per gate name via
external_gates. #341 routes every gate inside a#pragma braket verbatimbox through the same path, so any Braket verbatim program containing a decomposable gate silently reports an inflated depth without the user naming anything:emits one instruction and reports
depth == 12.Suggested fix
Suppress depth recording around the validation-only
_visit_basic_gate_operationcall, the same way_recording_ext_gate_depthalready does for the custom-gate path, and record the external gate's own depth instead.Found in review of #341 (M1).