Skip to content

Commit b8b457c

Browse files
StrilancCirqBot
authored andcommitted
Polish pass over the documentation (#1191)
1 parent 965800b commit b8b457c

File tree

11 files changed

+209
-105
lines changed

11 files changed

+209
-105
lines changed

cirq/devices/grid_qubit.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class GridQubit(ops.QubitId):
2626
GridQubit(0, 0) < GridQubit(0, 1) < GridQubit(1, 0) < GridQubit(1, 1)
2727
"""
2828

29-
def __init__(self, row, col):
29+
def __init__(self, row: int, col: int):
3030
self.row = row
3131
self.col = col
3232

cirq/linalg/decompositions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ def so4_to_magic_su2s(
271271
class KakDecomposition:
272272
"""A convenient description of an arbitrary two-qubit operation.
273273
274-
Any two qubit operation U = can be decomposed into the form
274+
Any two qubit operation U can be decomposed into the form
275275
276276
U = g · (a1 ⊗ a0) · exp(i·(x·XX + y·YY + z·ZZ)) · (b1 ⊗ b0)
277277

cirq/ops/common_gates.py

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -328,18 +328,19 @@ class MeasurementGate(raw_types.Gate):
328328
329329
The measurement gate contains a key that is used to identify results
330330
of measurements.
331-
332-
Attributes:
333-
key: The string key of the measurement.
334-
invert_mask: A list of values indicating whether the corresponding
335-
qubits should be flipped. The list's length must not be longer than
336-
the number of qubits, but it is permitted to be shorted.
337-
Qubits with indices past the end of the mask are not flipped.
338331
"""
339332

340333
def __init__(self,
341334
key: str = '',
342335
invert_mask: Tuple[bool, ...] = ()) -> None:
336+
"""
337+
Args:
338+
key: The string key of the measurement.
339+
invert_mask: A list of values indicating whether the corresponding
340+
qubits should be flipped. The list's length must not be longer
341+
than the number of qubits, but it is permitted to be shorter.
342+
Qubits with indices past the end of the mask are not flipped.
343+
"""
343344
self.key = key
344345
self.invert_mask = invert_mask or ()
345346

@@ -474,16 +475,20 @@ class HPowGate(eigen_gate.EigenGate, gate_features.SingleQubitGate):
474475
"""A Gate that performs a rotation around the X+Z axis of the Bloch sphere.
475476
476477
477-
HPowGate()**t = HPowGate(exponent=t) is given by the matrix
478+
The unitary matrix of ``HPowGate(exponent=t)`` is:
479+
478480
[[g·(c-i·s/sqrt(2)), -i·g·s/sqrt(2)],
479481
[-i·g·s/sqrt(2)], g·(c+i·s/sqrt(2))]]
482+
480483
where
484+
481485
c = cos(π·t/2)
482486
s = sin(π·t/2)
483487
g = exp(i·π·t/2).
484-
Note in particular that for t=1, this gives the Hadamard matrix.
485488
486-
`cirq.H`, the Hadamard gate, is an instance of this gate at exponent=1.
489+
Note in particular that for `t=1`, this gives the Hadamard matrix.
490+
491+
`cirq.H`, the Hadamard gate, is an instance of this gate at `exponent=1`.
487492
"""
488493

489494
def _eigen_components(self):
@@ -575,7 +580,7 @@ class CZPowGate(eigen_gate.EigenGate,
575580
576581
g = exp(i·π·t/2).
577582
578-
`cirq.Z``, the controlled Z gate, is an instance of this gate at
583+
`cirq.CZ`, the controlled Z gate, is an instance of this gate at
579584
`exponent=1`.
580585
"""
581586

cirq/ops/matrix_gates.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,9 @@ def _phase_matrix(turns: float) -> np.ndarray:
2929
class SingleQubitMatrixGate(raw_types.Gate):
3030
"""A 1-qubit gate defined by its matrix.
3131
32-
More general than specialized classes like ZGate, but more expensive and
33-
more float-error sensitive to work with (due to using eigendecompositions).
32+
More general than specialized classes like `ZPowGate`, but more expensive
33+
and more float-error sensitive to work with (due to using
34+
eigendecompositions).
3435
"""
3536

3637
def __init__(self, matrix: np.ndarray) -> None:
@@ -108,8 +109,9 @@ def __str__(self):
108109
class TwoQubitMatrixGate(raw_types.Gate):
109110
"""A 2-qubit gate defined only by its matrix.
110111
111-
More general than specialized classes like CZGate, but more expensive and
112-
more float-error sensitive to work with (due to using eigendecompositions).
112+
More general than specialized classes like `CZPowGate`, but more expensive
113+
and more float-error sensitive to work with (due to using
114+
eigendecompositions).
113115
"""
114116

