qiskit-aer icon indicating copy to clipboard operation
qiskit-aer copied to clipboard

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

Open zlatko-minev opened this issue 9 months ago • 1 comments

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 avatar May 08 '24 16:05 zlatko-minev

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 ?

atharva-satpute avatar May 15 '24 02:05 atharva-satpute

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.

hhorii avatar May 20 '24 15:05 hhorii

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

zlatko-minev avatar May 20 '24 15:05 zlatko-minev

Thank you

zlatko-minev avatar May 31 '24 14:05 zlatko-minev