diff --git a/src/qibotn/backends/cutensornet.py b/src/qibotn/backends/cutensornet.py index f7d1270..c8341bd 100644 --- a/src/qibotn/backends/cutensornet.py +++ b/src/qibotn/backends/cutensornet.py @@ -95,12 +95,9 @@ class CuTensorNet(NumpyBackend): # pragma: no cover def cuda_type(self, dtype="complex64"): """Get CUDA Type. - Args: + Parameters: dtype (str, optional): Either single ("complex64") or double (complex128) precision. Defaults to "complex64". - Raises: - TypeError: dtype either complex64 or complex128 - Returns: CUDA Type: tuple of cuquantum.cudaDataType and cuquantum.ComputeType """ @@ -114,13 +111,13 @@ class CuTensorNet(NumpyBackend): # pragma: no cover ): # pragma: no cover """Executes a quantum circuit using selected TN backend. - Args: + Parameters: circuit (:class:`qibo.models.circuit.Circuit`): Circuit to execute. initial_state (:class:`qibo.models.circuit.Circuit`): Circuit to prepare the initial state. If ``None`` the default ``|00...0>`` state is used. Returns: - QuantumState if return_array=False. Numpy array if return_array=True. + QuantumState or numpy.ndarray: If `return_array` is False, returns a QuantumState object representing the quantum state. If `return_array` is True, returns a numpy array representing the quantum state. """ import qibotn.eval as eval diff --git a/src/qibotn/circuit_convertor.py b/src/qibotn/circuit_convertor.py index 46e7c81..f05eb49 100644 --- a/src/qibotn/circuit_convertor.py +++ b/src/qibotn/circuit_convertor.py @@ -26,9 +26,12 @@ class QiboCircuitToEinsum: self.circuit = circuit def state_vector_operands(self): - """Create the operands for expectation computation in the interleave + """Create the operands for dense vector computation in the interleave format. - + + Parameters: + None + Returns: Operands for the contraction in the interleave format. """ @@ -85,8 +88,14 @@ class QiboCircuitToEinsum: return mode_labels, operands def op_shape_from_qubits(self, nqubits): - """Modify tensor to cuQuantum shape (qubit_states,input_output) * - qubits_involved.""" + """Modify tensor to cuQuantum shape + + Parameters: + nqubits (int): The number of qubits in quantum circuit. + + Returns: + (qubit_states,input_output) * nqubits + """ return (2, 2) * nqubits def init_intermediate_circuit(self, circuit): @@ -175,7 +184,7 @@ class QiboCircuitToEinsum: def get_pauli_gates(self, pauli_map, dtype="complex128", backend=cp): """Populate the gates for all pauli operators. - Args: + Parameters: pauli_map: A dictionary mapping qubits to pauli operators. dtype: Data type for the tensor operands. backend: The package the tensor operands belong to. @@ -202,7 +211,7 @@ class QiboCircuitToEinsum: """Create the operands for pauli string expectation computation in the interleave format. - Args: + Parameters: pauli_string: A string representating the list of pauli gates. Returns: diff --git a/src/qibotn/eval.py b/src/qibotn/eval.py index 6375aa6..42d5ec8 100644 --- a/src/qibotn/eval.py +++ b/src/qibotn/eval.py @@ -9,14 +9,31 @@ from qibotn.mps_contraction_helper import MPSContractionHelper def dense_vector_tn(qibo_circ, datatype): """Convert qibo circuit to tensornet (TN) format and perform contraction to - dense vector.""" + dense vector. + + Parameters: + qibo_circ: The quantum circuit object. + datatype (str): Either single ("complex64") or double (complex128) precision. + + Returns: + Dense vector of quantum circuit. + """ myconvertor = QiboCircuitToEinsum(qibo_circ, dtype=datatype) return contract(*myconvertor.state_vector_operands()) def expectation_pauli_tn(qibo_circ, datatype, pauli_string_pattern): """Convert qibo circuit to tensornet (TN) format and perform contraction to - expectation of given Pauli string.""" + expectation of given Pauli string. + + Parameters: + qibo_circ: The quantum circuit object. + datatype (str): Either single ("complex64") or double (complex128) precision. + pauli_string_pattern(str): pauli string pattern. + + Returns: + Expectation of quantum circuit due to pauli string. + """ myconvertor = QiboCircuitToEinsum(qibo_circ, dtype=datatype) return contract( *myconvertor.expectation_operands( @@ -35,6 +52,14 @@ def dense_vector_tn_MPI(qibo_circ, datatype, n_samples=8): the least costly contraction path. This is sped up with multi thread. After pathfinding the optimal path is used in the actual contraction to give a dense vector representation of the TN. + + Parameters: + qibo_circ: The quantum circuit object. + datatype (str): Either single ("complex64") or double (complex128) precision. + n_samples(int): Number of samples for pathfinding. + + Returns: + Dense vector of quantum circuit. """ from cuquantum import Network @@ -102,6 +127,14 @@ def dense_vector_tn_nccl(qibo_circ, datatype, n_samples=8): the least costly contraction path. This is sped up with multi thread. After pathfinding the optimal path is used in the actual contraction to give a dense vector representation of the TN. + + Parameters: + qibo_circ: The quantum circuit object. + datatype (str): Either single ("complex64") or double (complex128) precision. + n_samples(int): Number of samples for pathfinding. + + Returns: + Dense vector of quantum circuit. """ from cupy.cuda import nccl from cuquantum import Network @@ -183,6 +216,15 @@ def expectation_pauli_tn_nccl(qibo_circ, datatype, pauli_string_pattern, n_sampl select the least costly contraction path. This is sped up with multi thread. After pathfinding the optimal path is used in the actual contraction to give an expectation value. + + Parameters: + qibo_circ: The quantum circuit object. + datatype (str): Either single ("complex64") or double (complex128) precision. + pauli_string_pattern(str): pauli string pattern. + n_samples(int): Number of samples for pathfinding. + + Returns: + Expectation of quantum circuit due to pauli string. """ from cupy.cuda import nccl from cuquantum import Network @@ -266,6 +308,15 @@ def expectation_pauli_tn_MPI(qibo_circ, datatype, pauli_string_pattern, n_sample select the least costly contraction path. This is sped up with multi thread. After pathfinding the optimal path is used in the actual contraction to give an expectation value. + + Parameters: + qibo_circ: The quantum circuit object. + datatype (str): Either single ("complex64") or double (complex128) precision. + pauli_string_pattern(str): pauli string pattern. + n_samples(int): Number of samples for pathfinding. + + Returns: + Expectation of quantum circuit due to pauli string. """ from cuquantum import Network from mpi4py import MPI # this line initializes MPI @@ -326,7 +377,16 @@ def expectation_pauli_tn_MPI(qibo_circ, datatype, pauli_string_pattern, n_sample def dense_vector_mps(qibo_circ, gate_algo, datatype): """Convert qibo circuit to matrix product state (MPS) format and perform - contraction to dense vector.""" + contraction to dense vector. + + Parameters: + qibo_circ: The quantum circuit object. + gate_algo(dict): Dictionary for SVD and QR settings. + datatype (str): Either single ("complex64") or double (complex128) precision. + + Returns: + Dense vector of quantum circuit. + """ myconvertor = QiboCircuitToMPS(qibo_circ, gate_algo, dtype=datatype) mps_helper = MPSContractionHelper(myconvertor.num_qubits) @@ -339,6 +399,13 @@ def pauli_string_gen(nqubits, pauli_string_pattern): """Used internally to generate the string based on given pattern and number of qubit. + Parameters: + nqubits(int): Number of qubits of Quantum Circuit + pauli_string_pattern(str): Strings representing sequence of pauli gates. + + Returns: + String representation of the actual pauli string from the pattern. + Example: pattern: "XZ", number of qubit: 7, output = XZXZXZX """ if nqubits <= 0: diff --git a/src/qibotn/mps_contraction_helper.py b/src/qibotn/mps_contraction_helper.py index a3dc32d..fbf0285 100644 --- a/src/qibotn/mps_contraction_helper.py +++ b/src/qibotn/mps_contraction_helper.py @@ -10,7 +10,7 @@ class MPSContractionHelper: Reference: https://github.com/NVIDIA/cuQuantum/blob/main/python/samples/cutensornet/tn_algorithms/mps_algorithms.ipynb - The follwing compute quantities are supported: + The following compute quantities are supported: - the norm of the MPS. - the equivalent state vector from the MPS.