コード例 #1
0
    def test_exception_wrong_shape(self, state_vector):
        """Verifies that exception is raised if the
        number of dimensions of features is incorrect."""

        with pytest.raises(ValueError,
                           match="State vectors must be one-dimensional"):
            qml.MottonenStatePreparation(state_vector, 2)
コード例 #2
0
    def test_error_state_vector_not_normalized(self, state_vector, wires):
        """Tests that the correct error messages is raised if
        the given state vector is not normalized."""

        with pytest.raises(ValueError,
                           match="State vectors have to be of norm"):
            qml.MottonenStatePreparation(state_vector, wires)
コード例 #3
0
    def test_error_num_entries(self, state_vector, wires):
        """Tests that the correct error messages is raised  if
        the number of entries in the given state vector does not match
        with the number of wires in the system."""

        with pytest.raises(ValueError,
                           match="State vectors must be of (length|shape)"):
            qml.MottonenStatePreparation(state_vector, wires)
コード例 #4
0
 def circuit(inputs):
     qml.MottonenStatePreparation(inputs, wires=[0, 1])
     return qml.probs(wires=[0, 1])
コード例 #5
0
 def circuit(state_vector):
     qml.MottonenStatePreparation(state_vector, wires=range(1))
     return qml.expval(qml.PauliZ(0))
コード例 #6
0
 def test_id(self):
     """Tests that the id attribute can be set."""
     template = qml.MottonenStatePreparation(np.array([0, 1]),
                                             wires=[0],
                                             id="a")
     assert template.id == "a"
コード例 #7
0
 def circuit2():
     qml.MottonenStatePreparation(state, wires=["z", "a", "k"])
     return qml.expval(qml.Identity("z"))
コード例 #8
0
 def circuit():
     qml.MottonenStatePreparation(state, wires=range(3))
     return qml.expval(qml.Identity(0))
コード例 #9
0
 def circuit():
     qml.MottonenStatePreparation(state_vector, wires)
     return qml.expval(qml.PauliZ(0)), qml.expval(
         qml.PauliZ(1)), qml.expval(qml.PauliZ(2))