Skip to content

Commit

Permalink
Formatting and typo issues in qiskit.transpiler.Target (#11164)
Browse files Browse the repository at this point in the history
* formatting and typo issues in qiskit.transpiler.Target

* #11164 (comment)

* #11164 (comment)
  • Loading branch information
1ucian0 authored Nov 4, 2023
1 parent 6c923a1 commit 2818cf0
Showing 1 changed file with 29 additions and 29 deletions.
58 changes: 29 additions & 29 deletions qiskit/transpiler/target.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,11 +173,11 @@ class Target(Mapping):
}
gmap.add_instruction(CXGate(), cx_props)
Each instruction in the Target is indexed by a unique string name that uniquely
Each instruction in the ``Target`` is indexed by a unique string name that uniquely
identifies that instance of an :class:`~qiskit.circuit.Instruction` object in
the Target. There is a 1:1 mapping between a name and an
:class:`~qiskit.circuit.Instruction` instance in the target and each name must
be unique. By default the name is the :attr:`~qiskit.circuit.Instruction.name`
be unique. By default, the name is the :attr:`~qiskit.circuit.Instruction.name`
attribute of the instruction, but can be set to anything. This lets a single
target have multiple instances of the same instruction class with different
parameters. For example, if a backend target has two instances of an
Expand Down Expand Up @@ -261,7 +261,7 @@ def __init__(
concurrent_measurements=None,
):
"""
Create a new Target object
Create a new ``Target`` object
Args:
description (str): An optional string to describe the Target.
Expand Down Expand Up @@ -296,10 +296,11 @@ def __init__(
``None``
concurrent_measurements(list): A list of sets of qubits that must be
measured together. This must be provided
as a nested list like [[0, 1], [2, 3, 4]].
as a nested list like ``[[0, 1], [2, 3, 4]]``.
Raises:
ValueError: If both ``num_qubits`` and ``qubit_properties`` are both
defined and the value of ``num_qubits`` differs from the length of
``qubit_properties``.
defined and the value of ``num_qubits`` differs from the length of
``qubit_properties``.
"""
self.num_qubits = num_qubits
# A mapping of gate name -> gate instance
Expand Down Expand Up @@ -337,7 +338,7 @@ def add_instruction(self, instruction, properties=None, name=None):
"""Add a new instruction to the :class:`~qiskit.transpiler.Target`
As ``Target`` objects are strictly additive this is the primary method
for modifying a ``Target``. Typically you will use this to fully populate
for modifying a ``Target``. Typically, you will use this to fully populate
a ``Target`` before using it in :class:`~qiskit.providers.BackendV2`. For
example::
Expand Down Expand Up @@ -368,7 +369,7 @@ def add_instruction(self, instruction, properties=None, name=None):
Args:
instruction (qiskit.circuit.Instruction): The operation object to add to the map. If it's
paramerterized any value of the parameter can be set. Optionally for variable width
parameterized any value of the parameter can be set. Optionally for variable width
instructions (such as control flow operations such as :class:`~.ForLoop` or
:class:`~MCXGate`) you can specify the class. If the class is specified than the
``name`` argument must be specified. When a class is used the gate is treated as global
Expand All @@ -379,7 +380,7 @@ def add_instruction(self, instruction, properties=None, name=None):
for any instruction implementation, if there are no
:class:`~qiskit.transpiler.InstructionProperties` available for the
backend the value can be None. If there are no constraints on the
instruction (as in a noisless/ideal simulation) this can be set to
instruction (as in a noiseless/ideal simulation) this can be set to
``{None, None}`` which will indicate it runs on all qubits (or all
available permutations of qubits for multi-qubit gates). The first
``None`` indicates it applies to all qubits and the second ``None``
Expand All @@ -391,7 +392,7 @@ def add_instruction(self, instruction, properties=None, name=None):
specified the :attr:`~qiskit.circuit.Instruction.name` attribute
of ``gate`` will be used. All gates in the ``Target`` need unique
names. Backends can differentiate between different
parameterizations of a single gate by providing a unique name for
parameterization of a single gate by providing a unique name for
each (e.g. `"rx30"`, `"rx60", ``"rx90"`` similar to the example in the
documentation for the :class:`~qiskit.transpiler.Target` class).
Raises:
Expand Down Expand Up @@ -618,7 +619,7 @@ def timing_constraints(self):
"""Get an :class:`~qiskit.transpiler.TimingConstraints` object from the target
Returns:
TimingConstraints: The timing constraints represented in the Target
TimingConstraints: The timing constraints represented in the ``Target``
"""
return TimingConstraints(
self.granularity, self.min_length, self.pulse_alignment, self.acquire_alignment
Expand Down Expand Up @@ -691,16 +692,15 @@ def operation_names_for_qargs(self, qargs):
"""Get the operation names for a specified qargs tuple
Args:
qargs (tuple): A qargs tuple of the qubits to get the gates that apply
qargs (tuple): A ``qargs`` tuple of the qubits to get the gates that apply
to it. For example, ``(0,)`` will return the set of all
instructions that apply to qubit 0. If set to ``None`` this will
return the names for any globally defined operations in the target.
Returns:
set: The set of operation names that apply to the specified
`qargs``.
set: The set of operation names that apply to the specified ``qargs``.
Raises:
KeyError: If qargs is not in target
KeyError: If ``qargs`` is not in target
"""
if qargs is not None and any(x not in range(0, self.num_qubits) for x in qargs):
raise KeyError(f"{qargs} not in target.")
Expand Down Expand Up @@ -740,7 +740,7 @@ def instruction_supported(
is supported on the backend. For example, if you wanted to
check whether a :class:`~.RXGate` was supported on a specific
qubit with a fixed angle. That fixed angle variant will
typically have a name different than the object's
typically have a name different from the object's
:attr:`~.Instruction.name` attribute (``"rx"``) in the target.
This can be used to check if any instances of the class are
available in such a case.
Expand All @@ -762,7 +762,7 @@ def instruction_supported(
parameters = [Parameter("theta")]
target.instruction_supported("rx", (0,), parameters=parameters)
will return ``True`` if an :class:`~.RXGate` is suporrted on qubit 0
will return ``True`` if an :class:`~.RXGate` is supported on qubit 0
that will accept any parameter. If you need to check for a fixed numeric
value parameter this argument is typically paired with the ``operation_class``
argument. For example::
Expand Down Expand Up @@ -792,7 +792,7 @@ def check_obj_params(parameters, obj):
if inspect.isclass(obj):
if obj != operation_class:
continue
# If no qargs a operation class is supported
# If no qargs operation class is supported
if qargs is None:
return True
# If qargs set then validate no duplicates and all indices are valid on device
Expand Down Expand Up @@ -1021,15 +1021,15 @@ def build_coupling_map(self, two_q_gate=None, filter_idle_qubits=False):
Args:
two_q_gate (str): An optional gate name for a two qubit gate in
the Target to generate the coupling map for. If specified the
the ``Target`` to generate the coupling map for. If specified the
output coupling map will only have edges between qubits where
this gate is present.
filter_idle_qubits (bool): If set to ``True`` the output :class:`~.CouplingMap`
will remove any qubits that don't have any operations defined in the
target. Note that using this argument will result in an output
:class:`~.CouplingMap` object which has holes in its indices
which might differ from the assumptions of the class. The typical use
case of this argument is to be paired with with
case of this argument is to be paired with
:meth:`.CouplingMap.connected_components` which will handle the holes
as expected.
Returns:
Expand All @@ -1039,7 +1039,7 @@ def build_coupling_map(self, two_q_gate=None, filter_idle_qubits=False):
Raises:
ValueError: If a non-two qubit gate is passed in for ``two_q_gate``.
IndexError: If an Instruction not in the Target is passed in for
IndexError: If an Instruction not in the ``Target`` is passed in for
``two_q_gate``.
"""
if self.qargs is None:
Expand Down Expand Up @@ -1094,13 +1094,13 @@ def get_non_global_operation_names(self, strict_direction=False):
"""Return the non-global operation names for the target
The non-global operations are those in the target which don't apply
on all qubits (for single qubit operations) or all multiqubit qargs
on all qubits (for single qubit operations) or all multi-qubit qargs
(for multi-qubit operations).
Args:
strict_direction (bool): If set to ``True`` the multi-qubit
operations considered as non-global respect the strict
direction (or order of qubits in the qargs is signifcant). For
direction (or order of qubits in the qargs is significant). For
example, if ``cx`` is defined on ``(0, 1)`` and ``ecr`` is
defined over ``(1, 0)`` by default neither would be considered
non-global, but if ``strict_direction`` is set ``True`` both
Expand Down Expand Up @@ -1255,7 +1255,7 @@ def from_configuration(
Args:
basis_gates: The list of basis gate names for the backend. For the
target to be created these names must either be in the output
from :func:~.get_standard_gate_name_mapping` or present in the
from :func:`~.get_standard_gate_name_mapping` or present in the
specified ``custom_name_mapping`` argument.
num_qubits: The number of qubits supported on the backend.
coupling_map: The coupling map representing connectivity constraints
Expand All @@ -1266,7 +1266,7 @@ def from_configuration(
is specified ``coupling_map`` must be specified. The
``coupling_map`` is used as the source of truth for connectivity
and if ``inst_map`` is used the schedule is looked up based
on the instuctions from the pair of ``basis_gates`` and
on the instructions from the pair of ``basis_gates`` and
``coupling_map``. If you want to define a custom gate for
a particular qubit or qubit pair, you can manually build :class:`.Target`.
backend_properties: The :class:`~.BackendProperties` object which is
Expand All @@ -1282,13 +1282,13 @@ def from_configuration(
:class:`~InstructionProperties` objects for the instructions in the target.
concurrent_measurements(list): A list of sets of qubits that must be
measured together. This must be provided
as a nested list like [[0, 1], [2, 3, 4]].
as a nested list like ``[[0, 1], [2, 3, 4]]``.
dt: The system time resolution of input signals in seconds
timing_constraints: Optional timing constraints to include in the
:class:`~.Target`
custom_name_mapping: An optional dictionary that maps custom gate/operation names in
``basis_gates`` to an :class:`~.Operation` object representing that
gate/operation. By default most standard gates names are mapped to the
gate/operation. By default, most standard gates names are mapped to the
standard gate object from :mod:`qiskit.circuit.library` this only needs
to be specified if the input ``basis_gates`` defines gates in names outside
that set.
Expand Down Expand Up @@ -1333,9 +1333,9 @@ def from_configuration(
name_mapping.update(custom_name_mapping)

# While BackendProperties can also contain coupling information we
# rely solely on CouplingMap to determin connectivity. This is because
# rely solely on CouplingMap to determine connectivity. This is because
# in legacy transpiler usage (and implicitly in the BackendV1 data model)
# the coupling map is used to define connecitivity constraints and
# the coupling map is used to define connectivity constraints and
# the properties is only used for error rate and duration population.
# If coupling map is not specified we ignore the backend_properties
if coupling_map is None:
Expand Down

0 comments on commit 2818cf0

Please sign in to comment.