From fea2b1150f679a19d6cc852c85da41def0d47366 Mon Sep 17 00:00:00 2001 From: tankya2 Date: Tue, 30 Jan 2024 10:34:10 +0800 Subject: [PATCH] Remove eval_tn_MPI_expectation --- src/qibotn/cutn.py | 65 ---------------------------------------------- 1 file changed, 65 deletions(-) diff --git a/src/qibotn/cutn.py b/src/qibotn/cutn.py index 84eda78..36d6a1c 100644 --- a/src/qibotn/cutn.py +++ b/src/qibotn/cutn.py @@ -368,71 +368,6 @@ def eval_tn_MPI_2_expectation(qibo_circ, datatype, n_samples=8): return result, rank - -def eval_tn_MPI_expectation(qibo_circ, datatype, n_samples=8): - from mpi4py import MPI # this line initializes MPI - import socket - - # Get the hostname - # hostname = socket.gethostname() - - ncpu_threads = multiprocessing.cpu_count() // 2 - - comm = MPI.COMM_WORLD - rank = comm.Get_rank() - size = comm.Get_size() - # mem_avail = cp.cuda.Device().mem_info[0] - # print("Mem avail: Start",mem_avail, "rank =",rank, "hostname =",hostname) - device_id = rank % getDeviceCount() - cp.cuda.Device(device_id).use() - - handle = cutn.create() - network_opts = cutn.NetworkOptions(handle=handle, blocking="auto") - # mem_avail = cp.cuda.Device().mem_info[0] - # print("Mem avail: aft network opts",mem_avail, "rank =",rank) - cutn.distributed_reset_configuration(handle, *cutn.get_mpi_comm_pointer(comm)) - # mem_avail = cp.cuda.Device().mem_info[0] - # print("Mem avail: aft distributed reset config",mem_avail, "rank =",rank) - # Perform circuit conversion - myconvertor = QiboCircuitToEinsum(qibo_circ, dtype=datatype) - operands_interleave = myconvertor.expectation_operands( - PauliStringGen(qibo_circ.nqubits) - ) - # mem_avail = cp.cuda.Device().mem_info[0] - # print("Mem avail: aft convetor",mem_avail, "rank =",rank) - # mem_avail = cp.cuda.Device().mem_info[0] - # print("Mem avail: aft operand interleave",mem_avail, "rank =",rank) - - # Pathfinder: To search for the optimal path. Optimal path are assigned to path and info attribute of the network object. - network = cutn.Network(*operands_interleave, options=network_opts) - # mem_avail = cp.cuda.Device().mem_info[0] - # print("Mem avail: aft cutn.Network(*operands_interleave,",mem_avail, "rank =",rank) - path, opt_info = network.contract_path( - optimize={ - "samples": n_samples, - "threads": ncpu_threads, - "slicing": {"min_slices": max(16, size)}, - } - ) - # mem_avail = cp.cuda.Device().mem_info[0] - # print("Mem avail: aft contract path",mem_avail, "rank =",rank) - # Execution: To execute the contraction using the optimal path found previously - # print("opt_cost",opt_info.opt_cost, "Process =",rank) - - num_slices = opt_info.num_slices # Andy - chunk, extra = num_slices // size, num_slices % size # Andy - slice_begin = rank * chunk + min(rank, extra) # Andy - slice_end = ( - num_slices if rank == size - 1 else (rank + 1) * chunk + min(rank + 1, extra) - ) # Andy - slices = range(slice_begin, slice_end) # Andy - result = network.contract(slices=slices) - # mem_avail = cp.cuda.Device().mem_info[0] - # print("Mem avail: aft contract",mem_avail, "rank =",rank) - cutn.destroy(handle) - - return result, rank - def eval_mps(qibo_circ, gate_algo, datatype): myconvertor = QiboCircuitToMPS(qibo_circ, gate_algo, dtype=datatype) mps_helper = MPSContractionHelper(myconvertor.num_qubits)