Skip to content

Commit 2b60958

Browse files
author
Nate Thompson
committed
Add missing-raises-doc rule to the linter and subsequent refactor.
1 parent 912110f commit 2b60958

File tree

106 files changed

+574
-122
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

106 files changed

+574
-122
lines changed

cirq-aqt/cirq_aqt/aqt_device.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,14 @@
3131
gate_dict = {'X': cirq.X, 'Y': cirq.Y, 'Z': cirq.Z, 'MS': cirq.XX, 'R': cirq.PhasedXPowGate}
3232

3333

34+
# TODO(#3388) Add documentation for Raises.
35+
# pylint: disable=missing-raises-doc
3436
def get_op_string(op_obj: cirq.Operation) -> str:
3537
"""Find the string representation for a given gate
3638
3739
Args:
3840
op_obj: Gate object, one of: XXPowGate, XPowGate, YPowGate, ZPowGate,
39-
PhasedXPowGate
41+
PhasedXPowGate
4042
4143
Returns:
4244
String representing the gate operations
@@ -58,6 +60,7 @@ def get_op_string(op_obj: cirq.Operation) -> str:
5860
return op_str
5961

6062

63+
# pylint: enable=missing-raises-doc
6164
class AQTNoiseModel(cirq.NoiseModel):
6265
"""A noise model for the AQT ion trap """
6366

@@ -190,6 +193,8 @@ def generate_circuit_from_list(self, json_string: str):
190193
# Github issue: https://github.com/quantumlib/Cirq/issues/2199
191194
self.circuit.append(cirq.measure(*[qubit for qubit in self.qubit_list], key='m'))
192195

196+
# TODO(#3388) Add documentation for Raises.
197+
# pylint: disable=missing-raises-doc
193198
def simulate_samples(self, repetitions: int) -> cirq.Result:
194199
"""Samples the circuit
195200
@@ -210,6 +215,7 @@ def simulate_samples(self, repetitions: int) -> cirq.Result:
210215
return result
211216

212217

218+
# pylint: enable=missing-raises-doc
213219
def get_aqt_device(num_qubits: int) -> Tuple[cirq.IonDevice, List[cirq.LineQubit]]:
214220
"""Returns an AQT ion device
215221

cirq-aqt/cirq_aqt/aqt_sampler.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,14 @@ def __init__(self, remote_host: str, access_token: str):
5050
self.remote_host = remote_host
5151
self.access_token = access_token
5252

53+
# TODO(#3388) Add documentation for Raises.
54+
# pylint: disable=missing-raises-doc
5355
def _generate_json(
5456
self,
5557
circuit: cirq.Circuit,
5658
param_resolver: cirq.ParamResolverOrSimilarType,
5759
) -> str:
58-
"""Generates the JSON string from a Circuit
60+
"""Generates the JSON string from a Circuit.
5961
6062
The json format is defined as follows:
6163
@@ -99,6 +101,7 @@ def _generate_json(
99101
json_str = json.dumps(seq_list)
100102
return json_str
101103

104+
# TODO(#3388) Add documentation for Raises.
102105
def _send_json(
103106
self,
104107
*,
@@ -171,6 +174,7 @@ def _send_json(
171174
measurements[i, j] = int(measurement_int_bin[j])
172175
return measurements
173176

177+
# pylint: enable=missing-raises-doc
174178
def run_sweep(
175179
self, program: cirq.Circuit, params: cirq.Sweepable, repetitions: int = 1
176180
) -> List[cirq.Result]:

cirq-core/cirq/circuits/circuit.py

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1814,6 +1814,8 @@ def zip(
18141814

18151815
zip.__doc__ = AbstractCircuit.zip.__doc__
18161816

1817+
# TODO(#3388) Add documentation for Raises.
1818+
# pylint: disable=missing-raises-doc
18171819
def transform_qubits(
18181820
self,
18191821
qubit_map: Union[Dict['cirq.Qid', 'cirq.Qid'], Callable[['cirq.Qid'], 'cirq.Qid']],
@@ -1847,6 +1849,7 @@ def transform_qubits(
18471849
new_device=self.device if new_device is None else new_device, qubit_mapping=transform
18481850
)
18491851

1852+
# pylint: enable=missing-raises-doc
18501853
def _prev_moment_available(self, op: 'cirq.Operation', end_moment_index: int) -> Optional[int]:
18511854
last_available = end_moment_index
18521855
k = end_moment_index
@@ -2083,6 +2086,8 @@ def _insert_operations(
20832086
self._moments[moment_index].operations + tuple(new_ops)
20842087
)
20852088

2089+
# TODO(#3388) Add documentation for Raises.
2090+
# pylint: disable=missing-raises-doc
20862091
def insert_at_frontier(
20872092
self, operations: 'cirq.OP_TREE', start: int, frontier: Dict['cirq.Qid', int] = None
20882093
) -> Dict['cirq.Qid', int]:
@@ -2116,6 +2121,7 @@ def insert_at_frontier(
21162121

21172122
return frontier
21182123

2124+
# pylint: enable=missing-raises-doc
21192125
def batch_remove(self, removals: Iterable[Tuple[int, 'cirq.Operation']]) -> None:
21202126
"""Removes several operations from a circuit.
21212127
@@ -2125,11 +2131,9 @@ def batch_remove(self, removals: Iterable[Tuple[int, 'cirq.Operation']]) -> None
21252131
listed operations must actually be present or the edit will
21262132
fail (without making any changes to the circuit).
21272133
2128-
ValueError:
2129-
One of the operations to delete wasn't present to start with.
2130-
2131-
IndexError:
2132-
Deleted from a moment that doesn't exist.
2134+
Raises:
2135+
ValueError: One of the operations to delete wasn't present to start with.
2136+
IndexError: Deleted from a moment that doesn't exist.
21332137
"""
21342138
copy = self.copy()
21352139
for i, op in removals:
@@ -2152,11 +2156,9 @@ def batch_replace(
21522156
operations must actually be present or the edit will fail
21532157
(without making any changes to the circuit).
21542158
2155-
ValueError:
2156-
One of the operations to replace wasn't present to start with.
2157-
2158-
IndexError:
2159-
Replaced in a moment that doesn't exist.
2159+
Raises:
2160+
ValueError: One of the operations to replace wasn't present to start with.
2161+
IndexError: Replaced in a moment that doesn't exist.
21602162
"""
21612163
copy = self.copy()
21622164
for i, op, new_op in replacements:

