コード例 #1
0
    def test_parameter_shift_tape_unknown_model(self, monkeypatch):
        """Test that an unknown model raises an exception"""
        def capabilities(cls):
            capabilities = cls._capabilities
            capabilities.update(model="None")
            return capabilities

        monkeypatch.setattr(qml.devices.DefaultQubit, "capabilities",
                            capabilities)
        dev = qml.device("default.qubit", wires=1)

        with pytest.raises(qml.QuantumFunctionError,
                           match="does not support the parameter-shift rule"):
            QNode._validate_parameter_shift(dev)
コード例 #2
0
 def test_parameter_shift_cv_device(self):
     """Test that the _validate_parameter_shift method
     returns the correct gradient transform for cv devices."""
     dev = qml.device("default.gaussian", wires=1)
     gradient_fn = QNode._validate_parameter_shift(dev)
     assert gradient_fn[0] is qml.gradients.param_shift_cv
     assert gradient_fn[1] == {"dev": dev}
コード例 #3
0
 def test_parameter_shift_qubit_device(self):
     """Test that the _validate_parameter_shift method
     returns the correct gradient transform for qubit devices."""
     dev = qml.device("default.qubit", wires=1)
     gradient_fn = QNode._validate_parameter_shift(dev)
     assert gradient_fn[0] is qml.gradients.param_shift