예제 #1
0
 def test_unitary_to_su2_random(self) -> None:
     """Tests det(unitary_to_su2(X)) == 1 for random unitary X."""
     # Abort if we don't want random tests
     if not other_consts.USE_RANDOM_TESTS:
         return
     for idx in range(other_consts.RANDOM_SAMPLES):
         unitary = gen_unitary.generate_random_unitary_matrix()
         self.assertAlmostEqual(
             numpy.linalg.det(trans.unitary_to_su2(unitary)), 1.0)
예제 #2
0
    def test_unitary_to_su2_repeated_random(self) -> None:
        """Test that repetition of unitary_to_su2 has no effect."""
        # Abort if we don't want random tests
        if not other_consts.USE_RANDOM_TESTS:
            return

        ReturnType = typing.TypeVar("ReturnType")

        def repeat_func(f: typing.Callable[[ReturnType], ReturnType], n: int,
                        args: ReturnType) -> ReturnType:
            for i in range(n):
                args = f(args)
            return args

        for idx in range(other_consts.RANDOM_SAMPLES):
            unitary = gen_unitary.generate_random_unitary_matrix()
            # We will repeat the application of unitary_to_su2 up to 6 times.
            # 6 has been arbitrarily chosen.
            su2_matrix = trans.unitary_to_su2(unitary)
            for i in range(6):
                self.assertOperatorNormClose(
                    repeat_func(trans.unitary_to_su2, i, su2_matrix),
                    su2_matrix)
예제 #3
0
 def test_unitary_to_su2_pauli_z(self) -> None:
     """Test validity of unitary_to_su2 for the Pauli Z matrix."""
     self.assertOperatorNormClose(mconsts.P_Z_SU2,
                                  trans.unitary_to_su2(mconsts.P_Z))
예제 #4
0
 def test_unitary_to_su2_identity(self) -> None:
     """Test validity of unitary_to_su2 for the identity matrix."""
     self.assertOperatorNormClose(mconsts.ID2,
                                  trans.unitary_to_su2(mconsts.ID2))