Add docstring

This commit is contained in:
tankya2
2024-03-04 14:52:47 +08:00
parent fb5b755fe4
commit bcacd9dc57
2 changed files with 62 additions and 2 deletions

View File

@@ -18,7 +18,9 @@ CUDA_TYPES = {
class CuTensorNet(NumpyBackend): # pragma: no cover
# CI does not test for GPU
"""Creates CuQuantum backend for QiboTN.
"""
def __init__(self, runcard):
super().__init__()
from cuquantum import cutensornet as cutn # pylint: disable=import-error
@@ -92,6 +94,17 @@ class CuTensorNet(NumpyBackend): # pragma: no cover
super().set_precision(precision)
def cuda_type(self, dtype="complex64"):
"""Get CUDA Type
Args:
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
"""
if dtype in CUDA_TYPES:
return CUDA_TYPES[dtype]
else:
@@ -100,7 +113,7 @@ class CuTensorNet(NumpyBackend): # pragma: no cover
def execute_circuit(
self, circuit, initial_state=None, nshots=None, return_array=False
): # pragma: no cover
"""Executes a quantum circuit.
"""Executes a quantum circuit using selected TN backend.
Args:
circuit (:class:`qibo.models.circuit.Circuit`): Circuit to execute.
@@ -108,7 +121,7 @@ class CuTensorNet(NumpyBackend): # pragma: no cover
If ``None`` the default ``|00...0>`` state is used.
Returns:
xxx.
QuantumState if return_array=False. Numpy array if return_array=True.
"""
import qibotn.eval as eval

View File

@@ -26,6 +26,11 @@ class QiboCircuitToEinsum:
self.circuit = circuit
def state_vector_operands(self):
"""Create the operands for expectation computation in the interleave format.
Returns:
Operands for the contraction in the interleave format.
"""
input_bitstring = "0" * len(self.active_qubits)
input_operands = self._get_bitstring_tensors(input_bitstring)
@@ -84,6 +89,17 @@ class QiboCircuitToEinsum:
return (2, 2) * nqubits
def init_intermediate_circuit(self, circuit):
"""Initialize the intermediate circuit representation.
This method initializes the intermediate circuit representation by extracting gate matrices and qubit IDs
from the given quantum circuit.
Parameters:
circuit (object): The quantum circuit object.
Returns:
None
"""
self.gate_tensors = []
gates_qubits = []
@@ -105,6 +121,18 @@ class QiboCircuitToEinsum:
self.active_qubits = np.unique(gates_qubits)
def init_basis_map(self, backend, dtype):
"""Initialize the basis map for the quantum circuit.
This method initializes a basis map for the quantum circuit, which maps binary
strings representing qubit states to their corresponding quantum state vectors.
Parameters:
backend (object): The backend object providing the array conversion method.
dtype (object): The data type for the quantum state vectors.
Returns:
None
"""
asarray = backend.asarray
state_0 = asarray([1, 0], dtype=dtype)
state_1 = asarray([0, 1], dtype=dtype)
@@ -112,6 +140,17 @@ class QiboCircuitToEinsum:
self.basis_map = {"0": state_0, "1": state_1}
def init_inverse_circuit(self, circuit):
"""Initialize the inverse circuit representation.
This method initializes the inverse circuit representation by extracting gate matrices and qubit IDs
from the given quantum circuit.
Parameters:
circuit (object): The quantum circuit object.
Returns:
None
"""
self.gate_tensors_inverse = []
gates_qubits_inverse = []
@@ -159,6 +198,14 @@ class QiboCircuitToEinsum:
return gates
def expectation_operands(self, pauli_string):
"""Create the operands for pauli string expectation computation in the interleave format.
Args:
pauli_string: A string representating the list of pauli gates.
Returns:
Operands for the contraction in the interleave format.
"""
input_bitstring = "0" * self.circuit.nqubits
input_operands = self._get_bitstring_tensors(input_bitstring)