-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
This commit fixes the handling in the target for working with instructions defined globally in the target. It adds handling to the operation_names_for_qargs() and operations_for_qargs() methods to build outputs that include globally defined operations instead of ignoring them. Additionally the add_instruction() method is updated to validate the input qargs to ensure that only valid qubits and qargs are allowed to be added to the target for an instruction. Fixes #8914 Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com> (cherry picked from commit 3a073c7) Co-authored-by: Matthew Treinish <mtreinish@kortar.org>
- Loading branch information
1 parent
e0befd7
commit 450108c
Showing
4 changed files
with
188 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
releasenotes/notes/fix-global-inst-qarg-method-target-a9188e172ea7f325.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
--- | ||
fixes: | ||
- | | ||
Fixed handling of globally defined instructions for the :class:`~.Target` | ||
class. Previously, two methods, :meth:`~.Target.operations_for_qargs` and | ||
:meth:`~.Target.operation_names_for_qargs` would ignore/incorrectly handle | ||
any globally defined ideal operations present in the target. For example:: | ||
from qiskit.transpiler import Target | ||
from qiskit.circuit.library import CXGate | ||
target = Target(num_qubits=5) | ||
target.add_instruction(CXGate()) | ||
names = target.operation_names_for_qargs((1, 2)) | ||
ops = target.operations_for_qargs((1, 2)) | ||
will now return ``{"cx"}`` for ``names`` and ``[CXGate()]`` for ``ops`` | ||
instead of raising a ``KeyError`` or an empty return. | ||
- | | ||
Fixed an issue in the :meth:`.Target.add_instruction` method where it | ||
would previously have accepted an argument with an invalid number of | ||
qubits as part of the ``properties`` argument. For example:: | ||
from qiskit.transpiler import Target | ||
from qiskit.circuit.library import CXGate | ||
target = Target() | ||
target.add_instruction(CXGate(), {(0, 1, 2): None}) | ||
This will now correctly raise a ``TranspilerError`` instead of causing | ||
runtime issues when interacting with the target. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters