Exemplo n.º 1
0
    def test_additive_schwarmafier(self):

        S1 = msim.SimpleDephasingSchWARMAFier([.01,],[1,-.9])
        S2 = msim.SimpleDephasingSchWARMAFier([.2,],[1,])
        S = msim.AdditiveSchWARMAFier([S1,S2])

        qbit = cirq.GridQubit.rect(1,1)[0]
        circ = cirq.Circuit(cirq.X(qbit)**.5 for _ in range(10))

        noisy_circ, syms = S.schwarmafy(circ)

        self.assertEqual(len(circ.moments),len(syms))
        self.assertEqual(2*len(circ.moments),len(noisy_circ.moments))
        self.assertTrue(all([circ.moments[i]==noisy_circ.moments[2*i] for i in range(len(circ.moments))]))

        #for older cirq
        test1 = all([type(noisy_circ.moments[2*i+1].operations[0].gate)==cirq.ops.common_gates.ZPowGate for i in range(len(circ.moments))])
        
        #for newer cirq
        try:
            test2 = all([type(noisy_circ.moments[2*i+1].operations[0].gate)==cirq.ops.common_gates.Rz for i in range(len(circ.moments))])
        except AttributeError:
            test2 = False

        self.assertTrue( test1 or test2)
        noise = S.gen_noise_instances(circ,5)

        self.assertEqual(noise.shape[0],5)
        self.assertEqual(noise.shape[1], len(circ.moments))
Exemplo n.º 2
0
    def test_noise_mc(self):

        circ = cirq.generate_boixo_2018_supremacy_circuits_v2_grid(2,2,10,0)

        S1 = msim.SimpleDephasingSchWARMAFier([0,],[1,-.9])
        S2 = msim.SimpleDephasingSchWARMAFier([0,],[1,-.9])

        rgen1 = np.random.RandomState(0)
        rgen2 = np.random.RandomState(0)

        out1 = S1.gen_noise_instances(circ,5,rgen1)
        out2 = S2.gen_noise_instances(circ,5,rgen2)

        self.assertEqual(np.linalg.norm(out1-out2),0.0)
Exemplo n.º 3
0
    def test_single_x_dephasing(self):
        qbit = cirq.GridQubit.rect(1,1)[0]
        circ = cirq.Circuit(cirq.X(qbit)**.5 for _ in range(10))

        S = msim.SimpleDephasingSchWARMAFier(.1*np.ones(1),[1,], op=cirq.rx)
        noisy_circ, syms = S.schwarmafy(circ)

        self.assertEqual(2*len(circ.moments),len(noisy_circ.moments))
        self.assertTrue(all([circ.moments[i]==noisy_circ.moments[2*i] for i in range(len(circ.moments))]))

        #for older cirq
        test1 = all([type(noisy_circ.moments[2*i+1].operations[0].gate)==cirq.ops.common_gates.XPowGate for i in range(len(circ.moments))])
        
        #for newer cirq
        try:
            test2 = all([type(noisy_circ.moments[2*i+1].operations[0].gate)==cirq.ops.common_gates.Rx for i in range(len(circ.moments))])
        except AttributeError:
            test2=False

        self.assertTrue( test1 or test2)
        
        noise = S.gen_noise_instances(circ,5)

        self.assertEqual(noise.shape[0],5)
        self.assertEqual(noise.shape[1], len(circ.moments))
Exemplo n.º 4
0
    def test_max_time_corr(self):

        S = msim.SimpleDephasingSchWARMAFier([1,],[1,-.999999999])

        max_time=4096
        corr_time = S.corr_time(max_time=max_time)
        self.assertEqual(corr_time,max_time)
