Currently Supported Constructs

The qbraid_qir.qasm3.qasm3_to_qir() converter supports the following OpenQASM 3 constructs:

1. Register Declarations

OpenQASM declarations of all forms qreg, qubit, bit, and creg are supported.

OPENQASM 3;

// qubit declaration
qubit q1;
qubit[2] q2;
qreg q3[3];
qubit[1] q4;

// bit declaration
bit c1;
bit[2] c2;
creg c3[3];
bit[1] c4;

2. Quantum Measurements

OpenQASM measurements are supported which involve single qubit measurement and full register measurements. Range based measurements are not supported currently.

OPENQASM 3;

qubit[2] q1;
qubit[5] q2;
qubit q3;

bit[2] c1;
bit c2;

// supported
c1 = measure q1;
measure q1 -> c1;
c2[0] = measure q3[0];

//ERROR: not supported
c1[0:2] = measure q1[0:2];

3. Quantum Reset

Resets are supported on declared quantum registers in all forms.

OPENQASM 3;

include "stdgates.inc";

// qubit declarations
qubit q1;
qubit[2] q2;
qreg q3[3];

// reset operations
reset q1;
reset q2[1];
reset q3[2];
reset q3[:2];

4. Quantum Gates

  • pyqir._native gates are supported along with support for U3 and U2 gates. The U[x] gates are defined in terms of existing rx and rz gates according to the decomposition present on the Qiskit UGate documentation and PhaseGate documentation.
  • Full set of the openqasm3 “stdgates.inc” gates are supported. These gates are decomposed with the help of the pyqir._native gate set and subsequently converted to QIR.

5. Quantum Barriers

Barriers are supported only if they are placed on ALL the qubits in the circuit. For example:

qubit q[2];

U(0.1, 0.2, 0.3) q[0];

// Barrier on all qubits
barrier q;

// ERROR: Barrier on a subset of qubits
barrier q[0];

6. Custom Quantum Gates

Gates defined by users are supported as long as they are defined in terms of pyqir._native gate set. Identifier mapping in gate parameter expressions is not supported at the moment. Example:

OPENQASM 3.0;
include "stdgates.inc";

// Supported
gate custom2(g) s {
  h s;
  rz(g) s;
}

// Supported
gate custom(a,b,c) p, q {
  custom2(a) q;
  h p;
  cx p,q;
  rx(a) q;
  ry(0.5/0.1) q;
}

qubit[2] q;
custom(2 + 3 - 1/5, 0.1, 0.3) q[0], q[1];

7. Simple Branching Statements

Since QIR supports branching on a measurement result, single bit branching statements are supported at the moment. General boolean expressions and support for branching on full registers will be added in future. For example:

OPENQASM 3;
include "stdgates.inc";
qubit[4] q;
bit[4] c;
h q;
measure q -> c;

// supported
if (c[0]) {
    x q[0];
    cx q[0], q[1];
}

if (c[1] == 1) {
    cx q[1], q[2];
}

if (!c[2]) {
    h q[2];
}

// ERROR: not supported
if (c == 8) {
    x q[0];
}
// ERROR: not supported
int[4] element;
if (element > 5) {
    y q[1];
}

8. Expressions

  • General expression evaluation involving literals and constants is supported.
  • Expressions involving constants and variables are fully supported.
  • Expressions with arrays are also supported (in global scopes).

9. Variables and Types

  • Scalar types int, uint, float, bool and bit with arbitrary sizes are supported.
  • array type is supported for int, uint, float, bool and bit.
  • complex and angle types are not supported yet.

10. Loops

for loops are supported at the moment with while loop support coming soon. For example:

11. Aliasing

  • Aliasing quantum registers is supported and can be used to refer to the same quantum register with different names.
  • Aliases are currently supported in global scope of the qasm3 program, with support for function scopes coming soon.

12. Subroutines

We support QASM3 subroutines in the QIR converter

13. Switch

Switch statements in QASM3 are supported in the QIR converter. These are defined according to the OpenQASM3 spec and support all the features mentioned in the specification.