Skip to content

Commit 33580bb

Browse files
authored
Rename TestDevice -> FakeDevice to avoid pytest confusion (#5066)
Pytest tries to collect `TestDevice` as a test class, and fails with the following wraning: ``` cirq-core/cirq/circuits/circuit_dag_test.py:24 cirq-core/cirq/circuits/circuit_dag_test.py:24 /home/runner/work/Cirq/Cirq/cirq-core/cirq/circuits/circuit_dag_test.py:24: PytestCollectionWarning: cannot collect test class 'TestDevice' because it has a __init__ constructor (from: cirq-core/cirq/circuits/circuit_dag_test.py) class TestDevice(cirq.Device): ```
1 parent 45624ff commit 33580bb

File tree

10 files changed

+29
-30
lines changed

10 files changed

+29
-30
lines changed

cirq-core/cirq/circuits/circuit_dag_test.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,8 @@
2121
import cirq
2222

2323

24-
class TestDevice(cirq.Device):
25-
def __init__(self):
26-
pass
24+
class FakeDevice(cirq.Device):
25+
pass
2726

2827

2928
def test_wrapper_eq():
@@ -124,7 +123,7 @@ def test_from_ops_device_deprecated():
124123
cirq.circuits.circuit._DEVICE_DEP_MESSAGE, deadline='v0.15'
125124
):
126125
q0 = cirq.LineQubit(0)
127-
_ = cirq.CircuitDag.from_ops(cirq.X(q0), cirq.Y(q0), device=TestDevice())
126+
_ = cirq.CircuitDag.from_ops(cirq.X(q0), cirq.Y(q0), device=FakeDevice())
128127

129128

130129
def test_from_circuit():
@@ -140,7 +139,7 @@ def test_from_circuit():
140139
def test_from_circuit_deprecated():
141140
q0 = cirq.LineQubit(0)
142141
circuit = cirq.Circuit(cirq.X(q0), cirq.Y(q0))
143-
circuit._device = TestDevice()
142+
circuit._device = FakeDevice()
144143
with cirq.testing.assert_deprecated(
145144
cirq.circuits.circuit._DEVICE_DEP_MESSAGE, deadline='v0.15'
146145
):
@@ -172,7 +171,7 @@ def test_to_circuit_device_deprecated():
172171
q0 = cirq.LineQubit(0)
173172
circuit = cirq.Circuit(cirq.X(q0), cirq.Y(q0))
174173
dag = cirq.CircuitDag.from_circuit(circuit)
175-
dag._device = TestDevice()
174+
dag._device = FakeDevice()
176175

