Skip to content

Commit

Permalink
Format cirq-google with latest version of black (quantumlib#5160)
Browse files Browse the repository at this point in the history
Follow-up to quantumlib#5157. Format code in cirq-google to ensure these formatting changes don't get mixed in with future logic changes.
  • Loading branch information
maffoo authored and rht committed May 1, 2023
1 parent 184500d commit e186841
Show file tree
Hide file tree
Showing 11 changed files with 63 additions and 75 deletions.
2 changes: 1 addition & 1 deletion cirq-google/cirq_google/calibration/phased_fsim_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
33 changes: 12 additions & 21 deletions cirq-google/cirq_google/engine/abstract_local_processor_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
4 changes: 2 additions & 2 deletions cirq-google/cirq_google/line/placement/anneal_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down
8 changes: 4 additions & 4 deletions cirq-google/cirq_google/ops/fsim_gate_family_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}),
(
Expand All @@ -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}),
(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down
4 changes: 2 additions & 2 deletions cirq-google/cirq_google/serialization/common_serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
],
Expand All @@ -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,
Expand Down
30 changes: 15 additions & 15 deletions cirq-google/cirq_google/serialization/common_serializers_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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),
],
)
Expand Down Expand Up @@ -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])
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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),
Expand Down
12 changes: 6 additions & 6 deletions cirq-google/cirq_google/serialization/gate_sets_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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),
],
)
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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):
Expand All @@ -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:
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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):
Expand Down
15 changes: 6 additions & 9 deletions cirq-google/cirq_google/workflow/quantum_executable_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'):
Expand Down

0 comments on commit e186841

Please sign in to comment.