Skip to content

Commit fbd1240

Browse files
authored
Format cirq-core with latest version of black (quantumlib#5159)
Review: @dabacon
1 parent 4956eae commit fbd1240

File tree

150 files changed

+895
-946
lines changed

Some content is hidden

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

150 files changed

+895
-946
lines changed

cirq/circuits/circuit.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1035,7 +1035,7 @@ def _superoperator_(self) -> np.ndarray:
10351035
if n > 10:
10361036
raise ValueError(f"{n} > 10 qubits is too many to compute superoperator")
10371037

1038-
circuit_superoperator = np.eye(4 ** n)
1038+
circuit_superoperator = np.eye(4**n)
10391039
for moment in self:
10401040
full_moment = moment.expand_to(all_qubits)
10411041
moment_superoperator = full_moment._superoperator_()

cirq/circuits/circuit_operation.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ def _mapped_single_loop(self, repetition_id: Optional[str] = None) -> 'cirq.Circ
300300
if self.qubit_map:
301301
circuit = circuit.transform_qubits(lambda q: self.qubit_map.get(q, q))
302302
if isinstance(self.repetitions, INT_CLASSES) and self.repetitions < 0:
303-
circuit = circuit ** -1
303+
circuit = circuit**-1
304304
if self.measurement_key_map:
305305
circuit = protocols.with_measurement_key_mapping(circuit, self.measurement_key_map)
306306
if self.param_resolver:

cirq/circuits/circuit_operation_test.py

+7-7
Original file line numberDiff line numberDiff line change
@@ -307,12 +307,12 @@ def test_repeat(add_measurements, use_default_ids_for_initial_rep):
307307
if use_default_ids_for_initial_rep:
308308
op_with_reps = op_base.repeat(initial_repetitions)
309309
rep_ids = ['0', '1', '2']
310-
assert op_base ** initial_repetitions == op_with_reps
310+
assert op_base**initial_repetitions == op_with_reps
311311
else:
312312
rep_ids = ['a', 'b', 'c']
313313
op_with_reps = op_base.repeat(initial_repetitions, rep_ids)
314-
assert op_base ** initial_repetitions != op_with_reps
315-
assert (op_base ** initial_repetitions).replace(repetition_ids=rep_ids) == op_with_reps
314+
assert op_base**initial_repetitions != op_with_reps
315+
assert (op_base**initial_repetitions).replace(repetition_ids=rep_ids) == op_with_reps
316316
assert op_with_reps.repetitions == initial_repetitions
317317
assert op_with_reps.repetition_ids == rep_ids
318318
assert op_with_reps.repeat(1) is op_with_reps
@@ -322,7 +322,7 @@ def test_repeat(add_measurements, use_default_ids_for_initial_rep):
322322
op_with_consecutive_reps = op_with_reps.repeat(2)
323323
assert op_with_consecutive_reps.repetitions == final_repetitions
324324
assert op_with_consecutive_reps.repetition_ids == _full_join_string_lists(['0', '1'], rep_ids)
325-
assert op_base ** final_repetitions != op_with_consecutive_reps
325+
assert op_base**final_repetitions != op_with_consecutive_reps
326326

327327
op_with_consecutive_reps = op_with_reps.repeat(2, ['a', 'b'])
328328
assert op_with_reps.repeat(repetition_ids=['a', 'b']) == op_with_consecutive_reps
@@ -357,7 +357,7 @@ def test_repeat_zero_times(add_measurements, use_repetition_ids, initial_reps):
357357
)
358358
result = cirq.Simulator().simulate(cirq.Circuit(op))
359359
assert np.allclose(result.state_vector(), [0, 1] if initial_reps % 2 else [1, 0])
360-
result = cirq.Simulator().simulate(cirq.Circuit(op ** 0))
360+
result = cirq.Simulator().simulate(cirq.Circuit(op**0))
361361
assert np.allclose(result.state_vector(), [1, 0])
362362

363363