177176
with cirq.testing.assert_deprecated(
178177
cirq.circuits.circuit._DEVICE_DEP_MESSAGE, deadline='v0.15'

cirq-core/cirq/circuits/circuit_test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -208,15 +208,15 @@ def test_approx_eq(circuit_cls):
208208

209209
@pytest.mark.parametrize('circuit_cls', [cirq.Circuit, cirq.FrozenCircuit])
210210
def test_approx_eq_device_deprecated(circuit_cls):
211-
class TestDevice(cirq.Device):
211+
class FakeDevice(cirq.Device):
212212
def validate_operation(self, operation: cirq.Operation) -> None:
213213
pass
214214

215215
a = cirq.NamedQubit('a')
216216
with cirq.testing.assert_deprecated(
217217
cirq.circuits.circuit._DEVICE_DEP_MESSAGE, deadline='v0.15'
218218
):
219-
other_device = circuit_cls([cirq.Moment([cirq.X(a)])], device=TestDevice())
219+
other_device = circuit_cls([cirq.Moment([cirq.X(a)])], device=FakeDevice())
220220
assert not cirq.approx_eq(
221221
circuit_cls([cirq.Moment([cirq.X(a)])]),
222222
other_device,

cirq-core/cirq/contrib/quantum_volume/quantum_volume_test.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from cirq.contrib.quantum_volume import CompilationResult
1111

1212

13-
class TestDevice(cirq.Device):
13+
class FakeDevice(cirq.Device):
1414
qubits = cirq.GridQubit.rect(5, 5)
1515

1616

@@ -123,7 +123,7 @@ def test_compile_circuit_router():
123123
router_mock = MagicMock()
124124
cirq.contrib.quantum_volume.compile_circuit(
125125
cirq.Circuit(),
126-
device_graph=ccr.gridqubits_to_graph_device(TestDevice().qubits),
126+
device_graph=ccr.gridqubits_to_graph_device(FakeDevice().qubits),
127127
router=router_mock,
128128
routing_attempts=1,
129129
)
@@ -141,15 +141,15 @@ def test_compile_circuit():
141141
)
142142
compilation_result = cirq.contrib.quantum_volume.compile_circuit(
143143
model_circuit,
144-
device_graph=ccr.gridqubits_to_graph_device(TestDevice().qubits),
144+
device_graph=ccr.gridqubits_to_graph_device(FakeDevice().qubits),
145145
compiler=compiler_mock,
146146
routing_attempts=1,
147147
)
148148

149149
assert len(compilation_result.mapping) == 3
150150
assert cirq.contrib.routing.ops_are_consistent_with_device_graph(
151151
compilation_result.circuit.all_operations(),
152-
cirq.contrib.routing.gridqubits_to_graph_device(TestDevice().qubits),
152+
cirq.contrib.routing.gridqubits_to_graph_device(FakeDevice().qubits),
153153
)
154154
compiler_mock.assert_called_with(compilation_result.circuit)
155155

@@ -169,7 +169,7 @@ def test_compile_circuit_replaces_swaps():
169169
)
170170
compilation_result = cirq.contrib.quantum_volume.compile_circuit(
171171
model_circuit,
172-
device_graph=ccr.gridqubits_to_graph_device(TestDevice().qubits),
172+
device_graph=ccr.gridqubits_to_graph_device(FakeDevice().qubits),
173173
compiler=compiler_mock,
174174
routing_attempts=1,
175175
)
@@ -209,7 +209,7 @@ def test_compile_circuit_with_readout_correction():
209209
)
210210
compilation_result = cirq.contrib.quantum_volume.compile_circuit(
211211
model_circuit,
212-
device_graph=ccr.gridqubits_to_graph_device(TestDevice().qubits),
212+
device_graph=ccr.gridqubits_to_graph_device(FakeDevice().qubits),
213213
compiler=compiler_mock,
214214
router=router_mock,
215215
routing_attempts=1,
@@ -258,7 +258,7 @@ def test_compile_circuit_multiple_routing_attempts():
258258

259259
compilation_result = cirq.contrib.quantum_volume.compile_circuit(
260260
model_circuit,
261-
device_graph=ccr.gridqubits_to_graph_device(TestDevice().qubits),
261+
device_graph=ccr.gridqubits_to_graph_device(FakeDevice().qubits),
262262
compiler=compiler_mock,
263263
router=router_mock,
264264
routing_attempts=3,
@@ -281,7 +281,7 @@ def test_compile_circuit_no_routing_attempts():
281281
with pytest.raises(AssertionError) as e:
282282
cirq.contrib.quantum_volume.compile_circuit(
283283
model_circuit,
284-
device_graph=ccr.gridqubits_to_graph_device(TestDevice().qubits),
284+
device_graph=ccr.gridqubits_to_graph_device(FakeDevice().qubits),
285285
routing_attempts=0,
286286
)
287287
assert e.match('Unable to get routing for circuit')

cirq-google/cirq_google/line/placement/anneal_test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,13 @@
2828
from cirq_google.line.placement.chip import chip_as_adjacency_list
2929

3030

31-
class TestDevice(cirq.Device):
31+
class FakeDevice(cirq.Device):
3232
def __init__(self, qubits):
3333
self.qubits = qubits
3434

3535

3636
def _create_device(qubits: Iterable[cirq.GridQubit]):
37-
return TestDevice(qubits)
37+
return FakeDevice(qubits)
3838

3939

4040
@mock.patch('cirq_google.line.placement.optimization.anneal_minimize')

cirq-google/cirq_google/line/placement/chip_test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,13 @@ def test_qubit_not_mutated():
4242
assert qubit == cirq.GridQubit(0, 0)
4343

4444

45-
class TestDevice(cirq.Device):
45+
class FakeDevice(cirq.Device):
4646
def __init__(self, qubits):
4747
self.qubits = qubits
4848

4949

5050
def _create_device(qubits: Iterable[cirq.GridQubit]):
51-
return TestDevice(qubits)
51+
return FakeDevice(qubits)
5252

5353

5454
def test_empty():

cirq-google/cirq_google/line/placement/greedy_test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,13 @@
2424
)
2525

2626

27-
class TestDevice(cirq.Device):
27+
class FakeDevice(cirq.Device):
2828
def __init__(self, qubits):
2929
self.qubits = qubits
3030

3131

3232
def _create_device(qubits: Iterable[cirq.GridQubit]):
33-
return TestDevice(qubits)
33+
return FakeDevice(qubits)
3434

3535

3636
def test_greedy_sequence_search_fails_on_wrong_start_qubit():

cirq-google/cirq_google/line/placement/line_test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
from cirq_google.line.placement import GridQubitLineTuple
2020

2121

22-
class TestDevice(cirq.Device):
22+
class FakeDevice(cirq.Device):
2323
def __init__(self, qubits):
2424
self.qubits = qubits
2525

@@ -28,7 +28,7 @@ def test_anneal_method_calls_anneal_search():
2828
q00 = cirq.GridQubit(0, 0)
2929
q01 = cirq.GridQubit(0, 1)
3030
q03 = cirq.GridQubit(0, 3)
31-
device = TestDevice(qubits=[q00, q01, q03])
31+
device = FakeDevice(qubits=[q00, q01, q03])
3232
length = 2
3333
method = cg.AnnealSequenceSearchStrategy()
3434

cirq-google/cirq_google/optimizers/optimize_for_sycamore_test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
import cirq_google as cg
2020

2121

22-
class TestDevice(cirq.Device):
22+
class FakeDevice(cirq.Device):
2323
def __init__(self):
2424
pass
2525

@@ -132,7 +132,7 @@ def test_assert_new_device_deprecated():
132132
cirq.circuits.circuit._DEVICE_DEP_MESSAGE, deadline='v0.15'
133133
):
134134
_ = cg.optimized_for_sycamore(
135-
circuit0, optimizer_type='sqrt_iswap', new_device=TestDevice()
135+
circuit0, optimizer_type='sqrt_iswap', new_device=FakeDevice()
136136
)
137137