115117
def __init__(self, matrix: np.ndarray) -> None:

cirq/ops/named_qubit.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@
1818
class NamedQubit(raw_types.QubitId):
1919
"""A qubit identified by name.
2020
21-
By default, NamedQubit has a lexicographic order except that numbers within
21+
By default, NamedQubit has a lexicographic order. However, numbers within
2222
the name are handled correctly. So, for example, if you print a circuit
23-
containing cirq.NamedQubit('qubit22') and cirq.NamedQubit('qubit3'), the
24-
wire for 'qubit3' will come before 'qubit22'.
23+
containing `cirq.NamedQubit('qubit22')` and `cirq.NamedQubit('qubit3')`, the
24+
wire for 'qubit3' will correctly come before 'qubit22'.
2525
"""
2626

2727
def __init__(self, name: str) -> None:

cirq/ops/raw_types.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@ class QubitId(metaclass=abc.ABCMeta):
2727
"""Identifies a qubit. Child classes implement specific types of qubits.
2828
2929
The main criteria that a "qubit id" must satisfy is *comparability*. Child
30-
classes meet this criteria by implementing the _comparison_key method. For
31-
example, cirq.LineQubit's _comparison_key method returns `self.x`. This
30+
classes meet this criteria by implementing the `_comparison_key` method. For
31+
example, `cirq.LineQubit`'s `_comparison_key` method returns `self.x`. This
3232
ensures that line qubits with the same `x` are equal, and that line qubits
33-
will be sorted ascending by `x`. QubitId implements all equality,
34-
comparison, and hashing methods via`_comparison_key`.
33+
will be sorted ascending by `x`. `QubitId` implements all equality,
34+
comparison, and hashing methods via `_comparison_key`.
3535
"""
3636

3737
@abc.abstractmethod

cirq/ops/three_qubit_gates.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class CCZPowGate(eigen_gate.EigenGate,
3434
gate_features.InterchangeableQubitsGate):
3535
"""A doubly-controlled-Z that can be raised to a power.
3636
37-
The matrix of CCZ**t is diag(1, 1, 1, 1, 1, 1, 1, exp(i pi t)).
37+
The matrix of `CCZ**t` is `diag(1, 1, 1, 1, 1, 1, 1, exp(i pi t))`.
3838
"""
3939

4040
def _eigen_components(self):
@@ -126,7 +126,8 @@ class CCXPowGate(eigen_gate.EigenGate,
126126
gate_features.InterchangeableQubitsGate):
127127
"""A Toffoli (doubly-controlled-NOT) that can be raised to a power.
128128
129-
The matrix of CCX**t is an 8x8 identity except the bottom right 2x2 is X**t.
129+
The matrix of `CCX**t` is an 8x8 identity except the bottom right 2x2 area
130+
is the matrix of `X**t`.
130131
"""
131132

132133
def _eigen_components(self):

cirq/sim/wave_function.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ def density_matrix_from_state_vector(
6262
state: Sequence,
6363
indices: Iterable[int] = None
6464
) -> np.ndarray:
65-
"""Returns the density matrix of the wavefunction.
65+
r"""Returns the density matrix of the wavefunction.
6666
6767
Calculate the density matrix for the system on the given qubit
6868
indices, with the qubits not in indices that are present in state
@@ -71,12 +71,18 @@ def density_matrix_from_state_vector(
7171
convention of numpy.kron.
7272
7373
For example:
74+
7475
state = np.array([1/np.sqrt(2), 1/np.sqrt(2)], dtype=np.complex64)
7576
indices = None
76-
gives us \rho = \begin{bmatrix}
77-
0.5 & 0.5
78-
0.5 & 0.5
79-
\end{bmatrix}
77+
78+
gives us
79+
80+
$$
81+
\rho = \begin{bmatrix}
82+
0.5 & 0.5
83+
0.5 & 0.5
84+
\end{bmatrix}
85+
$$
8086
8187
Args:
8288
state: A sequence representing a wave function in which
@@ -120,8 +126,9 @@ def dirac_notation(state: Sequence, decimals: int=2) -> str:
120126
"""Returns the wavefunction as a string in Dirac notation.
121127
122128
For example:
129+
123130
state = np.array([1/np.sqrt(2), 1/np.sqrt(2)], dtype=np.complex64)
124-
print(pretty_state(state)) -> 0.71|0⟩ + 0.71|1⟩
131+
print(dirac_notation(state)) -> 0.71|0⟩ + 0.71|1⟩
125132
126133
Args:
127134
state: A sequence representing a wave function in which the ordering

0 commit comments

Comments
 (0)