@@ -378,7 +378,7 @@ def test_parameterized_repeat():
378378
cirq.Simulator().simulate(cirq.Circuit(op), param_resolver={'a': 1.5})
379379
with pytest.raises(ValueError, match='Circuit contains ops whose symbols were not specified'):
380380
cirq.Simulator().simulate(cirq.Circuit(op))
381-
op = op ** -1
381+
op = op**-1
382382
assert cirq.parameter_names(op) == {'a'}
383383
assert not cirq.has_unitary(op)
384384
result = cirq.Simulator().simulate(cirq.Circuit(op), param_resolver={'a': 0})
@@ -406,7 +406,7 @@ def test_parameterized_repeat():
406406
cirq.Simulator().simulate(cirq.Circuit(op), param_resolver={'a': 1.5, 'b': 1})
407407
with pytest.raises(ValueError, match='Circuit contains ops whose symbols were not specified'):
408408
cirq.Simulator().simulate(cirq.Circuit(op))
409-
op = op ** 2.0
409+
op = op**2.0
410410
assert cirq.parameter_names(op) == {'a', 'b'}
411411
assert not cirq.has_unitary(op)
412412
result = cirq.Simulator().simulate(cirq.Circuit(op), param_resolver={'a': 1, 'b': 1})

cirq/circuits/circuit_test.py

+32-41
Original file line numberDiff line numberDiff line change
@@ -1307,7 +1307,7 @@ def test_next_moment_operating_on_distance(circuit_cls):
13071307
assert c.next_moment_operating_on([a], 1, max_distance=500) == 4
13081308

13091309
# Huge max distances should be handled quickly due to capping.
1310-
assert c.next_moment_operating_on([a], 5, max_distance=10 ** 100) is None
1310+
assert c.next_moment_operating_on([a], 5, max_distance=10**100) is None
13111311

13121312
with pytest.raises(ValueError, match='Negative max_distance'):
13131313
c.next_moment_operating_on([a], 0, max_distance=-1)
@@ -1396,7 +1396,7 @@ def test_prev_moment_operating_on_distance(circuit_cls):
13961396
assert c.prev_moment_operating_on([a], 13, max_distance=500) == 1
13971397

13981398
# Huge max distances should be handled quickly due to capping.
1399-
assert c.prev_moment_operating_on([a], 1, max_distance=10 ** 100) is None
1399+
assert c.prev_moment_operating_on([a], 1, max_distance=10**100) is None
14001400

14011401
with pytest.raises(ValueError, match='Negative max_distance'):
14021402
c.prev_moment_operating_on([a], 6, max_distance=-1)
@@ -1703,7 +1703,7 @@ def test_findall_operations_until_blocked(circuit_cls):
17031703
)
17041704

17051705