138138

cirq-google/cirq_google/serialization/circuit_serializer_test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
from cirq_google.api import v2
2323

2424

25-
class TestDevice(cirq.Device):
25+
class FakeDevice(cirq.Device):
2626
def __init__(self):
2727
pass
2828

@@ -680,7 +680,7 @@ def test_deserialize_schedule_not_supported():
680680
),
681681
)
682682
with pytest.raises(ValueError, match='no longer supported'):
683-
serializer.deserialize(proto, TestDevice())
683+
serializer.deserialize(proto, FakeDevice())
684684

685685

686686
def test_deserialize_fsim_missing_parameters():

cirq-google/cirq_google/workflow/qubit_placement_test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
import numpy as np
2020

2121

22-
class TestDevice(cirq.Device):
22+
class FakeDevice(cirq.Device):
2323
def __init__(self):
2424
self.qubits = cirq.GridQubit.rect(2, 8)
2525
neighbors = [(a, b) for a in self.qubits for b in self.qubits if a.is_adjacent(b)]
@@ -123,7 +123,7 @@ def test_random_device_placer_small_device():
123123
qp.place_circuit(
124124
circuit,
125125
problem_topology=topo,
126-
shared_rt_info=cg.SharedRuntimeInfo(run_id='1', device=TestDevice()),
126+
shared_rt_info=cg.SharedRuntimeInfo(run_id='1', device=FakeDevice()),
127127
rs=np.random.RandomState(1),
128128
)
129129

0 commit comments

Comments
 (0)