Add more documentation

This commit is contained in:
tankya2
2024-02-01 11:35:55 +08:00
parent 460f5e7621
commit 6f4ffa777a
2 changed files with 23 additions and 8 deletions

View File

@@ -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. 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 # Sample Codes
## Single Node ## Single Node
The code below shows an example of how to activate the Cuquantum TensorNetwork backend of Qibo. The code below shows an example of how to activate the Cuquantum TensorNetwork backend of Qibo.

View File

@@ -18,7 +18,7 @@ def expectation_pauli_tn(qibo_circ, datatype, pauli_string):
myconvertor = QiboCircuitToEinsum(qibo_circ, dtype=datatype) myconvertor = QiboCircuitToEinsum(qibo_circ, dtype=datatype)
return contract( return contract(
*myconvertor.expectation_operands( *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] # mem_avail = cp.cuda.Device().mem_info[0]
# print("Mem avail: aft convetor",mem_avail, "rank =",rank) # print("Mem avail: aft convetor",mem_avail, "rank =",rank)
operands = myconvertor.expectation_operands( 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] # 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] # mem_avail = cp.cuda.Device().mem_info[0]
# print("Mem avail: aft convetor",mem_avail, "rank =",rank) # print("Mem avail: aft convetor",mem_avail, "rank =",rank)
operands = myconvertor.expectation_operands( 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] # mem_avail = cp.cuda.Device().mem_info[0]
# print("Mem avail: aft operand interleave",mem_avail, "rank =",rank) # 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): 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) myconvertor = QiboCircuitToMPS(qibo_circ, gate_algo, dtype=datatype)
mps_helper = MPSContractionHelper(myconvertor.num_qubits) 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: if nqubits <= 0:
return "Invalid input. N should be a positive integer." return "Invalid input. N should be a positive integer."
characters = pauli_string
# characters = "XXXZ"
result = "" result = ""
for i in range(nqubits): 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 result += char_to_add
print("pauli string", result) print("pauli string", result)
return result return result