Add docstring
This commit is contained in:
@@ -18,7 +18,9 @@ CUDA_TYPES = {
|
|||||||
|
|
||||||
class CuTensorNet(NumpyBackend): # pragma: no cover
|
class CuTensorNet(NumpyBackend): # pragma: no cover
|
||||||
# CI does not test for GPU
|
# CI does not test for GPU
|
||||||
|
"""Creates CuQuantum backend for QiboTN.
|
||||||
|
|
||||||
|
"""
|
||||||
def __init__(self, runcard):
|
def __init__(self, runcard):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
from cuquantum import cutensornet as cutn # pylint: disable=import-error
|
from cuquantum import cutensornet as cutn # pylint: disable=import-error
|
||||||
@@ -92,6 +94,17 @@ class CuTensorNet(NumpyBackend): # pragma: no cover
|
|||||||
super().set_precision(precision)
|
super().set_precision(precision)
|
||||||
|
|
||||||
def cuda_type(self, dtype="complex64"):
|
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:
|
if dtype in CUDA_TYPES:
|
||||||
return CUDA_TYPES[dtype]
|
return CUDA_TYPES[dtype]
|
||||||
else:
|
else:
|
||||||
@@ -100,7 +113,7 @@ class CuTensorNet(NumpyBackend): # pragma: no cover
|
|||||||
def execute_circuit(
|
def execute_circuit(
|
||||||
self, circuit, initial_state=None, nshots=None, return_array=False
|
self, circuit, initial_state=None, nshots=None, return_array=False
|
||||||
): # pragma: no cover
|
): # pragma: no cover
|
||||||
"""Executes a quantum circuit.
|
"""Executes a quantum circuit using selected TN backend.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
circuit (:class:`qibo.models.circuit.Circuit`): Circuit to execute.
|
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.
|
If ``None`` the default ``|00...0>`` state is used.
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
xxx.
|
QuantumState if return_array=False. Numpy array if return_array=True.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import qibotn.eval as eval
|
import qibotn.eval as eval
|
||||||
|
|||||||
@@ -26,6 +26,11 @@ class QiboCircuitToEinsum:
|
|||||||
self.circuit = circuit
|
self.circuit = circuit
|
||||||
|
|
||||||
def state_vector_operands(self):
|
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_bitstring = "0" * len(self.active_qubits)
|
||||||
|
|
||||||
input_operands = self._get_bitstring_tensors(input_bitstring)
|
input_operands = self._get_bitstring_tensors(input_bitstring)
|
||||||
@@ -84,6 +89,17 @@ class QiboCircuitToEinsum:
|
|||||||
return (2, 2) * nqubits
|
return (2, 2) * nqubits
|
||||||
|
|
||||||
def init_intermediate_circuit(self, circuit):
|
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 = []
|
self.gate_tensors = []
|
||||||
gates_qubits = []
|
gates_qubits = []
|
||||||
|
|
||||||
@@ -105,6 +121,18 @@ class QiboCircuitToEinsum:
|
|||||||
self.active_qubits = np.unique(gates_qubits)
|
self.active_qubits = np.unique(gates_qubits)
|
||||||
|
|
||||||
def init_basis_map(self, backend, dtype):
|
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
|
asarray = backend.asarray
|
||||||
state_0 = asarray([1, 0], dtype=dtype)
|
state_0 = asarray([1, 0], dtype=dtype)
|
||||||
state_1 = asarray([0, 1], dtype=dtype)
|
state_1 = asarray([0, 1], dtype=dtype)
|
||||||
@@ -112,6 +140,17 @@ class QiboCircuitToEinsum:
|
|||||||
self.basis_map = {"0": state_0, "1": state_1}
|
self.basis_map = {"0": state_0, "1": state_1}
|
||||||
|
|
||||||
def init_inverse_circuit(self, circuit):
|
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 = []
|
self.gate_tensors_inverse = []
|
||||||
gates_qubits_inverse = []
|
gates_qubits_inverse = []
|
||||||
|
|
||||||
@@ -159,6 +198,14 @@ class QiboCircuitToEinsum:
|
|||||||
return gates
|
return gates
|
||||||
|
|
||||||
def expectation_operands(self, pauli_string):
|
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_bitstring = "0" * self.circuit.nqubits
|
||||||
|
|
||||||
input_operands = self._get_bitstring_tensors(input_bitstring)
|
input_operands = self._get_bitstring_tensors(input_bitstring)
|
||||||
|
|||||||
Reference in New Issue
Block a user