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

OpenQASM3 exporter emits variables with reserved keywords #7742

Closed
taalexander opened this issue Mar 6, 2022 · 1 comment · Fixed by #7744
Closed

OpenQASM3 exporter emits variables with reserved keywords #7742

taalexander opened this issue Mar 6, 2022 · 1 comment · Fixed by #7744
Assignees
Labels
bug Something isn't working mod: qasm3 Related to OpenQASM 3 import or export

Comments

@taalexander
Copy link
Contributor

Environment

  • Qiskit Terra version: 0.19.2
  • Python version: 3.8
  • Operating system: OSX

What is happening?

When dumping QASM3 from a Qiskit circuit the emitted QASM3 has variables with names that are reserved keywords.

How can we reproduce the issue?

from qiskit import IBMQ, transpile, qasm3
from qiskit_experiments.library import QuantumVolume

from qiskit.test.mock import FakeMontreal

qv_exp = QuantumVolume([0, 1], seed=42)
circuits = qv_exp.circuits()

backend = FakeMontreal()

def dump_qasm3(circuit, backend=backend):
    return qasm3.Exporter(includes=[], basis_gates=backend.configuration().basis_gates).dumps(circuit)

transpiled_circuits = transpile(circuits, backend, optimization_level=0)
print(dump_qasm3(transpiled_circuits[0]))

Emits:

OPENQASM 3;
bit[2] measure;
rz(-0.527043787493904) $0;
sx $0;
rz(5.16854203223675) $0;
sx $0;
rz(7.52041849263069) $0;
rz(2.52883547684609) $1;
sx $1;
rz(4.18263287241389) $1;
sx $1;
rz(11.4206034322753) $1;
cx $0, $1;
rz(pi/2) $0;
sx $0;
rz(3.83403185518176) $0;
sx $0;
rz(5*pi/2) $0;
rz(-3.13722964498385) $1;
sx $1;
rz(3.43607384014569) $1;
sx $1;
rz(7.84942236436758) $1;
cx $0, $1;
rz(pi/2) $0;
sx $0;
rz(3.15129722109744) $0;
sx $0;
rz(2*pi) $0;
rz(-pi) $1;
sx $1;
rz(4.71106568778747) $1;
sx $1;
rz(10.9942509926498) $1;
cx $0, $1;
rz(0.0407864518524126) $0;
sx $0;
rz(3.68646663680408) $0;
sx $0;
rz(8.261303299549) $0;
rz(0.384886550311654) $0;
sx $0;
rz(4.72101136719892) $0;
sx $0;
rz(7.05118934560937) $0;
rz(0.360649613151623) $1;
sx $1;
rz(4.92286155451527) $1;
sx $1;
rz(11.7465986327618) $1;
rz(-0.879779034806911) $1;
sx $1;
rz(5.92954645622555) $1;
sx $1;
rz(7.17120533229796) $1;
cx $0, $1;
rz(pi/2) $0;
sx $0;
rz(4.06066473777189) $0;
sx $0;
rz(5*pi/2) $0;
rz(-3.1391797270208) $1;
sx $1;
rz(3.64322156481995) $1;
sx $1;
rz(7.85122966784221) $1;
cx $0, $1;
rz(-pi/2) $0;
sx $0;
rz(3.7166355179822) $0;
sx $0;
rz(3*pi) $0;
rz(-pi) $1;
sx $1;
rz(4.71106568778747) $1;
sx $1;
rz(10.9942509926498) $1;
cx $0, $1;
rz(-1.47560665166994) $0;
sx $0;
rz(4.18505473328482) $0;
sx $0;
rz(9.47043569736961) $0;
rz(0.398413507779781) $1;
sx $1;
rz(4.1804199287629) $1;
sx $1;
rz(12.3633552711276) $1;
barrier $0, $1;
measure[0] = measure $0;
measure[1] = measure $1;

Note the bit[2] measure; declaration which is invalid.

What should happen?

The QASM3 exporter should mangle the names of reserved keywords for classical/qubit registers with names that collied.

Any suggestions?

No response

@jakelishman
Copy link
Member

Good point, thanks for the report. I've pushed up a simple symbol table add-on to the exporter in #7744 that also handles generating new names when there are clashes. There's still a lot of work to be done in the QASM 3 exporter before 0.20 (see also #7136 and #7335 for example), and when I'm back from writing up my thesis we'll get a bit more on top of getting these things done.

@1ucian0 1ucian0 added the mod: qasm2 Relating to OpenQASM 2 import or export label Mar 14, 2022
@jakelishman jakelishman added mod: qasm3 Related to OpenQASM 3 import or export and removed mod: qasm2 Relating to OpenQASM 2 import or export labels Jun 15, 2023
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