diff --git a/qiskit/extensions/quantum_initializer/squ.py b/qiskit/extensions/quantum_initializer/squ.py index 0136898009f3..eb1c248e39de 100644 --- a/qiskit/extensions/quantum_initializer/squ.py +++ b/qiskit/extensions/quantum_initializer/squ.py @@ -59,7 +59,7 @@ def __init__(self, unitary_matrix, mode="ZYZ", up_to_diagonal=False, u=None): self._diag = None # Create new gate - super().__init__("unitary", 1, [unitary_matrix]) + super().__init__("squ", 1, [unitary_matrix]) def inverse(self): """Return the inverse. diff --git a/qiskit/transpiler/preset_passmanagers/level0.py b/qiskit/transpiler/preset_passmanagers/level0.py index e34cb4cd92a2..c306247022f1 100644 --- a/qiskit/transpiler/preset_passmanagers/level0.py +++ b/qiskit/transpiler/preset_passmanagers/level0.py @@ -105,7 +105,11 @@ def _choose_layout_condition(property_set): _embed = [FullAncillaAllocation(coupling_map), EnlargeWithAncilla(), ApplyLayout()] # 3. Decompose so only 1-qubit and 2-qubit gates remain - _unroll3q = Unroll3qOrMore() + _unroll3q = [ + # Use unitary synthesis for basis aware decomposition of UnitaryGates + UnitarySynthesis(basis_gates, approximation_degree=approximation_degree), + Unroll3qOrMore(), + ] # 4. Swap to fit the coupling map _swap_check = CheckMap(coupling_map) @@ -139,9 +143,14 @@ def _swap_condition(property_set): elif translation_method == "translator": from qiskit.circuit.equivalence_library import SessionEquivalenceLibrary as sel - _unroll = [UnrollCustomDefinitions(sel, basis_gates), BasisTranslator(sel, basis_gates)] + _unroll = [ + UnitarySynthesis(basis_gates, approximation_degree=approximation_degree), + UnrollCustomDefinitions(sel, basis_gates), + BasisTranslator(sel, basis_gates), + ] elif translation_method == "synthesis": _unroll = [ + UnitarySynthesis(basis_gates, approximation_degree=approximation_degree), Unroll3qOrMore(), Collect2qBlocks(), ConsolidateBlocks(basis_gates=basis_gates), diff --git a/qiskit/transpiler/preset_passmanagers/level1.py b/qiskit/transpiler/preset_passmanagers/level1.py index deab87f30467..05ea8c1225bc 100644 --- a/qiskit/transpiler/preset_passmanagers/level1.py +++ b/qiskit/transpiler/preset_passmanagers/level1.py @@ -125,7 +125,11 @@ def _not_perfect_yet(property_set): _embed = [FullAncillaAllocation(coupling_map), EnlargeWithAncilla(), ApplyLayout()] # 4. Decompose so only 1-qubit and 2-qubit gates remain - _unroll3q = Unroll3qOrMore() + _unroll3q = [ + # Use unitary synthesis for basis aware decomposition of UnitaryGates + UnitarySynthesis(basis_gates, approximation_degree=approximation_degree), + Unroll3qOrMore(), + ] # 5. Swap to fit the coupling map _swap_check = CheckMap(coupling_map) @@ -159,9 +163,18 @@ def _swap_condition(property_set): elif translation_method == "translator": from qiskit.circuit.equivalence_library import SessionEquivalenceLibrary as sel - _unroll = [UnrollCustomDefinitions(sel, basis_gates), BasisTranslator(sel, basis_gates)] + _unroll = [ + # Use unitary synthesis for basis aware decomposition of UnitaryGates before + # custom unrolling + UnitarySynthesis(basis_gates, approximation_degree=approximation_degree), + UnrollCustomDefinitions(sel, basis_gates), + BasisTranslator(sel, basis_gates), + ] elif translation_method == "synthesis": _unroll = [ + # Use unitary synthesis for basis aware decomposition of UnitaryGates before + # collection + UnitarySynthesis(basis_gates, approximation_degree=approximation_degree), Unroll3qOrMore(), Collect2qBlocks(), ConsolidateBlocks(basis_gates=basis_gates), diff --git a/qiskit/transpiler/preset_passmanagers/level2.py b/qiskit/transpiler/preset_passmanagers/level2.py index d26222b3cc61..6778e49d54bb 100644 --- a/qiskit/transpiler/preset_passmanagers/level2.py +++ b/qiskit/transpiler/preset_passmanagers/level2.py @@ -159,7 +159,11 @@ def _csp_not_found_match(property_set): _embed = [FullAncillaAllocation(coupling_map), EnlargeWithAncilla(), ApplyLayout()] # 3. Unroll to 1q or 2q gates - _unroll3q = Unroll3qOrMore() + _unroll3q = [ + # Use unitary synthesis for basis aware decomposition of UnitaryGates + UnitarySynthesis(basis_gates, approximation_degree=approximation_degree), + Unroll3qOrMore(), + ] # 4. Swap to fit the coupling map _swap_check = CheckMap(coupling_map) @@ -193,9 +197,18 @@ def _swap_condition(property_set): elif translation_method == "translator": from qiskit.circuit.equivalence_library import SessionEquivalenceLibrary as sel - _unroll = [UnrollCustomDefinitions(sel, basis_gates), BasisTranslator(sel, basis_gates)] + _unroll = [ + # Use unitary synthesis for basis aware decomposition of UnitaryGates before + # custom unrolling + UnitarySynthesis(basis_gates, approximation_degree=approximation_degree), + UnrollCustomDefinitions(sel, basis_gates), + BasisTranslator(sel, basis_gates), + ] elif translation_method == "synthesis": _unroll = [ + # Use unitary synthesis for basis aware decomposition of UnitaryGates before + # collection + UnitarySynthesis(basis_gates, approximation_degree=approximation_degree), Unroll3qOrMore(), Collect2qBlocks(), ConsolidateBlocks(basis_gates=basis_gates), diff --git a/qiskit/transpiler/preset_passmanagers/level3.py b/qiskit/transpiler/preset_passmanagers/level3.py index 257bc4babe88..ffe12c5918f4 100644 --- a/qiskit/transpiler/preset_passmanagers/level3.py +++ b/qiskit/transpiler/preset_passmanagers/level3.py @@ -100,7 +100,11 @@ def level_3_pass_manager(pass_manager_config: PassManagerConfig) -> PassManager: approximation_degree = pass_manager_config.approximation_degree # 1. Unroll to 1q or 2q gates - _unroll3q = Unroll3qOrMore() + _unroll3q = [ + # Use unitary synthesis for basis aware decomposition of UnitaryGates + UnitarySynthesis(basis_gates, approximation_degree=approximation_degree), + Unroll3qOrMore(), + ] # 2. Layout on good qubits if calibration info available, otherwise on dense links _given_layout = SetLayout(initial_layout) diff --git a/releasenotes/notes/squ-gate-name-785b7896300a92ef.yaml b/releasenotes/notes/squ-gate-name-785b7896300a92ef.yaml new file mode 100644 index 000000000000..36608e046781 --- /dev/null +++ b/releasenotes/notes/squ-gate-name-785b7896300a92ef.yaml @@ -0,0 +1,9 @@ +--- +upgrade: + - | + The :attr:`~qiskit.extensions.SingleQubitUnitary.name` attribute of the + :class:`~qiskit.extensions.SingleQubitUnitary` gate class has been changed + from ``unitary`` to ``squ``. This was necessary to avoid a conflict with + the :class:`~qiskit.extensions.UnitaryGate` class's name which was also + ``unitary`` since the 2 gates are not the same and don't have the same + implementation (and can't be used interchangeably).