diff --git a/qiskit/circuit/library/standard_gates/__init__.py b/qiskit/circuit/library/standard_gates/__init__.py index 3dca1abb6201..a852acb75157 100644 --- a/qiskit/circuit/library/standard_gates/__init__.py +++ b/qiskit/circuit/library/standard_gates/__init__.py @@ -107,14 +107,20 @@ def get_standard_gate_name_mapping(): """Return a dictionary mapping the name of standard gates and instructions to an object for - that name.""" + that name. + + For variadic operations (i.e. operations that operate on a variable + number of qubits), such as :class:`~.MCXGate`, the class for that + operation is returned and not an instance. + """ from qiskit.circuit.parameter import Parameter from qiskit.circuit.measure import Measure from qiskit.circuit.delay import Delay from qiskit.circuit.reset import Reset + from qiskit.circuit.controlflow import IfElseOp, WhileLoopOp, ForLoopOp # Standard gates library mapping, multicontrolled gates not included since they're - # variable width + # variable width. gates = [ IGate(), SXGate(), @@ -171,4 +177,15 @@ def get_standard_gate_name_mapping(): Measure(), ] name_mapping = {gate.name: gate for gate in gates} + # Add variable width gates as a mapping between names and classes + # since an instance requires knowing how many qubits are being operated on + name_mapping["if_else"] = IfElseOp + name_mapping["for_loop"] = ForLoopOp + name_mapping["while_loop"] = WhileLoopOP + name_mapping["mcx"] = MCXGate + name_mapping["mcx_gray"] = MCXGrayCode + name_mapping["mcx_recursive"] = MCXRecursive + name_mapping["mcx_vchain"] = MCXVChain + name_mapping["mcp"] = MCPhaseGate + name_mapping["mcu1"] = MCU1Gate return name_mapping