Skip to content

Commit

Permalink
Format according to new black rules (quantumlib#5259)
Browse files Browse the repository at this point in the history
Follow up by will add hash to  .git-blame-ignore-revs
  • Loading branch information
dabacon authored and rht committed May 1, 2023
1 parent a959527 commit db95192
Show file tree
Hide file tree
Showing 409 changed files with 1,766 additions and 7,455 deletions.
4 changes: 1 addition & 3 deletions cirq-aqt/cirq_aqt/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@

"""Types and methods related to the AQT ion trap device"""

from cirq_aqt._version import (
__version__,
)
from cirq_aqt._version import __version__

from cirq_aqt.aqt_sampler import AQTSampler, AQTSamplerLocalSimulator
from cirq_aqt.aqt_device import AQTSimulator
4 changes: 1 addition & 3 deletions cirq-aqt/cirq_aqt/aqt_sampler.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,7 @@ def __init__(self, remote_host: str, access_token: str):
self.access_token = access_token

def _generate_json(
self,
circuit: cirq.AbstractCircuit,
param_resolver: cirq.ParamResolverOrSimilarType,
self, circuit: cirq.AbstractCircuit, param_resolver: cirq.ParamResolverOrSimilarType
) -> str:
"""Generates the JSON string from a Circuit.
Expand Down
5 changes: 1 addition & 4 deletions cirq-aqt/cirq_aqt/aqt_sampler_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,7 @@ def test_aqt_sampler_empty_circuit():


def test_aqt_sampler():
put_call_args0 = {
'access_token': 'testkey',
'id': '2131da',
}
put_call_args0 = {'access_token': 'testkey', 'id': '2131da'}

e_return = EngineReturn()
with mock.patch(
Expand Down
16 changes: 8 additions & 8 deletions cirq-aqt/cirq_aqt/aqt_simulator_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@ def test_ms_crosstalk_n_noise():
for moment in circuit.moments:
noisy_moment = noise_mod.noisy_moment(moment, qubits)
assert noisy_moment == [
(cirq.XX ** 0.5).on(cirq.LineQubit(1), cirq.LineQubit(2)),
(cirq.XX**0.5).on(cirq.LineQubit(1), cirq.LineQubit(2)),
cirq.depolarize(p=0.01).on(cirq.LineQubit(1)),
cirq.depolarize(p=0.01).on(cirq.LineQubit(2)),
(cirq.XX ** 0.015).on(cirq.LineQubit(1), cirq.LineQubit(0)),
(cirq.XX ** 0.015).on(cirq.LineQubit(1), cirq.LineQubit(3)),
(cirq.XX ** 0.015).on(cirq.LineQubit(2), cirq.LineQubit(0)),
(cirq.XX ** 0.015).on(cirq.LineQubit(2), cirq.LineQubit(3)),
(cirq.XX**0.015).on(cirq.LineQubit(1), cirq.LineQubit(0)),
(cirq.XX**0.015).on(cirq.LineQubit(1), cirq.LineQubit(3)),
(cirq.XX**0.015).on(cirq.LineQubit(2), cirq.LineQubit(0)),
(cirq.XX**0.015).on(cirq.LineQubit(2), cirq.LineQubit(3)),
]


Expand All @@ -57,8 +57,8 @@ def test_x_crosstalk_n_noise():
for moment in circuit.moments:
noisy_moment = noise_mod.noisy_moment(moment, qubits)
assert noisy_moment == [
(cirq.X ** 0.5).on(cirq.LineQubit(1)),
(cirq.X**0.5).on(cirq.LineQubit(1)),
cirq.depolarize(p=0.001).on(cirq.LineQubit(1)),
(cirq.X ** 0.015).on(cirq.LineQubit(0)),
(cirq.X ** 0.015).on(cirq.LineQubit(2)),
(cirq.X**0.015).on(cirq.LineQubit(0)),
(cirq.X**0.015).on(cirq.LineQubit(2)),
]
5 changes: 1 addition & 4 deletions cirq-aqt/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,5 @@
description=description,
long_description=long_description,
packages=cirq_packages,
package_data={
'cirq_aqt': ['py.typed'],
'cirq_aqt.json_test_data': ['*'],
},
package_data={'cirq_aqt': ['py.typed'], 'cirq_aqt.json_test_data': ['*']},
)
39 changes: 7 additions & 32 deletions cirq-core/cirq/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,7 @@

# End dependency order list of sub-modules

from cirq._version import (
__version__,
)
from cirq._version import __version__

# Flattened sub-modules.

Expand Down Expand Up @@ -125,10 +123,7 @@
xeb_fidelity,
)

from cirq.interop import (
quirk_json_to_circuit,
quirk_url_to_circuit,
)
from cirq.interop import quirk_json_to_circuit, quirk_url_to_circuit

from cirq.linalg import (
all_near_zero,
Expand Down Expand Up @@ -662,12 +657,7 @@
with_rescoped_keys,
)

from cirq.ion import (
ConvertToIonGates,
IonDevice,
ms,
two_qubit_matrix_to_ion_operations,
)
from cirq.ion import ConvertToIonGates, IonDevice, ms, two_qubit_matrix_to_ion_operations
from cirq.neutral_atoms import (
ConvertToNeutralAtomGates,
is_native_neutral_atom_gate,
Expand All @@ -684,21 +674,13 @@
plot_state_histogram,
)

from cirq.work import (
CircuitSampleJob,
PauliSumCollector,
Sampler,
Collector,
ZerosSampler,
)
from cirq.work import CircuitSampleJob, PauliSumCollector, Sampler, Collector, ZerosSampler

# pylint: enable=redefined-builtin

# Unflattened sub-modules.

from cirq import (
testing,
)
from cirq import testing

# Registers cirq-core's public classes for JSON serialization.
# pylint: disable=wrong-import-position
Expand All @@ -710,9 +692,7 @@

# contrib's json resolver cache depends on cirq.DEFAULT_RESOLVER

from cirq import (
contrib,
)
from cirq import contrib

# deprecate cirq.ops and related attributes

Expand All @@ -727,11 +707,6 @@
)

ops.Moment = Moment # type: ignore
_compat.deprecate_attributes(
'cirq.ops',
{
'Moment': ('v0.16', 'Use cirq.circuits.Moment instead'),
},
)
_compat.deprecate_attributes('cirq.ops', {'Moment': ('v0.16', 'Use cirq.circuits.Moment instead')})

# pylint: enable=wrong-import-position
14 changes: 4 additions & 10 deletions cirq-core/cirq/_compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,11 +175,7 @@ def _warn_or_error(msg):
if "_compat.py" in filename:
stack_level += 1

warnings.warn(
msg,
DeprecationWarning,
stacklevel=stack_level,
)
warnings.warn(msg, DeprecationWarning, stacklevel=stack_level)


def _validate_deadline(deadline: str):
Expand Down Expand Up @@ -324,7 +320,7 @@ def decorated_func(*args, **kwargs) -> Any:
f'The {parameter_desc} parameter of {qualname} was '
f'used but is deprecated.\n'
f'It will be removed in cirq {deadline}.\n'
f'{fix}\n',
f'{fix}\n'
)

return func(*args, **kwargs)
Expand Down Expand Up @@ -500,7 +496,7 @@ def _deduped_module_warn_or_error(old_module_name: str, new_module_name: str, de
_warn_or_error(
f"{old_module_name} was used but is deprecated.\n "
f"it will be removed in cirq {deadline}.\n "
f"Use {new_module_name} instead.\n",
f"Use {new_module_name} instead.\n"
)


Expand Down Expand Up @@ -700,8 +696,6 @@ def block_overlapping_deprecation(match_regex: str):
"""
with warnings.catch_warnings():
warnings.filterwarnings(
action='ignore',
category=DeprecationWarning,
message=f'(.|\n)*{match_regex}(.|\n)*',
action='ignore', category=DeprecationWarning, message=f'(.|\n)*{match_regex}(.|\n)*'
)
yield
44 changes: 10 additions & 34 deletions cirq-core/cirq/circuits/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,42 +14,18 @@

"""Circuit classes, mutators, and outputs."""

from cirq.circuits.text_diagram_drawer import (
TextDiagramDrawer,
)
from cirq.circuits.text_diagram_drawer import TextDiagramDrawer

from cirq.circuits.qasm_output import (
QasmOutput,
)
from cirq.circuits.qasm_output import QasmOutput

from cirq.circuits.quil_output import (
QuilOutput,
)
from cirq.circuits.quil_output import QuilOutput

from cirq.circuits.circuit import (
AbstractCircuit,
Alignment,
Circuit,
)
from cirq.circuits.circuit_dag import (
CircuitDag,
Unique,
)
from cirq.circuits.circuit_operation import (
CircuitOperation,
)
from cirq.circuits.frozen_circuit import (
FrozenCircuit,
)
from cirq.circuits.insert_strategy import (
InsertStrategy,
)
from cirq.circuits.circuit import AbstractCircuit, Alignment, Circuit
from cirq.circuits.circuit_dag import CircuitDag, Unique
from cirq.circuits.circuit_operation import CircuitOperation
from cirq.circuits.frozen_circuit import FrozenCircuit
from cirq.circuits.insert_strategy import InsertStrategy

from cirq.circuits.moment import (
Moment,
)
from cirq.circuits.moment import Moment

from cirq.circuits.optimization_pass import (
PointOptimizer,
PointOptimizationSummary,
)
from cirq.circuits.optimization_pass import PointOptimizer, PointOptimizationSummary
6 changes: 2 additions & 4 deletions cirq-core/cirq/circuits/_block_diagram_drawer.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,13 +212,11 @@ def render(
# Determine desired size of diagram in blocks.
if block_span_x is None:
block_span_x = 1 + max(
max(x for x, _ in self._blocks.keys()),
max(self._min_widths.keys()),
max(x for x, _ in self._blocks.keys()), max(self._min_widths.keys())
)
if block_span_y is None:
block_span_y = 1 + max(
max(y for _, y in self._blocks.keys()),
max(self._min_heights.keys()),
max(y for _, y in self._blocks.keys()), max(self._min_heights.keys())
)

# Method for accessing blocks without creating new entries.
Expand Down
16 changes: 4 additions & 12 deletions cirq-core/cirq/circuits/_bucket_priority_queue_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,18 +55,10 @@ def test_eq():
BucketPriorityQueue(entries=[(0, 'a')], drop_duplicate_entries=True),
BucketPriorityQueue(entries=[(0, 'a'), (0, 'a')], drop_duplicate_entries=True),
)
eq.add_equality_group(
BucketPriorityQueue(entries=[(0, 'a')]),
)
eq.add_equality_group(
BucketPriorityQueue(entries=[(0, 'a'), (0, 'a')]),
)
eq.add_equality_group(
BucketPriorityQueue(entries=[(1, 'a')]),
)
eq.add_equality_group(
BucketPriorityQueue(entries=[(0, 'b')]),
)
eq.add_equality_group(BucketPriorityQueue(entries=[(0, 'a')]))
eq.add_equality_group(BucketPriorityQueue(entries=[(0, 'a'), (0, 'a')]))
eq.add_equality_group(BucketPriorityQueue(entries=[(1, 'a')]))
eq.add_equality_group(BucketPriorityQueue(entries=[(0, 'b')]))
eq.add_equality_group(
BucketPriorityQueue(entries=[(0, 'a'), (1, 'b')]),
BucketPriorityQueue(entries=[(1, 'b'), (0, 'a')]),
Expand Down
24 changes: 6 additions & 18 deletions cirq-core/cirq/circuits/circuit.py
Original file line number Diff line number Diff line change
Expand Up @@ -928,9 +928,7 @@ def _with_key_path_prefix_(self, prefix: Tuple[str, ...]):
)

def _with_rescoped_keys_(
self,
path: Tuple[str, ...],
bindable_keys: FrozenSet['cirq.MeasurementKey'],
self, path: Tuple[str, ...], bindable_keys: FrozenSet['cirq.MeasurementKey']
):
moments = []
for moment in self.moments:
Expand Down Expand Up @@ -1689,9 +1687,7 @@ class Circuit(AbstractCircuit):
"""

def __init__(
self,
*contents: 'cirq.OP_TREE',
strategy: 'cirq.InsertStrategy' = InsertStrategy.EARLIEST,
self, *contents: 'cirq.OP_TREE', strategy: 'cirq.InsertStrategy' = InsertStrategy.EARLIEST
) -> None:
"""Initializes a circuit.
Expand Down Expand Up @@ -1826,8 +1822,7 @@ def zip(
zip.__doc__ = AbstractCircuit.zip.__doc__

def transform_qubits(
self,
qubit_map: Union[Dict['cirq.Qid', 'cirq.Qid'], Callable[['cirq.Qid'], 'cirq.Qid']],
self, qubit_map: Union[Dict['cirq.Qid', 'cirq.Qid'], Callable[['cirq.Qid'], 'cirq.Qid']]
) -> 'cirq.Circuit':
"""Returns the same circuit, but with different qubits.
Expand Down Expand Up @@ -1973,10 +1968,7 @@ def insert(
"""
moments_and_operations = list(
ops.flatten_to_ops_or_moments(
ops.transform_op_tree(
moment_or_operation_tree,
preserve_moments=True,
),
ops.transform_op_tree(moment_or_operation_tree, preserve_moments=True)
)
)
# limit index to 0..len(self._moments), also deal with indices smaller 0
Expand Down Expand Up @@ -2313,9 +2305,7 @@ def with_noise(self, noise: 'cirq.NOISE_MODEL_LIKE') -> 'cirq.Circuit':


def _pick_inserted_ops_moment_indices(
operations: Sequence['cirq.Operation'],
start: int = 0,
frontier: Dict['cirq.Qid', int] = None,
operations: Sequence['cirq.Operation'], start: int = 0, frontier: Dict['cirq.Qid', int] = None
) -> Tuple[Sequence[int], Dict['cirq.Qid', int]]:
"""Greedily assigns operations to moments.
Expand Down Expand Up @@ -2351,9 +2341,7 @@ def _resolve_operations(
return resolved_operations


def _get_moment_annotations(
moment: 'cirq.Moment',
) -> Iterator['cirq.Operation']:
def _get_moment_annotations(moment: 'cirq.Moment') -> Iterator['cirq.Operation']:
for op in moment.operations:
if op.qubits:
continue
Expand Down
Loading

0 comments on commit db95192

Please sign in to comment.