Exemplo n.º 5
0
    def test_SPAM_additive(self):
        q0 = cirq.GridQubit(0,0)
        q1 = cirq.GridQubit(1,0)
        q2 = cirq.GridQubit(2,0)

        circ = [cirq.H(q0),cirq.CX(q0,q1),cirq.CX(q1,q2), cirq.I(q0), cirq.Z(q0)**.5,cirq.Z(q1)**.5,cirq.Z(q2)**.5, cirq.CX(q2,q1), cirq.CX(q1,q0),cirq.I(q2), cirq.Z(q0)**.25,cirq.Z(q1)**.25, cirq.Z(q2)**.25]
        circ = cirq.Circuit(circ)

        S = msim.SimpleDephasingSchWARMAFier(si.firwin(256,.001))

        vals = S.gen_noise_instances(circ, 1000, SPAM=0)

        x = vals[:,0]
        X = np.fft.fft(x)
        acv = np.real(np.fft.ifft(X*X.conj()))
        self.assertGreater(acv[1]/acv[0],.9)


        vals = S.gen_noise_instances(circ, 1000, SPAM=257)

        x = vals[:,0]
        X = np.fft.fft(x)
        acv = np.real(np.fft.ifft(X*X.conj()))
        self.assertLess(acv[1]/acv[0],.1)



        S  = msim.GateQubitDependentSchWARMAFier(si.firwin(256,.001),[1,], cirq.ops.common_gates.CXPowGate, [q0,q1], msim.cirq_gate_multiplicative)
        vals = S.gen_noise_instances(circ, 1000, SPAM=0)

        x = vals[:,0]
        X = np.fft.fft(x)
        acv = np.real(np.fft.ifft(X*X.conj()))
        self.assertGreater(acv[1]/acv[0],.9)


        vals = S.gen_noise_instances(circ, 1000, SPAM=257)

        x = vals[:,0]
        X = np.fft.fft(x)
        acv = np.real(np.fft.ifft(X*X.conj()))
        self.assertLess(acv[1]/acv[0],.1)
Exemplo n.º 6
0
    def test_one_qubit_rb_dep_ff(self):

        cliffords = cirq.experiments.qubit_characterizations._single_qubit_cliffords()
        cliffords = cliffords.c1_in_xy
        clifford_mats = np.array([cirq.experiments.qubit_characterizations._gate_seq_to_mats(gates) for gates in cliffords])

        q0 = cirq.GridQubit(0,0)
        circ =cirq.experiments.qubit_characterizations._random_single_q_clifford(
                    q0,20,cliffords,clifford_mats)

        b = np.random.randn(128)
        b = b/np.sum(b**2)*.025

        S = msim.SimpleDephasingSchWARMAFier(b)

        sim = msim.CirqSchWARMASim(circ,S)
        ps = np.real(sim.dm_sim(1000)[0,0])

        pred = mfil.compute_Z_dephasing_prob(circ,S)

        self.assertTrue(np.abs(ps-pred)<1e-2)
Exemplo n.º 7
0
    def test_unitary_props_sim(self):

        circ = cirq.generate_boixo_2018_supremacy_circuits_v2_grid(2,2,10,0)
        S = msim.SimpleDephasingSchWARMAFier([0,],[1,-.9])

        noisy_circ, syms = S.schwarmafy(circ)

        sim = msim.CirqSchWARMASim(circ,S)

        props = sim.unitary_props_sim(num_MC=10,rgen=np.random.RandomState(124))
        self.assertEqual(len(props),10)
        self.assertEqual(type(props[0]),ch.QuantumChannel)

        dm = sim.dm_sim(num_MC=1,rgen=np.random.RandomState(124))

        state = ch.QuantumState(np.eye(4**4)[0,:,np.newaxis],'dv')

        dm2 = props[0]*state

        self.assertLess(np.linalg.norm(dm-dm2.density_matrix()),1e-6)

        props = sim.unitary_props_sim(num_MC=10,as_channel=False,rgen=np.random.RandomState(124))
        self.assertEqual(len(props),10)
        self.assertEqual(type(props[0]),np.ndarray)