1706-
@pytest.mark.parametrize('seed', [randint(0, 2 ** 31)])
1706+
@pytest.mark.parametrize('seed', [randint(0, 2**31)])
17071707
@pytest.mark.parametrize('circuit_cls', [cirq.Circuit, cirq.FrozenCircuit])
17081708
def test_findall_operations_until_blocked_docstring_examples(seed, circuit_cls):
17091709
prng = np.random.RandomState(seed)
@@ -2861,7 +2861,7 @@ def pauli_error_probability(r: float, n_qubits: int) -> float:
28612861
makes it simple to compute the serial composition of depolarizing channels. It
28622862
is multiplicative under channel composition.
28632863
"""
2864-
d2 = 4 ** n_qubits
2864+
d2 = 4**n_qubits
28652865
return (1 - r) * (d2 - 1) / d2
28662866

28672867
def depolarize(r: float, n_qubits: int) -> cirq.DepolarizingChannel:
@@ -4062,9 +4062,9 @@ def test_submoments(circuit_cls):
40624062
cirq.H.on(d),
40634063
cirq.CZ.on(a, d),
40644064
cirq.CZ.on(b, c),
4065-
(cirq.CNOT ** 0.5).on(a, d),
4066-
(cirq.CNOT ** 0.5).on(b, e),
4067-
(cirq.CNOT ** 0.5).on(c, f),
4065+
(cirq.CNOT**0.5).on(a, d),
4066+
(cirq.CNOT**0.5).on(b, e),
4067+
(cirq.CNOT**0.5).on(c, f),
40684068
cirq.H.on(c),
40694069
cirq.H.on(e),
40704070
)
@@ -4191,15 +4191,12 @@ def test_measurement_key_mapping(circuit_cls):
41914191
assert simulator.run(c).measurements == {'m1': 1, 'm2': 0}
41924192
assert simulator.run(c_swapped).measurements == {'m1': 0, 'm2': 1}
41934193

4194-
assert (
4195-
cirq.with_measurement_key_mapping(
4196-
c,
4197-
{
4198-
'x': 'z',
4199-
},
4200-
).all_measurement_key_names()
4201-
== {'m1', 'm2'}
4202-
)
4194+
assert cirq.with_measurement_key_mapping(
4195+
c,
4196+
{
4197+
'x': 'z',
4198+
},
4199+
).all_measurement_key_names() == {'m1', 'm2'}
42034200

42044201

42054202
@pytest.mark.parametrize('circuit_cls', [cirq.Circuit, cirq.FrozenCircuit])
@@ -4222,7 +4219,7 @@ def test_measurement_key_mapping_preserves_moments(circuit_cls):
42224219
@pytest.mark.parametrize('circuit_cls', [cirq.Circuit, cirq.FrozenCircuit])
42234220
def test_inverse(circuit_cls):
42244221
a, b = cirq.LineQubit.range(2)
4225-
forward = circuit_cls((cirq.X ** 0.5)(a), (cirq.Y ** -0.2)(b), cirq.CZ(a, b))
4222+
forward = circuit_cls((cirq.X**0.5)(a), (cirq.Y**-0.2)(b), cirq.CZ(a, b))
42264223
backward = circuit_cls((cirq.CZ ** (-1.0))(a, b), (cirq.X ** (-0.5))(a), (cirq.Y ** (0.2))(b))
42274224
cirq.testing.assert_same_circuits(cirq.inverse(forward), backward)
42284225

@@ -4233,15 +4230,15 @@ def test_inverse(circuit_cls):
42334230
cirq.inverse(no_inverse)
42344231

42354232
# Default when there is no inverse for an op.
4236-
default = circuit_cls((cirq.X ** 0.5)(a), (cirq.Y ** -0.2)(b))
4233+
default = circuit_cls((cirq.X**0.5)(a), (cirq.Y**-0.2)(b))
42374234
cirq.testing.assert_same_circuits(cirq.inverse(no_inverse, default), default)
42384235
assert cirq.inverse(no_inverse, None) is None
42394236

42404237

42414238
@pytest.mark.parametrize('circuit_cls', [cirq.Circuit, cirq.FrozenCircuit])
42424239
def test_pow_valid_only_for_minus_1(circuit_cls):
42434240
a, b = cirq.LineQubit.range(2)
4244-
forward = circuit_cls((cirq.X ** 0.5)(a), (cirq.Y ** -0.2)(b), cirq.CZ(a, b))
4241+
forward = circuit_cls((cirq.X**0.5)(a), (cirq.Y**-0.2)(b), cirq.CZ(a, b))
42454242

42464243
backward = circuit_cls((cirq.CZ ** (-1.0))(a, b), (cirq.X ** (-0.5))(a), (cirq.Y ** (0.2))(b))
42474244
cirq.testing.assert_same_circuits(cirq.pow(forward, -1), backward)
@@ -4642,28 +4639,22 @@ def _measurement_key_name_(self):
46424639
assert circuit_cls().all_measurement_key_names() == set()
46434640

46444641
# Order does not matter.
4645-
assert (
4646-
circuit_cls(
4647-
cirq.Moment(
4648-
[
4649-
cirq.measure(a, key='x'),
4650-
cirq.measure(b, key='y'),
4651-
]
4652-
)
4653-
).all_measurement_key_names()
4654-
== {'x', 'y'}
4655-
)
4656-
assert (
4657-
circuit_cls(
4658-
cirq.Moment(
4659-
[
4660-
cirq.measure(b, key='y'),
4661-
cirq.measure(a, key='x'),
4662-
]
4663-
)
4664-
).all_measurement_key_names()
4665-
== {'x', 'y'}
4666-
)
4642+
assert circuit_cls(
4643+
cirq.Moment(
4644+
[
4645+
cirq.measure(a, key='x'),
4646+
cirq.measure(b, key='y'),
4647+
]
4648+
)
4649+
).all_measurement_key_names() == {'x', 'y'}
4650+
assert circuit_cls(
4651+
cirq.Moment(
4652+
[
4653+
cirq.measure(b, key='y'),
4654+
cirq.measure(a, key='x'),
4655+
]
4656+
)
4657+
).all_measurement_key_names() == {'x', 'y'}
46674658

46684659

46694660
def test_zip():

cirq/circuits/moment.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,7 @@ def kraus_tensors(op: 'cirq.Operation') -> Sequence[np.ndarray]:
414414
transpose = input_subscripts + '->' + output_subscripts
415415

416416
r = []
417-
d = 2 ** n
417+
d = 2**n
418418
kss = [kraus_tensors(op) for op in self.operations]
419419
for ks in itertools.product(*kss):
420420
k = np.einsum(transpose, *ks)

cirq/circuits/moment_test.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -409,10 +409,10 @@ def test_json_dict():
409409
def test_inverse():
410410
a, b, c = cirq.LineQubit.range(3)
411411
m = cirq.Moment([cirq.S(a), cirq.CNOT(b, c)])
412-
assert m ** 1 is m
413-
assert m ** -1 == cirq.Moment([cirq.S(a) ** -1, cirq.CNOT(b, c)])
414-
assert m ** 0.5 == cirq.Moment([cirq.T(a), cirq.CNOT(b, c) ** 0.5])
415-
assert cirq.inverse(m) == m ** -1
412+
assert m**1 is m
413+
assert m**-1 == cirq.Moment([cirq.S(a) ** -1, cirq.CNOT(b, c)])
414+
assert m**0.5 == cirq.Moment([cirq.T(a), cirq.CNOT(b, c) ** 0.5])
415+
assert cirq.inverse(m) == m**-1
416416
assert cirq.inverse(cirq.inverse(m)) == m
417417
assert cirq.inverse(cirq.Moment([cirq.measure(a)]), default=None) is None
418418

cirq/circuits/optimization_pass_test.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ def test_point_optimizer_post_clean_up():
135135

136136
def clean_up(operations):
137137
for op in operations:
138-
yield op ** 0.5
138+
yield op**0.5
139139

140140
ReplaceWithXGates(post_clean_up=clean_up)(c)
141141

cirq/contrib/acquaintance/executor_test.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ def random_diagonal_gates(
8989
) -> Dict[Tuple[cirq.Qid, ...], cirq.Gate]:
9090

9191
return {
92-
Q: cirq.DiagonalGate(np.random.random(2 ** acquaintance_size))
92+
Q: cirq.DiagonalGate(np.random.random(2**acquaintance_size))
9393
for Q in combinations(cirq.LineQubit.range(num_qubits), acquaintance_size)
9494
}
9595

cirq/contrib/acquaintance/permutation_test.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ def test_linear_permutation_gate_pow_not_implemented():
184184
def test_linear_permutation_gate_pow_identity(num_qubits, permutation):
185185
permutation_gate = cca.LinearPermutationGate(num_qubits, permutation)
186186

187-
assert permutation_gate ** 1 == permutation_gate
187+
assert permutation_gate**1 == permutation_gate
188188

189189

190190
@pytest.mark.parametrize(
@@ -201,7 +201,7 @@ def test_linear_permutation_gate_pow_inverse(num_qubits, permutation, inverse):
201201
permutation_gate = cca.LinearPermutationGate(num_qubits, permutation)
202202
inverse_gate = cca.LinearPermutationGate(num_qubits, inverse)
203203

204-
assert permutation_gate ** -1 == inverse_gate
204+
assert permutation_gate**-1 == inverse_gate
205205
assert cirq.inverse(permutation_gate) == inverse_gate
206206

207207

cirq/contrib/qasm_import/_parser.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -240,8 +240,8 @@ def __init__(self):
240240
qasm_gate='cswap', num_params=0, num_args=3, cirq_gate=ops.CSWAP
241241
),
242242
'ccx': QasmGateStatement(qasm_gate='ccx', num_params=0, num_args=3, cirq_gate=ops.CCX),
243-
'sdg': QasmGateStatement(qasm_gate='sdg', num_params=0, num_args=1, cirq_gate=ops.S ** -1),
244-
'tdg': QasmGateStatement(qasm_gate='tdg', num_params=0, num_args=1, cirq_gate=ops.T ** -1),
243+
'sdg': QasmGateStatement(qasm_gate='sdg', num_params=0, num_args=1, cirq_gate=ops.S**-1),
244+
'tdg': QasmGateStatement(qasm_gate='tdg', num_params=0, num_args=1, cirq_gate=ops.T**-1),
245245
}
246246

247247
all_gates = {**basic_gates, **qelib_gates}

cirq/contrib/qasm_import/_parser_test.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -434,8 +434,8 @@ def test_unknown_function():
434434
('h', cirq.H),
435435
('s', cirq.S),
436436
('t', cirq.T),
437-
('sdg', cirq.S ** -1),
438-
('tdg', cirq.T ** -1),
437+
('sdg', cirq.S**-1),
438+
('tdg', cirq.T**-1),
439439
('sx', cirq.XPowGate(exponent=0.5)),
440440
]
441441

cirq/contrib/quantum_volume/quantum_volume.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ def compute_heavy_set(circuit: cirq.Circuit) -> List[int]:
8686
# The output wave function is a vector from the result value (big-endian) to
8787
# the probability of that bit-string. Return all of the bit-string
8888
# values that have a probability greater than the median.
89-
return [idx for idx, amp in enumerate(results.state_vector()) if np.abs(amp ** 2) > median]
89+
return [idx for idx, amp in enumerate(results.state_vector()) if np.abs(amp**2) > median]
9090

9191

9292
@dataclass

cirq/contrib/quirk/quirk_gate.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -176,11 +176,11 @@ def z_to_quirk_op(gate: ops.ZPowGate) -> QuirkOp:
176176

177177

178178
def cz_to_quirk_op(gate: ops.CZPowGate) -> Optional[QuirkOp]:
179-
return z_to_quirk_op(ops.Z ** gate.exponent).controlled()
179+
return z_to_quirk_op(ops.Z**gate.exponent).controlled()
180180

181181

182182
def cnot_to_quirk_op(gate: ops.CXPowGate) -> Optional[QuirkOp]:
183-
return x_to_quirk_op(ops.X ** gate.exponent).controlled()
183+
return x_to_quirk_op(ops.X**gate.exponent).controlled()
184184

185185

186186
def h_to_quirk_op(gate: ops.HPowGate) -> Optional[QuirkOp]:

cirq/contrib/routing/initialization_test.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def get_seeded_initial_mapping(graph_seed, init_seed):
2929
return ccr.initialization.get_initial_mapping(logical_graph, device_graph, init_seed)
3030

3131

32-
@pytest.mark.parametrize('seed', [random.randint(0, 2 ** 32) for _ in range(10)])
32+
@pytest.mark.parametrize('seed', [random.randint(0, 2**32) for _ in range(10)])
3333
def test_initialization_reproducible_with_seed(seed):
3434
wrappers = (lambda s: s, np.random.RandomState)
3535
mappings = [
@@ -39,7 +39,7 @@ def test_initialization_reproducible_with_seed(seed):
3939
eq.add_equality_group(*mappings)
4040

4141

42-
@pytest.mark.parametrize('graph_seed,state', [(random.randint(0, 2 ** 32), np.random.get_state())])
42+
@pytest.mark.parametrize('graph_seed,state', [(random.randint(0, 2**32), np.random.get_state())])
4343
def test_initialization_with_no_seed(graph_seed, state):
4444
mappings = []
4545
for _ in range(3):

cirq/contrib/routing/router_test.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525

2626
def random_seed():
27-
return random.randint(0, 2 ** 32)
27+
return random.randint(0, 2**32)
2828

2929

3030
@pytest.mark.parametrize(

cirq/devices/noise_model_test.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -121,15 +121,15 @@ def test_constant_qubit_noise():
121121
cirq.testing.assert_equivalent_repr(damp_all)
122122

123123
with pytest.raises(ValueError, match='num_qubits'):
124-
_ = cirq.ConstantQubitNoiseModel(cirq.CNOT ** 0.01)
124+
_ = cirq.ConstantQubitNoiseModel(cirq.CNOT**0.01)
125125

126126

127127
def test_noise_composition():
128128
# Verify that noise models can be composed without regard to ordering, as
129129
# long as the noise operators commute with one another.
130130
a, b, c = cirq.LineQubit.range(3)
131131
noise_z = cirq.ConstantQubitNoiseModel(cirq.Z)
132-
noise_inv_s = cirq.ConstantQubitNoiseModel(cirq.S ** -1)
132+
noise_inv_s = cirq.ConstantQubitNoiseModel(cirq.S**-1)
133133
base_moments = [cirq.Moment([cirq.X(a)]), cirq.Moment([cirq.Y(b)]), cirq.Moment([cirq.H(c)])]
134134
circuit_z = cirq.Circuit(noise_z.noisy_moments(base_moments, [a, b, c]))
135135
circuit_s = cirq.Circuit(noise_inv_s.noisy_moments(base_moments, [a, b, c]))
@@ -154,7 +154,7 @@ def test_noise_composition():
154154

155155

156156
def test_constant_qubit_noise_repr():
157-
cirq.testing.assert_equivalent_repr(cirq.ConstantQubitNoiseModel(cirq.X ** 0.01))
157+
cirq.testing.assert_equivalent_repr(cirq.ConstantQubitNoiseModel(cirq.X**0.01))
158158

159159

160160
def test_wrap():
@@ -168,16 +168,16 @@ def noisy_operation(self, operation):
168168
assert cirq.NoiseModel.from_noise_model_like(
169169
cirq.depolarize(0.1)
170170
) == cirq.ConstantQubitNoiseModel(cirq.depolarize(0.1))
171-
assert cirq.NoiseModel.from_noise_model_like(cirq.Z ** 0.01) == cirq.ConstantQubitNoiseModel(
172-
cirq.Z ** 0.01
171+
assert cirq.NoiseModel.from_noise_model_like(cirq.Z**0.01) == cirq.ConstantQubitNoiseModel(
172+
cirq.Z**0.01
173173
)
174174
assert cirq.NoiseModel.from_noise_model_like(forget) is forget
175175

176176
with pytest.raises(TypeError, match='Expected a NOISE_MODEL_LIKE'):
177177
_ = cirq.NoiseModel.from_noise_model_like('test')
178178

179179
with pytest.raises(ValueError, match='Multi-qubit gate'):
180-
_ = cirq.NoiseModel.from_noise_model_like(cirq.CZ ** 0.01)
180+
_ = cirq.NoiseModel.from_noise_model_like(cirq.CZ**0.01)
181181

182182

183183
def test_gate_substitution_noise_model():

0 commit comments

Comments
 (0)