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

behaviour of qasmparser is unclear when parse is called multiple times #148

Closed
dlyongemallo opened this issue Sep 6, 2023 · 1 comment · Fixed by #150
Closed

behaviour of qasmparser is unclear when parse is called multiple times #148

dlyongemallo opened this issue Sep 6, 2023 · 1 comment · Fixed by #150

Comments

@dlyongemallo
Copy link
Contributor

It's unclear how to use qasmparser if there are multiple strings or circuits to be parsed. In particular, parse has behaviour which is surprising to me. I expect each call to basically be independent and return a circuit based on the input string. What actually happens is parse builds on top of the circuit processed in previous calls.

In particular, it looks to me like this line is intended to clear the previous state, but is bugged because gates rather than self.gates is used.

Repro case:

from pyzx.circuit.qasmparser import QASMParser
s = """
OPENQASM 2;
include "qelib1.inc";
qreg q[1];
h q[0];
"""
p = QASMParser()
c1 = p.parse(s)
c2 = p.parse(s)
print(c1)
print(c1.gates)
print(c2)
print(c2.gates)

Expected output:

Circuit(1 qubits, 0 bits, 1 gates)
[HAD(0)]
Circuit(1 qubits, 0 bits, 1 gates)
[HAD(0)]

Actual output:

Circuit(1 qubits, 0 bits, 2 gates)
[HAD(0), HAD(1)]
Circuit(2 qubits, 0 bits, 2 gates)
[HAD(0), HAD(1)]

In particular, it is surprising that a subsequent call to parse alters the value of c1.

@jvdwetering
Copy link
Collaborator

Yes, I agree that that is weird and unexpected. I would call that a bug.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants