From 6f4ffa777a3050582680c4a2d849c5f56e96fa7d Mon Sep 17 00:00:00 2001 From: tankya2 Date: Thu, 1 Feb 2024 11:35:55 +0800 Subject: [PATCH] Add more documentation --- README.md | 13 +++++++++++++ src/qibotn/eval.py | 18 ++++++++++-------- 2 files changed, 23 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 09281c8..68f2830 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,19 @@ Qibotn is the tensor-network translation module for Qibo to support large-scale To get started, `python setup.py install` to install the tools and dependencies. +# Computation Supported + +- Tensornet (TN) + - TN contraction to dense vector + - TN contraction to dense vector with Message Passing Interface (MPI) + - TN contraction to dense vector with NCCL + - TN contraction to expectation of given Pauli string + - TN contraction to expectation of given Pauli string with Message Passing Interface (MPI) + - TN contraction to expectation of given Pauli string with NCCL + +- Matrix Product State (MPS) + - MPS contraction to dense vector + # Sample Codes ## Single Node The code below shows an example of how to activate the Cuquantum TensorNetwork backend of Qibo. diff --git a/src/qibotn/eval.py b/src/qibotn/eval.py index afa6cbd..a9aeaac 100644 --- a/src/qibotn/eval.py +++ b/src/qibotn/eval.py @@ -18,7 +18,7 @@ def expectation_pauli_tn(qibo_circ, datatype, pauli_string): myconvertor = QiboCircuitToEinsum(qibo_circ, dtype=datatype) return contract( *myconvertor.expectation_operands( - PauliStringGen(qibo_circ.nqubits, pauli_string) + pauli_string_gen(qibo_circ.nqubits, pauli_string) ) ) @@ -234,7 +234,7 @@ def expectation_pauli_tn_nccl(qibo_circ, datatype, pauli_string, n_samples=8): # mem_avail = cp.cuda.Device().mem_info[0] # print("Mem avail: aft convetor",mem_avail, "rank =",rank) operands = myconvertor.expectation_operands( - PauliStringGen(qibo_circ.nqubits, pauli_string) + pauli_string_gen(qibo_circ.nqubits, pauli_string) ) # mem_avail = cp.cuda.Device().mem_info[0] @@ -315,7 +315,7 @@ def expectation_pauli_tn_MPI(qibo_circ, datatype, pauli_string, n_samples=8): # mem_avail = cp.cuda.Device().mem_info[0] # print("Mem avail: aft convetor",mem_avail, "rank =",rank) operands = myconvertor.expectation_operands( - PauliStringGen(qibo_circ.nqubits, pauli_string) + pauli_string_gen(qibo_circ.nqubits, pauli_string) ) # mem_avail = cp.cuda.Device().mem_info[0] # print("Mem avail: aft operand interleave",mem_avail, "rank =",rank) @@ -376,6 +376,8 @@ def expectation_pauli_tn_MPI(qibo_circ, datatype, pauli_string, n_samples=8): def dense_vector_mps(qibo_circ, gate_algo, datatype): + """Convert qibo circuit to matrix product state (MPS) format and perform contraction to dense vector. + """ myconvertor = QiboCircuitToMPS(qibo_circ, gate_algo, dtype=datatype) mps_helper = MPSContractionHelper(myconvertor.num_qubits) @@ -384,17 +386,17 @@ def dense_vector_mps(qibo_circ, gate_algo, datatype): ) -def PauliStringGen(nqubits, pauli_string): +def pauli_string_gen(nqubits, pauli_string_pattern): + """ Used internally to generate the string based on given pattern and number of qubit. + Example: pattern: "XZ", number of qubit: 7, output = XZXZXZX + """ if nqubits <= 0: return "Invalid input. N should be a positive integer." - characters = pauli_string - # characters = "XXXZ" - result = "" for i in range(nqubits): - char_to_add = characters[i % len(characters)] + char_to_add = pauli_string_pattern[i % len(pauli_string_pattern)] result += char_to_add print("pauli string", result) return result