def test_param_unused(self, operable_mock_device_2_wires): """Test that the gradient is 0 of an unused parameter""" def circuit(x, y): qml.RX(x, wires=[0]) return qml.expval(qml.PauliZ(0)) q = QubitQNode(circuit, operable_mock_device_2_wires) q._construct([1.0, 1.0], {}) assert q.par_to_grad_method == {0: "A", 1: "0"}
def test_no_following_observable(self, operable_mock_device_2_wires): """Test that the gradient is 0 if no observables succeed""" def circuit(x): qml.RX(x, wires=[1]) return qml.expval(qml.PauliZ(0)) q = QubitQNode(circuit, operable_mock_device_2_wires) q._construct([1.0], {}) assert q.par_to_grad_method == {0: "0"}
def test_not_differentiable(self, operable_mock_device_2_wires): """Test that an operation with grad_method=None is marked as non-differentiable""" def circuit(x): qml.BasisState(x, wires=[1]) return qml.expval(qml.PauliZ(0)) q = QubitQNode(circuit, operable_mock_device_2_wires) q._construct([np.array([1.0])], {}) assert q.par_to_grad_method == {0: None}