Add the pytest function for MPS in cuquantum.
This commit is contained in:
@@ -2,6 +2,7 @@ from timeit import default_timer as timer
|
||||
|
||||
import config
|
||||
import numpy as np
|
||||
import cupy as cp
|
||||
import pytest
|
||||
import qibo
|
||||
from qibo.models import QFT
|
||||
@@ -46,3 +47,40 @@ def test_eval(nqubits: int, dtype="complex128"):
|
||||
assert 1e-2 * qibo_time < cutn_time < 1e2 * qibo_time
|
||||
assert np.allclose(
|
||||
result_sv, result_tn), "Resulting dense vectors do not match"
|
||||
|
||||
|
||||
@pytest.mark.gpu
|
||||
@pytest.mark.parametrize("nqubits", [2, 5, 10])
|
||||
def test_mps(nqubits: int, dtype="complex128"):
|
||||
"""Evaluate MPS with cuQuantum.
|
||||
|
||||
Args:
|
||||
nqubits (int): Total number of qubits in the system.
|
||||
dtype (str): The data type for precision, 'complex64' for single,
|
||||
'complex128' for double.
|
||||
"""
|
||||
import qibotn.cutn
|
||||
|
||||
# Test qibo
|
||||
qibo.set_backend(backend=config.qibo.backend,
|
||||
platform=config.qibo.platform)
|
||||
|
||||
qibo_time, (circ_qibo, result_sv) = time(
|
||||
lambda: qibo_qft(nqubits, swaps=True))
|
||||
|
||||
result_sv_cp = cp.asarray(result_sv)
|
||||
|
||||
# Test of MPS
|
||||
gate_algo = {'qr_method': False,
|
||||
'svd_method': {
|
||||
'partition': 'UV',
|
||||
'abs_cutoff': 1e-12,
|
||||
}}
|
||||
|
||||
cutn_time, result_tn = time(
|
||||
lambda: qibotn.cutn.eval_mps(circ_qibo, gate_algo, dtype).flatten())
|
||||
|
||||
print(
|
||||
f"State vector difference: {abs(result_tn - result_sv_cp).max():0.3e}")
|
||||
|
||||
assert cp.allclose(result_tn, result_sv_cp)
|
||||
|
||||
Reference in New Issue
Block a user