-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement wire cutting as a two-qubit instruction (#174)
* Implement wire cutting as a two-qubit instruction * Update type annotation * s/gate/instruction/ * Add overhead test for `Move` instruction * Add wire cutting tutorial * Add `Move` to Sphinx build * Doc updates suggested by Caleb * Add release note and link to new tutorial * Clarify wording following #174 (comment) * Improvements to `Move` docstring * Use svg as the plot format This avoids pixelation on high-dpi displays * Remove unnecessary uses of `CircuitInstruction` https://github.com/Qiskit-Extensions/circuit-knitting-toolbox/pull/174/files#r1278067109 * The notebook tests should ignore any files that crop up in `docs/_build` `matplotlib.sphinxext.plot_directive` likes to leave python files there
- Loading branch information
Showing
16 changed files
with
669 additions
and
22 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# This code is a Qiskit project. | ||
|
||
# (C) Copyright IBM 2023. | ||
|
||
# This code is licensed under the Apache License, Version 2.0. You may | ||
# obtain a copy of this license in the LICENSE.txt file in the root directory | ||
# of this source tree or at http://www.apache.org/licenses/LICENSE-2.0. | ||
# Any modifications or derivative works of this code must retain this | ||
# copyright notice, and modified files need to carry a notice indicating | ||
# that they have been altered from the originals. | ||
|
||
r"""Quantum circuit :class:`~qiskit.Instruction`\ s useful for circuit cutting.""" | ||
|
||
from .move import Move | ||
|
||
__all__ = [ | ||
"Move", | ||
] |
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,82 @@ | ||
# This code is part of Qiskit. | ||
# | ||
# (C) Copyright IBM 2023. | ||
# | ||
# This code is licensed under the Apache License, Version 2.0. You may | ||
# obtain a copy of this license in the LICENSE.txt file in the root directory | ||
# of this source tree or at http://www.apache.org/licenses/LICENSE-2.0. | ||
# | ||
# Any modifications or derivative works of this code must retain this | ||
# copyright notice, and modified files need to carry a notice indicating | ||
# that they have been altered from the originals. | ||
|
||
"""Two-qubit instruction representing a swap + single-qubit reset.""" | ||
from __future__ import annotations | ||
|
||
from qiskit.circuit import QuantumCircuit, Instruction | ||
|
||
|
||
class Move(Instruction): | ||
"""A two-qubit instruction representing a reset of the second qubit followed by a swap. | ||
**Circuit Symbol:** | ||
.. parsed-literal:: | ||
┌───────┐ | ||
q_0: ┤0 ├ q_0: ──────X─ | ||
│ Move │ = │ | ||
q_1: ┤1 ├ q_1: ─|0>──X─ | ||
└───────┘ | ||
The desired effect of this instruction, typically, is to move the state of | ||
the first qubit to the second qubit. For this to work as expected, the | ||
second incoming qubit must share no entanglement with the remainder of the | ||
system. If this qubit *is* entangled, then performing the reset operation | ||
will in turn implement a quantum channel on the other qubit(s) with which | ||
it is entangled, resulting in the partial collapse of those qubits. | ||
The simplest way to ensure that the second (i.e., destination) qubit shares | ||
no entanglement with the remainder of the system is to use a fresh qubit | ||
which has not been used since initialization. | ||
Another valid way is to use, as a desination qubit, a qubit whose immediate | ||
prior use was as the source (i.e., first) qubit of a preceding | ||
:class:`Move` operation. | ||
The following circuit contains two :class:`Move` operations, corresponding | ||
to each of the aforementioned cases: | ||
.. plot:: | ||
:include-source: | ||
import numpy as np | ||
from qiskit import QuantumCircuit | ||
from circuit_knitting.cutting.instructions import Move | ||
qc = QuantumCircuit(4) | ||
qc.ryy(np.pi / 4, 0, 1) | ||
qc.rx(np.pi / 4, 3) | ||
qc.append(Move(), [1, 2]) | ||
qc.rz(np.pi / 4, 0) | ||
qc.ryy(np.pi / 4, 2, 3) | ||
qc.append(Move(), [2, 1]) | ||
qc.ryy(np.pi / 4, 0, 1) | ||
qc.rx(np.pi / 4, 3) | ||
qc.draw("mpl") | ||
A full demonstration of the :class:`Move` instruction is available in `the | ||
introductory tutorial on wire cutting | ||
<../circuit_cutting/tutorials/03_wire_cutting_via_move_instruction.ipynb>`__. | ||
""" | ||
|
||
def __init__(self, label: str | None = None): | ||
"""Create a :class:`Move` instruction.""" | ||
super().__init__("move", 2, 0, [], label=label) | ||
|
||
def _define(self): | ||
"""Set definition to equivalent circuit.""" | ||
qc = QuantumCircuit(2, name=self.name) | ||
qc.reset(1) | ||
qc.swap(0, 1) | ||
self.definition = qc |
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
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
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
487 changes: 487 additions & 0 deletions
487
docs/circuit_cutting/tutorials/03_wire_cutting_via_move_instruction.ipynb
Large diffs are not rendered by default.
Oops, something went wrong.
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
6 changes: 6 additions & 0 deletions
6
releasenotes/notes/two-qubit-wire-cutting-27aff379403ea226.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,6 @@ | ||
--- | ||
features: | ||
- | | ||
The :mod:`circuit_knitting.cutting` module now supports wire | ||
cutting. There is a :ref:`new tutorial <circuit cutting | ||
tutorials>` that explains how to use it. |
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
Oops, something went wrong.