Skip to content

Qiskit’s OpenQASM 3 exporter: not correctly escaping the names of custom gates it’s defining #11761

@felicitysplatt

Description

@felicitysplatt

Environment

  • Qiskit version:
  • Python version:
  • Operating system:

What is happening?

I submit a job to the IBM Platform, a max cut using QAOA, for very simple circuits (less than 10 nodes, few edges). This will produce a parameterized circuit.
The OpenQASM 3 string created cannot be drawn - there's something wrong with the string, likely not correctly escaping the names of custom gates it's defining.

Jake Lishman has requested I submit this bug report.

Here's an example of a string it produces:

"""
OPENQASM 3;
include "stdgates.inc";
input float[64] β_0;
input float[64] γ_0;
gate exp(it IZ)(γ_0) _gate_q_0, _gate_q_1 {
rz(5.0*γ_0) _gate_q_0;
}
gate rzz_140434630696240(γ_0) _gate_q_0, _gate_q_1 {
cx _gate_q_0, _gate_q_1;
rz(1.0*γ_0) _gate_q_1;
cx _gate_q_0, _gate_q_1;
}
gate exp(it ZZ)(γ_0) _gate_q_0, _gate_q_1 {
rzz_140434630696240(1.0*γ_0) _gate_q_0, _gate_q_1;
}
gate PauliEvolution(γ_0) _gate_q_0, _gate_q_1 {
exp(it IZ)(γ_0) _gate_q_0, _gate_q_1;
exp(it ZZ)(γ_0) _gate_q_0, _gate_q_1;
}
bit[2] meas;
qubit[2] q;
h q[0];
h q[1];
PauliEvolution(γ_0) q[0], q[1];
PauliEvolution(β_0) q[0], q[1];
barrier q[0], q[1];
meas[0] = measure q[0];
meas[1] = measure q[1];
"""

How can we reproduce the issue?

This code will not run for you as it depends on some custom functions and config files.

However, the problem should be reproducible from the concept - we are creating a really straightforward QAOA / maxcut problem.

from docplex.mp.model import Model
from qiskit_optimization.algorithms import MinimumEigenOptimizer
from qiskit_optimization.translators import from_docplex_mp
from qiskit_ibm_runtime import QiskitRuntimeService, Session, Sampler, Options
from qiskit_algorithms import QAOA
from qiskit_algorithms.optimizers import COBYLA, SPSA
from qiskit_aer.noise import NoiseModel

from quantum_computing_for_energy_sector.settings import load_config
from quantum_computing_for_energy_sector.utils import root_path, read_args, show_graph
from quantum_computing_for_energy_sector.logging_config import logger

token = load_config(root_path(".venv", "IBMQ-API-token.yml"))
args = read_args()

device_config = load_config(args.device_conf_file)
logger.info(f"Device config: {device_config}")

service = QiskitRuntimeService(
    channel = "ibm_quantum",
    token = token["IBM_Quantum_API_key"]
)

if device_config["device"] == "Simulator":
    backend = service.backend(device_config["simulator"])

backend = service.least_busy(operational=True, simulator=False)
graph_config = load_config(args.graph_conf_file)

number_of_nodes = len(graph_config["nodes"])
edges = [(edge['first_node'], edge['second_node'], edge['weight']) for edge in graph_config["edges"]]

model = Model()

x = model.binary_var_list(number_of_nodes)
model.maximize(model.sum(w * x[i] * (1 - x[j]) + w * (1 - x[i]) * x[j] for i, j, w in edges))

model.add(x[0] == 1)

problem = from_docplex_mp(model)

optimizer = COBYLA(maxiter = device_config["maxiter"])

session = Session(backend = backend)
options = Options()

sampler = Sampler(session = session, options = options)

qaoa = QAOA(sampler=sampler, optimizer=optimizer)
algorithm = MinimumEigenOptimizer(qaoa)
result = algorithm.solve(problem)

What should happen?

The code above will run - that is not the problem.

The problem is the OpenQASM 3 string that qiskit generates on the IBM Quantum Platform - this string has a bug in it. A circuit cannot be drawn from that string.

Any suggestions?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

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

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions