Skip to content

Commit 4339d4d

Browse files
authored
A Cauldron of Doc fixes (quantumlib#5680)
Miscellaneous doc fixes around cirq - Fix indenting where it is inappropriately detected as blockquotes - Fix references and commas at a few places. - Move some docstrings from init to class so that they show up on the API reference properly. - Fix list formatting - Fix one-line summaries that are more than one line.
1 parent b41793f commit 4339d4d

File tree

9 files changed

+265
-259
lines changed

9 files changed

+265
-259
lines changed

cirq/circuits/circuit.py

+7-4
Original file line numberDiff line numberDiff line change
@@ -93,13 +93,16 @@ def foo(circuit: CIRCUIT_TYPE) -> CIRCUIT_TYPE:
9393

9494

9595
class Alignment(enum.Enum):
96-
"""Alignment option for combining/zipping two circuits together."""
96+
"""Alignment option for combining/zipping two circuits together.
97+
98+
Args:
99+
LEFT: Stop when left ends are lined up.
100+
RIGHT: Stop when right ends are lined up.
101+
FIRST: Stop the first time left ends are lined up or right ends are lined up.
102+
"""
97103

98-
# Stop when left ends are lined up.
99104
LEFT = 1
100-
# Stop when right ends are lined up.
101105
RIGHT = 2
102-
# Stop the first time left ends are lined up or right ends are lined up.
103106
FIRST = 3
104107

105108
def __repr__(self) -> str:

cirq/linalg/transformations.py

+31-26
Original file line numberDiff line numberDiff line change
@@ -187,10 +187,13 @@ def targeted_conjugate_about(
187187
is a contraction between the given indices (indices for first $\cdot$,
188188
conj_indices for second $\cdot$).
189189
190-
More specifically this computes
191-
$\sum tensor_{i_0,...,i_{r-1},j_0,...,j_{r-1}} *
190+
More specifically, this computes:
191+
192+
$$
193+
\sum tensor_{i_0,...,i_{r-1},j_0,...,j_{r-1}} *
192194
target_{k_0,...,k_{r-1},l_0,...,l_{r-1}} *
193-
tensor_{m_0,...,m_{r-1},n_0,...,n_{r-1}}^*$
195+
tensor_{m_0,...,m_{r-1},n_0,...,n_{r-1}}^*
196+
$$
194197
195198
where the sum is over indices where $j_s$ = $k_s$ and $s$ is in `indices`
196199
and $l_s$ = $m_s$ and s is in `conj_indices`.
@@ -212,7 +215,7 @@ def targeted_conjugate_about(
212215
buffer is used. Must have the same shape as target.
213216
214217
Returns:
215-
The result the conjugation.
218+
The result of the conjugation, as a numpy array.
216219
"""
217220
conj_indices = conj_indices or [i + target.ndim // 2 for i in indices]
218221
first_multiply = targeted_left_multiply(tensor, target, indices, out=buffer)
@@ -230,28 +233,30 @@ def apply_matrix_to_slices(
230233
*,
231234
out: Optional[np.ndarray] = None,
232235
) -> np.ndarray:
233-
"""Left-multiplies an NxN matrix onto N slices of a numpy array.
234-
235-
Example:
236-
The 4x4 matrix of a fractional SWAP gate can be expressed as
237-
238-
[ 1 ]
239-
[ X**t ]
240-
[ 1 ]
241-
242-
Where X is the 2x2 Pauli X gate and t is the power of the swap with t=1
243-
being a full swap. X**t is a power of the Pauli X gate's matrix.
244-
Applying the fractional swap is equivalent to applying a fractional X
245-
within the inner 2x2 subspace; the rest of the matrix is identity. This
246-
can be expressed using `apply_matrix_to_slices` as follows:
247-
248-
def fractional_swap(target):
249-
assert target.shape == (4,)
250-
return apply_matrix_to_slices(
251-
target=target,
252-
matrix=cirq.unitary(cirq.X**t),
253-
slices=[1, 2]
254-
)
236+
r"""Left-multiplies an NxN matrix onto N slices of a numpy array.
237+
238+
One example is that the 4x4 matrix of a fractional SWAP gate can be expressed as
239+
240+
$$
241+
\begin{bmatrix}
242+
1 & & \\
243+
& X**t & \\
244+
& & 1 \\
245+
\end{bmatrix}
246+
247+
Where X is the 2x2 Pauli X gate and t is the power of the swap with t=1
248+
being a full swap. X**t is a power of the Pauli X gate's matrix.
249+
Applying the fractional swap is equivalent to applying a fractional X
250+
within the inner 2x2 subspace; the rest of the matrix is identity. This
251+
can be expressed using `apply_matrix_to_slices` as follows:
252+
253+
def fractional_swap(target):
254+
assert target.shape == (4,)
255+
return apply_matrix_to_slices(
256+
target=target,
257+
matrix=cirq.unitary(cirq.X**t),
258+
slices=[1, 2]
259+
)
255260
256261
Args:
257262
target: The input array with slices that need to be left-multiplied.

0 commit comments

Comments
 (0)