Skip to content

Commit 2e579ee

Browse files
committed
Change numpy dtype repr
1 parent 25ecba9 commit 2e579ee

11 files changed

+26
-28
lines changed

cirq-core/cirq/_compat.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -138,9 +138,7 @@ def _print(self, expr, **kwargs):
138138
return Printer().doprint(value)
139139

140140
if isinstance(value, np.ndarray):
141-
if np.issubdtype(value.dtype, np.datetime64):
142-
return f'np.array({value.tolist()!r}, dtype=np.{value.dtype!r})'
143-
return f'np.array({value.tolist()!r}, dtype=np.{value.dtype})'
141+
return f'np.array({value.tolist()!r}, dtype=np.{value.dtype!r})'
144142

145143
if isinstance(value, pd.MultiIndex):
146144
return f'pd.MultiIndex.from_tuples({repr(list(value))}, names={repr(list(value.names))})'

cirq-core/cirq/_compat_test.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ def __repr__(self):
110110
return dataclass_repr(self, namespace='cirq.testing')
111111

112112
tc = TestClass2(np.ones(3))
113-
assert repr(tc) == "cirq.testing.TestClass2(x=np.array([1.0, 1.0, 1.0], dtype=np.float64))"
113+
assert repr(tc) == "cirq.testing.TestClass2(x=np.array([1.0, 1.0, 1.0], dtype=np.dtype('float64')))"
114114

115115

116116
def test_proper_eq():

