Skip to content

Commit b76b7a2

Browse files
committed
Format with black skip-magic-trailing-comma
1 parent f82b6fd commit b76b7a2

File tree

83 files changed

+409
-1492
lines changed

Some content is hidden

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

83 files changed

+409
-1492
lines changed

Diff for: cirq-google/cirq_google/__init__.py

+2-10
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,7 @@
1818
from cirq import _compat
1919
from cirq_google import api
2020

21-
from cirq_google._version import (
22-
__version__,
23-
)
21+
from cirq_google._version import __version__
2422

2523
from cirq_google.calibration import (
2624
ALL_ANGLES_FLOQUET_PHASED_FSIM_CHARACTERIZATION,
@@ -89,13 +87,7 @@
8987
LinePlacementStrategy,
9088
)
9189

92-
from cirq_google.ops import (
93-
CalibrationTag,
94-
FSimGateFamily,
95-
PhysicalZTag,
96-
SycamoreGate,
97-
SYC,
98-
)
90+
from cirq_google.ops import CalibrationTag, FSimGateFamily, PhysicalZTag, SycamoreGate, SYC
9991

10092
from cirq_google.optimizers import (
10193
ConvertToXmonGates,

Diff for: cirq-google/cirq_google/api/v1/__init__.py

+1-5
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,7 @@
1313
# limitations under the License.
1414
"""Data format v1 for google api."""
1515

16-
from cirq_google.api.v1 import (
17-
operations_pb2,
18-
params_pb2,
19-
program_pb2,
20-
)
16+
from cirq_google.api.v1 import operations_pb2, params_pb2, program_pb2
2117

2218
from cirq_google.api.v1.params import sweep_from_proto, sweep_to_proto
2319

Diff for: cirq-google/cirq_google/api/v1/params.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,7 @@ def _sweep_from_param_sweep_zip_proto(param_sweep_zip: params_pb2.ZipSweep) -> c
8181
return cirq.UnitSweep
8282

8383

84-
def _sweep_from_single_param_sweep_proto(
85-
single_param_sweep: params_pb2.SingleSweep,
86-
) -> cirq.Sweep:
84+
def _sweep_from_single_param_sweep_proto(single_param_sweep: params_pb2.SingleSweep) -> cirq.Sweep:
8785
key = single_param_sweep.parameter_key
8886
if single_param_sweep.HasField('points'):
8987
points = single_param_sweep.points

Diff for: cirq-google/cirq_google/api/v1/programs.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -314,8 +314,7 @@ def xmon_op_from_proto(proto: operations_pb2.Operation) -> cirq.Operation:
314314
if proto.HasField('exp_w'):
315315
exp_w = proto.exp_w
316316
return cirq.PhasedXPowGate(
317-
exponent=param(exp_w.half_turns),
318-
phase_exponent=param(exp_w.axis_half_turns),
317+
exponent=param(exp_w.half_turns), phase_exponent=param(exp_w.axis_half_turns)
319318
).on(qubit(exp_w.target))
320319
if proto.HasField('exp_z'):
321320
exp_z = proto.exp_z

Diff for: cirq-google/cirq_google/api/v1/programs_test.py

+14-55
Original file line numberDiff line numberDiff line change
@@ -91,32 +91,9 @@ def test_pack_results():
9191
measurements = [
9292
(
9393
'a',
94-
np.array(
95-
[
96-
[0, 0, 0],
97-
[0, 0, 1],
98-
[0, 1, 0],
99-
[0, 1, 1],
100-
[1, 0, 0],
101-
[1, 0, 1],
102-
[1, 1, 0],
103-
]
104-
),
105-
),
106-
(
107-
'b',
108-
np.array(
109-
[
110-
[0, 0],
111-
[0, 1],
112-
[1, 0],
113-
[1, 1],
114-
[0, 0],
115-
[0, 1],
116-
[1, 0],
117-
]
118-
),
94+
np.array([[0, 0, 0], [0, 0, 1], [0, 1, 0], [0, 1, 1], [1, 0, 0], [1, 0, 1], [1, 1, 0]]),
11995
),
96+
('b', np.array([[0, 0], [0, 1], [1, 0], [1, 1], [0, 0], [0, 1], [1, 0]])),
12097
]
12198
data = programs.pack_results(measurements)
12299
expected = make_bytes(
@@ -168,32 +145,14 @@ def test_unpack_results():
168145
assert results['a'].shape == (7, 3)
169146
assert results['a'].dtype == bool
170147
np.testing.assert_array_equal(
171-
results['a'],
172-
[
173-
[0, 0, 0],
174-
[0, 0, 1],
175-
[0, 1, 0],
176-
[0, 1, 1],
177-
[1, 0, 0],
178-
[1, 0, 1],
179-
[1, 1, 0],
180-
],
148+
results['a'], [[0, 0, 0], [0, 0, 1], [0, 1, 0], [0, 1, 1], [1, 0, 0], [1, 0, 1], [1, 1, 0]]
181149
)
182150

183151
assert 'b' in results
184152
assert results['b'].shape == (7, 2)
185153
assert results['b'].dtype == bool
186154
np.testing.assert_array_equal(
187-
results['b'],
188-
[
189-
[0, 0],
190-
[0, 1],
191-
[1, 0],
192-
[1, 1],
193-
[0, 0],
194-
[0, 1],
195-
[1, 0],
196-
],
155+
results['b'], [[0, 0], [0, 1], [1, 0], [1, 1], [0, 0], [0, 1], [1, 0]]
197156
)
198157

199158

@@ -252,7 +211,7 @@ def test_z_proto_convert():
252211
)
253212

254213
assert_proto_dict_convert(gate, proto, cirq.GridQubit(2, 3))
255-
gate = cirq.Z ** 0.5
214+
gate = cirq.Z**0.5
256215
proto = operations_pb2.Operation(
257216
exp_z=operations_pb2.ExpZ(
258217
target=operations_pb2.Qubit(row=2, col=3),
@@ -273,7 +232,7 @@ def test_cz_proto_convert():
273232
)
274233
assert_proto_dict_convert(gate, proto, cirq.GridQubit(2, 3), cirq.GridQubit(3, 4))
275234

276-
gate = cirq.CZ ** 0.5
235+
gate = cirq.CZ**0.5
277236
proto = operations_pb2.Operation(
278237
exp_11=operations_pb2.Exp11(
279238
target1=operations_pb2.Qubit(row=2, col=3),
@@ -305,7 +264,7 @@ def test_w_to_proto():
305264
)
306265
assert_proto_dict_convert(gate, proto, cirq.GridQubit(2, 3))
307266

308-
gate = cirq.X ** 0.25
267+
gate = cirq.X**0.25
309268
proto = operations_pb2.Operation(
310269
exp_w=operations_pb2.ExpW(
311270
target=operations_pb2.Qubit(row=2, col=3),
@@ -315,7 +274,7 @@ def test_w_to_proto():
315274
)
316275
assert_proto_dict_convert(gate, proto, cirq.GridQubit(2, 3))
317276

318-
gate = cirq.Y ** 0.25
277+
gate = cirq.Y**0.25
319278
proto = operations_pb2.Operation(
320279
exp_w=operations_pb2.ExpW(
321280
target=operations_pb2.Qubit(row=2, col=3),
@@ -347,9 +306,9 @@ def test_unsupported_op():
347306

348307
def test_invalid_to_proto_dict_qubit_number():
349308
with pytest.raises(ValueError, match='Wrong number of qubits'):
350-
_ = programs.gate_to_proto(cirq.CZ ** 0.5, (cirq.GridQubit(2, 3),), delay=0)
309+
_ = programs.gate_to_proto(cirq.CZ**0.5, (cirq.GridQubit(2, 3),), delay=0)
351310
with pytest.raises(ValueError, match='Wrong number of qubits'):
352-
programs.gate_to_proto(cirq.Z ** 0.5, (cirq.GridQubit(2, 3), cirq.GridQubit(3, 4)), delay=0)
311+
programs.gate_to_proto(cirq.Z**0.5, (cirq.GridQubit(2, 3), cirq.GridQubit(3, 4)), delay=0)
353312
with pytest.raises(ValueError, match='Wrong number of qubits'):
354313
programs.gate_to_proto(
355314
cirq.PhasedXPowGate(exponent=0.5, phase_exponent=0),
@@ -398,10 +357,10 @@ def test_is_supported():
398357

399358
def test_is_native_xmon_gate():
400359
assert programs.is_native_xmon_gate(cirq.CZ)
401-
assert programs.is_native_xmon_gate(cirq.X ** 0.5)
402-
assert programs.is_native_xmon_gate(cirq.Y ** 0.5)
403-
assert programs.is_native_xmon_gate(cirq.Z ** 0.5)
360+
assert programs.is_native_xmon_gate(cirq.X**0.5)
361+
assert programs.is_native_xmon_gate(cirq.Y**0.5)
362+
assert programs.is_native_xmon_gate(cirq.Z**0.5)
404363
assert programs.is_native_xmon_gate(cirq.PhasedXPowGate(phase_exponent=0.2) ** 0.5)
405-
assert programs.is_native_xmon_gate(cirq.Z ** 1)
364+
assert programs.is_native_xmon_gate(cirq.Z**1)
406365
assert not programs.is_native_xmon_gate(cirq.CCZ)
407366
assert not programs.is_native_xmon_gate(cirq.SWAP)

Diff for: cirq-google/cirq_google/api/v2/results.py

+4-17
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,7 @@
1111
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
14-
from typing import (
15-
cast,
16-
Dict,
17-
Hashable,
18-
Iterable,
19-
Iterator,
20-
List,
21-
Optional,
22-
Sequence,
23-
Set,
24-
)
14+
from typing import cast, Dict, Hashable, Iterable, Iterator, List, Optional, Sequence, Set
2515
from collections import OrderedDict
2616
import dataclasses
2717
import numpy as np
@@ -161,8 +151,7 @@ def results_to_proto(
161151

162152

163153
def results_from_proto(
164-
msg: result_pb2.Result,
165-
measurements: List[MeasureInfo] = None,
154+
msg: result_pb2.Result, measurements: List[MeasureInfo] = None
166155
) -> Sequence[Sequence[cirq.Result]]:
167156
"""Converts a v2 result proto into List of list of trial results.
168157
@@ -184,8 +173,7 @@ def results_from_proto(
184173

185174

186175
def _trial_sweep_from_proto(
187-
msg: result_pb2.SweepResult,
188-
measure_map: Dict[str, MeasureInfo] = None,
176+
msg: result_pb2.SweepResult, measure_map: Dict[str, MeasureInfo] = None
189177
) -> Sequence[cirq.Result]:
190178
"""Converts a SweepResult proto into List of list of trial results.
191179
@@ -220,8 +208,7 @@ def _trial_sweep_from_proto(
220208
m_data[mr.key] = np.array(ordered_results).transpose()
221209
trial_sweep.append(
222210
cirq.ResultDict(
223-
params=cirq.ParamResolver(dict(pr.params.assignments)),
224-
measurements=m_data,
211+
params=cirq.ParamResolver(dict(pr.params.assignments)), measurements=m_data
225212
)
226213
)
227214
return trial_sweep

Diff for: cirq-google/cirq_google/api/v2/results_test.py

+9-33
Original file line numberDiff line numberDiff line change
@@ -142,29 +142,21 @@ def test_results_to_proto():
142142
[
143143
cirq.ResultDict(
144144
params=cirq.ParamResolver({'i': 0}),
145-
measurements={
146-
'foo': np.array([[0], [1], [0], [1]], dtype=bool),
147-
},
145+
measurements={'foo': np.array([[0], [1], [0], [1]], dtype=bool)},
148146
),
149147
cirq.ResultDict(
150148
params=cirq.ParamResolver({'i': 1}),
151-
measurements={
152-
'foo': np.array([[0], [1], [1], [0]], dtype=bool),
153-
},
149+
measurements={'foo': np.array([[0], [1], [1], [0]], dtype=bool)},
154150
),
155151
],
156152
[
157153
cirq.ResultDict(
158154
params=cirq.ParamResolver({'i': 0}),
159-
measurements={
160-
'foo': np.array([[0], [1], [0], [1]], dtype=bool),
161-
},
155+
measurements={'foo': np.array([[0], [1], [0], [1]], dtype=bool)},
162156
),
163157
cirq.ResultDict(
164158
params=cirq.ParamResolver({'i': 1}),
165-
measurements={
166-
'foo': np.array([[0], [1], [1], [0]], dtype=bool),
167-
},
159+
measurements={'foo': np.array([[0], [1], [1], [0]], dtype=bool)},
168160
),
169161
],
170162
]
@@ -189,15 +181,11 @@ def test_results_to_proto_sweep_repetitions():
189181
[
190182
cirq.ResultDict(
191183
params=cirq.ParamResolver({'i': 0}),
192-
measurements={
193-
'foo': np.array([[0]], dtype=bool),
194-
},
184+
measurements={'foo': np.array([[0]], dtype=bool)},
195185
),
196186
cirq.ResultDict(
197187
params=cirq.ParamResolver({'i': 1}),
198-
measurements={
199-
'foo': np.array([[0], [1]], dtype=bool),
200-
},
188+
measurements={'foo': np.array([[0], [1]], dtype=bool)},
201189
),
202190
]
203191
]
@@ -218,11 +206,7 @@ def test_results_from_proto_qubit_ordering():
218206
pr.params.assignments.update({'i': 1})
219207
mr = pr.measurement_results.add()
220208
mr.key = 'foo'
221-
for qubit, results in [
222-
(q(0, 1), 0b1100_1100),
223-
(q(1, 1), 0b1010_1010),
224-
(q(0, 0), 0b1111_0000),
225-
]:
209+
for qubit, results in [(q(0, 1), 0b1100_1100), (q(1, 1), 0b1010_1010), (q(0, 0), 0b1111_0000)]:
226210
qmr = mr.qubit_measurement_results.add()
227211
qmr.qubit.id = v2.qubit_to_proto_id(qubit)
228212
qmr.results = bytes([results])
@@ -262,11 +246,7 @@ def test_results_from_proto_duplicate_qubit():
262246
pr.params.assignments.update({'i': 0})
263247
mr = pr.measurement_results.add()
264248
mr.key = 'foo'
265-
for qubit, results in [
266-
(q(0, 0), 0b1100_1100),
267-
(q(0, 1), 0b1010_1010),
268-
(q(0, 1), 0b1111_0000),
269-
]:
249+
for qubit, results in [(q(0, 0), 0b1100_1100), (q(0, 1), 0b1010_1010), (q(0, 1), 0b1111_0000)]:
270250
qmr = mr.qubit_measurement_results.add()
271251
qmr.qubit.id = v2.qubit_to_proto_id(qubit)
272252
qmr.results = bytes([results])
@@ -282,11 +262,7 @@ def test_results_from_proto_default_ordering():
282262
pr.params.assignments.update({'i': 1})
283263
mr = pr.measurement_results.add()
284264
mr.key = 'foo'
285-
for qubit, results in [
286-
(q(0, 1), 0b1100_1100),
287-
(q(1, 1), 0b1010_1010),
288-
(q(0, 0), 0b1111_0000),
289-
]:
265+
for qubit, results in [(q(0, 1), 0b1100_1100), (q(1, 1), 0b1010_1010), (q(0, 0), 0b1111_0000)]:
290266
qmr = mr.qubit_measurement_results.add()
291267
qmr.qubit.id = v2.qubit_to_proto_id(qubit)
292268
qmr.results = bytes([results])

Diff for: cirq-google/cirq_google/api/v2/sweeps.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,7 @@
2020

2121

2222
def sweep_to_proto(
23-
sweep: cirq.Sweep,
24-
*,
25-
out: Optional[run_context_pb2.Sweep] = None,
23+
sweep: cirq.Sweep, *, out: Optional[run_context_pb2.Sweep] = None
2624
) -> run_context_pb2.Sweep:
2725
"""Converts a Sweep to v2 protobuf message.
2826

Diff for: cirq-google/cirq_google/calibration/__init__.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,7 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
from cirq_google.calibration.engine_simulator import (
16-
PhasedFSimEngineSimulator,
17-
)
15+
from cirq_google.calibration.engine_simulator import PhasedFSimEngineSimulator
1816

1917
from cirq_google.calibration.phased_fsim import (
2018
ALL_ANGLES_FLOQUET_PHASED_FSIM_CHARACTERIZATION,

0 commit comments

Comments
 (0)