cirq-core/cirq/contrib/acquaintance/executor.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,8 @@ class GreedyExecutionStrategy(ExecutionStrategy):
131131
qubits in any order are inserted.
132132
"""
133133

134+
# TODO(#3388) Add documentation for Raises.
135+
# pylint: disable=missing-raises-doc
134136
def __init__(
135137
self, gates: LogicalGates, initial_mapping: LogicalMapping, device: 'cirq.Device' = None
136138
) -> None:
@@ -149,6 +151,7 @@ def __init__(
149151
self._initial_mapping = initial_mapping.copy()
150152
self._device = device or devices.UNCONSTRAINED_DEVICE
151153

154+
# pylint: enable=missing-raises-doc
152155
@property
153156
def initial_mapping(self) -> LogicalMapping:
154157
return self._initial_mapping

cirq-core/cirq/contrib/acquaintance/mutation_utils.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
STRATEGY_GATE = Union[AcquaintanceOpportunityGate, PermutationGate]
2929

3030

31+
# TODO(#3388) Add documentation for Raises.
32+
# pylint: disable=missing-raises-doc
3133
def rectify_acquaintance_strategy(circuit: 'cirq.Circuit', acquaint_first: bool = True) -> None:
3234
"""Splits moments so that they contain either only acquaintance gates
3335
or only permutation gates. Orders resulting moments so that the first one
@@ -57,6 +59,7 @@ def rectify_acquaintance_strategy(circuit: 'cirq.Circuit', acquaint_first: bool
5759
circuit._moments = rectified_moments
5860

5961

62+
# pylint: enable=missing-raises-doc
6063
# TODO(#3388) Add summary line to docstring.
6164
# pylint: disable=docstring-first-line-empty
6265
def replace_acquaintance_with_swap_network(

cirq-core/cirq/contrib/acquaintance/strategies/complete.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@
2828

2929

3030
# TODO(#3388) Add summary line to docstring.
31-
# pylint: disable=docstring-first-line-empty
31+
# TODO(#3388) Add documentation for Raises.
32+
# pylint: disable=docstring-first-line-empty,missing-raises-doc
3233
def complete_acquaintance_strategy(
3334
qubit_order: Sequence['cirq.Qid'], acquaintance_size: int = 0, swap_gate: 'cirq.Gate' = ops.SWAP
3435
) -> 'cirq.Circuit':
@@ -65,4 +66,4 @@ def complete_acquaintance_strategy(
6566
return strategy
6667

6768

68-
# pylint: enable=docstring-first-line-empty
69+
# pylint: enable=docstring-first-line-empty,missing-raises-doc

cirq-core/cirq/contrib/graph_device/graph_device.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,8 @@ class UndirectedGraphDevice(devices.Device):
120120
* duration_of does not check that operation is valid.
121121
"""
122122

123+
# TODO(#3388) Add documentation for Raises.
124+
# pylint: disable=missing-raises-doc
123125
def __init__(
124126
self,
125127
device_graph: Optional[UndirectedHypergraph] = None,
@@ -148,6 +150,7 @@ def __init__(
148150
self.device_graph = device_graph
149151
self.crosstalk_graph = crosstalk_graph
150152

153+
# pylint: enable=missing-raises-doc
151154
@property
152155
def qubits(self) -> Tuple['cirq.Qid', ...]:
153156
return cast(Tuple['cirq.Qid', ...], tuple(sorted(self.device_graph.vertices)))

cirq-core/cirq/contrib/qcircuit/qcircuit_pdf.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
from cirq.contrib.qcircuit.qcircuit_diagram import circuit_to_latex_using_qcircuit
2424

2525

26+
# TODO(#3388) Add documentation for Raises.
27+
# pylint: disable=missing-raises-doc
2628
def circuit_to_pdf_using_qcircuit_via_tex(
2729
circuit: circuits.Circuit,
2830
filepath: str,
@@ -63,3 +65,6 @@ def circuit_to_pdf_using_qcircuit_via_tex(
6365
except (OSError, IOError) as e:
6466
if e.errno != errno.ENOENT:
6567
raise
68+
69+
70+
# pylint: enable=missing-raises-doc

cirq-core/cirq/contrib/quimb/density_matrix.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ def _add_to_positions(
7070
positions[(f'i{mi}b', _qpos_tag(qubits))] = (mi * x_scale, y_scale * qy + yb_offset)
7171

7272

73+
# TODO(#3388) Add documentation for Raises.
74+
# pylint: disable=missing-raises-doc
7375
def circuit_to_density_matrix_tensors(
7476
circuit: cirq.Circuit, qubits: Optional[Sequence[cirq.LineQubit]] = None
7577
) -> Tuple[List[qtn.Tensor], Dict['cirq.Qid', int], Dict[Tuple[str, str], Tuple[float, float]]]:
@@ -186,6 +188,7 @@ def _positions(mi, qubits):
186188
return tensors, qubit_frontier, positions
187189

188190

191+
# pylint: enable=missing-raises-doc
189192
def tensor_density_matrix(
190193
circuit: cirq.Circuit, qubits: Optional[List[cirq.LineQubit]] = None
191194
) -> np.ndarray:

cirq-core/cirq/contrib/quimb/mps_simulator.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ class MPSSimulator(
5959
):
6060
"""An efficient simulator for MPS circuits."""
6161

62+
# TODO(#3388) Add documentation for Raises.
63+
# pylint: disable=missing-raises-doc
6264
def __init__(
6365
self,
6466
noise: 'cirq.NOISE_MODEL_LIKE' = None,
@@ -85,6 +87,7 @@ def __init__(
8587
seed=seed,
8688
)
8789

90+
# pylint: enable=missing-raises-doc
8891
def _create_partial_act_on_args(
8992
self,
9093
initial_state: Union[int, 'MPSState'],
@@ -206,6 +209,8 @@ def _simulator_state(self):
206209
class MPSState(ActOnArgs):
207210
"""A state of the MPS simulation."""
208211

212+
# TODO(#3388) Add documentation for Raises.
213+
# pylint: disable=missing-raises-doc
209214
@deprecated_parameter(
210215
deadline='v0.13',
211216
fix='No longer needed. `protocols.act_on` infers axes.',
@@ -274,6 +279,7 @@ def __init__(
274279
self.simulation_options = simulation_options
275280
self.estimated_gate_error_list: List[float] = []
276281

282+
# pylint: enable=missing-raises-doc
277283
def i_str(self, i: int) -> str:
278284
# Returns the index name for the i'th qid.
279285
return self.format_i.format(i)
@@ -464,6 +470,8 @@ def estimation_stats(self):
464470
"estimated_fidelity": estimated_fidelity,
465471
}
466472

473+
# TODO(#3388) Add documentation for Raises.
474+
# pylint: disable=missing-raises-doc
467475
def perform_measurement(
468476
self, qubits: Sequence[ops.Qid], prng: np.random.RandomState, collapse_state_vector=True
469477
) -> List[int]:
@@ -513,6 +521,7 @@ def perform_measurement(
513521

514522
return results
515523

524+
# pylint: enable=missing-raises-doc
516525
def _perform_measurement(self, qubits: Sequence['cirq.Qid']) -> List[int]:
517526
"""Measures the axes specified by the simulator."""
518527
return self.perform_measurement(qubits, self.prng)

0 commit comments

Comments
 (0)