Rename function name to be more descriptive [skip CI]
This commit is contained in:
@@ -10,19 +10,19 @@ from qibotn.QiboCircuitConvertor import QiboCircuitToEinsum
|
|||||||
from qibotn.QiboCircuitToMPS import QiboCircuitToMPS
|
from qibotn.QiboCircuitToMPS import QiboCircuitToMPS
|
||||||
|
|
||||||
|
|
||||||
def eval(qibo_circ, datatype):
|
def dense_vector_tn(qibo_circ, datatype):
|
||||||
myconvertor = QiboCircuitToEinsum(qibo_circ, dtype=datatype)
|
myconvertor = QiboCircuitToEinsum(qibo_circ, dtype=datatype)
|
||||||
return contract(*myconvertor.state_vector_operands())
|
return contract(*myconvertor.state_vector_operands())
|
||||||
|
|
||||||
|
|
||||||
def eval_expectation(qibo_circ, datatype):
|
def expectation_tn(qibo_circ, datatype):
|
||||||
myconvertor = QiboCircuitToEinsum(qibo_circ, dtype=datatype)
|
myconvertor = QiboCircuitToEinsum(qibo_circ, dtype=datatype)
|
||||||
return contract(
|
return contract(
|
||||||
*myconvertor.expectation_operands(PauliStringGen(qibo_circ.nqubits))
|
*myconvertor.expectation_operands(PauliStringGen(qibo_circ.nqubits))
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def eval_tn_MPI(qibo_circ, datatype, n_samples=8):
|
def dense_vector_tn_MPI(qibo_circ, datatype, n_samples=8):
|
||||||
"""Convert qibo circuit to tensornet (TN) format and perform contraction using multi node and multi GPU through MPI.
|
"""Convert qibo circuit to tensornet (TN) format and perform contraction using multi node and multi GPU through MPI.
|
||||||
The conversion is performed by QiboCircuitToEinsum(), after which it goes through 2 steps: pathfinder and execution.
|
The conversion is performed by QiboCircuitToEinsum(), after which it goes through 2 steps: pathfinder and execution.
|
||||||
The pathfinder looks at user defined number of samples (n_samples) iteratively to select the least costly contraction path. This is sped up with multi thread.
|
The pathfinder looks at user defined number of samples (n_samples) iteratively to select the least costly contraction path. This is sped up with multi thread.
|
||||||
@@ -118,7 +118,7 @@ def eval_tn_MPI(qibo_circ, datatype, n_samples=8):
|
|||||||
return result, rank
|
return result, rank
|
||||||
|
|
||||||
|
|
||||||
def eval_tn_nccl(qibo_circ, datatype, n_samples=8):
|
def dense_vector_tn_nccl(qibo_circ, datatype, n_samples=8):
|
||||||
from mpi4py import MPI # this line initializes MPI
|
from mpi4py import MPI # this line initializes MPI
|
||||||
import socket
|
import socket
|
||||||
from cuquantum import Network
|
from cuquantum import Network
|
||||||
@@ -204,7 +204,7 @@ def eval_tn_nccl(qibo_circ, datatype, n_samples=8):
|
|||||||
return result, rank
|
return result, rank
|
||||||
|
|
||||||
|
|
||||||
def eval_tn_nccl_expectation(qibo_circ, datatype, n_samples=8):
|
def expectation_tn_nccl(qibo_circ, datatype, n_samples=8):
|
||||||
from mpi4py import MPI # this line initializes MPI
|
from mpi4py import MPI # this line initializes MPI
|
||||||
import socket
|
import socket
|
||||||
from cuquantum import Network
|
from cuquantum import Network
|
||||||
@@ -291,7 +291,7 @@ def eval_tn_nccl_expectation(qibo_circ, datatype, n_samples=8):
|
|||||||
return result, rank
|
return result, rank
|
||||||
|
|
||||||
|
|
||||||
def eval_tn_MPI_expectation(qibo_circ, datatype, n_samples=8):
|
def expectation_tn_MPI(qibo_circ, datatype, n_samples=8):
|
||||||
from mpi4py import MPI # this line initializes MPI
|
from mpi4py import MPI # this line initializes MPI
|
||||||
import socket
|
import socket
|
||||||
from cuquantum import Network
|
from cuquantum import Network
|
||||||
@@ -370,7 +370,7 @@ def eval_tn_MPI_expectation(qibo_circ, datatype, n_samples=8):
|
|||||||
return result, rank
|
return result, rank
|
||||||
|
|
||||||
|
|
||||||
def eval_mps(qibo_circ, gate_algo, datatype):
|
def dense_vector_mps(qibo_circ, gate_algo, datatype):
|
||||||
myconvertor = QiboCircuitToMPS(qibo_circ, gate_algo, dtype=datatype)
|
myconvertor = QiboCircuitToMPS(qibo_circ, gate_algo, dtype=datatype)
|
||||||
mps_helper = MPSContractionHelper(myconvertor.num_qubits)
|
mps_helper = MPSContractionHelper(myconvertor.num_qubits)
|
||||||
|
|
||||||
|
|||||||
@@ -39,7 +39,9 @@ def test_eval(nqubits: int, dtype="complex128"):
|
|||||||
qibo_time, (qibo_circ, result_sv) = time(lambda: qibo_qft(nqubits, swaps=True))
|
qibo_time, (qibo_circ, result_sv) = time(lambda: qibo_qft(nqubits, swaps=True))
|
||||||
|
|
||||||
# Test Cuquantum
|
# Test Cuquantum
|
||||||
cutn_time, result_tn = time(lambda: qibotn.cutn.eval(qibo_circ, dtype).flatten())
|
cutn_time, result_tn = time(
|
||||||
|
lambda: qibotn.eval.dense_vector_tn(qibo_circ, dtype).flatten()
|
||||||
|
)
|
||||||
|
|
||||||
assert 1e-2 * qibo_time < cutn_time < 1e2 * qibo_time
|
assert 1e-2 * qibo_time < cutn_time < 1e2 * qibo_time
|
||||||
assert np.allclose(result_sv, result_tn), "Resulting dense vectors do not match"
|
assert np.allclose(result_sv, result_tn), "Resulting dense vectors do not match"
|
||||||
@@ -74,7 +76,7 @@ def test_mps(nqubits: int, dtype="complex128"):
|
|||||||
}
|
}
|
||||||
|
|
||||||
cutn_time, result_tn = time(
|
cutn_time, result_tn = time(
|
||||||
lambda: qibotn.eval.eval_mps(circ_qibo, gate_algo, dtype).flatten()
|
lambda: qibotn.eval.dense_vector_mps(circ_qibo, gate_algo, dtype).flatten()
|
||||||
)
|
)
|
||||||
|
|
||||||
print(f"State vector difference: {abs(result_tn - result_sv_cp).max():0.3e}")
|
print(f"State vector difference: {abs(result_tn - result_sv_cp).max():0.3e}")
|
||||||
|
|||||||
Reference in New Issue
Block a user