示例#1
0
    def test_jamiolkowski_ops(self):
        mxGM  = np.array([[1, 0, 0, 0],
                          [0, 0, 1, 0],
                          [0,-1, 0, 0],
                          [0, 0, 0, 1]], 'complex')

        mxStd = pygsti.gm_to_std(mxGM)
        mxPP  = pygsti.gm_to_pp(mxGM)

        choiStd = pygsti.jamiolkowski_iso(mxStd, "std","std")
        choiStd2 = pygsti.jamiolkowski_iso(mxGM, "gm","std")
        choiStd3 = pygsti.jamiolkowski_iso(mxPP, "pp","std")

        choiGM = pygsti.jamiolkowski_iso(mxStd, "std","gm")
        choiGM2 = pygsti.jamiolkowski_iso(mxGM, "gm","gm")
        choiGM3 = pygsti.jamiolkowski_iso(mxPP, "pp","gm")

        choiPP = pygsti.jamiolkowski_iso(mxStd, "std","pp")
        choiPP2 = pygsti.jamiolkowski_iso(mxGM, "gm","pp")
        choiPP3 = pygsti.jamiolkowski_iso(mxPP, "pp","pp")

        self.assertArraysAlmostEqual( choiStd, choiStd2)
        self.assertArraysAlmostEqual( choiStd, choiStd3)
        self.assertArraysAlmostEqual( choiGM, choiGM2)
        self.assertArraysAlmostEqual( choiGM, choiGM3)
        self.assertArraysAlmostEqual( choiPP, choiPP2)
        self.assertArraysAlmostEqual( choiPP, choiPP3)

        gateStd = pygsti.jamiolkowski_iso_inv(choiStd, "std","std")
        gateStd2 = pygsti.jamiolkowski_iso_inv(choiGM, "gm","std")
        gateStd3 = pygsti.jamiolkowski_iso_inv(choiPP, "pp","std")

        gateGM = pygsti.jamiolkowski_iso_inv(choiStd, "std","gm")
        gateGM2 = pygsti.jamiolkowski_iso_inv(choiGM, "gm","gm")
        gateGM3 = pygsti.jamiolkowski_iso_inv(choiPP, "pp","gm")

        gatePP = pygsti.jamiolkowski_iso_inv(choiStd, "std","pp")
        gatePP2 = pygsti.jamiolkowski_iso_inv(choiGM, "gm","pp")
        gatePP3 = pygsti.jamiolkowski_iso_inv(choiPP, "pp","pp")

        self.assertArraysAlmostEqual( gateStd, mxStd)
        self.assertArraysAlmostEqual( gateStd2, mxStd)
        self.assertArraysAlmostEqual( gateStd3, mxStd)

        self.assertArraysAlmostEqual( gateGM,  mxGM)
        self.assertArraysAlmostEqual( gateGM2, mxGM)
        self.assertArraysAlmostEqual( gateGM3, mxGM)

        self.assertArraysAlmostEqual( gatePP,  mxPP)
        self.assertArraysAlmostEqual( gatePP2, mxPP)
        self.assertArraysAlmostEqual( gatePP3, mxPP)


        with self.assertRaises(ValueError):
            pygsti.jamiolkowski_iso(mxStd, "foobar","gm") #invalid gate basis
        with self.assertRaises(ValueError):
            pygsti.jamiolkowski_iso(mxStd, "std","foobar") #invalid choi basis
        with self.assertRaises(ValueError):
            pygsti.jamiolkowski_iso_inv(choiStd, "foobar","gm") #invalid choi basis
        with self.assertRaises(ValueError):
            pygsti.jamiolkowski_iso_inv(choiStd, "std","foobar") #invalid gate basis
        

        sumOfNeg  = pygsti.sum_of_negative_choi_evals(std.gs_target)
        sumsOfNeg = pygsti.sums_of_negative_choi_evals(std.gs_target)
        magsOfNeg = pygsti.mags_of_negative_choi_evals(std.gs_target)
        self.assertAlmostEqual(sumOfNeg, 0.0)
        self.assertArraysAlmostEqual(sumsOfNeg, np.zeros(3,'d')) # 3 gates in std.gs_target
        self.assertArraysAlmostEqual(magsOfNeg, np.zeros(12,'d')) # 3 gates * 4 evals each = 12
