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

qasm() mistranslate the operator QuantumCircuit.ecr #8086

Closed
weucode opened this issue May 19, 2022 · 3 comments · Fixed by #9953
Closed

qasm() mistranslate the operator QuantumCircuit.ecr #8086

weucode opened this issue May 19, 2022 · 3 comments · Fixed by #9953
Labels
bug Something isn't working help wanted community contributions welcome. For filters like http://github-help-wanted.com/

Comments

@weucode
Copy link

weucode commented May 19, 2022

Environment

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

What is happening?

The circuit shown below can be translated into OpenQASM successfully,but there exists two rzx gates.The one and only difference between two rzx gates is the parameter of rz gate,one is -pi/4,and another is pi/4.

Here is the error message.

OPENQASM 2.0;
include "qelib1.inc";
gate rzx(param0) q0,q1 { h q1; cx q0,q1; rz(-pi/4) q1; cx q0,q1; h q1; }
gate rzx(param0) q0,q1 { h q1; cx q0,q1; rz(pi/4) q1; cx q0,q1; h q1; }
gate ecr q0,q1 { rzx(pi/4) q0,q1; x q0; rzx(-pi/4) q0,q1; }
qreg q[2];
ecr q[0],q[1];
Traceback (most recent call last):
  File "20220518.py", line 8, in <module>
    another_circuit.from_qasm_str(qasm_str)
  File "D:\Anaconda3\lib\site-packages\qiskit\circuit\quantumcircuit.py", line 2334, in from_qasm_str
    return _circuit_from_qasm(qasm)
  File "D:\Anaconda3\lib\site-packages\qiskit\circuit\quantumcircuit.py", line 4667, in _circuit_from_qasm
    ast = qasm.parse()
  File "D:\Anaconda3\lib\site-packages\qiskit\qasm\qasm.py", line 53, in parse
    return qasm_p.parse(self._data)
  File "D:\Anaconda3\lib\site-packages\qiskit\qasm\qasmparser.py", line 1137, in parse
    self.parser.parse(data, lexer=self.lexer, debug=self.parse_deb)
  File "D:\Anaconda3\lib\site-packages\ply\yacc.py", line 333, in parse
    return self.parseopt_notrack(input, lexer, debug, tracking, tokenfunc)
  File "D:\Anaconda3\lib\site-packages\ply\yacc.py", line 1120, in parseopt_notrack
    p.callable(pslice)
  File "D:\Anaconda3\lib\site-packages\qiskit\qasm\qasmparser.py", line 612, in p_gate_decl_2
    self.update_symtab(program[0])
  File "D:\Anaconda3\lib\site-packages\qiskit\qasm\qasmparser.py", line 78, in update_symtab
    prev.file,
qiskit.qasm.exceptions.QasmError: "Duplicate declaration for gate 'rzx' at line 4, file .\nPrevious occurrence at line 3, file "

How can we reproduce the issue?

from qiskit import QuantumCircuit

circuit = QuantumCircuit(2)
circuit.ecr(0, 1)
qasm_str = circuit.qasm()
print(qasm_str)
another_circuit = QuantumCircuit(2)
another_circuit.from_qasm_str(qasm_str)
print(another_circuit)

What should happen?

An expected OpenQASM code about QuantumCircuit.ecr is something like this.

gate rzx(param0) q0,q1 { h q1; cx q0,q1; rz(param0) q1; cx q0,q1; h q1; }
gate ecr q0,q1 { rzx(pi/4) q0,q1; x q0; rzx(-pi/4) q0,q1; }

Any suggestions?

No response

@weucode weucode added the bug Something isn't working label May 19, 2022
@jakelishman
Copy link
Member

Thanks for the report. Sorry this is a bit bugged out - we have some problems with the OQ 2 exporter when dealing with gates that can take arbitrary parameters but are only used with exact angles, as you've seen.

I unfortunately can't promise that this will be a top priority for the internal team because we're busy with a lot of new features for OpenQASM 3.0 support, but we'd be happy to accept PRs from other people about this issue.

@jakelishman jakelishman added the help wanted community contributions welcome. For filters like http://github-help-wanted.com/ label May 23, 2022
pollyshaw added a commit to pollyshaw/qiskit-terra that referenced this issue Aug 13, 2022
pollyshaw added a commit to pollyshaw/qiskit-terra that referenced this issue Aug 13, 2022
@pollyshaw
Copy link
Contributor

I have a fix for this which is just to include RZX as an atomic gate in qelib1.inc. Is this a suitable approach?

@javabster javabster moved this to Waiting for maintainer response in Contributor Monitoring Aug 16, 2022
@jakelishman
Copy link
Member

For linking purposes, I gave the reason we can't add rzx to qelib1.inc here #8534 (review).

@HuangJunye HuangJunye moved this from Waiting for maintainer response to Tagged but unassigned in Contributor Monitoring Jan 12, 2023
@1ucian0 1ucian0 moved this from Tagged but unassigned to Not relevant in Contributor Monitoring Apr 12, 2023
@github-project-automation github-project-automation bot moved this from Not relevant to Done in Contributor Monitoring Apr 17, 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 help wanted community contributions welcome. For filters like http://github-help-wanted.com/
Projects
Status: Done
3 participants