コード例 #1
0
    def test_expand_contract(self):
        # matrix that operates on 2x2 density matrices, but only on the 0-th and 3-rd
        # elements which correspond to the diagonals of the 2x2 density matrix.
        mxInStdBasis = np.array([[1,0,0,2],
                                 [0,0,0,0],
                                 [0,0,0,0],
                                 [3,0,0,4]],'d')

        # Reduce to a matrix operating on a density matrix space with 2 1x1 blocks (hence [1,1])
        mxInReducedBasis = pygsti.contract_to_std_direct_sum_mx(mxInStdBasis,[1,1])
        notReallyContracted = pygsti.contract_to_std_direct_sum_mx(mxInStdBasis,4)
        correctAnswer = np.array([[ 1.0,  2.0],
                                  [ 3.0,  4.0]])
        self.assertArraysAlmostEqual( mxInReducedBasis, correctAnswer )
        self.assertArraysAlmostEqual( notReallyContracted, mxInStdBasis )
        
        expandedMx = pygsti.expand_from_std_direct_sum_mx(mxInReducedBasis,[1,1])
        expandedMxAgain = pygsti.expand_from_std_direct_sum_mx(expandedMx,4)
        self.assertArraysAlmostEqual( expandedMx, mxInStdBasis )
        self.assertArraysAlmostEqual( expandedMxAgain, mxInStdBasis )
コード例 #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 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)