Skip to content

Commit

Permalink
More documentation fixes (quantumlib#4654)
Browse files Browse the repository at this point in the history
What do you do every night?  Fix more documentation lint errors pinky.
  • Loading branch information
dabacon authored Nov 11, 2021
1 parent 2119156 commit 53596d3
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 44 deletions.
10 changes: 3 additions & 7 deletions cirq/contrib/acquaintance/permutation.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,13 @@
LogicalMapping = Dict[LogicalMappingKey, LogicalIndex]


# TODO(#3388) Add documentation for Args.
# pylint: disable=missing-param-doc
class PermutationGate(ops.Gate, metaclass=abc.ABCMeta):
"""A permutation gate indicates a change in the mapping from qubits to
logical indices.
Args:
swap_gate: the gate that swaps the indices mapped to by a pair of
num_qubits: The number of qubits the gate should act on.
swap_gate: The gate that swaps the indices mapped to by a pair of
qubits (e.g. SWAP or fermionic swap).
"""

Expand Down Expand Up @@ -108,7 +107,6 @@ def _circuit_diagram_info_(
return wire_symbols


# pylint: enable=missing-param-doc
class MappingDisplayGate(ops.Gate):
"""Displays the indices mapped to a set of wires."""

Expand Down Expand Up @@ -188,22 +186,20 @@ class LinearPermutationGate(PermutationGate):
"""A permutation gate that decomposes a given permutation using a linear
sorting network."""

# TODO(#3388) Add documentation for Args.
# pylint: disable=missing-param-doc
def __init__(
self, num_qubits: int, permutation: Dict[int, int], swap_gate: 'cirq.Gate' = ops.SWAP
) -> None:
"""Initializes a linear permutation gate.
Args:
num_qubits: The number of qubits to permute.
permutation: The permutation effected by the gate.
swap_gate: The swap gate used in decompositions.
"""
super().__init__(num_qubits, swap_gate)
PermutationGate.validate_permutation(permutation, num_qubits)
self._permutation = permutation

# pylint: enable=missing-param-doc
def permutation(self) -> Dict[int, int]:
return self._permutation

Expand Down
10 changes: 5 additions & 5 deletions cirq/contrib/paulistring/separate.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,20 @@
from cirq.contrib.paulistring.convert_gate_set import converted_gate_set


# TODO(#3388) Add documentation for Args.
# pylint: disable=missing-param-doc
def convert_and_separate_circuit(
circuit: circuits.Circuit,
leave_cliffords: bool = True,
atol: float = 1e-8,
) -> Tuple[circuits.Circuit, circuits.Circuit]:
"""Converts any circuit into two circuits where (circuit_left+circuit_right)
is equivalent to the given circuit.
"""Converts a circuit into two, one made of PauliStringPhasor and the other Clifford gates.
Args:
circuit: Any Circuit that cirq.google.optimized_for_xmon() supports.
All gates should either provide a decomposition or have a known one
or two qubit unitary matrix.
leave_cliffords: If set, single qubit rotations in the Clifford group
are not converted to SingleQubitCliffordGates.
atol: The absolute tolerance for the conversion.
Returns:
(circuit_left, circuit_right)
Expand All @@ -43,12 +43,12 @@ def convert_and_separate_circuit(
SingleQubitCliffordGate and PauliInteractionGate gates.
It also contains MeasurementGates if the
given circuit contains measurements.
"""
circuit = converted_gate_set(circuit, no_clifford_gates=not leave_cliffords, atol=atol)
return pauli_string_half(circuit), regular_half(circuit)


# pylint: enable=missing-param-doc
def regular_half(circuit: circuits.Circuit) -> circuits.Circuit:
"""Return only the Clifford part of a circuit. See
convert_and_separate_circuit().
Expand Down
8 changes: 2 additions & 6 deletions cirq/interop/quirk/cells/testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@
from cirq import quirk_url_to_circuit


# TODO(#3388) Add summary line to docstring.
# pylint: disable=docstring-first-line-empty
def assert_url_to_circuit_returns(
json_text: str,
circuit: 'cirq.Circuit' = None,
Expand All @@ -31,7 +29,8 @@ def assert_url_to_circuit_returns(
output_amplitudes_from_quirk: Optional[List[Dict[str, float]]] = None,
maps: Optional[Dict[int, int]] = None,
):
"""
"""Assert that `quirk_url_to_circuit` functions correctly.
Args:
json_text: The part of the quirk URL after "#circuit=".
circuit: The optional expected circuit. If specified and not
Expand Down Expand Up @@ -80,6 +79,3 @@ def assert_url_to_circuit_returns(

if maps:
cirq.testing.assert_equivalent_computational_basis_map(maps, parsed)


# pylint: enable=docstring-first-line-empty
10 changes: 5 additions & 5 deletions cirq/ion/convert_to_ion_gates.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,17 @@ def __init__(self, ignore_failures: bool = False) -> None:
self.ignore_failures = ignore_failures
self.gateset = ion_device.get_ion_gateset()

# TODO(#3388) Add documentation for Raises.
# pylint: disable=missing-raises-doc
def convert_one(self, op: ops.Operation) -> ops.OP_TREE:
"""Convert a single (one- or two-qubit) operation into ion trap native gates.
Args:
op: gate operation to be converted
op: The gate operation to be converted.
Returns:
the desired operation implemented with ion trap gates
The desired operations implemented with ion trap gates.
Raises:
TypeError: If the operation cannot be converted.
"""

# Known gate name
Expand Down Expand Up @@ -80,7 +81,6 @@ def convert_one(self, op: ops.Operation) -> ops.OP_TREE:
"or composite.".format(op.gate)
)

# pylint: enable=missing-raises-doc
def convert_circuit(self, circuit: circuits.Circuit) -> circuits.Circuit:
new_circuit = circuits.Circuit()
for moment in circuit:
Expand Down
18 changes: 9 additions & 9 deletions cirq/ops/moment.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,6 @@ def operation_at(self, qubit: raw_types.Qid) -> Optional['cirq.Operation']:
else:
return None

# TODO(#3388) Add documentation for Raises.
# pylint: disable=missing-raises-doc
def with_operation(self, operation: 'cirq.Operation') -> 'cirq.Moment':
"""Returns an equal moment, but with the given op added.
Expand All @@ -147,6 +145,9 @@ def with_operation(self, operation: 'cirq.Operation') -> 'cirq.Moment':
Returns:
The new moment.
Raises:
ValueError: If the operation given overlaps a current operation in the moment.
"""
if any(q in self._qubits for q in operation.qubits):
raise ValueError(f'Overlapping operations: {operation}')
Expand All @@ -161,7 +162,6 @@ def with_operation(self, operation: 'cirq.Operation') -> 'cirq.Moment':

return m

# TODO(#3388) Add documentation for Raises.
def with_operations(self, *contents: 'cirq.OP_TREE') -> 'cirq.Moment':
"""Returns a new moment with the given contents added.
Expand All @@ -170,6 +170,9 @@ def with_operations(self, *contents: 'cirq.OP_TREE') -> 'cirq.Moment':
Returns:
The new moment.
Raises:
ValueError: If the contents given overlaps a current operation in the moment.
"""
from cirq.ops import op_tree

Expand All @@ -192,7 +195,6 @@ def with_operations(self, *contents: 'cirq.OP_TREE') -> 'cirq.Moment':

return m

# pylint: enable=missing-raises-doc
def without_operations_touching(self, qubits: Iterable['cirq.Qid']) -> 'cirq.Moment':
"""Returns an equal moment, but without ops on the given qubits.
Expand Down Expand Up @@ -375,8 +377,6 @@ def __getitem__(self, key):
ops_to_keep.append(self._qubit_to_op[q])
return Moment(frozenset(ops_to_keep))

# TODO(#3388) Add summary line to docstring.
# pylint: disable=docstring-first-line-empty
def to_text_diagram(
self: 'cirq.Moment',
*,
Expand All @@ -385,8 +385,9 @@ def to_text_diagram(
use_unicode_characters: bool = True,
precision: Optional[int] = None,
include_tags: bool = True,
):
"""
) -> str:
"""Create a text diagram for the moment.
Args:
xy_breakdown_func: A function to split qubits/qudits into x and y
components. For example, the default breakdown turns
Expand Down Expand Up @@ -469,7 +470,6 @@ def cleanup_key(key: Any) -> Any:

return diagram.render()

# pylint: enable=docstring-first-line-empty
def _commutes_(
self, other: Any, *, atol: Union[int, float] = 1e-8
) -> Union[bool, NotImplementedType]:
Expand Down
6 changes: 2 additions & 4 deletions cirq/sim/sparse_simulator_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -1174,10 +1174,9 @@ def test_random_seed_mixture_deterministic():
)


# TODO(#3388) Add summary line to docstring.
# pylint: disable=docstring-first-line-empty
def test_entangled_reset_does_not_break_randomness():
"""
"""Test for bad assumptions on caching the wave function on general channels.
A previous version of cirq made the mistake of assuming that it was okay to
cache the wavefunction produced by general channels on unrelated qubits
before repeatedly sampling measurements. This test checks for that mistake.
Expand All @@ -1194,7 +1193,6 @@ def test_entangled_reset_does_not_break_randomness():
assert 10 <= counts[1] <= 90


# pylint: enable=docstring-first-line-empty
def test_overlapping_measurements_at_end():
a, b = cirq.LineQubit.range(2)
circuit = cirq.Circuit(
Expand Down
12 changes: 4 additions & 8 deletions cirq/testing/equivalent_repr_eval.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
from typing import Any, Dict, Optional


# TODO(#3388) Add documentation for Raises.
# pylint: disable=missing-raises-doc
def assert_equivalent_repr(
value: Any,
*,
Expand All @@ -37,10 +35,11 @@ def assert_equivalent_repr(
evaluating the repr.
local_vals: Pre-defined values that should be in the local scope when
evaluating the repr.
Raises:
AssertionError: If the assertion fails, or eval(repr(value)) raises an error.
"""
# pylint: disable=unused-variable
__tracebackhide__ = True
# pylint: enable=unused-variable
__tracebackhide__ = True # pylint: disable=unused-variable

global_vals = global_vals or {}
local_vals = local_vals or {}
Expand Down Expand Up @@ -99,6 +98,3 @@ def assert_equivalent_repr(
"{!r}.XXX must be equivalent to ({!r}).XXX, "
"but it wasn't.".format(type(value), value, value)
)


# pylint: enable=missing-raises-doc

0 comments on commit 53596d3

Please sign in to comment.