From 168003376a94b4c7d207af4b50fdfa2ae4b5c998 Mon Sep 17 00:00:00 2001 From: andrijapau Date: Mon, 25 Nov 2024 16:27:48 -0500 Subject: [PATCH] change default.mixed to default.qubit.legacy --- tests/test_qnode_legacy.py | 169 ++++++++++++++++++++----------------- 1 file changed, 93 insertions(+), 76 deletions(-) diff --git a/tests/test_qnode_legacy.py b/tests/test_qnode_legacy.py index d8de663a748..d3624a75326 100644 --- a/tests/test_qnode_legacy.py +++ b/tests/test_qnode_legacy.py @@ -65,7 +65,7 @@ class DummyDevice(qml.devices.LegacyDevice): pennylane_requires = 0.38 def capabilities(self): - return {"passthru_devices": {"autograd": "default.mixed"}} + return {"passthru_devices": {"autograd": "default.qubit.legacy"}} def reset(self): pass @@ -98,7 +98,7 @@ class TestValidation: def test_invalid_interface(self): """Test that an exception is raised for an invalid interface""" - dev = qml.device("default.mixed", wires=1) + dev = DefaultQubitLegacy(wires=1) test_interface = "something" expected_error = rf"Unknown interface {test_interface}\. Interface must be one of" @@ -108,7 +108,7 @@ def test_invalid_interface(self): def test_changing_invalid_interface(self): """Test that an exception is raised for an invalid interface on a pre-existing QNode""" - dev = qml.device("default.mixed", wires=1) + dev = DefaultQubitLegacy(wires=1) test_interface = "something" @qnode(dev) @@ -145,7 +145,7 @@ def test_best_method_is_device(self, monkeypatch): """Test that the method for determining the best diff method for a given device and interface returns the device""" - dev = qml.device("default.mixed", wires=1) + dev = DefaultQubitLegacy(wires=1) monkeypatch.setitem(dev._capabilities, "passthru_interface", "some_interface") monkeypatch.setitem(dev._capabilities, "provides_jacobian", True) @@ -154,42 +154,56 @@ def test_best_method_is_device(self, monkeypatch): with pytest.warns( qml.PennyLaneDeprecationWarning, match="QNode.get_best_method is deprecated" ): - res = QNode.get_best_method(dev, "another_interface") - assert res == ("device", {}, dev) + gradient_fn, gradient_kwargs, execution_device = QNode.get_best_method( + dev, "another_interface" + ) + assert gradient_fn == "device" + assert not gradient_kwargs + assert "DefaultQubitLegacy device" in repr(execution_device) # device is returned even if backpropagation is possible with pytest.warns( qml.PennyLaneDeprecationWarning, match="QNode.get_best_method is deprecated" ): - res = QNode.get_best_method(dev, "some_interface") - assert res == ("device", {}, dev) + gradient_fn, gradient_kwargs, execution_device = QNode.get_best_method( + dev, "some_interface" + ) + assert gradient_fn == "device" + assert not gradient_kwargs + assert "DefaultQubitLegacy device" in repr(execution_device) # pylint: disable=protected-access @pytest.mark.parametrize("interface", ["jax", "tensorflow", "torch", "autograd"]) def test_best_method_is_backprop(self, interface): """Test that the method for determining the best diff method for a given device and interface returns backpropagation""" - dev = qml.device("default.mixed", wires=1) + dev = DefaultQubitLegacy(wires=1) # backprop is returned when the interface is an allowed interface for the device and Jacobian is not provided with pytest.warns( qml.PennyLaneDeprecationWarning, match="QNode.get_best_method is deprecated" ): - res = QNode.get_best_method(dev, interface) - assert res == ("backprop", {}, dev) + gradient_fn, gradient_kwargs, execution_device = QNode.get_best_method(dev, interface) + assert gradient_fn == "backprop" + assert not gradient_kwargs + assert "DefaultQubitLegacy device" in repr(execution_device) # pylint: disable=protected-access def test_best_method_is_param_shift(self): """Test that the method for determining the best diff method for a given device and interface returns the parameter shift rule""" - dev = qml.device("default.mixed", wires=1) + dev = DefaultQubitLegacy(wires=1) tape = qml.tape.QuantumScript([], [], shots=50) with pytest.warns( qml.PennyLaneDeprecationWarning, match="QNode.get_best_method is deprecated" ): - res = QNode.get_best_method(dev, None, tape=tape) - assert res == (qml.gradients.param_shift, {}, dev) + gradient_fn, gradient_kwargs, execution_device = QNode.get_best_method( + dev, None, tape=tape + ) + assert gradient_fn is qml.gradients.param_shift + assert not gradient_kwargs + assert "DefaultQubitLegacy device" in repr(execution_device) # pylint: disable=protected-access @pytest.mark.xfail(reason="No longer possible thanks to the new Legacy Facade") @@ -205,7 +219,7 @@ def capabilities(cls): # finite differences is the fallback when we know nothing about the device monkeypatch.setattr(DefaultQubitLegacy, "capabilities", capabilities) - dev = qml.device("default.mixed", wires=1) + dev = DefaultQubitLegacy(wires=1) monkeypatch.setitem(dev._capabilities, "passthru_interface", "some_interface") monkeypatch.setitem(dev._capabilities, "provides_jacobian", False) with pytest.warns( @@ -218,7 +232,7 @@ def capabilities(cls): def test_best_method_str_is_device(self, monkeypatch): """Test that the method for determining the best diff method string for a given device and interface returns 'device'""" - dev = qml.device("default.mixed", wires=1) + dev = DefaultQubitLegacy(wires=1) monkeypatch.setitem(dev._capabilities, "passthru_interface", "some_interface") monkeypatch.setitem(dev._capabilities, "provides_jacobian", True) @@ -240,7 +254,7 @@ def test_best_method_str_is_device(self, monkeypatch): def test_best_method_str_is_backprop(self, monkeypatch): """Test that the method for determining the best diff method string for a given device and interface returns 'backprop'""" - dev = qml.device("default.mixed", wires=1) + dev = DefaultQubitLegacy(wires=1) monkeypatch.setitem(dev._capabilities, "passthru_interface", "some_interface") monkeypatch.setitem(dev._capabilities, "provides_jacobian", False) @@ -267,7 +281,7 @@ def test_best_method_str_wraps_legacy_device_correctly(self, mocker): def test_best_method_str_is_param_shift(self): """Test that the method for determining the best diff method string for a given device and interface returns 'parameter-shift'""" - dev = qml.device("default.mixed", wires=1, shots=50) + dev = DefaultQubitLegacy(wires=1, shots=50) # parameter shift is returned when Jacobian is not provided and # the backprop interfaces do not match @@ -281,7 +295,7 @@ def test_best_method_str_is_param_shift(self): def test_best_method_str_is_finite_diff(self, mocker): """Test that the method for determining the best diff method string for a given device and interface returns 'finite-diff'""" - dev = qml.device("default.mixed", wires=1) + dev = DefaultQubitLegacy(wires=1) mocker.patch.object(QNode, "get_best_method", return_value=[qml.gradients.finite_diff]) @@ -294,7 +308,7 @@ def test_best_method_str_is_finite_diff(self, mocker): def test_unknown_diff_method_string(self): """Test that an exception is raised for an unknown differentiation method string""" - dev = qml.device("default.mixed", wires=1) + dev = DefaultQubitLegacy(wires=1) with pytest.raises( qml.QuantumFunctionError, match="Differentiation method hello not recognized" @@ -303,7 +317,7 @@ def test_unknown_diff_method_string(self): def test_unknown_diff_method_type(self): """Test that an exception is raised for an unknown differentiation method type""" - dev = qml.device("default.mixed", wires=1) + dev = DefaultQubitLegacy(wires=1) with pytest.raises( ValueError, @@ -316,7 +330,7 @@ def test_adjoint_finite_shots(self): on QNode construction when the device has finite shots """ - dev = qml.device("default.mixed", wires=1, shots=1) + dev = DefaultQubitLegacy(wires=1, shots=1) with pytest.raises( qml.QuantumFunctionError, match="does not support adjoint with requested circuit." @@ -332,7 +346,7 @@ def circ(): def test_sparse_diffmethod_error(self): """Test that an error is raised when the observable is SparseHamiltonian and the differentiation method is not parameter-shift.""" - dev = qml.device("default.mixed", wires=2, shots=None) + dev = DefaultQubitLegacy(wires=2, shots=None) @qnode(dev, diff_method="backprop") def circuit(param): @@ -346,7 +360,7 @@ def circuit(param): def test_qnode_print(self): """Test that printing a QNode object yields the right information.""" - dev = qml.device("default.mixed", wires=1) + dev = DefaultQubitLegacy(wires=1) def func(x): qml.RX(x, wires=0) @@ -356,14 +370,14 @@ def func(x): assert ( repr(qn) - == "" + == "" ) qn = QNode(func, dev, interface="autograd") assert ( repr(qn) - == "" + == "" ) # QNode can still be executed @@ -377,7 +391,7 @@ def func(x): # pylint: disable=unused-variable def test_unrecognized_kwargs_raise_warning(self): """Test that passing gradient_kwargs not included in qml.gradients.SUPPORTED_GRADIENT_KWARGS raises warning""" - dev = qml.device("default.mixed", wires=2) + dev = DefaultQubitLegacy(wires=2) with warnings.catch_warnings(record=True) as w: @@ -393,7 +407,7 @@ def circuit(params): def test_incorrect_diff_method_kwargs_raise_warning(self): """Tests that using one of the incorrect kwargs previously used in some examples in PennyLane (grad_method, gradient_fn) to set the qnode diff_method raises a warning""" - dev = qml.device("default.mixed", wires=2) + dev = DefaultQubitLegacy(wires=2) with warnings.catch_warnings(record=True) as w: @@ -413,7 +427,7 @@ def circuit2(params): def test_auto_interface_tracker_device_switched(self): """Test that checks that the tracker is switched to the new device.""" - dev = qml.device("default.mixed", wires=1) + dev = DefaultQubitLegacy(wires=1) @qml.qnode(dev) def circuit(params): @@ -436,7 +450,7 @@ def circuit(params): def test_autograd_interface_device_switched_no_warnings(self): """Test that checks that no warning is raised for device switch when you define an interface, except for the deprecation warnings which will be caught by the fixture.""" - dev = qml.device("default.mixed", wires=1) + dev = DefaultQubitLegacy(wires=1) @qml.qnode(dev, interface="autograd") def circuit(params): @@ -449,7 +463,7 @@ def test_not_giving_mode_kwarg_does_not_raise_warning(self): """Test that not providing a value for mode does not raise a warning.""" with warnings.catch_warnings(record=True) as record: - qml.QNode(lambda f: f, qml.device("default.mixed", wires=1)) + qml.QNode(lambda f: f, DefaultQubitLegacy(wires=1)) assert len(record) == 0 @@ -459,7 +473,7 @@ class TestTapeConstruction: def test_basic_tape_construction(self, tol): """Test that a quantum tape is properly constructed""" - dev = qml.device("default.mixed", wires=2) + dev = DefaultQubitLegacy(wires=2) def func(x, y): qml.RX(x, wires=0) @@ -495,7 +509,7 @@ def func(x, y): def test_returning_non_measurements(self): """Test that an exception is raised if a non-measurement is returned from the QNode.""" - dev = qml.device("default.mixed", wires=2) + dev = DefaultQubitLegacy(wires=2) def func0(x, y): qml.RX(x, wires=0) @@ -539,7 +553,7 @@ def func3(x, y): def test_inconsistent_measurement_order(self): """Test that an exception is raised if measurements are returned in an order different to how they were queued on the tape""" - dev = qml.device("default.mixed", wires=2) + dev = DefaultQubitLegacy(wires=2) def func(x, y): qml.RX(x, wires=0) @@ -559,7 +573,7 @@ def func(x, y): def test_consistent_measurement_order(self): """Test evaluation proceeds as expected if measurements are returned in the same order to how they were queued on the tape""" - dev = qml.device("default.mixed", wires=2) + dev = DefaultQubitLegacy(wires=2) contents = [] @@ -587,7 +601,7 @@ def test_jit_counts_raises_error(self): jitting raises an error.""" import jax - dev = qml.device("default.mixed", wires=2, shots=5) + dev = DefaultQubitLegacy(wires=2, shots=5) def circuit1(param): qml.Hadamard(0) @@ -621,7 +635,7 @@ def circuit2(param): def test_decorator(tol): """Test that the decorator correctly creates a QNode.""" - dev = qml.device("default.mixed", wires=2) + dev = DefaultQubitLegacy(wires=2) @qnode(dev) def func(x, y): @@ -669,7 +683,7 @@ def func(): qml.CNOT(wires=[0, 1]) return qml.expval(qml.PauliZ(0)) - dev = qml.device("default.mixed", wires=2) + dev = DefaultQubitLegacy(wires=2) qn = QNode(func, dev, interface="autograd") for _ in range(2): @@ -693,7 +707,7 @@ def func(): qml.CNOT(wires=[0, 1]) return qml.expval(qml.PauliZ(0)) - dev = qml.device("default.mixed", wires=2) + dev = DefaultQubitLegacy(wires=2) qn = QNode(func, dev, interface=interface) for _ in range(2): qn() @@ -722,7 +736,7 @@ def func(): qml.CNOT(wires=[0, 1]) return qml.expval(qml.PauliZ(0)) - dev = qml.device("default.mixed", wires=2) + dev = DefaultQubitLegacy(wires=2) qn = QNode(func, dev, interface=interface) for _ in range(2): qn() @@ -745,7 +759,7 @@ def test_num_exec_caching_device_swap(self): """Tests that if we swapped the original device (e.g., when diff_method='backprop') then the number of executions recorded is correct.""" - dev = qml.device("default.mixed", wires=2) + dev = DefaultQubitLegacy(wires=2) cache = {} @@ -766,7 +780,7 @@ def test_num_exec_caching_device_swap_two_exec(self): """Tests that if we swapped the original device (e.g., when diff_method='backprop') then the number of executions recorded is correct even with multiple QNode evaluations.""" - dev = qml.device("default.mixed", wires=2) + dev = DefaultQubitLegacy(wires=2) cache = {} @@ -801,7 +815,7 @@ def test_single_expectation_value_with_argnum_one(self, diff_method, tol): This test relies on the fact that exactly one term of the estimated jacobian will match the expected analytical value. """ - dev = qml.device("default.mixed", wires=3) + dev = DefaultQubitLegacy(wires=3) x = pnp.array(0.543, requires_grad=True) y = pnp.array(-0.654, requires_grad=True) @@ -825,7 +839,7 @@ def circuit(x, y): def test_no_defer_measurements_if_supported(self, mocker): """Test that the defer_measurements transform is not used during QNode construction if the device supports mid-circuit measurements.""" - dev = qml.device("default.mixed", wires=3) + dev = DefaultQubitLegacy(wires=3) mocker.patch.object( qml.devices.LegacyDevice, "_capabilities", {"supports_mid_measure": True} ) @@ -844,7 +858,7 @@ def circuit(): assert len(tape.operations) == 2 assert isinstance(tape.operations[1], qml.measurements.MidMeasureMP) - @pytest.mark.parametrize("dev_name", ["default.qubit", "default.mixed"]) + @pytest.mark.parametrize("dev_name", ["default.qubit", "default.qubit.legacy"]) @pytest.mark.parametrize("first_par", np.linspace(0.15, np.pi - 0.3, 3)) @pytest.mark.parametrize("sec_par", np.linspace(0.15, np.pi - 0.3, 3)) @pytest.mark.parametrize( @@ -865,7 +879,10 @@ def test_defer_meas_if_mcm_unsupported( applied if the device doesn't support mid-circuit measurements natively.""" - dev = qml.device(dev_name, wires=3) + if dev_name == "default.qubit.legacy": + dev = DefaultQubitLegacy(wires=3) + else: + dev = qml.device(dev_name, wires=3) @qml.qnode(dev) def cry_qnode(x, y): @@ -891,13 +908,13 @@ def conditional_ry_qnode(x, y): assert np.allclose(r1, r2[0]) assert np.allclose(r2[1], mv_res(first_par)) - assert spy.call_count == 3 if dev.name == "defaut.qubit" else 1 + assert spy.call_count == (3 if dev.name == "default.qubit" else 1) @pytest.mark.parametrize("basis_state", [[1, 0], [0, 1]]) def test_sampling_with_mcm(self, basis_state, mocker): """Tests that a QNode with qml.sample and mid-circuit measurements returns the expected results.""" - dev = qml.device("default.mixed", wires=3, shots=1000) + dev = DefaultQubitLegacy(wires=3, shots=1000) first_par = np.pi @@ -929,7 +946,7 @@ def test_conditional_ops_tensorflow(self, interface): """Test conditional operations with TensorFlow.""" import tensorflow as tf - dev = qml.device("default.mixed", wires=3) + dev = DefaultQubitLegacy(wires=3) @qml.qnode(dev, interface=interface, diff_method="parameter-shift") def cry_qnode(x): @@ -972,7 +989,7 @@ def test_conditional_ops_torch(self, interface): """Test conditional operations with Torch.""" import torch - dev = qml.device("default.mixed", wires=3) + dev = DefaultQubitLegacy(wires=3) @qml.qnode(dev, interface=interface, diff_method="parameter-shift") def cry_qnode(x): @@ -1011,7 +1028,7 @@ def test_conditional_ops_jax(self, jax_interface): import jax jnp = jax.numpy - dev = qml.device("default.mixed", wires=3) + dev = DefaultQubitLegacy(wires=3) @qml.qnode(dev, interface=jax_interface, diff_method="parameter-shift") def cry_qnode(x): @@ -1042,7 +1059,7 @@ def conditional_ry_qnode(x): def test_qnode_does_not_support_nested_queuing(self): """Test that operators in QNodes are not queued to surrounding contexts.""" - dev = qml.device("default.mixed", wires=1) + dev = DefaultQubitLegacy(wires=1) @qml.qnode(dev) def circuit(): @@ -1063,7 +1080,7 @@ class TestShots: # pylint: disable=unexpected-keyword-arg def test_specify_shots_per_call_sample(self): """Tests that shots can be set per call for a sample return type.""" - dev = qml.device("default.mixed", wires=1, shots=10) + dev = DefaultQubitLegacy(wires=1, shots=10) @qnode(dev) def circuit(a): @@ -1079,7 +1096,7 @@ def circuit(a): def test_specify_shots_per_call_expval(self): """Tests that shots can be set per call for an expectation value. Note: this test has a vanishingly small probability to fail.""" - dev = qml.device("default.mixed", wires=1, shots=None) + dev = DefaultQubitLegacy(wires=1, shots=None) @qnode(dev) def circuit(): @@ -1105,7 +1122,7 @@ def test_no_shots_per_call_if_user_has_shots_qfunc_kwarg(self): """Tests that the per-call shots overwriting is suspended if user has a shots keyword argument, but a warning is raised.""" - dev = qml.device("default.mixed", wires=2, shots=10) + dev = DefaultQubitLegacy(wires=2, shots=10) def circuit(a, shots=0): qml.RX(a, wires=shots) @@ -1132,7 +1149,7 @@ def circuit(a, shots=0): def test_no_shots_per_call_if_user_has_shots_qfunc_arg(self): """Tests that the per-call shots overwriting is suspended if user has a shots argument, but a warning is raised.""" - dev = qml.device("default.mixed", wires=[0, 1], shots=10) + dev = DefaultQubitLegacy(wires=[0, 1], shots=10) def ansatz0(a, shots): qml.RX(a, wires=shots) @@ -1148,7 +1165,7 @@ def ansatz0(a, shots): tape = qml.workflow.construct_tape(circuit)(0.8, 1) assert tape.operations[0].wires.labels == (1,) - dev = qml.device("default.mixed", wires=2, shots=10) + dev = DefaultQubitLegacy(wires=2, shots=10) with pytest.warns( UserWarning, match="The 'shots' argument name is reserved for overriding" @@ -1167,21 +1184,21 @@ def ansatz1(a, shots): def test_shots_setting_does_not_mutate_device(self): """Tests that per-call shots setting does not change the number of shots in the device.""" - dev = qml.device("default.mixed", wires=1, shots=3) + dev = DefaultQubitLegacy(wires=1, shots=3) @qnode(dev) def circuit(a): qml.RX(a, wires=0) return qml.sample(qml.PauliZ(wires=0)) - assert dev.shots == qml.measurements.Shots(3) + assert dev.shots == 3 res = circuit(0.8, shots=2) assert len(res) == 2 - assert dev.shots == qml.measurements.Shots(3) + assert dev.shots == 3 def test_warning_finite_shots_dev(self): """Tests that a warning is raised when caching is used with finite shots.""" - dev = qml.device("default.mixed", wires=1, shots=5) + dev = DefaultQubitLegacy(wires=1, shots=5) @qml.qnode(dev, cache={}) def circuit(x): @@ -1196,7 +1213,7 @@ def circuit(x): # pylint: disable=unexpected-keyword-arg def test_warning_finite_shots_override(self): """Tests that a warning is raised when caching is used with finite shots.""" - dev = qml.device("default.mixed", wires=1, shots=5) + dev = DefaultQubitLegacy(wires=1, shots=5) @qml.qnode(dev, cache={}) def circuit(x): @@ -1210,7 +1227,7 @@ def circuit(x): def test_warning_finite_shots_tape(self): """Tests that a warning is raised when caching is used with finite shots.""" - dev = qml.device("default.mixed", wires=1, shots=5) + dev = DefaultQubitLegacy(wires=1, shots=5) with qml.queuing.AnnotatedQueue() as q: qml.RZ(0.3, wires=0) @@ -1225,7 +1242,7 @@ def test_warning_finite_shots_tape(self): def test_no_warning_infinite_shots(self): """Tests that no warning is raised when caching is used with infinite shots.""" - dev = qml.device("default.mixed", wires=1) + dev = DefaultQubitLegacy(wires=1) @qml.qnode(dev, cache={}) def circuit(x): @@ -1240,7 +1257,7 @@ def circuit(x): @pytest.mark.autograd def test_no_warning_internal_cache_reuse(self): """Tests that no warning is raised when only the internal cache is reused.""" - dev = qml.device("default.mixed", wires=1, shots=5) + dev = DefaultQubitLegacy(wires=1, shots=5) @qml.qnode(dev, cache=True) def circuit(x): @@ -1263,7 +1280,7 @@ def circuit(x): ) def test_tape_shots_set_on_call(self, shots, total_shots, shot_vector): """test that shots are placed on the tape if they are specified during a call.""" - dev = qml.device("default.mixed", wires=2, shots=5) + dev = DefaultQubitLegacy(wires=2, shots=5) def func(x, y): qml.RX(x, wires=0) @@ -1301,7 +1318,7 @@ def qn2(x, y): class TestTransformProgramIntegration: def test_transform_program_modifies_circuit(self): """Test qnode integration with a transform that turns the circuit into just a pauli x.""" - dev = qml.device("default.mixed", wires=1) + dev = DefaultQubitLegacy(wires=1) def null_postprocessing(results): return results[0] @@ -1334,7 +1351,7 @@ def circuit(x): def tet_transform_program_modifies_results(self): """Test integration with a transform that modifies the result output.""" - dev = qml.device("default.mixed", wires=2) + dev = DefaultQubitLegacy(wires=2) @qml.transform def pin_result( @@ -1359,7 +1376,7 @@ def circuit(x): def test_transform_order_circuit_processing(self): """Test that transforms are applied in the correct order in integration.""" - dev = qml.device("default.mixed", wires=2) + dev = DefaultQubitLegacy(wires=2) def null_postprocessing(results): return results[0] @@ -1408,7 +1425,7 @@ def circuit2(x): def test_transform_order_postprocessing(self): """Test that transform postprocessing is called in the right order.""" - dev = qml.device("default.mixed", wires=2) + dev = DefaultQubitLegacy(wires=2) def scale_by_factor(results, factor): return results[0] * factor @@ -1521,7 +1538,7 @@ def circuit(x): def test_no_gradient_expansion(self, mocker): """Test that an unsupported operation with defined gradient recipe is not expanded""" - dev = qml.device("default.mixed", wires=1) + dev = DefaultQubitLegacy(wires=1) # pylint: disable=too-few-public-methods class UnsupportedOp(qml.operation.Operation): @@ -1550,7 +1567,7 @@ def circuit(x): def test_gradient_expansion(self, mocker): """Test that a *supported* operation with no gradient recipe is expanded when applying the gradient transform, but not for execution.""" - dev = qml.device("default.mixed", wires=1) + dev = DefaultQubitLegacy(wires=1) # pylint: disable=too-few-public-methods class PhaseShift(qml.PhaseShift): @@ -1580,7 +1597,7 @@ def circuit(x): def test_hamiltonian_expansion_analytic(self): """Test result if there are non-commuting groups and the number of shots is None""" - dev = qml.device("default.mixed", wires=3, shots=None) + dev = DefaultQubitLegacy(wires=3, shots=None) obs = [qml.PauliX(0), qml.PauliX(0) @ qml.PauliZ(1), qml.PauliZ(0) @ qml.PauliZ(1)] c = np.array([-0.6543, 0.24, 0.54]) @@ -1599,7 +1616,7 @@ def circuit(): def test_hamiltonian_expansion_finite_shots(self, mocker): """Test that the Hamiltonian is expanded if there are non-commuting groups and the number of shots is finite""" - dev = qml.device("default.mixed", wires=3, shots=50000) + dev = DefaultQubitLegacy(wires=3, shots=50000) obs = [qml.PauliX(0), qml.PauliX(0) @ qml.PauliZ(1), qml.PauliZ(0) @ qml.PauliZ(1)] c = np.array([-0.6543, 0.24, 0.54]) @@ -1625,7 +1642,7 @@ def circuit(): def test_multiple_hamiltonian_expansion_finite_shots(self, grouping): """Test that multiple Hamiltonians works correctly (sum_expand should be used)""" - dev = qml.device("default.mixed", wires=3, shots=50000) + dev = DefaultQubitLegacy(wires=3, shots=50000) obs = [qml.PauliX(0), qml.PauliX(0) @ qml.PauliZ(1), qml.PauliZ(0) @ qml.PauliZ(1)] c = np.array([-0.6543, 0.24, 0.54]) @@ -1646,7 +1663,7 @@ def circuit(): def test_expansion_multiple_qwc_observables(self, mocker): """Test that the QNode correctly expands tapes that return multiple measurements of commuting observables""" - dev = qml.device("default.mixed", wires=2) + dev = DefaultQubitLegacy(wires=2) obs = [qml.PauliX(0), qml.PauliX(0) @ qml.PauliY(1)] @qml.qnode(dev)