예제 #1
0
    def setUp(self):
        #Set GateSet objects to "strict" mode for testing
        pygsti.objects.GateSet._strict = True


        # density matrix == 3x3 block diagonal matrix: a 2x2 block followed by a 1x1 block 
        self.stateSpaceDims = [2,1] 

        #labels which give a tensor product interp. for the states within each density matrix block
        self.stateSpaceLabels = [('Qhappy',),('Lsad',)] 
                                            
        #Build a test gate   -- old # X(pi,Qhappy)*LX(pi,0,2)
        self.testGate = pygsti.construction.build_gate( self.stateSpaceDims, self.stateSpaceLabels, "LX(pi,0,2)","std") 
        self.testGateGM_mx = pygsti.std_to_gm(self.testGate, self.stateSpaceDims)
        self.expTestGate_mx = pygsti.expand_from_std_direct_sum_mx(self.testGate, self.stateSpaceDims)
        self.expTestGateGM_mx = pygsti.std_to_gm(self.expTestGate_mx)
예제 #2
0
    def setUp(self):
        #Set GateSet objects to "strict" mode for testing
        pygsti.objects.GateSet._strict = True

        # density matrix == 3x3 block diagonal matrix: a 2x2 block followed by a 1x1 block
        self.stateSpaceDims = [2, 1]

        #labels which give a tensor product interp. for the states within each density matrix block
        self.stateSpaceLabels = [('Qhappy', ), ('Lsad', )]

        #Build a test gate   -- old # X(pi,Qhappy)*LX(pi,0,2)
        self.testGate = pygsti.construction.build_gate(self.stateSpaceDims,
                                                       self.stateSpaceLabels,
                                                       "LX(pi,0,2)", "std")
        self.testGateGM_mx = pygsti.std_to_gm(self.testGate,
                                              self.stateSpaceDims)
        self.expTestGate_mx = pygsti.expand_from_std_direct_sum_mx(
            self.testGate, self.stateSpaceDims)
        self.expTestGateGM_mx = pygsti.std_to_gm(self.expTestGate_mx)
예제 #3
0
    def test_transforms(self):
        mxStd = np.array([[1,0,0,0],
                          [0,1,0,0],
                          [0,0,1,0],
                          [0,0,0,1]], 'complex')
        vecStd = np.array([1,0,0,0], 'complex')

        mxGM = pygsti.std_to_gm(mxStd)
        mxStd2 = pygsti.gm_to_std(mxGM)
        self.assertArraysAlmostEqual( mxStd, mxStd2 )

        vecGM = pygsti.std_to_gm(vecStd)
        vecStd2 = pygsti.gm_to_std(vecGM)
        self.assertArraysAlmostEqual( vecStd, vecStd2 )
        
        mxPP = pygsti.std_to_pp(mxStd)
        mxStd2 = pygsti.pp_to_std(mxPP)
        self.assertArraysAlmostEqual( mxStd, mxStd2 )

        vecPP = pygsti.std_to_pp(vecStd)
        vecStd2 = pygsti.pp_to_std(vecPP)
        self.assertArraysAlmostEqual( vecStd, vecStd2 )

        mxPP2 = pygsti.gm_to_pp(mxGM)
        self.assertArraysAlmostEqual( mxPP, mxPP2 )

        vecPP2 = pygsti.gm_to_pp(vecGM)
        self.assertArraysAlmostEqual( vecPP, vecPP2 )
        
        mxGM2 = pygsti.pp_to_gm(mxPP)
        self.assertArraysAlmostEqual( mxGM, mxGM2 )

        vecGM2 = pygsti.pp_to_gm(vecPP)
        self.assertArraysAlmostEqual( vecGM, vecGM2 )

        
        non_herm_mxStd = np.array([[1,0,2,3j],
                                   [0,1,0,2],
                                   [0,0,1,0],
                                   [0,0,0,1]], 'complex')
        non_herm_vecStd = np.array([1,0,2,3j], 'complex') # ~ non-herm 2x2 density mx
        rank3tensor = np.ones((4,4,4),'d')

        with self.assertRaises(ValueError):
            pygsti.std_to_gm(non_herm_mxStd) #will result in gm mx with *imag* part
        with self.assertRaises(ValueError):
            pygsti.std_to_gm(non_herm_vecStd) #will result in gm vec with *imag* part
        with self.assertRaises(ValueError):
            pygsti.std_to_pp(non_herm_mxStd) #will result in pp mx with *imag* part
        with self.assertRaises(ValueError):
            pygsti.std_to_pp(non_herm_vecStd) #will result in pp vec with *imag* part

        with self.assertRaises(ValueError):
            pygsti.std_to_gm(rank3tensor) #only convert rank 1 & 2 objects
        with self.assertRaises(ValueError):
            pygsti.gm_to_std(rank3tensor) #only convert rank 1 & 2 objects
        with self.assertRaises(ValueError):
            pygsti.std_to_pp(rank3tensor) #only convert rank 1 & 2 objects
        with self.assertRaises(ValueError):
            pygsti.pp_to_std(rank3tensor) #only convert rank 1 & 2 objects
        with self.assertRaises(ValueError):
            pygsti.gm_to_pp(rank3tensor) #only convert rank 1 & 2 objects
        with self.assertRaises(ValueError):
            pygsti.pp_to_gm(rank3tensor) #only convert rank 1 & 2 objects

        densityMx = np.array( [[1,0],[0,-1]], 'complex' )
        gmVec = pygsti.stdmx_to_gmvec(densityMx)
        ppVec = pygsti.stdmx_to_ppvec(densityMx)
        stdVec = pygsti.stdmx_to_stdvec(densityMx)
        self.assertArraysAlmostEqual( gmVec, np.array( [[0],[0],[0],[np.sqrt(2)]], 'd') )
        self.assertArraysAlmostEqual( ppVec, np.array( [[0],[0],[0],[np.sqrt(2)]], 'd') )
        self.assertArraysAlmostEqual( stdVec, np.array( [[1],[0],[0],[-1]], 'complex') )

        mxFromGM  = pygsti.gmvec_to_stdmx(gmVec)
        mxFromPP  = pygsti.ppvec_to_stdmx(ppVec)
        mxFromStd = pygsti.stdvec_to_stdmx(stdVec)
        self.assertArraysAlmostEqual( mxFromGM, densityMx)
        self.assertArraysAlmostEqual( mxFromPP, densityMx)
        self.assertArraysAlmostEqual( mxFromStd, densityMx)