Exemplo n.º 1
0
def test_states_close():
    ket0 = qf.w_state(4)
    ket1 = qf.w_state(3)
    ket2 = qf.w_state(4)

    assert qf.states_close(ket0, ket2)
    assert not qf.states_close(ket0, ket1)
    assert qf.states_close(ket2, ket2)
Exemplo n.º 2
0
def test_states_close() -> None:
    ket0 = qf.w_state(4)
    ket1 = qf.w_state(3)
    ket2 = qf.w_state(4)
    ket3 = qf.ghz_state(3)

    assert qf.states_close(ket0, ket2)
    assert not qf.states_close(ket1, ket3)
    assert qf.states_close(ket2, ket2)
Exemplo n.º 3
0
def test_probability() -> None:
    state = qf.w_state(3)
    qf.print_state(state)
    prob = state.probabilities()

    qf.print_probabilities(state)
    assert np.isclose(prob.sum(), 1)
Exemplo n.º 4
0
def test_probability():
    state = qf.w_state(3)
    qf.print_state(state)
    prob = state.probabilities()

    qf.print_probabilities(state)
    assert qf.asarray(prob).sum() == ALMOST_ONE
Exemplo n.º 5
0
def test_expectation_again() -> None:
    ket = qf.zero_state(4)
    M = np.zeros(shape=([2] * 4))
    M[0, 0, 0, 0] = 42
    M[1, 0, 0, 0] = 1
    M[0, 1, 0, 0] = 2
    M[0, 0, 1, 0] = 3
    M[0, 0, 0, 1] = 4

    avg = ket.expectation(M)
    assert avg == 42

    ket = qf.w_state(4)
    assert ket.expectation(M) == 2.5
Exemplo n.º 6
0
def test_expectation():
    ket = qf.zero_state(4)
    M = np.zeros(shape=([2] * 4))
    M[0, 0, 0, 0] = 42
    M[1, 0, 0, 0] = 1
    M[0, 1, 0, 0] = 2
    M[0, 0, 1, 0] = 3
    M[0, 0, 0, 1] = 4
    M = bk.astensor(M)

    avg = ket.expectation(M)
    assert qf.asarray(avg) == 42

    ket = qf.w_state(4)
    assert qf.asarray(ket.expectation(M)) == 2.5
Exemplo n.º 7
0
def test_print_state() -> None:
    f = io.StringIO()
    state = qf.w_state(5)
    qf.print_state(state, file=f)
Exemplo n.º 8
0
def test_w_state() -> None:
    ket = qf.w_state(4)
    assert ket.tensor[0, 0, 0, 0] == 0
    assert ket.tensor[0, 0, 1, 0] * 2.0 == 1
Exemplo n.º 9
0
def test_print_probabilities() -> None:
    f = io.StringIO()
    state = qf.w_state(5)
    qf.print_probabilities(state, file=f)
Exemplo n.º 10
0
def test_print_probabilities():
    f = io.StringIO()
    state = qf.w_state(5)
    qf.print_probabilities(state, file=f)
    print(f.getvalue())
Exemplo n.º 11
0
def test_w_state():
    vec = qf.w_state(4).vec.asarray()
    assert vec[0, 0, 0, 0] == ALMOST_ZERO
    assert vec[0, 0, 1, 0] * 2. == ALMOST_ONE
Exemplo n.º 12
0
def test_prepare_w16():
    import examples.state_prep_w16 as ex

    ket = ex.prepare_w16()
    assert qf.states_close(ket, qf.w_state(16))