Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
felicitysplatt opened this issue Feb 9, 2024 · 2 comments · Fixed by #12776
Labels
bug Something isn't working mod: qasm3 Related to OpenQASM 3 import or export
Milestone

Comments

@felicitysplatt
Copy link

felicitysplatt commented Feb 9, 2024

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

@felicitysplatt felicitysplatt added the bug Something isn't working label Feb 9, 2024
@jakelishman
Copy link
Member

Thanks for the report. We have logic that does this in the OpenQASM 2 exporter, so I think we must have forgotten to port over similar behaviour to the OpenQASM 3 exporter.

@jakelishman jakelishman added the mod: qasm3 Related to OpenQASM 3 import or export label Feb 9, 2024
@jakelishman jakelishman added this to the 1.1.0 milestone Feb 9, 2024
@felicitysplatt felicitysplatt changed the title Qiskit’s OpenQASM 3 exporter:s not correctly escaping the names of custom gates it’s defining Qiskit’s OpenQASM 3 exporter: not correctly escaping the names of custom gates it’s defining Feb 10, 2024
@jakelishman jakelishman modified the milestones: 1.1.0, 1.1.1 May 1, 2024
@ElePT ElePT modified the milestones: 1.1.1, 1.2.0 Jun 18, 2024
@jakelishman
Copy link
Member

I believe this should be fixed by #12776, but since I can't generate the exact initial circuit to check, I'm not absolutely 100% sure. I'll mark it as "being fixed", and if I'm wrong, feel free to re-open (if it closes).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working mod: qasm3 Related to OpenQASM 3 import or export
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants