Exemple #1
0
    def dot_product(self, alpha: Sequence[float] | np.ndarray) -> np.ndarray:
        """
        Computes the standard dot product of `alpha` with the paulis.

        Args:
            alpha (Sequence[float] | np.ndarray): The pauli coefficients.

        Returns:
            (np.ndarray): Sum of element-wise multiplication of `alpha`
                and `self.paulis`.

        Raises:
            ValueError: If `alpha` and `self.paulis` are incompatible.
        """

        if not is_sequence(alpha) or not all(is_numeric(a) for a in alpha):
            raise TypeError(
                'Expected a sequence of numbers, got %s.' % type(alpha), )

        if len(alpha) != len(self):
            raise ValueError(
                'Incorrect number of alpha values, expected %d, got %d.' %
                (len(self), len(alpha)), )

        return np.array(np.sum([a * s for a, s in zip(alpha, self.paulis)], 0))
Exemple #2
0
    def check_parameters(self, params: Sequence[float] | np.ndarray) -> None:
        """Checks to ensure parameters are valid and match the unitary."""
        if not is_sequence(params):
            raise TypeError(
                'Expected a sequence type for params, got %s.' %
                type(params), )

        if not all(is_numeric(p) for p in params):
            typechecks = [is_numeric(p) for p in params]
            fail_idx = typechecks.index(False)
            raise TypeError(
                'Expected params to be floats, got %s.' %
                type(params[fail_idx]), )

        if len(params) != self.get_num_params():
            raise ValueError(
                'Expected %d params, got %d.' %
                (self.get_num_params(), len(params)), )
Exemple #3
0
 def test_type(self, r6_qudit_circuit: Circuit) -> None:
     params = r6_qudit_circuit.get_params()
     assert isinstance(params, np.ndarray)
     assert all(is_numeric(param) for param in params)
Exemple #4
0
 def test_not_a_seq_float(self, not_a_seq_float: Any) -> None:
     assert (not is_sequence(not_a_seq_float)
             or isinstance(not_a_seq_float, str)
             or any(not is_numeric(f) or is_integer(f) or is_complex(f)
                    for f in not_a_seq_float))
Exemple #5
0
 def test_a_seq_float(self, a_seq_float: Any) -> None:
     assert is_sequence(a_seq_float)
     assert len(a_seq_float) >= 0
     assert all(
         is_numeric(f) and not is_integer(f) and not is_complex(f)
         for f in a_seq_float)
Exemple #6
0
 def test_not_a_float(self, not_a_float: Any) -> None:
     assert (not is_numeric(not_a_float) or is_integer(not_a_float)
             or is_complex(not_a_float))
Exemple #7
0
 def test_a_float(self, a_float: Any) -> None:
     assert (is_numeric(a_float) and not is_integer(a_float)
             and not is_complex(a_float))