Skip to content

QASM 2 and 3 exporters do not handle parameterised gates correctly #7335

@jakelishman

Description

@jakelishman

Environment

  • Qiskit Terra version: 0.19.dev @ 2c402dd
  • Python version: any
  • Operating system: any

What is happening?

The QASM3 exporter (and the QASM2 exporter) does not handle arbitrary parameterised gates correctly. It emits a gate definition which includes parameters in the signature, but hardcodes them in the body to the first instance of the gate it found. This is because there's currently no way in Terra to get from a gate with its parameters assigned back to the fully parameterised version.

How can we reproduce the issue?

In [1]: import qiskit.qasm3
   ...: qc = qiskit.QuantumCircuit(2, 2)
   ...: qc.rzx(0.2, 0, 1)
   ...: qc.rzx(0.3, 0, 1)
   ...:
   ...: print(qiskit.qasm3.dumps(qc))
OPENQASM 3;
include "stdgates.inc";
gate rzx(_gate_p_0) _gate_q_0, _gate_q_1 {
  h _gate_q_1;
  cx _gate_q_0, _gate_q_1;
  rz(0.2) _gate_q_1;
  cx _gate_q_0, _gate_q_1;
  h _gate_q_1;
}
bit[2] c;
qubit[2] _all_qubits;
let q = _all_qubits[0:1];
rzx(0.2) q[0], q[1];
rzx(0.3) q[0], q[1];

The two rzx calls have different parameters, but the parameter is hardcoded to 0.2 in the actual definition.

What should happen?

A full fix of this issue will have the rz line in the rzx gate definition use the gate parameter.

Any suggestions?

As a temporary measure before the 0.19 release, we can hack the exporter to always output a new declaration for each instance of every gate that is not in the include files. This is pretty awful, and the output QASM won't correctly represent the structure of the program with re-used gates, but it will at least produce the correct behaviour.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingmod: qasm2Relating to OpenQASM 2 import or exportmod: qasm3Related to OpenQASM 3 import or export

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions