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

A translation about initialize from qiskit in OpenQASM cannot translate back into qiskit #8048

Open
weucode opened this issue May 11, 2022 · 2 comments
Labels
bug Something isn't working mod: qasm2 Relating to OpenQASM 2 import or export

Comments

@weucode
Copy link

weucode commented May 11, 2022

Environment

  • Qiskit Terra version: 0.36.1
  • Python version: 3.7.4
  • Operating system: Windows

What is happening?

After got the OpenQASM code about initialize operator, it will fail to use from_qasm_file/from_qasm_str to translate it back into qiskit code.
Part of error message is shown below:

File "D:\Program Files\pycharm_project\qiskit-benchmarks\venv\lib\site-packages\ply\yacc.py", line 1120, in parseopt_notrack
p.callable(pslice)
File "D:\Program Files\pycharm_project\qiskit-benchmarks\venv\lib\site-packages\qiskit\qasm\qasmparser.py", line 400, in p_id_e
raise QasmError("Expected an ID, received '" + str(program[1].value) + "'")
qiskit.qasm.exceptions.QasmError: "Expected an ID, received 'reset'"

How can we reproduce the issue?

from qiskit import QuantumCircuit

circuit = QuantumCircuit(1)
circuit.initialize('0', circuit.qubits)
qasm_str = circuit.qasm()
print(qasm_str)
same_circuit = QuantumCircuit(1)
same_circuit = same_circuit.from_qasm_str(qasm_str)
print(same_circuit)

What should happen?

Run successfully.

Any suggestions?

No response

@weucode weucode added the bug Something isn't working label May 11, 2022
@HuangJunye HuangJunye added the mod: qasm2 Relating to OpenQASM 2 import or export label May 11, 2022
@jakelishman
Copy link
Member

Sorry for the slow reply! This is very related to #7351 and the reasons in #7750 (comment). The gist is that initialize is a non-unitary instruction (it includes a reset), and so we can't actually write it as a valid OpenQASM 2 gate. It's a bug that the exporter here puts a reset instruction within a gate - it should probably just fail at that point.

There won't be a way to round-trip a circuit with initialize in it from QASM 2 even if we do some tricks in the export, because the language just can't represent that instruction without it being inlined into the circuit, sorry. We could do some tricks with the (unitary) StatePreparation class, but extending the OpenQASM 2 support is a low priority for us right now, sorry.

@harshitta-gandhi
Copy link

harshitta-gandhi commented May 30, 2023

Hey, @jakelishman,
I too am facing the same issue while converting a pennylane circuit to qasm. What do you think, in the circuit, is causing this error to prop up?
And what is the probable timeline for this bug to be resolved?

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: qasm2 Relating to OpenQASM 2 import or export
Projects
None yet
Development

No branches or pull requests

4 participants