Skip to content

Commit 1a6c16a

Browse files
authored
Format all files with black-24.3.0 (#6513)
Executed check/format-incremental --all --apply No change in code function.
1 parent ce045e3 commit 1a6c16a

File tree

57 files changed

+1798
-2786
lines changed

Some content is hidden

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

57 files changed

+1798
-2786
lines changed

cirq-aqt/cirq_aqt/aqt_sampler.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,9 @@ def _generate_json(
7777
RuntimeError: If the circuit is empty.
7878
"""
7979

80-
seq_list: List[
81-
Union[Tuple[str, float, List[int]], Tuple[str, float, float, List[int]]]
82-
] = []
80+
seq_list: List[Union[Tuple[str, float, List[int]], Tuple[str, float, float, List[int]]]] = (
81+
[]
82+
)
8383
circuit = cirq.resolve_parameters(circuit, param_resolver)
8484
for op in circuit.all_operations():
8585
line_qubit = cast(Tuple[cirq.LineQubit], op.qubits)

cirq-core/cirq/_compat.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -69,13 +69,11 @@ def with_debug(value: bool) -> Iterator[None]:
6969

7070

7171
@overload
72-
def cached_method(__func: TFunc) -> TFunc:
73-
...
72+
def cached_method(__func: TFunc) -> TFunc: ...
7473

7574

7675
@overload
77-
def cached_method(*, maxsize: int = 128) -> Callable[[TFunc], TFunc]:
78-
...
76+
def cached_method(*, maxsize: int = 128) -> Callable[[TFunc], TFunc]: ...
7977

8078

8179
def cached_method(method: Optional[TFunc] = None, *, maxsize: int = 128) -> Any:

cirq-core/cirq/circuits/moment.py

+10-6
Original file line numberDiff line numberDiff line change
@@ -283,9 +283,11 @@ def _resolve_parameters_(
283283

284284
def _with_measurement_key_mapping_(self, key_map: Mapping[str, str]):
285285
return Moment(
286-
protocols.with_measurement_key_mapping(op, key_map)
287-
if protocols.measurement_keys_touched(op)
288-
else op
286+
(
287+
protocols.with_measurement_key_mapping(op, key_map)
288+
if protocols.measurement_keys_touched(op)
289+
else op
290+
)
289291
for op in self.operations
290292
)
291293

@@ -320,9 +322,11 @@ def _with_key_path_(self, path: Tuple[str, ...]):
320322

321323
def _with_key_path_prefix_(self, prefix: Tuple[str, ...]):
322324
return Moment(
323-
protocols.with_key_path_prefix(op, prefix)
324-
if protocols.measurement_keys_touched(op)
325-
else op
325+
(
326+
protocols.with_key_path_prefix(op, prefix)
327+
if protocols.measurement_keys_touched(op)
328+
else op
329+
)
326330
for op in self.operations
327331
)
328332

cirq-core/cirq/circuits/qasm_output_test.py

+12-10
Original file line numberDiff line numberDiff line change
@@ -331,16 +331,18 @@ def __repr__(self):
331331
cirq.PhasedXPowGate(phase_exponent=0.333, exponent=0.5).on(q1),
332332
cirq.PhasedXPowGate(phase_exponent=0.777, exponent=-0.5).on(q1),
333333
(
334-
cirq.measure(q0, key='xX'),
335-
cirq.measure(q2, key='x_a'),
336-
cirq.measure(q1, key='x?'),
337-
cirq.measure(q3, key='X'),
338-
cirq.measure(q4, key='_x'),
339-
cirq.measure(q2, key='x_a'),
340-
cirq.measure(q1, q2, q3, key='multi', invert_mask=(False, True)),
341-
)
342-
if include_measurements
343-
else (),
334+
(
335+
cirq.measure(q0, key='xX'),
336+
cirq.measure(q2, key='x_a'),
337+
cirq.measure(q1, key='x?'),
338+
cirq.measure(q3, key='X'),
339+
cirq.measure(q4, key='_x'),
340+
cirq.measure(q2, key='x_a'),
341+
cirq.measure(q1, q2, q3, key='multi', invert_mask=(False, True)),
342+
)
343+
if include_measurements
344+
else ()
345+
),
344346
ExampleOperation(),
345347
ExampleCompositeOperation(),
346348
)

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

+9-7
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,15 @@ def hardcoded_qcircuit_diagram_info(op: ops.Operation) -> Optional[protocols.Cir
5151
symbols = (
5252
(r'\targ',)
5353
if op.gate == ops.X
54-
else (r'\control', r'\control')
55-
if op.gate == ops.CZ
56-
else (r'\control', r'\targ')
57-
if op.gate == ops.CNOT
58-
else (r'\meter',)
59-
if isinstance(op.gate, ops.MeasurementGate)
60-
else ()
54+
else (
55+
(r'\control', r'\control')
56+
if op.gate == ops.CZ
57+
else (
58+
(r'\control', r'\targ')
59+
if op.gate == ops.CNOT
60+
else (r'\meter',) if isinstance(op.gate, ops.MeasurementGate) else ()
61+
)
62+
)
6163
)
6264
return protocols.CircuitDiagramInfo(symbols) if symbols else None
6365

cirq-core/cirq/devices/superconducting_qubits_noise_properties.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -180,9 +180,9 @@ def build_noise_models(self) -> List['cirq.NoiseModel']:
180180
p_00, p_11 = self.readout_errors[qubit]
181181
p = p_11 / (p_00 + p_11)
182182
gamma = p_11 / p
183-
added_measure_errors[
184-
noise_utils.OpIdentifier(ops.MeasurementGate, qubit)
185-
] = ops.generalized_amplitude_damp(p, gamma).on(qubit)
183+
added_measure_errors[noise_utils.OpIdentifier(ops.MeasurementGate, qubit)] = (
184+
ops.generalized_amplitude_damp(p, gamma).on(qubit)
185+
)
186186

187187
noise_models.append(
188188
devices.InsertionNoiseModel(ops_added=added_measure_errors, prepend=True)

cirq-core/cirq/experiments/qubit_characterizations.py

+2-10
Original file line numberDiff line numberDiff line change
@@ -953,16 +953,8 @@ def _single_qubit_cliffords() -> Cliffords:
953953
for z0, x, z1 in phi_xz:
954954
c1_in_xz.append([Z**z0, X**x, Z**z1])
955955

956-
s1: List[List[ops.SingleQubitCliffordGate]] = [
957-
[X**0.0],
958-
[Y**0.5, X**0.5],
959-
[X**-0.5, Y**-0.5],
960-
]
961-
s1_x: List[List[ops.SingleQubitCliffordGate]] = [
962-
[X**0.5],
963-
[X**0.5, Y**0.5, X**0.5],
964-
[Y**-0.5],
965-
]
956+
s1: List[List[ops.SingleQubitCliffordGate]] = [[X**0.0], [Y**0.5, X**0.5], [X**-0.5, Y**-0.5]]
957+
s1_x: List[List[ops.SingleQubitCliffordGate]] = [[X**0.5], [X**0.5, Y**0.5, X**0.5], [Y**-0.5]]
966958
s1_y: List[List[ops.SingleQubitCliffordGate]] = [
967959
[Y**0.5],
968960
[X**-0.5, Y**-0.5, X**0.5],

cirq-core/cirq/experiments/single_qubit_readout_calibration.py

+10-6
Original file line numberDiff line numberDiff line change
@@ -343,15 +343,19 @@ def estimate_parallel_single_qubit_readout_errors(
343343
trial_idx += 1
344344

345345
zero_state_errors = {
346-
q: zero_state_trials[0][qubit_idx] / zero_state_totals[0][qubit_idx]
347-
if zero_state_totals[0][qubit_idx] > 0
348-
else np.nan
346+
q: (
347+
zero_state_trials[0][qubit_idx] / zero_state_totals[0][qubit_idx]
348+
if zero_state_totals[0][qubit_idx] > 0
349+
else np.nan
350+
)
349351
for qubit_idx, q in enumerate(qubits)
350352
}
351353
one_state_errors = {
352-
q: one_state_trials[0][qubit_idx] / one_state_totals[0][qubit_idx]
353-
if one_state_totals[0][qubit_idx] > 0
354-
else np.nan
354+
q: (
355+
one_state_trials[0][qubit_idx] / one_state_totals[0][qubit_idx]
356+
if one_state_totals[0][qubit_idx] > 0
357+
else np.nan
358+
)
355359
for qubit_idx, q in enumerate(qubits)
356360
}
357361

cirq-core/cirq/linalg/decompositions.py

+6-10
Original file line numberDiff line numberDiff line change
@@ -451,18 +451,14 @@ def __init__(
451451
single_qubit_operations_after: a0, a1 from the above equation.
452452
"""
453453
self.global_phase: complex = global_phase
454-
self.single_qubit_operations_before: Tuple[
455-
np.ndarray, np.ndarray
456-
] = single_qubit_operations_before or (
457-
np.eye(2, dtype=np.complex64),
458-
np.eye(2, dtype=np.complex64),
454+
self.single_qubit_operations_before: Tuple[np.ndarray, np.ndarray] = (
455+
single_qubit_operations_before
456+
or (np.eye(2, dtype=np.complex64), np.eye(2, dtype=np.complex64))
459457
)
460458
self.interaction_coefficients = interaction_coefficients
461-
self.single_qubit_operations_after: Tuple[
462-
np.ndarray, np.ndarray
463-
] = single_qubit_operations_after or (
464-
np.eye(2, dtype=np.complex64),
465-
np.eye(2, dtype=np.complex64),
459+
self.single_qubit_operations_after: Tuple[np.ndarray, np.ndarray] = (
460+
single_qubit_operations_after
461+
or (np.eye(2, dtype=np.complex64), np.eye(2, dtype=np.complex64))
466462
)
467463

468464
def _value_equality_values_(self) -> Any:

cirq-core/cirq/linalg/decompositions_test.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -422,9 +422,7 @@ def test_axis_angle_decomposition_str():
422422
assert (
423423
str(
424424
cirq.axis_angle(
425-
cirq.unitary(cirq.X**0.25)
426-
@ cirq.unitary(cirq.Y**0.25)
427-
@ cirq.unitary(cirq.Z**0.25)
425+
cirq.unitary(cirq.X**0.25) @ cirq.unitary(cirq.Y**0.25) @ cirq.unitary(cirq.Z**0.25)
428426
)
429427
)
430428
== '0.477*π around 0.679*X+0.281*Y+0.679*Z'

cirq-core/cirq/linalg/transformations_test.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -584,7 +584,7 @@ def test_partial_trace_of_state_vector_as_mixture_mixed_result():
584584
(0.5, np.array([1, 0, 0, 0]).reshape((2, 2))),
585585
(0.5, np.array([0, 0, 0, 1]).reshape((2, 2))),
586586
)
587-
for (q1, q2) in [(0, 1), (0, 2), (1, 2)]:
587+
for q1, q2 in [(0, 1), (0, 2), (1, 2)]:
588588
mixture = cirq.partial_trace_of_state_vector_as_mixture(state, [q1, q2], atol=1e-8)
589589
assert mixtures_equal(mixture, truth)
590590

cirq-core/cirq/ops/common_gates_test.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,7 @@ def test_cz_unitary():
8787
)
8888

8989
assert np.allclose(
90-
cirq.unitary(cirq.CZ**0),
91-
np.array([[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]]),
90+
cirq.unitary(cirq.CZ**0), np.array([[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]])
9291
)
9392

9493
assert np.allclose(

cirq-core/cirq/ops/controlled_gate_test.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -452,9 +452,7 @@ def test_extrapolatable_effect():
452452

453453
assert cirq.ControlledGate(cirq.Z) ** 0.5 == cirq.ControlledGate(cirq.Z**0.5)
454454

455-
assert cirq.ControlledGate(cirq.Z).on(a, b) ** 0.5 == cirq.ControlledGate(cirq.Z**0.5).on(
456-
a, b
457-
)
455+
assert cirq.ControlledGate(cirq.Z).on(a, b) ** 0.5 == cirq.ControlledGate(cirq.Z**0.5).on(a, b)
458456

459457
assert cirq.ControlledGate(cirq.Z) ** 0.5 == cirq.ControlledGate(cirq.Z**0.5)
460458

cirq-core/cirq/ops/phased_iswap_gate_test.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,7 @@ def test_phased_iswap_init():
3434

3535
def test_phased_iswap_equality():
3636
eq = cirq.testing.EqualsTester()
37-
eq.add_equality_group(
38-
cirq.PhasedISwapPowGate(phase_exponent=0, exponent=0.4), cirq.ISWAP**0.4
39-
)
37+
eq.add_equality_group(cirq.PhasedISwapPowGate(phase_exponent=0, exponent=0.4), cirq.ISWAP**0.4)
4038
eq.add_equality_group(
4139
cirq.PhasedISwapPowGate(phase_exponent=0, exponent=0.4, global_shift=0.3),
4240
cirq.ISwapPowGate(global_shift=0.3) ** 0.4,

cirq-core/cirq/ops/qid_util.py

+3-6
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,15 @@
1919

2020

2121
@overload
22-
def q(__x: int) -> 'cirq.LineQubit':
23-
...
22+
def q(__x: int) -> 'cirq.LineQubit': ...
2423

2524

2625
@overload
27-
def q(__row: int, __col: int) -> 'cirq.GridQubit':
28-
...
26+
def q(__row: int, __col: int) -> 'cirq.GridQubit': ...
2927

3028

3129
@overload
32-
def q(__name: str) -> 'cirq.NamedQubit':
33-
...
30+
def q(__name: str) -> 'cirq.NamedQubit': ...
3431

3532

3633
def q(*args: Union[int, str]) -> Union['cirq.LineQubit', 'cirq.GridQubit', 'cirq.NamedQubit']:

cirq-core/cirq/protocols/circuit_diagram_info_protocol.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -221,9 +221,11 @@ def _value_equality_values_(self) -> Any:
221221
self.known_qubit_count,
222222
self.use_unicode_characters,
223223
self.precision,
224-
None
225-
if self.label_map is None
226-
else tuple(sorted(self.label_map.items(), key=lambda e: e[0])),
224+
(
225+
None
226+
if self.label_map is None
227+
else tuple(sorted(self.label_map.items(), key=lambda e: e[0]))
228+
),
227229
self.include_tags,
228230
self.transpose,
229231
)

cirq-core/cirq/protocols/commutes_protocol.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -74,15 +74,13 @@ def _commutes_(self, other: Any, *, atol: float) -> Union[None, bool, NotImpleme
7474

7575

7676
@overload
77-
def commutes(v1: Any, v2: Any, *, atol: Union[int, float] = 1e-8) -> bool:
78-
...
77+
def commutes(v1: Any, v2: Any, *, atol: Union[int, float] = 1e-8) -> bool: ...
7978

8079

8180
@overload
8281
def commutes(
8382
v1: Any, v2: Any, *, atol: Union[int, float] = 1e-8, default: TDefault
84-
) -> Union[bool, TDefault]:
85-
...
83+
) -> Union[bool, TDefault]: ...
8684

8785

8886
def commutes(

cirq-core/cirq/protocols/decompose_protocol.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,7 @@
5757
class OpDecomposerWithContext(Protocol):
5858
def __call__(
5959
self, __op: 'cirq.Operation', *, context: Optional['cirq.DecompositionContext'] = None
60-
) -> DecomposeResult:
61-
...
60+
) -> DecomposeResult: ...
6261

6362

6463
OpDecomposer = Union[Callable[['cirq.Operation'], DecomposeResult], OpDecomposerWithContext]

cirq-core/cirq/protocols/decompose_protocol_test.py

+7-3
Original file line numberDiff line numberDiff line change
@@ -346,9 +346,13 @@ def _num_qubits_(self) -> int:
346346

347347
def _decompose_impl(self, qubits, mock_qm: mock.Mock):
348348
mock_qm.qalloc(self.recurse)
349-
yield RecursiveDecompose(
350-
recurse=False, mock_qm=self.mock_qm, with_context=self.with_context
351-
).on(*qubits) if self.recurse else cirq.Z.on_each(*qubits)
349+
yield (
350+
RecursiveDecompose(
351+
recurse=False, mock_qm=self.mock_qm, with_context=self.with_context
352+
).on(*qubits)
353+
if self.recurse
354+
else cirq.Z.on_each(*qubits)
355+
)
352356
mock_qm.qfree(self.recurse)
353357

354358
def _decompose_(self, qubits):

cirq-core/cirq/protocols/json_serialization.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,7 @@
4747
class JsonResolver(Protocol):
4848
"""Protocol for json resolver functions passed to read_json."""
4949

50-
def __call__(self, cirq_type: str) -> Optional[ObjectFactory]:
51-
...
50+
def __call__(self, cirq_type: str) -> Optional[ObjectFactory]: ...
5251

5352

5453
def _lazy_resolver(dict_factory: Callable[[], Dict[str, ObjectFactory]]) -> JsonResolver:

cirq-core/cirq/protocols/pow_protocol_test.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,4 @@ def test_pow_error():
4949

5050
@pytest.mark.parametrize('val,exponent,out', ((ReturnsExponent(), 2, 2), (1, 2, 1), (2, 3, 8)))
5151
def test_pow_with_result(val, exponent, out):
52-
assert (
53-
cirq.pow(val, exponent) == cirq.pow(val, exponent, default=None) == val**exponent == out
54-
)
52+
assert cirq.pow(val, exponent) == cirq.pow(val, exponent, default=None) == val**exponent == out

cirq-core/cirq/sim/mux.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -292,9 +292,11 @@ def final_density_matrix(
292292
density_result = density_matrix_simulator.DensityMatrixSimulator(
293293
dtype=dtype, noise=noise, seed=seed
294294
).simulate(
295-
program=measurement_transformers.dephase_measurements(circuit_like)
296-
if ignore_measurement_results
297-
else circuit_like,
295+
program=(
296+
measurement_transformers.dephase_measurements(circuit_like)
297+
if ignore_measurement_results
298+
else circuit_like
299+
),
298300
initial_state=initial_state,
299301
qubit_order=qubit_order,
300302
param_resolver=param_resolver,

cirq-core/cirq/sim/simulation_product_state.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,7 @@ def _act_on_fallback_(
8383
gate_opt = (
8484
action
8585
if isinstance(action, ops.Gate)
86-
else action.gate
87-
if isinstance(action, ops.Operation)
88-
else None
86+
else action.gate if isinstance(action, ops.Operation) else None
8987
)
9088

9189
if isinstance(gate_opt, ops.IdentityGate):

cirq-core/cirq/sim/simulator_base.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -261,9 +261,9 @@ def _run(
261261
for i in range(repetitions):
262262
for step_result in self._core_iterator(
263263
general_suffix,
264-
sim_state=sim_state.copy(deep_copy_buffers=False)
265-
if i < repetitions - 1
266-
else sim_state,
264+
sim_state=(
265+
sim_state.copy(deep_copy_buffers=False) if i < repetitions - 1 else sim_state
266+
),
267267
):
268268
pass
269269
for k, r in step_result._classical_data.records.items():

cirq-core/cirq/transformers/heuristic_decompositions/two_qubit_gate_tabulation.py

+1
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ class TwoQubitGateTabulationResult(NamedTuple):
5555
equal to U_target.
5656
success: Whether actual_gate is expected to be close to U_target.
5757
"""
58+
5859
base_gate_unitary: np.ndarray
5960
target_gate: np.ndarray
6061
local_unitaries: Tuple[_SingleQubitGatePair, ...]

0 commit comments

Comments
 (0)