Skip to content

Refactor json_test's TEST_OBJECTS value into test data files #2527

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Nov 14, 2019
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions cirq/_compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,24 @@ def proper_repr(value: Any) -> str:
return repr(value)


def proper_eq(a: Any, b: Any) -> bool:
"""Compares objects for equality, working around __eq__ not always working.

For example, in numpy a == b broadcasts and returns an array instead of
doing what np.array_equal(a, b) does. This method uses np.array_equal(a, b)
when dealing with numpy arrays.
"""
if type(a) == type(b):
if isinstance(a, np.ndarray):
return np.array_equal(a, b)
if isinstance(a, (pd.DataFrame, pd.Index, pd.MultiIndex)):
return a.equals(b)
if isinstance(a, (tuple, list)):
return len(a) == len(b) and all(proper_eq(x, y)
for x, y in zip(a, b))
return a == b


def deprecated(*, deadline: str, fix: str, func_name: Optional[str] = None
) -> Callable[[Callable], Callable]:
"""Marks a function as deprecated.
Expand Down
13 changes: 9 additions & 4 deletions cirq/google/devices/known_devices.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

from typing import Dict, Optional, Iterable, List, Set, Tuple

from cirq import value
from cirq._doc import document
from cirq.devices import GridQubit
from cirq.google import gate_sets, serializable_gate_set
Expand Down Expand Up @@ -172,14 +173,18 @@ def __init__(self, constant: str, **kwargs) -> None:
def __repr__(self):
return self._repr

@classmethod
def _from_json_dict_(cls, constant: str, **kwargs):
if constant == Foxtail._repr:
return Foxtail
if constant == Bristlecone._repr:
return Bristlecone
raise ValueError(f'Unrecognized xmon device name: {constant!r}')

def _json_dict_(self):
return {
'cirq_type': self.__class__.__name__,
'constant': self._repr,
'measurement_duration': self._measurement_duration,
'exp_w_duration': self._exp_w_duration,
'exp_11_duration': self._exp_z_duration,
'qubits': sorted(self.qubits)
}


Expand Down
Loading