Esempio n. 1
0
    def test_singular_values_random4x4(self):
        """Tests computing the singular values for random 4 x 4 matrices."""
        for _ in range(10):
            matrix = np.random.randn(4, 4)
            matrix += matrix.conj().T
            qsve = QSVE(matrix)

            print("Matrix:")
            print(matrix)

            sigmas = qsve.singular_values_classical()

            print("Sigmas:", sigmas)

            n = 6
            qsigmas = qsve.top_singular_values(nprecision_bits=n,
                                               init_state_row_and_col=None,
                                               shots=50000,
                                               ntop=4)

            print("QSigmas:", qsigmas)
            print("Max theory error:", qsve.max_error(n))
            self.assertTrue(
                qsve.has_value_close_to_singular_values(
                    qsigmas, qsve.max_error(n)))
            print("Success!\n\n")
Esempio n. 2
0
 def test_non_square(self):
     """Tests QSVE on a simple non-square matrix."""
     matrix = np.array([[1, 0, 0, 0], [0, 1, 0, 0]], dtype=np.float64)
     qsve = QSVE(matrix)
     qsigmas = qsve.top_singular_values(nprecision_bits=2, ntop=2)
     self.assertTrue(
         qsve.has_value_close_to_singular_values(qsigmas,
                                                 qsve.max_error(2)))
Esempio n. 3
0
 def test_non_square_random(self):
     """Tests QSVE on a non-square random matrix."""
     for _ in range(10):
         matrix = np.random.randn(2, 4)
         qsve = QSVE(matrix)
         qsigmas = qsve.top_singular_values(nprecision_bits=4, ntop=-1)
         self.assertTrue(
             qsve.has_value_close_to_singular_values(
                 qsigmas, qsve.max_error(4)))
Esempio n. 4
0
    def test_singular_values_identity8(self):
        """Tests QSVE gets close to the correct singular values for the 8 x 8 identity matrix."""
        qsve = QSVE(np.identity(8))

        sigma = max(qsve.singular_values_classical())

        for n in range(3, 7):
            qsigma = qsve.top_singular_values(nprecision_bits=n,
                                              init_state_row_and_col=None,
                                              shots=50000,
                                              ntop=3)

            self.assertTrue(abs(sigma - qsigma[0]) < qsve.max_error(n))