From 33580bb95b498c02faf695bf83978bf76e3b4a72 Mon Sep 17 00:00:00 2001 From: Matthew Neeley Date: Tue, 22 Mar 2022 16:07:45 -0700 Subject: [PATCH] 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): ``` --- cirq-core/cirq/circuits/circuit_dag_test.py | 11 +++++------ cirq-core/cirq/circuits/circuit_test.py | 4 ++-- .../quantum_volume/quantum_volume_test.py | 16 ++++++++-------- .../cirq_google/line/placement/anneal_test.py | 4 ++-- .../cirq_google/line/placement/chip_test.py | 4 ++-- .../cirq_google/line/placement/greedy_test.py | 4 ++-- .../cirq_google/line/placement/line_test.py | 4 ++-- .../optimizers/optimize_for_sycamore_test.py | 4 ++-- .../serialization/circuit_serializer_test.py | 4 ++-- .../cirq_google/workflow/qubit_placement_test.py | 4 ++-- 10 files changed, 29 insertions(+), 30 deletions(-) diff --git a/cirq-core/cirq/circuits/circuit_dag_test.py b/cirq-core/cirq/circuits/circuit_dag_test.py index 38776e7953c..8a17589ccf7 100644 --- a/cirq-core/cirq/circuits/circuit_dag_test.py +++ b/cirq-core/cirq/circuits/circuit_dag_test.py @@ -21,9 +21,8 @@ import cirq -class TestDevice(cirq.Device): - def __init__(self): - pass +class FakeDevice(cirq.Device): + pass def test_wrapper_eq(): @@ -124,7 +123,7 @@ def test_from_ops_device_deprecated(): cirq.circuits.circuit._DEVICE_DEP_MESSAGE, deadline='v0.15' ): q0 = cirq.LineQubit(0) - _ = cirq.CircuitDag.from_ops(cirq.X(q0), cirq.Y(q0), device=TestDevice()) + _ = cirq.CircuitDag.from_ops(cirq.X(q0), cirq.Y(q0), device=FakeDevice()) def test_from_circuit(): @@ -140,7 +139,7 @@ def test_from_circuit(): def test_from_circuit_deprecated(): q0 = cirq.LineQubit(0) circuit = cirq.Circuit(cirq.X(q0), cirq.Y(q0)) - circuit._device = TestDevice() + circuit._device = FakeDevice() with cirq.testing.assert_deprecated( cirq.circuits.circuit._DEVICE_DEP_MESSAGE, deadline='v0.15' ): @@ -172,7 +171,7 @@ def test_to_circuit_device_deprecated(): q0 = cirq.LineQubit(0) circuit = cirq.Circuit(cirq.X(q0), cirq.Y(q0)) dag = cirq.CircuitDag.from_circuit(circuit) - dag._device = TestDevice() + dag._device = FakeDevice() with cirq.testing.assert_deprecated( cirq.circuits.circuit._DEVICE_DEP_MESSAGE, deadline='v0.15' diff --git a/cirq-core/cirq/circuits/circuit_test.py b/cirq-core/cirq/circuits/circuit_test.py index aedfa273d51..05bacd7efd4 100644 --- a/cirq-core/cirq/circuits/circuit_test.py +++ b/cirq-core/cirq/circuits/circuit_test.py @@ -208,7 +208,7 @@ def test_approx_eq(circuit_cls): @pytest.mark.parametrize('circuit_cls', [cirq.Circuit, cirq.FrozenCircuit]) def test_approx_eq_device_deprecated(circuit_cls): - class TestDevice(cirq.Device): + class FakeDevice(cirq.Device): def validate_operation(self, operation: cirq.Operation) -> None: pass @@ -216,7 +216,7 @@ def validate_operation(self, operation: cirq.Operation) -> None: with cirq.testing.assert_deprecated( cirq.circuits.circuit._DEVICE_DEP_MESSAGE, deadline='v0.15' ): - other_device = circuit_cls([cirq.Moment([cirq.X(a)])], device=TestDevice()) + other_device = circuit_cls([cirq.Moment([cirq.X(a)])], device=FakeDevice()) assert not cirq.approx_eq( circuit_cls([cirq.Moment([cirq.X(a)])]), other_device, diff --git a/cirq-core/cirq/contrib/quantum_volume/quantum_volume_test.py b/cirq-core/cirq/contrib/quantum_volume/quantum_volume_test.py index ef66b989b4e..3b452ebdf2e 100644 --- a/cirq-core/cirq/contrib/quantum_volume/quantum_volume_test.py +++ b/cirq-core/cirq/contrib/quantum_volume/quantum_volume_test.py @@ -10,7 +10,7 @@ from cirq.contrib.quantum_volume import CompilationResult -class TestDevice(cirq.Device): +class FakeDevice(cirq.Device): qubits = cirq.GridQubit.rect(5, 5) @@ -123,7 +123,7 @@ def test_compile_circuit_router(): router_mock = MagicMock() cirq.contrib.quantum_volume.compile_circuit( cirq.Circuit(), - device_graph=ccr.gridqubits_to_graph_device(TestDevice().qubits), + device_graph=ccr.gridqubits_to_graph_device(FakeDevice().qubits), router=router_mock, routing_attempts=1, ) @@ -141,7 +141,7 @@ def test_compile_circuit(): ) compilation_result = cirq.contrib.quantum_volume.compile_circuit( model_circuit, - device_graph=ccr.gridqubits_to_graph_device(TestDevice().qubits), + device_graph=ccr.gridqubits_to_graph_device(FakeDevice().qubits), compiler=compiler_mock, routing_attempts=1, ) @@ -149,7 +149,7 @@ def test_compile_circuit(): assert len(compilation_result.mapping) == 3 assert cirq.contrib.routing.ops_are_consistent_with_device_graph( compilation_result.circuit.all_operations(), - cirq.contrib.routing.gridqubits_to_graph_device(TestDevice().qubits), + cirq.contrib.routing.gridqubits_to_graph_device(FakeDevice().qubits), ) compiler_mock.assert_called_with(compilation_result.circuit) @@ -169,7 +169,7 @@ def test_compile_circuit_replaces_swaps(): ) compilation_result = cirq.contrib.quantum_volume.compile_circuit( model_circuit, - device_graph=ccr.gridqubits_to_graph_device(TestDevice().qubits), + device_graph=ccr.gridqubits_to_graph_device(FakeDevice().qubits), compiler=compiler_mock, routing_attempts=1, ) @@ -209,7 +209,7 @@ def test_compile_circuit_with_readout_correction(): ) compilation_result = cirq.contrib.quantum_volume.compile_circuit( model_circuit, - device_graph=ccr.gridqubits_to_graph_device(TestDevice().qubits), + device_graph=ccr.gridqubits_to_graph_device(FakeDevice().qubits), compiler=compiler_mock, router=router_mock, routing_attempts=1, @@ -258,7 +258,7 @@ def test_compile_circuit_multiple_routing_attempts(): compilation_result = cirq.contrib.quantum_volume.compile_circuit( model_circuit, - device_graph=ccr.gridqubits_to_graph_device(TestDevice().qubits), + device_graph=ccr.gridqubits_to_graph_device(FakeDevice().qubits), compiler=compiler_mock, router=router_mock, routing_attempts=3, @@ -281,7 +281,7 @@ def test_compile_circuit_no_routing_attempts(): with pytest.raises(AssertionError) as e: cirq.contrib.quantum_volume.compile_circuit( model_circuit, - device_graph=ccr.gridqubits_to_graph_device(TestDevice().qubits), + device_graph=ccr.gridqubits_to_graph_device(FakeDevice().qubits), routing_attempts=0, ) assert e.match('Unable to get routing for circuit') diff --git a/cirq-google/cirq_google/line/placement/anneal_test.py b/cirq-google/cirq_google/line/placement/anneal_test.py index 0a835b5eb83..539cd4f1476 100644 --- a/cirq-google/cirq_google/line/placement/anneal_test.py +++ b/cirq-google/cirq_google/line/placement/anneal_test.py @@ -28,13 +28,13 @@ from cirq_google.line.placement.chip import chip_as_adjacency_list -class TestDevice(cirq.Device): +class FakeDevice(cirq.Device): def __init__(self, qubits): self.qubits = qubits def _create_device(qubits: Iterable[cirq.GridQubit]): - return TestDevice(qubits) + return FakeDevice(qubits) @mock.patch('cirq_google.line.placement.optimization.anneal_minimize') diff --git a/cirq-google/cirq_google/line/placement/chip_test.py b/cirq-google/cirq_google/line/placement/chip_test.py index ced8b9e2b74..af5fc32cc02 100644 --- a/cirq-google/cirq_google/line/placement/chip_test.py +++ b/cirq-google/cirq_google/line/placement/chip_test.py @@ -42,13 +42,13 @@ def test_qubit_not_mutated(): assert qubit == cirq.GridQubit(0, 0) -class TestDevice(cirq.Device): +class FakeDevice(cirq.Device): def __init__(self, qubits): self.qubits = qubits def _create_device(qubits: Iterable[cirq.GridQubit]): - return TestDevice(qubits) + return FakeDevice(qubits) def test_empty(): diff --git a/cirq-google/cirq_google/line/placement/greedy_test.py b/cirq-google/cirq_google/line/placement/greedy_test.py index 16c15213234..67911be46b2 100644 --- a/cirq-google/cirq_google/line/placement/greedy_test.py +++ b/cirq-google/cirq_google/line/placement/greedy_test.py @@ -24,13 +24,13 @@ ) -class TestDevice(cirq.Device): +class FakeDevice(cirq.Device): def __init__(self, qubits): self.qubits = qubits def _create_device(qubits: Iterable[cirq.GridQubit]): - return TestDevice(qubits) + return FakeDevice(qubits) def test_greedy_sequence_search_fails_on_wrong_start_qubit(): diff --git a/cirq-google/cirq_google/line/placement/line_test.py b/cirq-google/cirq_google/line/placement/line_test.py index 7013ba7710e..f105e8c6fbd 100644 --- a/cirq-google/cirq_google/line/placement/line_test.py +++ b/cirq-google/cirq_google/line/placement/line_test.py @@ -19,7 +19,7 @@ from cirq_google.line.placement import GridQubitLineTuple -class TestDevice(cirq.Device): +class FakeDevice(cirq.Device): def __init__(self, qubits): self.qubits = qubits @@ -28,7 +28,7 @@ def test_anneal_method_calls_anneal_search(): q00 = cirq.GridQubit(0, 0) q01 = cirq.GridQubit(0, 1) q03 = cirq.GridQubit(0, 3) - device = TestDevice(qubits=[q00, q01, q03]) + device = FakeDevice(qubits=[q00, q01, q03]) length = 2 method = cg.AnnealSequenceSearchStrategy() diff --git a/cirq-google/cirq_google/optimizers/optimize_for_sycamore_test.py b/cirq-google/cirq_google/optimizers/optimize_for_sycamore_test.py index 1c4484f9a58..f3af74fede9 100644 --- a/cirq-google/cirq_google/optimizers/optimize_for_sycamore_test.py +++ b/cirq-google/cirq_google/optimizers/optimize_for_sycamore_test.py @@ -19,7 +19,7 @@ import cirq_google as cg -class TestDevice(cirq.Device): +class FakeDevice(cirq.Device): def __init__(self): pass @@ -132,7 +132,7 @@ def test_assert_new_device_deprecated(): cirq.circuits.circuit._DEVICE_DEP_MESSAGE, deadline='v0.15' ): _ = cg.optimized_for_sycamore( - circuit0, optimizer_type='sqrt_iswap', new_device=TestDevice() + circuit0, optimizer_type='sqrt_iswap', new_device=FakeDevice() ) diff --git a/cirq-google/cirq_google/serialization/circuit_serializer_test.py b/cirq-google/cirq_google/serialization/circuit_serializer_test.py index 483a2e0d63f..ce91b08708a 100644 --- a/cirq-google/cirq_google/serialization/circuit_serializer_test.py +++ b/cirq-google/cirq_google/serialization/circuit_serializer_test.py @@ -22,7 +22,7 @@ from cirq_google.api import v2 -class TestDevice(cirq.Device): +class FakeDevice(cirq.Device): def __init__(self): pass @@ -680,7 +680,7 @@ def test_deserialize_schedule_not_supported(): ), ) with pytest.raises(ValueError, match='no longer supported'): - serializer.deserialize(proto, TestDevice()) + serializer.deserialize(proto, FakeDevice()) def test_deserialize_fsim_missing_parameters(): diff --git a/cirq-google/cirq_google/workflow/qubit_placement_test.py b/cirq-google/cirq_google/workflow/qubit_placement_test.py index 1babdb91191..72ac78afe48 100644 --- a/cirq-google/cirq_google/workflow/qubit_placement_test.py +++ b/cirq-google/cirq_google/workflow/qubit_placement_test.py @@ -19,7 +19,7 @@ import numpy as np -class TestDevice(cirq.Device): +class FakeDevice(cirq.Device): def __init__(self): self.qubits = cirq.GridQubit.rect(2, 8) 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(): qp.place_circuit( circuit, problem_topology=topo, - shared_rt_info=cg.SharedRuntimeInfo(run_id='1', device=TestDevice()), + shared_rt_info=cg.SharedRuntimeInfo(run_id='1', device=FakeDevice()), rs=np.random.RandomState(1), )