Skip to content

Commit

Permalink
Merge pull request #22 from qiboteam/fix_result_state_mismatch
Browse files Browse the repository at this point in the history
Fix result state mismatch
  • Loading branch information
liweintu authored Dec 14, 2023
2 parents 918958a + c593965 commit 8e2db68
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 19 deletions.
2 changes: 1 addition & 1 deletion tests/test_cuquantum_cutensor_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

def qibo_qft(nqubits, swaps):
circ_qibo = QFT(nqubits, swaps)
state_vec = np.array(circ_qibo())
state_vec = circ_qibo().state(numpy=True)
return circ_qibo, state_vec


Expand Down
26 changes: 8 additions & 18 deletions tests/test_qasm_quimb_backend.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import copy
import os
from timeit import default_timer as timer

import config
import numpy as np
import pytest
Expand All @@ -18,18 +16,10 @@ def create_init_state(nqubits):

def qibo_qft(nqubits, init_state, swaps):
circ_qibo = QFT(nqubits, swaps)
state_vec = np.array(circ_qibo(init_state))
state_vec = circ_qibo(init_state).state(numpy=True)
return circ_qibo, state_vec


def time(func):
start = timer()
res = func()
end = timer()
time = end - start
return time, res


@pytest.mark.parametrize("nqubits, tolerance, is_mps",
[(1, 1e-6, True), (2, 1e-6, False), (5, 1e-3, True), (10, 1e-3, False)])
def test_eval(nqubits: int, tolerance: float, is_mps: bool):
Expand All @@ -45,20 +35,20 @@ def test_eval(nqubits: int, tolerance: float, is_mps: bool):
# Test qibo
qibo.set_backend(backend=config.qibo.backend,
platform=config.qibo.platform)
qibo_time, (qibo_circ, result_sv) = time(
lambda: qibo_qft(nqubits, init_state, swaps=True)
)
#qibo_time, (qibo_circ, result_sv) = time(
#lambda: qibo_qft(nqubits, init_state, swaps=True)
#)
qibo_circ, result_sv= qibo_qft(nqubits, init_state, swaps=True)


# Convert to qasm for other backends
qasm_circ = qibo_circ.to_qasm()

# Test quimb
quimb_time, result_tn = time(
lambda: qibotn.quimb.eval(
result_tn = qibotn.quimb.eval(
qasm_circ, init_state_tn, is_mps, backend=config.quimb.backend
)
)


assert 1e-2 * qibo_time < quimb_time < 1e2 * qibo_time
assert np.allclose(result_sv, result_tn,
atol=tolerance), "Resulting dense vectors do not match"

0 comments on commit 8e2db68

Please sign in to comment.