def checkBasis(self, cmb): #Op with Jamio map on gate in std and gm bases Jmx1 = pygsti.jamiolkowski_iso(self.testGate, gateMxBasis='std', choiMxBasis=cmb, dimOrStateSpaceDims=self.stateSpaceDims) Jmx2 = pygsti.jamiolkowski_iso(self.testGateGM_mx, gateMxBasis='gm', choiMxBasis=cmb, dimOrStateSpaceDims=self.stateSpaceDims) #Make sure these yield the same trace == 1 matrix self.assertArraysAlmostEqual(Jmx1,Jmx2) self.assertAlmostEqual(np.trace(Jmx1), 1.0) #Op on expanded gate in std and gm bases JmxExp1 = pygsti.jamiolkowski_iso(self.expTestGate_mx,gateMxBasis='std',choiMxBasis=cmb) JmxExp2 = pygsti.jamiolkowski_iso(self.expTestGateGM_mx,gateMxBasis='gm',choiMxBasis=cmb) #Make sure these are the same as operating on the contracted basis self.assertArraysAlmostEqual(Jmx1,JmxExp1) self.assertArraysAlmostEqual(Jmx1,JmxExp2) #Reverse transform should yield back the gate matrix revTestGate_mx = pygsti.jamiolkowski_iso_inv(Jmx1,choiMxBasis=cmb, dimOrStateSpaceDims=self.stateSpaceDims, gateMxBasis='gm') self.assertArraysAlmostEqual(revTestGate_mx, self.testGateGM_mx) #Reverse transform without specifying stateSpaceDims, then contraction, should yield same result revExpTestGate_mx = pygsti.jamiolkowski_iso_inv(Jmx1,choiMxBasis=cmb, gateMxBasis='std') self.assertArraysAlmostEqual( pygsti.contract_to_std_direct_sum_mx(revExpTestGate_mx,self.stateSpaceDims), self.testGate)
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 )
def checkBasis(self, cmb): #Op with Jamio map on gate in std and gm bases Jmx1 = pygsti.jamiolkowski_iso(self.testGate, gateMxBasis='std', choiMxBasis=cmb, dimOrStateSpaceDims=self.stateSpaceDims) Jmx2 = pygsti.jamiolkowski_iso(self.testGateGM_mx, gateMxBasis='gm', choiMxBasis=cmb, dimOrStateSpaceDims=self.stateSpaceDims) #Make sure these yield the same trace == 1 matrix self.assertArraysAlmostEqual(Jmx1, Jmx2) self.assertAlmostEqual(np.trace(Jmx1), 1.0) #Op on expanded gate in std and gm bases JmxExp1 = pygsti.jamiolkowski_iso(self.expTestGate_mx, gateMxBasis='std', choiMxBasis=cmb) JmxExp2 = pygsti.jamiolkowski_iso(self.expTestGateGM_mx, gateMxBasis='gm', choiMxBasis=cmb) #Make sure these are the same as operating on the contracted basis self.assertArraysAlmostEqual(Jmx1, JmxExp1) self.assertArraysAlmostEqual(Jmx1, JmxExp2) #Reverse transform should yield back the gate matrix revTestGate_mx = pygsti.jamiolkowski_iso_inv( Jmx1, choiMxBasis=cmb, dimOrStateSpaceDims=self.stateSpaceDims, gateMxBasis='gm') self.assertArraysAlmostEqual(revTestGate_mx, self.testGateGM_mx) #Reverse transform without specifying stateSpaceDims, then contraction, should yield same result revExpTestGate_mx = pygsti.jamiolkowski_iso_inv(Jmx1, choiMxBasis=cmb, gateMxBasis='std') self.assertArraysAlmostEqual( pygsti.contract_to_std_direct_sum_mx(revExpTestGate_mx, self.stateSpaceDims), self.testGate)