Beispiel #1
0
def test_decomposite3(basis):
    p = random.random()
    q = random.random()
    r = random.random()
    s = random.random()

    c = Circuit().ry(p)[1].rz(q)[1].ry(r)[0].rz(s)[0].zz[0, 1].h[2].ry(
        r)[0].rz(s)[0].ry(p)[1].rz(q)[1]
    v1 = c.run()
    v2 = c.run_with_2q_decomposition(basis=basis).run()
    assert np.allclose(ignore_global_phase(v1), ignore_global_phase(v2))
Beispiel #2
0
def test_rz1(backend):
    assert np.allclose(
        ignore_global_phase(Circuit().h[0].rz(
            math.pi)[0].run(backend=backend)),
        Circuit().x[0].h[0].run(backend=backend))
    assert np.allclose(Circuit().h[0].r(math.pi)[0].run(backend=backend),
                       Circuit().x[0].h[0].run(backend=backend))
Beispiel #3
0
def test_complicated_circuit(backend):
    c = Circuit()
    c.x[0].h[0].rx(-1.5707963267948966)[2].cx[0, 2].rz(0.095491506289)[2]
    c.cx[0, 2].h[0].rx(1.5707963267948966)[2].h[0].ry(-1.5707963267948966)[2]
    c.cx[0, 2].cx[2, 3].rz(0.095491506289)[3].cx[2, 3].cx[0, 2].h[0]
    c.rx(1.5707963267948966)[2].h[0].ry(-1.5707963267948966)[2].cx[0, 1]
    c.cx[1,
         2].rz(0.095491506289)[2].cx[1,
                                     2].cx[0,
                                           1].h[0].u(math.pi / 2, 1.58,
                                                     -0.62)[2]
    c.h[0].rx(-1.5707963267948966)[2].cx[0, 1].cx[1, 2].cx[2, 3]
    c.rz(0.095491506289)[3].cx[2, 3].cx[1, 2].cx[0, 1].h[0]
    c.rx(1.5707963267948966)[2].u(0.42, -1.5707963267948966, 1.64)[2].h[2]
    c.cx[0, 2].rz(-0.095491506289)[2].cx[0, 2].rx(1.5707963267948966)[0].h[2]
    c.rx(-1.5707963267948966)[0].h[2].cx[0, 2].cx[2, 3].rz(-0.095491506289)[3]
    c.cx[2, 3].cx[0, 2].rx(1.5707963267948966)[0].h[2]
    c.rx(-1.5707963267948966)[0].h[2].cx[0, 1].cx[1, 2].rz(-0.095491506289)[2]
    c.cx[1, 2].cx[0, 1].rx(1.5707963267948966)[0].h[2]
    c.rx(-1.5707963267948966)[0].t[2].s[2].cx[0, 1].cx[1, 2].sdg[1].cx[2, 3]
    c.rz(-0.095491506289)[3].cx[2, 3].cx[1, 2].cx[0, 1]
    c.rx(1.5707963267948966)[0].h[2].h[0].rx(-1.5707963267948966)[1].h[2]
    c.cx[0, 1].cx[1, 2].rz(1.1856905316303521e-08)[2].cx[1, 2].cx[0, 1].h[0]
    c.rx(1.5707963267948966)[1].h[2].rx(-1.5707963267948966)[0]
    c.rx(-1.5707963267948966)[1].rx(-1.5707963267948966)[2].cx[0, 1].cx[1, 2]
    c.rz(1.1856905316303521e-08)[2].cx[1, 2].cx[0, 1].rx(1.5707963267948966)[0]
    c.rx(1.5707963267948966)[1].rx(1.5707963267948966)[2]
    c.rx(-1.5707963267948966)[1].cx[1, 3].rz(1.2142490216037756e-08)[3]
    c.cx[1, 3].rx(1.5707963267948966)[1].rx(-1.5707963267948966)[1].cx[0, 1]
    c.cx[1, 2].rz(-1.2142490216037756e-08)[2].cx[1, 2].cx[0, 1]
    c.rx(1.5707963267948966)[1]
    c.cx[0, 3].u(0.23, 1.24, -0.65)[3].cx[3, 1].cx[3, 0]
    vec = c.run(backend=backend)
    assert np.allclose(
        ignore_global_phase(vec),
        np.array([
            5.88423813e-01 + 0.00000000e+00j, -3.82057626e-02 -
            5.70122617e-02j, -2.52821022e-17 - 5.09095967e-17j,
            -1.21188626e-11 + 5.63063568e-10j, -2.19604047e-01 -
            2.85449458e-01j, -2.59211189e-03 + 4.58219688e-02j,
            3.08617333e-09 - 3.56619861e-09j, 4.48946755e-18 - 3.62425819e-19j,
            4.64439684e-09 - 1.48402425e-09j, 4.61321871e-18 - 4.67197922e-18j,
            -3.59382904e-01 + 4.73135946e-01j, 2.20759589e-02 +
            6.42836440e-02j, -1.55912415e-17 - 3.57403200e-17j,
            5.05381446e-10 + 2.03362289e-10j, 3.82475330e-01 - 1.07620677e-01j,
            2.29456407e-02 - 3.47003613e-02j
        ]))
Beispiel #4
0
def test_pauli3(backend):
    assert np.allclose(
        Circuit().z[0].x[0].run(backend=backend),
        ignore_global_phase(Circuit().y[0].run(backend=backend)))
Beispiel #5
0
def test_tdg_gate(backend):
    assert np.allclose(
        ignore_global_phase(Circuit().s[1].tdg[1].tdg[1].run(backend=backend)),
        Circuit().i[1].run(backend=backend))
Beispiel #6
0
def test_sgate(backend):
    assert np.allclose(
        Circuit().s[0].run(backend=backend),
        ignore_global_phase(Circuit().rz(math.pi / 2)[0].run(backend=backend)))
def is_vec_same(a, b, ignore_global='', eps=EPS):
    if 'a' in ignore_global:
        ignore_global_phase(a)
    if 'b' in ignore_global:
        ignore_global_phase(b)
    return vec_distsq(a, b) < eps