qiskit-aer
qiskit-aer copied to clipboard
Fix multi-controlled gates in name mapping
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.
Unit test is failing because it needs #2327 to support the new Qiskit version.
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.
All gates from name_mapping.py are now in the tests as well.