From 13549ac90df7678080cfd7826f332f9a7970bb8f Mon Sep 17 00:00:00 2001 From: Liwei Yang Date: Tue, 12 Dec 2023 16:04:56 +0800 Subject: [PATCH 1/3] Use a numpy array for the result state representation --- tests/test_cuquantum_cutensor_backend.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_cuquantum_cutensor_backend.py b/tests/test_cuquantum_cutensor_backend.py index 1df3d0f9..3a87206a 100644 --- a/tests/test_cuquantum_cutensor_backend.py +++ b/tests/test_cuquantum_cutensor_backend.py @@ -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 From b77922784673e0cb6a5f65a827a8569f75f8e054 Mon Sep 17 00:00:00 2001 From: Vinitha Balachandran Date: Wed, 13 Dec 2023 16:16:22 +0800 Subject: [PATCH 2/3] Fixed result state mismatch for quimb --- tests/test_qasm_quimb_backend.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/test_qasm_quimb_backend.py b/tests/test_qasm_quimb_backend.py index f48d48ab..4eb62bac 100644 --- a/tests/test_qasm_quimb_backend.py +++ b/tests/test_qasm_quimb_backend.py @@ -18,7 +18,7 @@ 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 @@ -59,6 +59,5 @@ def test_eval(nqubits: int, tolerance: float, is_mps: bool): ) ) - 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" From c593965a59d0020eaec187b737b715b97d887eee Mon Sep 17 00:00:00 2001 From: Vinitha Balachandran Date: Thu, 14 Dec 2023 04:04:37 +0800 Subject: [PATCH 3/3] Removed timing infrastructure from tests --- tests/test_qasm_quimb_backend.py | 25 ++++++++----------------- 1 file changed, 8 insertions(+), 17 deletions(-) diff --git a/tests/test_qasm_quimb_backend.py b/tests/test_qasm_quimb_backend.py index 4eb62bac..54171159 100644 --- a/tests/test_qasm_quimb_backend.py +++ b/tests/test_qasm_quimb_backend.py @@ -1,7 +1,5 @@ import copy import os -from timeit import default_timer as timer - import config import numpy as np import pytest @@ -18,18 +16,10 @@ def create_init_state(nqubits): def qibo_qft(nqubits, init_state, swaps): circ_qibo = QFT(nqubits, swaps) - state_vec = (circ_qibo(init_state)).state(numpy=True) + 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): @@ -45,19 +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 np.allclose(result_sv, result_tn, atol=tolerance), "Resulting dense vectors do not match"