Skip to content

Commit a7d9c04

Browse files
committed
Add reno
1 parent 5340c68 commit a7d9c04

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
---
2+
features_qasm:
3+
- |
4+
Added partial support for ``defcal`` symbols in the OpenQASM3 exporter. This enables downstream packages to export custom instructions
5+
that operate on both quantum and classical bits using :meth:`qiskit.qasm3.dumps`.
6+
Users can now define custom instructions (e.g., a ``CustomMeasure`` that acts on a qubit and returns a classical bit) and specify their behavior using
7+
:class:`.DefcalInstruction`. These defcals are passed to the exporter via the ``implicit_defcals`` argument in :meth:`qiskit.qasm3.dumps`.
8+
9+
For example::
10+
11+
from qiskit.circuit import Instruction, QuantumCircuit
12+
from qiskit.qasm3 import dumps
13+
from qiskit.qasm3.exporter import DefcalInstruction, types
14+
15+
custom_measure = Instruction("measure_2", 1, 1, [])
16+
qc = QuantumCircuit(1, 1)
17+
qc.h(0)
18+
qc.append(custom_measure, [0], [0])
19+
qc.measure(0, 0)
20+
21+
defcals = {
22+
"measure_2": DefcalInstruction("measure_2", 0, 1, types.Bool()),
23+
}
24+
25+
out_qasm = dumps(qc, implicit_defcals=defcals)
26+
print(out_qasm)
27+
28+
Would output the following valid OpenQASM3 string::
29+
30+
OPENQASM 3.0;
31+
bit[1] c;
32+
qubit[1] q;
33+
h q[0];
34+
c[0] = measure_2 q[0];
35+
c[0] = measure q[0];
36+
37+
This approach assumes that the grammar definition for the defcal is provided externally (e.g., in a header file),
38+
although such a file is not strictly required for the exporter to function.
39+
40+

0 commit comments

Comments
 (0)