From 77fb93af5ebbb5bcf7f8a4dc3fd2fba0e827488c Mon Sep 17 00:00:00 2001 From: Matthew Neeley Date: Tue, 29 Mar 2022 12:03:03 -0700 Subject: [PATCH] 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. --- .../calibration/phased_fsim_test.py | 2 +- .../engine/abstract_local_processor_test.py | 33 +++++++------------ .../cirq_google/line/placement/anneal_test.py | 4 +-- .../cirq_google/ops/fsim_gate_family_test.py | 8 ++--- .../optimizers/convert_to_sqrt_iswap_test.py | 4 +-- .../serialization/arg_func_langs_test.py | 2 +- .../serialization/common_serializers.py | 4 +-- .../serialization/common_serializers_test.py | 30 ++++++++--------- .../serialization/gate_sets_test.py | 12 +++---- .../two_qubit_to_sycamore.py | 24 +++++++------- .../workflow/quantum_executable_test.py | 15 ++++----- 11 files changed, 63 insertions(+), 75 deletions(-) diff --git a/cirq-google/cirq_google/calibration/phased_fsim_test.py b/cirq-google/cirq_google/calibration/phased_fsim_test.py index 96fcda6f8d2..49848ace1e7 100644 --- a/cirq-google/cirq_google/calibration/phased_fsim_test.py +++ b/cirq-google/cirq_google/calibration/phased_fsim_test.py @@ -284,7 +284,7 @@ def test_from_moment(): ) request = FloquetPhasedFSimCalibrationRequest.from_moment(m, options) assert request == FloquetPhasedFSimCalibrationRequest( - gate=cirq.ISWAP ** 0.5, pairs=((q_00, q_01), (q_02, q_03)), options=options + gate=cirq.ISWAP**0.5, pairs=((q_00, q_01), (q_02, q_03)), options=options ) non_identical = cirq.Moment(cirq.ISWAP(q_00, q_01) ** 0.5, cirq.ISWAP(q_02, q_03)) diff --git a/cirq-google/cirq_google/engine/abstract_local_processor_test.py b/cirq-google/cirq_google/engine/abstract_local_processor_test.py index 7a3aad9e2f6..45afb97d5a6 100644 --- a/cirq-google/cirq_google/engine/abstract_local_processor_test.py +++ b/cirq-google/cirq_google/engine/abstract_local_processor_test.py @@ -213,27 +213,18 @@ def test_get_schedule(): slot_type=qenums.QuantumTimeSlot.TimeSlotType.OPEN_SWIM, ) p = NothingProcessor(processor_id='test', schedule=[unbounded_start, unbounded_end]) - assert ( - p.get_schedule( - from_time=_time(500000), - to_time=_time(2500000), - ) - == [unbounded_start, unbounded_end] - ) - assert ( - p.get_schedule( - from_time=_time(1500000), - to_time=_time(2500000), - ) - == [unbounded_end] - ) - assert ( - p.get_schedule( - from_time=_time(500000), - to_time=_time(1500000), - ) - == [unbounded_start] - ) + assert p.get_schedule( + from_time=_time(500000), + to_time=_time(2500000), + ) == [unbounded_start, unbounded_end] + assert p.get_schedule( + from_time=_time(1500000), + to_time=_time(2500000), + ) == [unbounded_end] + assert p.get_schedule( + from_time=_time(500000), + to_time=_time(1500000), + ) == [unbounded_start] assert ( p.get_schedule( from_time=_time(1200000), diff --git a/cirq-google/cirq_google/line/placement/anneal_test.py b/cirq-google/cirq_google/line/placement/anneal_test.py index 539cd4f1476..bf2d45c7ed4 100644 --- a/cirq-google/cirq_google/line/placement/anneal_test.py +++ b/cirq-google/cirq_google/line/placement/anneal_test.py @@ -100,8 +100,8 @@ def calculate_cost(seqs: List[List[cirq.GridQubit]]): assert np.isclose(calculate_cost([[q00]]), -1.0) assert np.isclose(calculate_cost([[q00, q01]]), -1.0) - assert np.isclose(calculate_cost([[q00], [q01]]), -(0.5 ** 2 + 0.5 ** 2)) - assert np.isclose(calculate_cost([[q00], [q01, q02, q03]]), -(0.25 ** 2 + 0.75 ** 2)) + assert np.isclose(calculate_cost([[q00], [q01]]), -(0.5**2 + 0.5**2)) + assert np.isclose(calculate_cost([[q00], [q01, q02, q03]]), -(0.25**2 + 0.75**2)) def test_force_edges_active_move_does_not_change_input(): diff --git a/cirq-google/cirq_google/ops/fsim_gate_family_test.py b/cirq-google/cirq_google/ops/fsim_gate_family_test.py index 640fe09d2a0..212149d6bb6 100644 --- a/cirq-google/cirq_google/ops/fsim_gate_family_test.py +++ b/cirq-google/cirq_google/ops/fsim_gate_family_test.py @@ -30,17 +30,17 @@ ] THETA, PHI = sympy.Symbol("theta"), sympy.Symbol("phi") VALID_IDENTITY = [ - (cirq.CZ ** THETA, {THETA: 2}), + (cirq.CZ**THETA, {THETA: 2}), (cirq.IdentityGate(2), {}), (cirq.FSimGate(THETA, PHI), {THETA: 0, PHI: 0}), (cirq.PhasedFSimGate(THETA, 0, 0, 0, PHI), {THETA: 0, PHI: 0}), - (cirq.ISWAP ** THETA, {THETA: 4}), + (cirq.ISWAP**THETA, {THETA: 4}), (cirq.PhasedISwapPowGate(exponent=THETA, phase_exponent=PHI), {THETA: 4, PHI: 2}), ] VALID_CZPOW_GATES = [ (cirq.CZPowGate(exponent=THETA, global_shift=2.5), {THETA: 0.1}), - (cirq.CZ ** THETA, {THETA: 0.5}), + (cirq.CZ**THETA, {THETA: 0.5}), (cirq.FSimGate(theta=THETA, phi=0.1), {THETA: 0}), (cirq.FSimGate(theta=2 * np.pi, phi=PHI), {PHI: -0.4}), ( @@ -67,7 +67,7 @@ VALID_ISWAP_GATES = [ (cirq.ISwapPowGate(exponent=THETA, global_shift=2.5), {THETA: 0.1}), (cirq.PhasedISwapPowGate(exponent=0.1, phase_exponent=PHI), {PHI: 2}), - (cirq.SQRT_ISWAP_INV ** THETA, {THETA: 0.1}), + (cirq.SQRT_ISWAP_INV**THETA, {THETA: 0.1}), (cirq.FSimGate(theta=THETA, phi=PHI), {THETA: 0.1, PHI: 0}), (cirq.FSimGate(theta=-0.4, phi=PHI), {PHI: 2 * np.pi}), ( diff --git a/cirq-google/cirq_google/optimizers/convert_to_sqrt_iswap_test.py b/cirq-google/cirq_google/optimizers/convert_to_sqrt_iswap_test.py index ba6f69371ab..4525f472fcf 100644 --- a/cirq-google/cirq_google/optimizers/convert_to_sqrt_iswap_test.py +++ b/cirq-google/cirq_google/optimizers/convert_to_sqrt_iswap_test.py @@ -23,8 +23,8 @@ def _unitaries_allclose(circuit1, circuit2): (cirq.CZ, 8), (cirq.SWAP, 7), (cirq.CNOT, 9), - (cirq.ISWAP ** 0.5, 1), - (cirq.ISWAP ** -0.5, 1), + (cirq.ISWAP**0.5, 1), + (cirq.ISWAP**-0.5, 1), (cirq.ISwapPowGate(exponent=0.5), 1), (cirq.ISwapPowGate(exponent=-0.5), 1), (cirq.FSimGate(theta=np.pi / 4, phi=0), 1), diff --git a/cirq-google/cirq_google/serialization/arg_func_langs_test.py b/cirq-google/cirq_google/serialization/arg_func_langs_test.py index e3376355b84..15eb318a3fb 100644 --- a/cirq-google/cirq_google/serialization/arg_func_langs_test.py +++ b/cirq-google/cirq_google/serialization/arg_func_langs_test.py @@ -166,7 +166,7 @@ def test_infer_language(): packed = cirq_google.XMON.serialize(c_empty) assert packed.language.arg_function_language == '' - c_exp = cirq.Circuit(cirq.X(q) ** (b ** a)) + c_exp = cirq.Circuit(cirq.X(q) ** (b**a)) packed = cirq_google.XMON.serialize(c_exp) assert packed.language.arg_function_language == 'exp' diff --git a/cirq-google/cirq_google/serialization/common_serializers.py b/cirq-google/cirq_google/serialization/common_serializers.py index 63c556ab180..afdaa95a7f5 100644 --- a/cirq-google/cirq_google/serialization/common_serializers.py +++ b/cirq-google/cirq_google/serialization/common_serializers.py @@ -506,7 +506,7 @@ def _add_phase_match(op: cirq.Operation, proto: v2.program_pb2.Operation): cirq.SQRT_ISWAP_INV, cirq.SQRT_ISWAP, cirq.ISWAP, - cirq.ISWAP ** -1, # type: ignore + cirq.ISWAP**-1, # type: ignore SYC, cirq.CZ, ], @@ -519,7 +519,7 @@ def _add_phase_match(op: cirq.Operation, proto: v2.program_pb2.Operation): cirq.SQRT_ISWAP_INV, cirq.SQRT_ISWAP, cirq.ISWAP, - cirq.ISWAP ** -1, # type: ignore + cirq.ISWAP**-1, # type: ignore ], gate_types_to_check=[cirq.ISwapPowGate], allow_symbols=True, diff --git a/cirq-google/cirq_google/serialization/common_serializers_test.py b/cirq-google/cirq_google/serialization/common_serializers_test.py index 6a7651366fa..5cc8542a164 100644 --- a/cirq-google/cirq_google/serialization/common_serializers_test.py +++ b/cirq-google/cirq_google/serialization/common_serializers_test.py @@ -142,8 +142,8 @@ def test_serialize_sqrt_y_pow_gate(): @pytest.mark.parametrize( ('gate', 'axis_half_turns', 'half_turns'), [ - (cirq.X ** 0.25, 0.0, 0.25), - (cirq.Y ** 0.25, 0.5, 0.25), + (cirq.X**0.25, 0.0, 0.25), + (cirq.Y**0.25, 0.5, 0.25), (cirq.XPowGate(exponent=0.125), 0.0, 0.125), (cirq.YPowGate(exponent=0.125), 0.5, 0.125), (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): ('gate', 'axis_half_turns', 'half_turns'), [ (cirq.X, 0.0, 1.0), - (cirq.X ** 0.25, 0.0, 0.25), + (cirq.X**0.25, 0.0, 0.25), (cirq.Y, 0.5, 1.0), - (cirq.Y ** 0.25, 0.5, 0.25), + (cirq.Y**0.25, 0.5, 0.25), (cirq.PhasedXPowGate(exponent=0.125, phase_exponent=0.25), 0.25, 0.125), (cirq.rx(0.125 * np.pi), 0.0, 0.125), (cirq.ry(0.25 * np.pi), 0.5, 0.25), @@ -324,7 +324,7 @@ def test_serialize_xy_parameterized_axis_half_turns(): ('gate', 'half_turns'), [ (cirq.Z, 1.0), - (cirq.Z ** 0.125, 0.125), + (cirq.Z**0.125, 0.125), (cirq.rz(0.125 * np.pi), 0.125), ], ) @@ -443,8 +443,8 @@ def assert_phys_z_tag(phys_z, op): ('gate', 'exponent'), [ (cirq.CZ, 1.0), - (cirq.CZ ** 3.0, 3.0), - (cirq.CZ ** -1.0, -1.0), + (cirq.CZ**3.0, 3.0), + (cirq.CZ**-1.0, -1.0), ], ) @pytest.mark.parametrize('phys_z', [False, True]) @@ -548,13 +548,13 @@ def test_wait_gate_multi_qubit(): @pytest.mark.parametrize( ('gate', 'theta', 'phi'), [ - (cirq.ISWAP ** 0.5, -np.pi / 4, 0), - (cirq.ISWAP ** -0.5, np.pi / 4, 0), - (cirq.ISWAP ** 1.0, -np.pi / 2, 0), - (cirq.ISWAP ** -1.0, np.pi / 2, 0), - (cirq.ISWAP ** 0.0, 0, 0), + (cirq.ISWAP**0.5, -np.pi / 4, 0), + (cirq.ISWAP**-0.5, np.pi / 4, 0), + (cirq.ISWAP**1.0, -np.pi / 2, 0), + (cirq.ISWAP**-1.0, np.pi / 2, 0), + (cirq.ISWAP**0.0, 0, 0), (cirq.CZ, 0, np.pi), - (cirq.CZ ** -1.0, 0, np.pi), + (cirq.CZ**-1.0, 0, np.pi), (cirq.FSimGate(theta=0, phi=0), 0, 0), (cirq.FSimGate(theta=0, phi=np.pi), 0, -np.pi), (cirq.FSimGate(theta=0, phi=-np.pi), 0, -np.pi), @@ -665,8 +665,8 @@ def test_serialize_deserialize_iswap_symbols(phys_z): @pytest.mark.parametrize( 'gate', [ - cirq.ISWAP ** 0.25, - cirq.ISWAP ** 0.75, + cirq.ISWAP**0.25, + cirq.ISWAP**0.75, cirq.FSimGate(theta=0.1, phi=0), cirq.FSimGate(theta=0, phi=0.1), cirq.FSimGate(theta=sympy.Symbol('t'), phi=0.1), diff --git a/cirq-google/cirq_google/serialization/gate_sets_test.py b/cirq-google/cirq_google/serialization/gate_sets_test.py index 8899f599b61..4533f160798 100644 --- a/cirq-google/cirq_google/serialization/gate_sets_test.py +++ b/cirq-google/cirq_google/serialization/gate_sets_test.py @@ -35,9 +35,9 @@ def op_proto(json_dict: Dict) -> v2.program_pb2.Operation: ('gate', 'axis_half_turns', 'half_turns'), [ (cirq.X, 0.0, 1.0), - (cirq.X ** 0.25, 0.0, 0.25), + (cirq.X**0.25, 0.0, 0.25), (cirq.Y, 0.5, 1.0), - (cirq.Y ** 0.25, 0.5, 0.25), + (cirq.Y**0.25, 0.5, 0.25), (cirq.PhasedXPowGate(exponent=0.125, phase_exponent=0.25), 0.25, 0.125), (cirq.rx(0.125 * np.pi), 0.0, 0.125), (cirq.ry(0.25 * np.pi), 0.5, 0.25), @@ -104,7 +104,7 @@ def test_serialize_exp_w_parameterized_axis_half_turns(): ('gate', 'half_turns'), [ (cirq.Z, 1.0), - (cirq.Z ** 0.125, 0.125), + (cirq.Z**0.125, 0.125), (cirq.rz(0.125 * np.pi), 0.125), ], ) @@ -141,7 +141,7 @@ def test_serialize_exp_z_parameterized(): ('gate', 'half_turns'), [ (cirq.CZ, 1.0), - (cirq.CZ ** 0.125, 0.125), + (cirq.CZ**0.125, 0.125), ], ) def test_serialize_exp_11(gate, half_turns): @@ -478,8 +478,8 @@ def test_serialize_deserialize_inv_sqrt_iswap(): @pytest.mark.parametrize( ('gate', 'axis_half_turns', 'half_turns'), [ - (cirq.X ** 0.25, 0.0, 0.25), - (cirq.Y ** 0.25, 0.5, 0.25), + (cirq.X**0.25, 0.0, 0.25), + (cirq.Y**0.25, 0.5, 0.25), (cirq.XPowGate(exponent=0.125), 0.0, 0.125), (cirq.YPowGate(exponent=0.125), 0.5, 0.125), (cirq.PhasedXPowGate(exponent=0.125, phase_exponent=0.25), 0.25, 0.125), diff --git a/cirq-google/cirq_google/transformers/analytical_decompositions/two_qubit_to_sycamore.py b/cirq-google/cirq_google/transformers/analytical_decompositions/two_qubit_to_sycamore.py index af5f11fceec..02ba473cb63 100644 --- a/cirq-google/cirq_google/transformers/analytical_decompositions/two_qubit_to_sycamore.py +++ b/cirq-google/cirq_google/transformers/analytical_decompositions/two_qubit_to_sycamore.py @@ -202,15 +202,15 @@ def _decompose_phased_iswap_into_syc_precomputed( yield cirq.PhasedXPowGate(phase_exponent=0.41175161497166024, exponent=0.5653807577895922).on(a) yield cirq.PhasedXPowGate(phase_exponent=1.0, exponent=0.5).on(b), - yield (cirq.Z ** 0.7099892314883478).on(b), - yield (cirq.Z ** 0.6746023442550453).on(a), + yield (cirq.Z**0.7099892314883478).on(b), + yield (cirq.Z**0.6746023442550453).on(a), yield ops.SYC(a, b) yield cirq.PhasedXPowGate(phase_exponent=-0.5154334589432878, exponent=0.5228733015013345).on(b) yield cirq.PhasedXPowGate(phase_exponent=0.06774925307475355).on(a) yield ops.SYC(a, b), yield cirq.PhasedXPowGate(phase_exponent=-0.5987667922766213, exponent=0.4136540654256824).on(a) - yield (cirq.Z ** -0.9255092746611595).on(b) - yield (cirq.Z ** -1.333333333333333).on(a) + yield (cirq.Z**-0.9255092746611595).on(b) + yield (cirq.Z**-1.333333333333333).on(a) yield cirq.rx(-theta).on(a) yield cirq.rx(-theta).on(b) @@ -222,8 +222,8 @@ def _decompose_phased_iswap_into_syc_precomputed( yield ops.SYC(a, b) yield cirq.PhasedXPowGate(phase_exponent=-0.8151665352515929, exponent=0.8906746535691492).on(a) yield cirq.PhasedXPowGate(phase_exponent=-0.07449072533884049, exponent=0.5).on(b) - yield (cirq.Z ** -0.9255092746611595).on(b) - yield (cirq.Z ** -0.9777346353961884).on(a) + yield (cirq.Z**-0.9255092746611595).on(b) + yield (cirq.Z**-0.9777346353961884).on(a) 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): yield cirq.PhasedXPowGate(phase_exponent=-0.5987667922766213, exponent=0.4136540654256824).on( a ), - yield (cirq.Z ** -0.9255092746611595).on(b), - yield (cirq.Z ** -1.333333333333333).on(a), + yield (cirq.Z**-0.9255092746611595).on(b), + yield (cirq.Z**-1.333333333333333).on(a), 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): b ), yield cirq.PhasedXPowGate(phase_exponent=0.9408341606787907).on(a), - yield (cirq.Z ** -1.1551880579397293).on(b), - yield (cirq.Z ** 0.31848343246696365).on(a), + yield (cirq.Z**-1.1551880579397293).on(b), + yield (cirq.Z**0.31848343246696365).on(a), 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): yield cirq.PhasedXPowGate(phase_exponent=-0.8150261316932077, exponent=0.11820787859471782).on( b ) - yield (cirq.Z ** -0.7384700844660306).on(b) - yield (cirq.Z ** -0.7034535141382525).on(a) + yield (cirq.Z**-0.7384700844660306).on(b) + yield (cirq.Z**-0.7034535141382525).on(a) def _find_local_equivalents(target_unitary: np.ndarray, source_unitary: np.ndarray): diff --git a/cirq-google/cirq_google/workflow/quantum_executable_test.py b/cirq-google/cirq_google/workflow/quantum_executable_test.py index e08b7249b39..a75b0df50f3 100644 --- a/cirq-google/cirq_google/workflow/quantum_executable_test.py +++ b/cirq-google/cirq_google/workflow/quantum_executable_test.py @@ -31,15 +31,12 @@ def test_bitstrings_measurement(): def _get_random_circuit(qubits, *, n_moments=10, random_state=52): - return ( - cirq.experiments.random_rotations_between_grid_interaction_layers_circuit( - qubits=qubits, - depth=n_moments, - seed=random_state, - two_qubit_op_factory=lambda a, b, _: cirq.SQRT_ISWAP(a, b), - ) - + cirq.measure(*qubits, key='z') - ) + return cirq.experiments.random_rotations_between_grid_interaction_layers_circuit( + qubits=qubits, + depth=n_moments, + seed=random_state, + two_qubit_op_factory=lambda a, b, _: cirq.SQRT_ISWAP(a, b), + ) + cirq.measure(*qubits, key='z') def _get_example_spec(name='example-program'):