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

qc.cx(0, 1, ctrl_state=0) fails - AerError: 'unknown instruction: cx_o0' #2127

Closed
zlatko-minev opened this issue May 8, 2024 · 4 comments · Fixed by #2148
Closed

qc.cx(0, 1, ctrl_state=0) fails - AerError: 'unknown instruction: cx_o0' #2127

zlatko-minev opened this issue May 8, 2024 · 4 comments · Fixed by #2148
Labels
bug Something isn't working

Comments

@zlatko-minev
Copy link

Informations

  • Qiskit Aer version: 0.14.1
  • Python version: 3.11
  • Operating system: Mac

What is the current behavior?

New version of AER does not recognize cx gate with control state = 0, while it did recognize cnot with control state = 0, which was not removed in favor of cx in 0.1.

Steps to reproduce the problem

qc = QuantumCircuit(2)
qc.cx(0, 1) # works
qc.cx(0, 1, ctrl_state=1) # works
qc.cx(0, 1, ctrl_state=0) # fails - AerError: 'unknown instruction: cx_o0'
qc.measure_all()

simulator = AerSimulator()
simulator.run(qc).result().get_counts()

What is the expected behavior?

Should handle the qc.cx(0, 1, ctrl_state=0) natively

Suggested solutions

Should be easy since we already had in there cnot with control on 0, just rename mapping

@zlatko-minev zlatko-minev added the bug Something isn't working label May 8, 2024
@atharva-satpute
Copy link

I'd like to work on this. Could you tell me what is supposed to be done? Do we need to check if _o is present in name in _assemble_op() in aer_compiler.py ?

@hhorii
Copy link
Collaborator

hhorii commented May 20, 2024

This is not a bug. qc.cx(0, 1, ctrl_state=0) inserts cx_o0 gate which is not cx. The name is defined here. cx_o0 gate is not in basis_gates of AerSimulator. You need to transpile the circuit as follows:

qc = QuantumCircuit(2)
qc.cx(0, 1, ctrl_state=0)
qc.measure_all()

simulator = AerSimulator()
qc = transpile(qc, simulator)
simulator.run(qc).result().get_counts()

transpiler generates a sequence of x, cx, and x gates.

@zlatko-minev
Copy link
Author

Yes, in that sense it's a feature request. In previous version Aer seems to have accepted both cx and cx_o0.

Resolving it with transpilation adds some overhead in transpiling on larger circuits, but I suppose it might not be that big of an issue. I don't have a strong opinion on this one. I guess I am fine to resolve the issue here by just leaving it as is, and using the transpiler

This was referenced May 23, 2024
@zlatko-minev
Copy link
Author

Thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants