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

Fix multi-controlled gates in name mapping

Open AlbertJP opened this issue 8 months ago • 3 comments

Summary

MCSXGate, MCYGate, MCZGate, MCRXGate, MCRYGate, MCRZGate, MCU3Gate, MCUGate, and MCSwapGate can not be instantiated due to a mismatch in the number of qubits with the base gate:

CircuitError: 'The number of control qubits must be in `[1, num_qubits - base_gate.num_qubits]`.'

Details and comments

I came across this issue while writing a unit test for Qiskit/qiskit#13952.

Commit https://github.com/doichanj/qiskit-aer/commit/4587384b63e894a60dc57fbd790b189c6be2d709 (pull #1995) changed the base gates of these gates from non-controlled gates into singly controlled gates, which means there is one qubit too much in the base gate.

An alternative solution would be to reduce num_ctrl_qubits by one when calling ControlledGate.__init__(), but then the multi-controlled gates can only be created for two or more control qubits and one would need to extract the last qubit from the control state to pass it to the base gate.

AlbertJP avatar Mar 05 '25 08:03 AlbertJP

Unit test is failing because it needs #2327 to support the new Qiskit version.

AlbertJP avatar Mar 12 '25 12:03 AlbertJP

I have just changed some existing tests to use the MCYGate and MCZGate classes instead of creating new gates. I'll add tests for the others as well.

AlbertJP avatar Mar 13 '25 10:03 AlbertJP

All gates from name_mapping.py are now in the tests as well.

AlbertJP avatar Mar 13 '25 14:03 AlbertJP