Example #1
0
    def test_decompose_gate_matrix(self):
        oneRealPair = np.array(
            [[1 + 1j, 0, 0, 0], [0, 1 - 1j, 0, 0], [0, 0, 2, 0], [0, 0, 0, 2]],
            'complex')
        decomp = ot.decompose_gate_matrix(oneRealPair)
        # decompose gate mx whose eigenvalues have a real but non-unit pair
        # TODO assert correctness

        dblRealPair = np.array(
            [[3, 0, 0, 0], [0, 3, 0, 0], [0, 0, 2, 0], [0, 0, 0, 2]],
            'complex')
        decomp = ot.decompose_gate_matrix(dblRealPair)
Example #2
0
    def test_decompose_gate_matrix(self):
        # decompose gate mx whose eigenvalues have a real but non-unit pair
        oneRealPair = np.array(
            [
                [1 + 1j, 0, 0, 0
                 ],  # Angle between 0 and 1 should give rotation
                [0, 1 - 1j, 0, 0],
                [
                    0, 0, 2, 0
                ],  # should be picked out as fixed point (first real eigenval)
                [0, 0, 0, 2]  # should be picked out as axis of rotation
            ],
            'complex')
        decomp = ot.decompose_gate_matrix(oneRealPair)

        self.assertEqual(decomp['isValid'], True)
        self.assertEqual(decomp['isUnitary'], False)
        self.assertArraysAlmostEqual(decomp['fixed point'], [0, 0, 1, 0])
        self.assertArraysAlmostEqual(decomp['axis of rotation'], [0, 0, 0, 1])
        self.assertArraysAlmostEqual(decomp['rotating axis 1'], [1, 0, 0, 0])
        self.assertArraysAlmostEqual(decomp['rotating axis 2'], [0, 1, 0, 0])
        self.assertEqual(decomp['decay of diagonal rotation terms'], 1.0 - 2.0)
        self.assertEqual(decomp['decay of off diagonal rotation terms'],
                         1.0 - abs(1 + 1j))
        self.assertEqual(decomp['pi rotations'], np.angle(1 + 1j) / np.pi)

        dblRealPair = np.array(
            [
                [3, 0, 0, 0],
                [0, 3, 0, 0],
                [
                    0, 0, 2, 0
                ],  # still taken as fixed point because closest to identity (1.0)
                [0, 0, 0, 2]
            ],
            'complex')
        decomp = ot.decompose_gate_matrix(dblRealPair)
        # decompose gate mx whose eigenvalues have two real but non-unit pairs

        self.assertEqual(decomp['isValid'], True)
        self.assertEqual(decomp['isUnitary'], False)
        self.assertArraysAlmostEqual(decomp['fixed point'], [0, 0, 1, 0])
        self.assertArraysAlmostEqual(decomp['axis of rotation'], [0, 0, 0, 1])
        self.assertArraysAlmostEqual(decomp['rotating axis 1'], [1, 0, 0, 0])
        self.assertArraysAlmostEqual(decomp['rotating axis 2'], [0, 1, 0, 0])
        self.assertEqual(decomp['decay of diagonal rotation terms'], 1.0 - 2.0)
        self.assertEqual(decomp['decay of off diagonal rotation terms'],
                         1.0 - 3.0)
        self.assertEqual(decomp['pi rotations'], np.angle(3.0) / np.pi)
Example #3
0
 def test_decompose_gate_matrix_invalidates_on_all_complex_eigval(self):
     unpairedMx = np.array([[1 + 1j, 0, 0, 0], [0, 2 - 1j, 0, 0],
                            [0, 0, 2 + 2j, 0], [0, 0, 0, 1.0 + 3j]],
                           'complex')
     decomp = ot.decompose_gate_matrix(unpairedMx)
     # decompose gate mx which has all complex eigenvalue -> bail out
     self.assertFalse(decomp['isValid'])
Example #4
0
 def test_decompose_gate_matrix_invalidates_on_large_matrix(self):
     largeMx = np.identity(16, 'd')
     decomp = ot.decompose_gate_matrix(largeMx)  # can only handle 1Q mxs
     self.assertFalse(decomp['isValid'])