Skip to content

Commit

Permalink
Improvements to Move docstring
Browse files Browse the repository at this point in the history
  • Loading branch information
garrison committed Jul 28, 2023
1 parent 88f98d3 commit c716d98
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 4 deletions.
38 changes: 34 additions & 4 deletions circuit_knitting/cutting/instructions/move.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,16 @@
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
Expand All @@ -34,10 +44,30 @@ class Move(Instruction):
prior use was as the source (i.e., first) qubit of a preceding
:class:`Move` operation.
See `the tutorial on wire cutting using the Move instruction
<../circuit_cutting/tutorials/03_wire_cutting_via_move_instruction.ipynb>`__
for an example whose two :class:`Move` instructions correspond to each of
the aforementioned cases.
The following circuit contains two :class:`Move` operations, corresponding
to each of the aforementioned cases:
.. plot::
:include-source:
import numpy as np
from qiskit.circuit import QuantumCircuit, CircuitInstruction
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(CircuitInstruction(Move(), [qc.qubits[1], qc.qubits[2]]))
qc.rz(np.pi / 4, 0)
qc.ryy(np.pi / 4, 2, 3)
qc.append(CircuitInstruction(Move(), [qc.qubits[2], qc.qubits[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):
Expand Down
4 changes: 4 additions & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
"sphinx.ext.mathjax",
"sphinx.ext.viewcode",
"sphinx.ext.extlinks",
"matplotlib.sphinxext.plot_directive",
# "sphinx.ext.autosectionlabel",
"jupyter_sphinx",
"sphinx_autodoc_typehints",
Expand Down Expand Up @@ -78,6 +79,9 @@
"**/README.rst",
]

# matplotlib.sphinxext.plot_directive options

This comment has been minimized.

Copy link
@caleb-johnson

caleb-johnson Jul 28, 2023

Collaborator

This is for rendering the docstring circuit in Sphinx?

This comment has been minimized.

Copy link
@garrison

garrison Jul 29, 2023

Author Member

It allows us to render circuits (or, really anything that matplotlib can render) in the Sphinx build from the docstrings. Qiskit uses it, and the revised Move docstring uses it too. (Long way of saying "yes".)

plot_html_show_formats = False

# Redirects for pages that have moved
redirects = {
"circuit_cutting/tutorials/gate_cutting_to_reduce_circuit_width.html": "01_gate_cutting_to_reduce_circuit_width.html",
Expand Down

0 comments on commit c716d98

Please sign in to comment.