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 Apr 14, 2022
1 parent c5f7dd9 commit 377ae66
Show file tree
Hide file tree
Showing 328 changed files with 1,522 additions and 6,633 deletions.
39 changes: 7 additions & 32 deletions 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/_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/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/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/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/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
31 changes: 5 additions & 26 deletions cirq/circuits/circuit_dag_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,22 +137,10 @@ def test_to_circuit():
def test_equality():
q0, q1 = cirq.LineQubit.range(2)
circuit1 = cirq.Circuit(
cirq.X(q0),
cirq.Y(q0),
cirq.Z(q1),
cirq.CZ(q0, q1),
cirq.X(q1),
cirq.Y(q1),
cirq.Z(q0),
cirq.X(q0), cirq.Y(q0), cirq.Z(q1), cirq.CZ(q0, q1), cirq.X(q1), cirq.Y(q1), cirq.Z(q0)
)
circuit2 = cirq.Circuit(
cirq.Z(q1),
cirq.X(q0),
cirq.Y(q0),
cirq.CZ(q0, q1),
cirq.Z(q0),
cirq.X(q1),
cirq.Y(q1),
cirq.Z(q1), cirq.X(q0), cirq.Y(q0), cirq.CZ(q0, q1), cirq.Z(q0), cirq.X(q1), cirq.Y(q1)
)
circuit3 = cirq.Circuit(
cirq.X(q0),
Expand All @@ -164,25 +152,16 @@ def test_equality():
cirq.Z(q0) ** 0.5,
)
circuit4 = cirq.Circuit(
cirq.X(q0),
cirq.Y(q0),
cirq.Z(q1),
cirq.CZ(q0, q1),
cirq.X(q1),
cirq.Y(q1),
cirq.X(q0), cirq.Y(q0), cirq.Z(q1), cirq.CZ(q0, q1), cirq.X(q1), cirq.Y(q1)
)

eq = cirq.testing.EqualsTester()
eq.make_equality_group(
lambda: cirq.CircuitDag.from_circuit(circuit1),
lambda: cirq.CircuitDag.from_circuit(circuit2),
)
eq.add_equality_group(
cirq.CircuitDag.from_circuit(circuit3),
)
eq.add_equality_group(
cirq.CircuitDag.from_circuit(circuit4),
)
eq.add_equality_group(cirq.CircuitDag.from_circuit(circuit3))
eq.add_equality_group(cirq.CircuitDag.from_circuit(circuit4))


def test_larger_circuit():
Expand Down
11 changes: 3 additions & 8 deletions cirq/circuits/circuit_operation.py
Original file line number Diff line number Diff line change
Expand Up @@ -486,9 +486,7 @@ def _from_json_dict_(
# Methods for constructing a similar object with one field modified.

def repeat(
self,
repetitions: Optional[IntParam] = None,
repetition_ids: Optional[List[str]] = None,
self, repetitions: Optional[IntParam] = None, repetition_ids: Optional[List[str]] = None
) -> 'CircuitOperation':
"""Returns a copy of this operation repeated 'repetitions' times.
Each repetition instance will be identified by a single repetition_id.
Expand Down Expand Up @@ -550,9 +548,7 @@ def _with_key_path_prefix_(self, prefix: Tuple[str, ...]):
return dataclasses.replace(self, parent_path=prefix + self.parent_path)

def _with_rescoped_keys_(
self,
path: Tuple[str, ...],
bindable_keys: FrozenSet['cirq.MeasurementKey'],
self, path: Tuple[str, ...], bindable_keys: FrozenSet['cirq.MeasurementKey']
):
# The following line prevents binding to measurement keys in previous repeated subcircuits
# "just because their repetition ids matched". If we eventually decide to change that
Expand All @@ -571,8 +567,7 @@ def with_repetition_ids(self, repetition_ids: List[str]) -> 'cirq.CircuitOperati
return self.replace(repetition_ids=repetition_ids)

def with_qubit_mapping(
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.CircuitOperation':
"""Returns a copy of this operation with an updated qubit mapping.
Expand Down
Loading

0 comments on commit 377ae66

Please sign in to comment.