Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multi node multi gpu #19

Merged
merged 13 commits into from
Oct 17, 2023
3 changes: 2 additions & 1 deletion src/qibotn/QiboCircuitConvertor.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,8 @@ def init_intermediate_circuit(self, circuit):
required_shape = self.op_shape_from_qubits(len(gate_qubits))
self.gate_tensors.append(
(
cp.asarray(gate.matrix).reshape(required_shape),
cp.asarray(gate.matrix(), dtype=self.dtype).reshape(
required_shape),
gate_qubits,
)
)
Expand Down
34 changes: 33 additions & 1 deletion src/qibotn/cutn.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,40 @@
# from qibotn import quimb as qiboquimb
from qibotn.QiboCircuitConvertor import QiboCircuitToEinsum
from cuquantum import contract
from cuquantum import cutensornet as cutn
from mpi4py import MPI # this line initializes MPI
Tankya2 marked this conversation as resolved.
Show resolved Hide resolved
import multiprocessing
from cupy.cuda.runtime import getDeviceCount
import cupy as cp


def eval(qibo_circ, datatype):
myconvertor = QiboCircuitToEinsum(qibo_circ, dtype=datatype)
return contract(*myconvertor.state_vector_operands())


def eval_tn_MPI(qibo_circ, datatype):
Tankya2 marked this conversation as resolved.
Show resolved Hide resolved
ncpu_threads = multiprocessing.cpu_count() // 2
n_samples = 8
Tankya2 marked this conversation as resolved.
Show resolved Hide resolved

comm = MPI.COMM_WORLD
rank = comm.Get_rank()
device_id = rank % getDeviceCount()
cp.cuda.Device(device_id).use()

handle = cutn.create()
cutn.distributed_reset_configuration(handle, *cutn.get_mpi_comm_pointer(comm))
network_opts = cutn.NetworkOptions(handle=handle, blocking="auto")

myconvertor = QiboCircuitToEinsum(qibo_circ, dtype=datatype)
operands_interleave = myconvertor.state_vector_operands()

network = cutn.Network(*operands_interleave, options=network_opts)
network.contract_path(
optimize={"samples": n_samples, "threads": ncpu_threads}
) # Calculate optimal path, returns path and info
Tankya2 marked this conversation as resolved.
Show resolved Hide resolved

result = network.contract()

cutn.destroy(handle)

return result, rank