Skip to content

Commit 77fb93a

Browse files
authored
Format cirq-google with latest version of black (#5160)
Follow-up to #5157. Format code in cirq-google to ensure these formatting changes don't get mixed in with future logic changes.
1 parent 5ca139d commit 77fb93a

File tree

11 files changed

+63
-75
lines changed

11 files changed

+63
-75
lines changed

cirq-google/cirq_google/calibration/phased_fsim_test.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ def test_from_moment():
284284
)
285285
request = FloquetPhasedFSimCalibrationRequest.from_moment(m, options)
286286
assert request == FloquetPhasedFSimCalibrationRequest(
287-
gate=cirq.ISWAP ** 0.5, pairs=((q_00, q_01), (q_02, q_03)), options=options
287+
gate=cirq.ISWAP**0.5, pairs=((q_00, q_01), (q_02, q_03)), options=options
288288
)
289289

290290
non_identical = cirq.Moment(cirq.ISWAP(q_00, q_01) ** 0.5, cirq.ISWAP(q_02, q_03))

cirq-google/cirq_google/engine/abstract_local_processor_test.py

+12-21
Original file line numberDiff line numberDiff line change
@@ -213,27 +213,18 @@ def test_get_schedule():
213213
slot_type=qenums.QuantumTimeSlot.TimeSlotType.OPEN_SWIM,
214214
)
215215
p = NothingProcessor(processor_id='test', schedule=[unbounded_start, unbounded_end])
216-
assert (
217-
p.get_schedule(
218-
from_time=_time(500000),
219-
to_time=_time(2500000),
220-
)
221-
== [unbounded_start, unbounded_end]
222-
)
223-
assert (
224-
p.get_schedule(
225-
from_time=_time(1500000),
226-
to_time=_time(2500000),
227-
)
228-
== [unbounded_end]
229-
)
230-
assert (
231-
p.get_schedule(
232-
from_time=_time(500000),
233-
to_time=_time(1500000),
234-
)
235-
== [unbounded_start]
236-
)
216+
assert p.get_schedule(
217+
from_time=_time(500000),
218+
to_time=_time(2500000),
219+
) == [unbounded_start, unbounded_end]
220+
assert p.get_schedule(
221+
from_time=_time(1500000),
222+
to_time=_time(2500000),
223+
) == [unbounded_end]
224+
assert p.get_schedule(
225+
from_time=_time(500000),
226+
to_time=_time(1500000),
227+
) == [unbounded_start]
237228
assert (
238229
p.get_schedule(
239230
from_time=_time(1200000),

cirq-google/cirq_google/line/placement/anneal_test.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,8 @@ def calculate_cost(seqs: List[List[cirq.GridQubit]]):
100100

101101
assert np.isclose(calculate_cost([[q00]]), -1.0)
102102
assert np.isclose(calculate_cost([[q00, q01]]), -1.0)
103-
assert np.isclose(calculate_cost([[q00], [q01]]), -(0.5 ** 2 + 0.5 ** 2))
104-
assert np.isclose(calculate_cost([[q00], [q01, q02, q03]]), -(0.25 ** 2 + 0.75 ** 2))
103+
assert np.isclose(calculate_cost([[q00], [q01]]), -(0.5**2 + 0.5**2))
104+
assert np.isclose(calculate_cost([[q00], [q01, q02, q03]]), -(0.25**2 + 0.75**2))
105105

106106

107107
def test_force_edges_active_move_does_not_change_input():

cirq-google/cirq_google/ops/fsim_gate_family_test.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -30,17 +30,17 @@
3030
]
3131
THETA, PHI = sympy.Symbol("theta"), sympy.Symbol("phi")
3232
VALID_IDENTITY = [
33-
(cirq.CZ ** THETA, {THETA: 2}),
33+
(cirq.CZ**THETA, {THETA: 2}),
3434
(cirq.IdentityGate(2), {}),
3535
(cirq.FSimGate(THETA, PHI), {THETA: 0, PHI: 0}),
3636
(cirq.PhasedFSimGate(THETA, 0, 0, 0, PHI), {THETA: 0, PHI: 0}),
37-
(cirq.ISWAP ** THETA, {THETA: 4}),
37+
(cirq.ISWAP**THETA, {THETA: 4}),
3838
(cirq.PhasedISwapPowGate(exponent=THETA, phase_exponent=PHI), {THETA: 4, PHI: 2}),
3939
]
4040

4141
VALID_CZPOW_GATES = [
4242
(cirq.CZPowGate(exponent=THETA, global_shift=2.5), {THETA: 0.1}),
43-
(cirq.CZ ** THETA, {THETA: 0.5}),
43+
(cirq.CZ**THETA, {THETA: 0.5}),
4444
(cirq.FSimGate(theta=THETA, phi=0.1), {THETA: 0}),
4545
(cirq.FSimGate(theta=2 * np.pi, phi=PHI), {PHI: -0.4}),
4646
(
@@ -67,7 +67,7 @@
6767
VALID_ISWAP_GATES = [
6868
(cirq.ISwapPowGate(exponent=THETA, global_shift=2.5), {THETA: 0.1}),
6969
(cirq.PhasedISwapPowGate(exponent=0.1, phase_exponent=PHI), {PHI: 2}),
70-
(cirq.SQRT_ISWAP_INV ** THETA, {THETA: 0.1}),
70+
(cirq.SQRT_ISWAP_INV**THETA, {THETA: 0.1}),
7171
(cirq.FSimGate(theta=THETA, phi=PHI), {THETA: 0.1, PHI: 0}),
7272
(cirq.FSimGate(theta=-0.4, phi=PHI), {PHI: 2 * np.pi}),
7373
(

cirq-google/cirq_google/optimizers/convert_to_sqrt_iswap_test.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ def _unitaries_allclose(circuit1, circuit2):
2323
(cirq.CZ, 8),
2424
(cirq.SWAP, 7),
2525
(cirq.CNOT, 9),
26-
(cirq.ISWAP ** 0.5, 1),
27-
(cirq.ISWAP ** -0.5, 1),
26+
(cirq.ISWAP**0.5, 1),
27+
(cirq.ISWAP**-0.5, 1),
2828
(cirq.ISwapPowGate(exponent=0.5), 1),
2929
(cirq.ISwapPowGate(exponent=-0.5), 1),
3030
(cirq.FSimGate(theta=np.pi / 4, phi=0), 1),

cirq-google/cirq_google/serialization/arg_func_langs_test.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ def test_infer_language():
166166
packed = cirq_google.XMON.serialize(c_empty)
167167
assert packed.language.arg_function_language == ''
168168

169-
c_exp = cirq.Circuit(cirq.X(q) ** (b ** a))
169+
c_exp = cirq.Circuit(cirq.X(q) ** (b**a))
170170
packed = cirq_google.XMON.serialize(c_exp)
171171
assert packed.language.arg_function_language == 'exp'
172172

cirq-google/cirq_google/serialization/common_serializers.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -506,7 +506,7 @@ def _add_phase_match(op: cirq.Operation, proto: v2.program_pb2.Operation):
506506
cirq.SQRT_ISWAP_INV,
507507
cirq.SQRT_ISWAP,
508508
cirq.ISWAP,
509-
cirq.ISWAP ** -1, # type: ignore
509+
cirq.ISWAP**-1, # type: ignore
510510
SYC,
511511
cirq.CZ,
512512
],
@@ -519,7 +519,7 @@ def _add_phase_match(op: cirq.Operation, proto: v2.program_pb2.Operation):
519519
cirq.SQRT_ISWAP_INV,
520520
cirq.SQRT_ISWAP,
521521
cirq.ISWAP,
522-
cirq.ISWAP ** -1, # type: ignore
522+
cirq.ISWAP**-1, # type: ignore
523523
],
524524
gate_types_to_check=[cirq.ISwapPowGate],
525525
allow_symbols=True,

cirq-google/cirq_google/serialization/common_serializers_test.py

+15-15
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,8 @@ def test_serialize_sqrt_y_pow_gate():
142142
@pytest.mark.parametrize(
143143
('gate', 'axis_half_turns', 'half_turns'),
144144
[
145-
(cirq.X ** 0.25, 0.0, 0.25),
146-
(cirq.Y ** 0.25, 0.5, 0.25),
145+
(cirq.X**0.25, 0.0, 0.25),
146+
(cirq.Y**0.25, 0.5, 0.25),
147147
(cirq.XPowGate(exponent=0.125), 0.0, 0.125),
148148
(cirq.YPowGate(exponent=0.125), 0.5, 0.125),
149149
(cirq.PhasedXPowGate(exponent=0.125, phase_exponent=0.25), 0.25, 0.125),
@@ -255,9 +255,9 @@ def test_serialize_deserialize_meas(qubits, qubit_ids, key, invert_mask):
255255
('gate', 'axis_half_turns', 'half_turns'),
256256
[
257257
(cirq.X, 0.0, 1.0),
258-
(cirq.X ** 0.25, 0.0, 0.25),
258+
(cirq.X**0.25, 0.0, 0.25),
259259
(cirq.Y, 0.5, 1.0),
260-
(cirq.Y ** 0.25, 0.5, 0.25),
260+
(cirq.Y**0.25, 0.5, 0.25),
261261
(cirq.PhasedXPowGate(exponent=0.125, phase_exponent=0.25), 0.25, 0.125),
262262
(cirq.rx(0.125 * np.pi), 0.0, 0.125),
263263
(cirq.ry(0.25 * np.pi), 0.5, 0.25),
@@ -324,7 +324,7 @@ def test_serialize_xy_parameterized_axis_half_turns():
324324
('gate', 'half_turns'),
325325
[
326326
(cirq.Z, 1.0),
327-
(cirq.Z ** 0.125, 0.125),
327+
(cirq.Z**0.125, 0.125),
328328
(cirq.rz(0.125 * np.pi), 0.125),
329329
],
330330
)
@@ -443,8 +443,8 @@ def assert_phys_z_tag(phys_z, op):
443443
('gate', 'exponent'),
444444
[
445445
(cirq.CZ, 1.0),
446-
(cirq.CZ ** 3.0, 3.0),
447-
(cirq.CZ ** -1.0, -1.0),
446+
(cirq.CZ**3.0, 3.0),
447+
(cirq.CZ**-1.0, -1.0),
448448
],
449449
)
450450
@pytest.mark.parametrize('phys_z', [False, True])
@@ -548,13 +548,13 @@ def test_wait_gate_multi_qubit():
548548
@pytest.mark.parametrize(
549549
('gate', 'theta', 'phi'),
550550
[
551-
(cirq.ISWAP ** 0.5, -np.pi / 4, 0),
552-
(cirq.ISWAP ** -0.5, np.pi / 4, 0),
553-
(cirq.ISWAP ** 1.0, -np.pi / 2, 0),
554-
(cirq.ISWAP ** -1.0, np.pi / 2, 0),
555-
(cirq.ISWAP ** 0.0, 0, 0),
551+
(cirq.ISWAP**0.5, -np.pi / 4, 0),
552+
(cirq.ISWAP**-0.5, np.pi / 4, 0),
553+
(cirq.ISWAP**1.0, -np.pi / 2, 0),
554+
(cirq.ISWAP**-1.0, np.pi / 2, 0),
555+
(cirq.ISWAP**0.0, 0, 0),
556556
(cirq.CZ, 0, np.pi),
557-
(cirq.CZ ** -1.0, 0, np.pi),
557+
(cirq.CZ**-1.0, 0, np.pi),
558558
(cirq.FSimGate(theta=0, phi=0), 0, 0),
559559
(cirq.FSimGate(theta=0, phi=np.pi), 0, -np.pi),
560560
(cirq.FSimGate(theta=0, phi=-np.pi), 0, -np.pi),
@@ -665,8 +665,8 @@ def test_serialize_deserialize_iswap_symbols(phys_z):
665665
@pytest.mark.parametrize(
666666
'gate',
667667
[
668-
cirq.ISWAP ** 0.25,
669-
cirq.ISWAP ** 0.75,
668+
cirq.ISWAP**0.25,
669+
cirq.ISWAP**0.75,
670670
cirq.FSimGate(theta=0.1, phi=0),
671671
cirq.FSimGate(theta=0, phi=0.1),
672672
cirq.FSimGate(theta=sympy.Symbol('t'), phi=0.1),

cirq-google/cirq_google/serialization/gate_sets_test.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@ def op_proto(json_dict: Dict) -> v2.program_pb2.Operation:
3535
('gate', 'axis_half_turns', 'half_turns'),
3636
[
3737
(cirq.X, 0.0, 1.0),
38-
(cirq.X ** 0.25, 0.0, 0.25),
38+
(cirq.X**0.25, 0.0, 0.25),
3939
(cirq.Y, 0.5, 1.0),
40-
(cirq.Y ** 0.25, 0.5, 0.25),
40+
(cirq.Y**0.25, 0.5, 0.25),
4141
(cirq.PhasedXPowGate(exponent=0.125, phase_exponent=0.25), 0.25, 0.125),
4242
(cirq.rx(0.125 * np.pi), 0.0, 0.125),
4343
(cirq.ry(0.25 * np.pi), 0.5, 0.25),
@@ -104,7 +104,7 @@ def test_serialize_exp_w_parameterized_axis_half_turns():
104104
('gate', 'half_turns'),
105105
[
106106
(cirq.Z, 1.0),
107-
(cirq.Z ** 0.125, 0.125),
107+
(cirq.Z**0.125, 0.125),
108108
(cirq.rz(0.125 * np.pi), 0.125),
109109
],
110110
)
@@ -141,7 +141,7 @@ def test_serialize_exp_z_parameterized():
141141
('gate', 'half_turns'),
142142
[
143143
(cirq.CZ, 1.0),
144-
(cirq.CZ ** 0.125, 0.125),
144+
(cirq.CZ**0.125, 0.125),
145145
],
146146
)
147147
def test_serialize_exp_11(gate, half_turns):
@@ -478,8 +478,8 @@ def test_serialize_deserialize_inv_sqrt_iswap():
478478
@pytest.mark.parametrize(
479479
('gate', 'axis_half_turns', 'half_turns'),
480480
[
481-
(cirq.X ** 0.25, 0.0, 0.25),
482-
(cirq.Y ** 0.25, 0.5, 0.25),
481+
(cirq.X**0.25, 0.0, 0.25),
482+
(cirq.Y**0.25, 0.5, 0.25),
483483
(cirq.XPowGate(exponent=0.125), 0.0, 0.125),
484484
(cirq.YPowGate(exponent=0.125), 0.5, 0.125),
485485
(cirq.PhasedXPowGate(exponent=0.125, phase_exponent=0.25), 0.25, 0.125),

cirq-google/cirq_google/transformers/analytical_decompositions/two_qubit_to_sycamore.py

+12-12
Original file line numberDiff line numberDiff line change
@@ -202,15 +202,15 @@ def _decompose_phased_iswap_into_syc_precomputed(
202202

203203
yield cirq.PhasedXPowGate(phase_exponent=0.41175161497166024, exponent=0.5653807577895922).on(a)
204204
yield cirq.PhasedXPowGate(phase_exponent=1.0, exponent=0.5).on(b),
205-
yield (cirq.Z ** 0.7099892314883478).on(b),
206-
yield (cirq.Z ** 0.6746023442550453).on(a),
205+
yield (cirq.Z**0.7099892314883478).on(b),
206+
yield (cirq.Z**0.6746023442550453).on(a),
207207
yield ops.SYC(a, b)
208208
yield cirq.PhasedXPowGate(phase_exponent=-0.5154334589432878, exponent=0.5228733015013345).on(b)
209209
yield cirq.PhasedXPowGate(phase_exponent=0.06774925307475355).on(a)
210210
yield ops.SYC(a, b),
211211
yield cirq.PhasedXPowGate(phase_exponent=-0.5987667922766213, exponent=0.4136540654256824).on(a)
212-
yield (cirq.Z ** -0.9255092746611595).on(b)
213-
yield (cirq.Z ** -1.333333333333333).on(a)
212+
yield (cirq.Z**-0.9255092746611595).on(b)
213+
yield (cirq.Z**-1.333333333333333).on(a)
214214
yield cirq.rx(-theta).on(a)
215215
yield cirq.rx(-theta).on(b)
216216

@@ -222,8 +222,8 @@ def _decompose_phased_iswap_into_syc_precomputed(
222222
yield ops.SYC(a, b)
223223
yield cirq.PhasedXPowGate(phase_exponent=-0.8151665352515929, exponent=0.8906746535691492).on(a)
224224
yield cirq.PhasedXPowGate(phase_exponent=-0.07449072533884049, exponent=0.5).on(b)
225-
yield (cirq.Z ** -0.9255092746611595).on(b)
226-
yield (cirq.Z ** -0.9777346353961884).on(a)
225+
yield (cirq.Z**-0.9255092746611595).on(b)
226+
yield (cirq.Z**-0.9777346353961884).on(a)
227227

228228

229229
def _decompose_cz_into_syc(a: cirq.Qid, b: cirq.Qid):
@@ -248,8 +248,8 @@ def _decompose_cz_into_syc(a: cirq.Qid, b: cirq.Qid):
248248
yield cirq.PhasedXPowGate(phase_exponent=-0.5987667922766213, exponent=0.4136540654256824).on(
249249
a
250250
),
251-
yield (cirq.Z ** -0.9255092746611595).on(b),
252-
yield (cirq.Z ** -1.333333333333333).on(a),
251+
yield (cirq.Z**-0.9255092746611595).on(b),
252+
yield (cirq.Z**-1.333333333333333).on(a),
253253

254254

255255
def _decompose_cphase_into_syc(theta: float, q0: cirq.Qid, q1: cirq.Qid) -> cirq.OP_TREE:
@@ -297,8 +297,8 @@ def _decompose_iswap_into_syc(a: cirq.Qid, b: cirq.Qid):
297297
b
298298
),
299299
yield cirq.PhasedXPowGate(phase_exponent=0.9408341606787907).on(a),
300-
yield (cirq.Z ** -1.1551880579397293).on(b),
301-
yield (cirq.Z ** 0.31848343246696365).on(a),
300+
yield (cirq.Z**-1.1551880579397293).on(b),
301+
yield (cirq.Z**0.31848343246696365).on(a),
302302

303303

304304
def _decompose_swap_into_syc(a: cirq.Qid, b: cirq.Qid):
@@ -326,8 +326,8 @@ def _decompose_swap_into_syc(a: cirq.Qid, b: cirq.Qid):
326326
yield cirq.PhasedXPowGate(phase_exponent=-0.8150261316932077, exponent=0.11820787859471782).on(
327327
b
328328
)
329-
yield (cirq.Z ** -0.7384700844660306).on(b)
330-
yield (cirq.Z ** -0.7034535141382525).on(a)
329+
yield (cirq.Z**-0.7384700844660306).on(b)
330+
yield (cirq.Z**-0.7034535141382525).on(a)
331331

332332

333333
def _find_local_equivalents(target_unitary: np.ndarray, source_unitary: np.ndarray):

cirq-google/cirq_google/workflow/quantum_executable_test.py

+6-9
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,12 @@ def test_bitstrings_measurement():
3131

3232

3333
def _get_random_circuit(qubits, *, n_moments=10, random_state=52):
34-
return (
35-
cirq.experiments.random_rotations_between_grid_interaction_layers_circuit(
36-
qubits=qubits,
37-
depth=n_moments,
38-
seed=random_state,
39-
two_qubit_op_factory=lambda a, b, _: cirq.SQRT_ISWAP(a, b),
40-
)
41-
+ cirq.measure(*qubits, key='z')
42-
)
34+
return cirq.experiments.random_rotations_between_grid_interaction_layers_circuit(
35+
qubits=qubits,
36+
depth=n_moments,
37+
seed=random_state,
38+
two_qubit_op_factory=lambda a, b, _: cirq.SQRT_ISWAP(a, b),
39+
) + cirq.measure(*qubits, key='z')
4340

4441

4542
def _get_example_spec(name='example-program'):

0 commit comments

Comments
 (0)