-
Notifications
You must be signed in to change notification settings - Fork 2.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add qubit_properties to Target class #7736
Changes from all commits
89dd944
3eed7d3
052fc62
0656d1b
d4e0fd4
bd43ead
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,6 +27,10 @@ | |
from qiskit.transpiler.instruction_durations import InstructionDurations | ||
from qiskit.transpiler.timing_constraints import TimingConstraints | ||
|
||
# import QubitProperties here to provide convenience alias for building a | ||
# full target | ||
from qiskit.providers.backend import QubitProperties # pylint: disable=unused-import | ||
|
||
Comment on lines
+30
to
+33
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't fully understand the motivation of this line. Can you explain a bit more? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's a convenience thing since from qiskit.transpiler.target import Target, InstructionProperties, QubitProperties instead of: from qiskit.transpiler.target import Target, InstructionProperties
from qiskit.providers.backend import QubitProperties (although the latter will still work even with this.) But, it is a bit weird to do this, so I'm not really tied to it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That makes a lot of sense. It's much more convenient this way. |
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
|
@@ -169,6 +173,7 @@ class Target(Mapping): | |
"aquire_alignment", | ||
"_non_global_basis", | ||
"_non_global_strict_basis", | ||
"qubit_properties", | ||
) | ||
|
||
def __init__( | ||
|
@@ -180,6 +185,7 @@ def __init__( | |
min_length=1, | ||
pulse_alignment=1, | ||
aquire_alignment=1, | ||
qubit_properties=None, | ||
): | ||
""" | ||
Create a new Target object | ||
|
@@ -208,6 +214,17 @@ def __init__( | |
resolution of measure instruction starting time. Measure | ||
instruction should start at time which is a multiple of the | ||
alignment value. | ||
qubit_properties (list): A list of :class:`~.QubitProperties` | ||
objects defining the characteristics of each qubit on the | ||
target device. If specified the length of this list must match | ||
the number of qubits in the target, where the index in the list | ||
matches the qubit number the properties are defined for. If some | ||
qubits don't have properties available you can set that entry to | ||
``None`` | ||
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``. | ||
""" | ||
self.num_qubits = num_qubits | ||
# A mapping of gate name -> gate instance | ||
|
@@ -227,6 +244,16 @@ def __init__( | |
self.aquire_alignment = aquire_alignment | ||
self._non_global_basis = None | ||
self._non_global_strict_basis = None | ||
if qubit_properties is not None: | ||
if not self.num_qubits: | ||
self.num_qubits = len(qubit_properties) | ||
else: | ||
if self.num_qubits != len(qubit_properties): | ||
raise ValueError( | ||
"The value of num_qubits specified does not match the " | ||
"length of the input qubit_properties list" | ||
) | ||
self.qubit_properties = qubit_properties | ||
|
||
def add_instruction(self, instruction, properties=None, name=None): | ||
"""Add a new instruction to the :class:`~qiskit.transpiler.Target` | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
--- | ||
features: | ||
- | | ||
Added a new attribute, :attr:`~.Target.qubit_properties` to the | ||
:class:`~.Target` class. This attribute contains a list of | ||
:class:`~.QubitProperties` objects for each qubit in the target. | ||
For example:: | ||
|
||
target.qubit_properties[2] | ||
|
||
will contain the :class:`~.QubitProperties` for qubit number 2 in the | ||
target. | ||
|
||
For :class:`~.BackendV2` authors, if you were previously defining | ||
:class:`~.QubitProperties` directly on your :class:`~.BackendV2` | ||
implementation by overriding :meth:`.BackendV2.qubit_properties` this | ||
will still work fine. However, if you do move the definition to the | ||
underlying :class:`~.Target` object and remove the specialized | ||
:meth:`.BackendV2.qubit_properties` implementation which will enable | ||
using qubit properties in the transpiler and also maintain API compatibility | ||
with your previous implementation |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was not introduced by this PR but I think it would be good to explain in the docstring the difference between
FakeBackendV2
andFakeBackendSimple
.