cirq-core/cirq/linalg/decompositions_test.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -367,12 +367,12 @@ def test_kak_repr():
367367
cirq.KakDecomposition(
368368
interaction_coefficients=(0.5, 0.25, 0),
369369
single_qubit_operations_before=(
370-
np.array([[0j, (1+0j)], [(1+0j), 0j]], dtype=np.complex128),
371-
np.array([[0j, -1j], [1j, 0j]], dtype=np.complex128),
370+
np.array([[0j, (1+0j)], [(1+0j), 0j]], dtype=np.dtype('complex128')),
371+
np.array([[0j, -1j], [1j, 0j]], dtype=np.dtype('complex128')),
372372
),
373373
single_qubit_operations_after=(
374-
np.array([[1.0, 0.0], [0.0, 1.0]], dtype=np.float64),
375-
np.array([[(1+0j), 0j], [0j, (-1+0j)]], dtype=np.complex128),
374+
np.array([[1.0, 0.0], [0.0, 1.0]], dtype=np.dtype('float64')),
375+
np.array([[(1+0j), 0j], [0j, (-1+0j)]], dtype=np.dtype('complex128')),
376376
),
377377
global_phase=1)
378378
""".strip()

cirq-core/cirq/ops/kraus_channel_test.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,8 @@ def test_kraus_channel_repr():
105105
repr(x_meas)
106106
== """\
107107
cirq.KrausChannel(kraus_ops=[\
108-
np.array([[(0.5+0j), (0.5+0j)], [(0.5+0j), (0.5+0j)]], dtype=np.complex64), \
109-
np.array([[(0.5+0j), (-0.5+0j)], [(-0.5+0j), (0.5+0j)]], dtype=np.complex64)], \
108+
np.array([[(0.5+0j), (0.5+0j)], [(0.5+0j), (0.5+0j)]], dtype=np.dtype('complex64')), \
109+
np.array([[(0.5+0j), (-0.5+0j)], [(-0.5+0j), (0.5+0j)]], dtype=np.dtype('complex64'))], \
110110
key='x_meas')"""
111111
)
112112

cirq-core/cirq/ops/measurement_gate_test.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -317,23 +317,23 @@ def test_op_repr():
317317
b,
318318
key='out',
319319
invert_mask=(False, True),
320-
confusion_map={(0,): np.array([[0, 1], [1, 0]], dtype=np.int64)},
320+
confusion_map={(0,): np.array([[0, 1], [1, 0]], dtype=np.dtype('int64'))},
321321
)
322322
) == (
323323
"cirq.measure(cirq.LineQubit(0), cirq.LineQubit(1), "
324324
"key=cirq.MeasurementKey(name='out'), "
325325
"invert_mask=(False, True), "
326-
"confusion_map={(0,): np.array([[0, 1], [1, 0]], dtype=np.int64)})"
326+
"confusion_map={(0,): np.array([[0, 1], [1, 0]], dtype=np.dtype('int64'))})"
327327
)
328328

329329

330330
def test_repr():
331331
gate = cirq.MeasurementGate(
332-
3, 'a', (True, False), (1, 2, 3), {(2,): np.array([[0, 1], [1, 0]], dtype=np.int64)}
332+
3, 'a', (True, False), (1, 2, 3), {(2,): np.array([[0, 1], [1, 0]], dtype=np.dtype('int64'))}
333333
)
334334
assert repr(gate) == (
335335
"cirq.MeasurementGate(3, cirq.MeasurementKey(name='a'), (True, False), "
336-
"qid_shape=(1, 2, 3), confusion_map={(2,): np.array([[0, 1], [1, 0]], dtype=np.int64)})"
336+
"qid_shape=(1, 2, 3), confusion_map={(2,): np.array([[0, 1], [1, 0]], dtype=np.dtype('int64'))})"
337337
)
338338

339339

cirq-core/cirq/ops/mixed_unitary_channel_test.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -95,16 +95,16 @@ def test_matrix_mixture_str():
9595

9696
def test_matrix_mixture_repr():
9797
mix = [
98-
(0.5, np.array([[1, 0], [0, 1]], dtype=np.complex64)),
99-
(0.5, np.array([[0, 1], [1, 0]], dtype=np.complex64)),
98+
(0.5, np.array([[1, 0], [0, 1]], dtype=np.dtype('complex64'))),
99+
(0.5, np.array([[0, 1], [1, 0]], dtype=np.dtype('complex64'))),
100100
]
101101
half_flip = cirq.MixedUnitaryChannel(mix, key='flip')
102102
assert (
103103
repr(half_flip)
104104
== """\
105105
cirq.MixedUnitaryChannel(mixture=[\
106-
(0.5, np.array([[(1+0j), 0j], [0j, (1+0j)]], dtype=np.complex64)), \
107-
(0.5, np.array([[0j, (1+0j)], [(1+0j), 0j]], dtype=np.complex64))], \
106+
(0.5, np.array([[(1+0j), 0j], [0j, (1+0j)]], dtype=np.dtype('complex64'))), \
107+
(0.5, np.array([[0j, (1+0j)], [(1+0j), 0j]], dtype=np.dtype('complex64')))], \
108108
key='flip')"""
109109
)
110110

cirq-core/cirq/sim/density_matrix_simulator.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ def __repr__(self) -> str:
303303
# Dtype doesn't have a good repr, so we work around by invoking __name__.
304304
return (
305305
f'cirq.DensityMatrixStepResult(sim_state={self._sim_state!r},'
306-
f' dtype=np.{self._dtype.__name__})'
306+
f' dtype=np.{np.dtype(self._dtype)!r})'
307307
)
308308

309309

cirq-core/cirq/sim/density_matrix_simulator_test.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -951,9 +951,9 @@ def test_density_matrix_step_result_repr():
951951
)
952952
)
953953
== "cirq.DensityMatrixStepResult(sim_state=cirq.DensityMatrixSimulationState("
954-
"initial_state=np.array([[(0.5+0j), (0.5+0j)], [(0.5+0j), (0.5+0j)]], dtype=np.complex64), "
954+
"initial_state=np.array([[(0.5+0j), (0.5+0j)], [(0.5+0j), (0.5+0j)]], dtype=np.dtype('complex64')), "
955955
"qubits=(cirq.LineQubit(0),), "
956-
"classical_data=cirq.ClassicalDataDictionaryStore()), dtype=np.complex64)"
956+
"classical_data=cirq.ClassicalDataDictionaryStore()), dtype=np.dtype('complex64'))"
957957
)
958958

959959

@@ -1034,9 +1034,9 @@ def test_density_matrix_trial_result_repr():
10341034
expected_repr = (
10351035
"cirq.DensityMatrixTrialResult("
10361036
"params=cirq.ParamResolver({'s': 1}), "
1037-
"measurements={'m': np.array([[1]], dtype=np.int32)}, "
1037+
"measurements={'m': np.array([[1]], dtype=np.dtype('int32'))}, "
10381038
"final_simulator_state=cirq.DensityMatrixSimulationState("
1039-
"initial_state=np.array([[(0.5+0j), (0.5+0j)], [(0.5+0j), (0.5+0j)]], dtype=np.complex64), "
1039+
"initial_state=np.array([[(0.5+0j), (0.5+0j)], [(0.5+0j), (0.5+0j)]], dtype=np.dtype('complex64')), "
10401040
"qubits=(cirq.LineQubit(0),), "
10411041
"classical_data=cirq.ClassicalDataDictionaryStore()))"
10421042
)

cirq-core/cirq/sim/sparse_simulator.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -282,5 +282,5 @@ def __repr__(self) -> str:
282282
# Dtype doesn't have a good repr, so we work around by invoking __name__.
283283
return (
284284
f'cirq.SparseSimulatorStep(sim_state={self._sim_state!r},'
285-
f' dtype=np.{self._dtype.__name__})'
285+
f' dtype=np.{np.dtype(self._dtype)!r})'
286286
)

cirq-core/cirq/sim/sparse_simulator_test.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -775,9 +775,9 @@ def test_sparse_simulator_repr():
775775
# No equality so cannot use cirq.testing.assert_equivalent_repr
776776
assert (
777777
repr(step) == "cirq.SparseSimulatorStep(sim_state=cirq.StateVectorSimulationState("
778-
"initial_state=np.array([[0j, (1+0j)], [0j, 0j]], dtype=np.complex64), "
778+
"initial_state=np.array([[0j, (1+0j)], [0j, 0j]], dtype=np.dtype('complex64')), "
779779
"qubits=(cirq.LineQubit(0), cirq.LineQubit(1)), "
780-
"classical_data=cirq.ClassicalDataDictionaryStore()), dtype=np.complex64)"
780+
"classical_data=cirq.ClassicalDataDictionaryStore()), dtype=np.dtype('complex64'))"
781781
)
782782

783783

cirq-core/cirq/sim/state_vector_simulator_test.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@ def test_state_vector_trial_result_repr():
3535
expected_repr = (
3636
"cirq.StateVectorTrialResult("
3737
"params=cirq.ParamResolver({'s': 1}), "
38-
"measurements={'m': np.array([[1]], dtype=np.int32)}, "
38+
"measurements={'m': np.array([[1]], dtype=np.dtype('int32'))}, "
3939
"final_simulator_state=cirq.StateVectorSimulationState("
40-
"initial_state=np.array([0j, (1+0j)], dtype=np.complex64), "
40+
"initial_state=np.array([0j, (1+0j)], dtype=np.dtype('complex64')), "
4141
"qubits=(cirq.NamedQubit('a'),), "
4242
"classical_data=cirq.ClassicalDataDictionaryStore()))"
4343
)

0 commit comments

Comments
 (0)