Пример #1
0
def test_distributed_circuit_get_initial_state_bad_type(backend, accelerators):
    import itertools
    from qibo.tests.utils import random_state
    target_state = random_state(5)
    c = DistributedCircuit(5, accelerators)
    c.queues.qubits = DistributedQubits(range(c.nglobal), c.nqubits)
    with pytest.raises(TypeError):
        c.get_initial_state("test")
Пример #2
0
def test_distributed_circuit_get_initial_state_default(backend, accelerators):
    c = DistributedCircuit(6, accelerators)
    c.queues.qubits = DistributedQubits(range(c.nglobal), c.nqubits)
    final_state = c.get_initial_state()
    target_state = np.zeros_like(final_state)
    target_state[0] = 1
    np.testing.assert_allclose(final_state, target_state)
Пример #3
0
def test_distributed_circuit_get_initial_state_random(backend, accelerators):
    import itertools
    from qibo.tests.utils import random_state
    target_state = random_state(5)
    c = DistributedCircuit(5, accelerators)
    c.queues.qubits = DistributedQubits(range(c.nglobal), c.nqubits)
    state = c.get_initial_state(target_state)
    np.testing.assert_allclose(state, target_state)

    target_state = np.reshape(target_state, 5 * (2, ))
    for i, s in enumerate(itertools.product([0, 1], repeat=c.nglobal)):
        target_piece = target_state[s].flatten()
        np.testing.assert_allclose(target_piece.ravel(), state.pieces[i])