コード例 #1
0
 def __init__(self, matrix: np.ndarray, targets: Optional[List[int]] = None):
     clone = np.array(matrix, dtype=complex)
     self._targets = tuple(targets) if targets else None
     if targets:
         check_matrix_dimensions(clone, self._targets)
     elif clone.shape != (2, 2):
         raise ValueError(
             f"Matrix must have shape (2, 2) if target is empty, but has shape {clone.shape}"
         )
     check_hermitian(clone)
     self._matrix = clone
コード例 #2
0
 def __init__(self,
              matrix: np.ndarray,
              targets: Optional[List[int]] = None):
     clone = np.array(matrix, dtype=complex)
     self._targets = tuple(targets) if targets else None
     if targets:
         check_matrix_dimensions(clone, self._targets)
     elif clone.shape != (2, 2):
         raise ValueError(
             f"Matrix must have shape (2, 2) if target is empty, but has shape {clone.shape}"
         )
     check_hermitian(clone)
     self._matrix = clone
     eigendecomposition = Hermitian._eigendecomposition(clone)
     self._eigenvalues = eigendecomposition["eigenvalues"]
     self._diagonalizing_matrix = eigendecomposition["eigenvectors"].conj(
     ).T
コード例 #3
0
 def __init__(self, targets, matrix):
     self._targets = tuple(targets)
     clone = np.array(matrix, dtype=complex)
     check_matrix_dimensions(clone, self._targets)
     check_unitary(clone)
     self._matrix = clone
コード例 #4
0
def test_check_matrix_dimensions_invalid_matrix(matrix):
    check_matrix_dimensions(matrix, (0, ))