def test_kraus(): pq = Program(X(0)) pq.define_noisy_gate("X", (0, ), [[[0., 1.], [1., 0.]], [[0., 0.], [0., 0.]]]) pq.inst(X(1)) pq.define_noisy_gate("X", (1, ), [[[0., 1.], [1., 0.]], [[0., 0.], [0., 0.]]]) ret = pq.out() assert ret == """X 0 PRAGMA ADD-KRAUS X 0 "(0.0 1.0 1.0 0.0)" PRAGMA ADD-KRAUS X 0 "(0.0 0.0 0.0 0.0)" X 1 PRAGMA ADD-KRAUS X 1 "(0.0 1.0 1.0 0.0)" PRAGMA ADD-KRAUS X 1 "(0.0 0.0 0.0 0.0)" """ # test error due to bad normalization with pytest.raises(ValueError): pq.define_noisy_gate("X", (0, ), [[[0., 1.], [1., 0.]], [[0., 1.], [1., 0.]]]) # test error due to bad shape of kraus op with pytest.raises(ValueError): pq.define_noisy_gate( "X", (0, ), [[[0., 1., 0.], [1., 0., 0.]], [[0., 1.], [1., 0.]]]) pq1 = Program(X(0)) pq1.define_noisy_gate("X", (0, ), [[[0., 1.], [1., 0.]], [[0., 0.], [0., 0.]]]) pq2 = Program(X(1)) pq2.define_noisy_gate("X", (1, ), [[[0., 1.], [1., 0.]], [[0., 0.], [0., 0.]]]) assert pq1 + pq2 == pq pq_nn = Program(X(0)) pq_nn.no_noise() pq_nn.inst(X(1)) assert pq_nn.out() == """X 0
def get_compiled_prog_1(): return Program([ RX(pi/2, 0), I(0), RZ(-pi/2, 0), RX(-pi/2, 0), I(0), RZ(pi/2, 0), ]) p = Program() p.inst(X(0)) # want increasing number of I-gates p.define_noisy_gate( "II", [0], append_damping_to_gate(np.eye(2), damping_per_I)) p.inst([I(0) for _ in range(num_I)]) # p.inst(H(0)) p.inst(MEASURE(0, [0])) #print("Expected 1 %s" % qvm.run(p, [0])) thetas = np.linspace(-pi, pi, num=20) t1s = np.logspace(-6, -5, num=3) # print(t1s[0]) prog = get_compiled_prog(pi/2) noisy = add_noise_to_program(prog, T1=t1s[0]).inst([ MEASURE(0, 0), ]) result = np.array(qvm.run(noisy, [0], 1))
##### Q's 1st move p.defgate("Q1", U_(a1, b1)) p.inst(("Q1", 0)) ##### Picard's random move # set the parameters for the random move prob = picard_prob # create a dummy gate a = np.random.rand() b = np.sqrt(1 - np.square(a)) Uf_ = U_(a, b) # perform the random move p.defgate("Uf", Uf_) p.inst(("Uf", 0)) p.define_noisy_gate("Uf", [0], [np.sqrt(prob) * X_, np.sqrt(1 - prob) * I_]) ##### Q's 2nd move p.defgate("Q2", U_(a2, b2)) p.inst(("Q2", 0)) ##### Measurement p.inst(MEASURE(0, [0])) result = qvm.run(p, [0], trials=100) result_1s = (len([i for i in result if i == [1]])) result_0s = (len([i for i in result if i == [0]])) text_1s = font.render("Picard's score: " + str(result_1s), True, (0, 0, 0)) screen.blit(text_1s, [size_x/2, size_y/2]) text_0s = font.render("Q's score: " + str(result_0s), True, (0, 0, 0))