Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 19 additions & 2 deletions qiskit/circuit/library/standard_gates/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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, WhileLoop, ForLoop

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not really certain we should be returning these as "standard gates"; they're no gates, and they don't really follow a standard form of accepting n float-like parameters.

I suppose it depends a bit on how the result of this function is meant to be used.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I was on the fence about this too, but we already had Delay, Reset, etc here. This was added in #8759 so we had a mapping for basis_gate entries to object for a target. I guess the function name isn't great and we should rename it (well, alias, then deprecate, then rename).


# Standard gates library mapping, multicontrolled gates not included since they're
# variable width
# variable width.
gates = [
IGate(),
SXGate(),
Expand Down Expand Up @@ -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
Comment thread
mtreinish marked this conversation as resolved.
Outdated
name_mapping["for_loop"] = ForLoop
name_mapping["while_loop"] = WhileLoop
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