示例#2
0
    def test_jamiolkowski_ops(self):
        mxGM  = np.array([[1, 0, 0, 0],
                          [0, 0, 1, 0],
                          [0,-1, 0, 0],
                          [0, 0, 0, 1]], 'complex')

        mxStd = pygsti.gm_to_std(mxGM)
        mxPP  = pygsti.gm_to_pp(mxGM)

        choiStd = pygsti.jamiolkowski_iso(mxStd, "std","std")
        choiStd2 = pygsti.jamiolkowski_iso(mxGM, "gm","std")
        choiStd3 = pygsti.jamiolkowski_iso(mxPP, "pp","std")

        choiGM = pygsti.jamiolkowski_iso(mxStd, "std","gm")
        choiGM2 = pygsti.jamiolkowski_iso(mxGM, "gm","gm")
        choiGM3 = pygsti.jamiolkowski_iso(mxPP, "pp","gm")

        choiPP = pygsti.jamiolkowski_iso(mxStd, "std","pp")
        choiPP2 = pygsti.jamiolkowski_iso(mxGM, "gm","pp")
        choiPP3 = pygsti.jamiolkowski_iso(mxPP, "pp","pp")

        self.assertArraysAlmostEqual( choiStd, choiStd2)
        self.assertArraysAlmostEqual( choiStd, choiStd3)
        self.assertArraysAlmostEqual( choiGM, choiGM2)
        self.assertArraysAlmostEqual( choiGM, choiGM3)
        self.assertArraysAlmostEqual( choiPP, choiPP2)
        self.assertArraysAlmostEqual( choiPP, choiPP3)

        gateStd = pygsti.jamiolkowski_iso_inv(choiStd, "std","std")
        gateStd2 = pygsti.jamiolkowski_iso_inv(choiGM, "gm","std")
        gateStd3 = pygsti.jamiolkowski_iso_inv(choiPP, "pp","std")

        gateGM = pygsti.jamiolkowski_iso_inv(choiStd, "std","gm")
        gateGM2 = pygsti.jamiolkowski_iso_inv(choiGM, "gm","gm")
        gateGM3 = pygsti.jamiolkowski_iso_inv(choiPP, "pp","gm")

        gatePP = pygsti.jamiolkowski_iso_inv(choiStd, "std","pp")
        gatePP2 = pygsti.jamiolkowski_iso_inv(choiGM, "gm","pp")
        gatePP3 = pygsti.jamiolkowski_iso_inv(choiPP, "pp","pp")

        self.assertArraysAlmostEqual( gateStd, mxStd)
        self.assertArraysAlmostEqual( gateStd2, mxStd)
        self.assertArraysAlmostEqual( gateStd3, mxStd)

        self.assertArraysAlmostEqual( gateGM,  mxGM)
        self.assertArraysAlmostEqual( gateGM2, mxGM)
        self.assertArraysAlmostEqual( gateGM3, mxGM)

        self.assertArraysAlmostEqual( gatePP,  mxPP)
        self.assertArraysAlmostEqual( gatePP2, mxPP)
        self.assertArraysAlmostEqual( gatePP3, mxPP)


        with self.assertRaises(ValueError):
            pygsti.jamiolkowski_iso(mxStd, "foobar","gm") #invalid gate basis
        with self.assertRaises(ValueError):
            pygsti.jamiolkowski_iso(mxStd, "std","foobar") #invalid choi basis
        with self.assertRaises(ValueError):
            pygsti.jamiolkowski_iso_inv(choiStd, "foobar","gm") #invalid choi basis
        with self.assertRaises(ValueError):
            pygsti.jamiolkowski_iso_inv(choiStd, "std","foobar") #invalid gate basis


        sumOfNeg  = pygsti.sum_of_negative_choi_evals(std.gs_target)
        sumsOfNeg = pygsti.sums_of_negative_choi_evals(std.gs_target)
        magsOfNeg = pygsti.mags_of_negative_choi_evals(std.gs_target)
        self.assertAlmostEqual(sumOfNeg, 0.0)
        self.assertArraysAlmostEqual(sumsOfNeg, np.zeros(3,'d')) # 3 gates in std.gs_target
        self.assertArraysAlmostEqual(magsOfNeg, np.zeros(12,'d')) # 3 gates * 4 evals each = 12
示例#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)