Update docstrings and refine
This commit is contained in:
@@ -95,12 +95,9 @@ class CuTensorNet(NumpyBackend): # pragma: no cover
|
|||||||
def cuda_type(self, dtype="complex64"):
|
def cuda_type(self, dtype="complex64"):
|
||||||
"""Get CUDA Type.
|
"""Get CUDA Type.
|
||||||
|
|
||||||
Args:
|
Parameters:
|
||||||
dtype (str, optional): Either single ("complex64") or double (complex128) precision. Defaults to "complex64".
|
dtype (str, optional): Either single ("complex64") or double (complex128) precision. Defaults to "complex64".
|
||||||
|
|
||||||
Raises:
|
|
||||||
TypeError: dtype either complex64 or complex128
|
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
CUDA Type: tuple of cuquantum.cudaDataType and cuquantum.ComputeType
|
CUDA Type: tuple of cuquantum.cudaDataType and cuquantum.ComputeType
|
||||||
"""
|
"""
|
||||||
@@ -114,13 +111,13 @@ class CuTensorNet(NumpyBackend): # pragma: no cover
|
|||||||
): # pragma: no cover
|
): # pragma: no cover
|
||||||
"""Executes a quantum circuit using selected TN backend.
|
"""Executes a quantum circuit using selected TN backend.
|
||||||
|
|
||||||
Args:
|
Parameters:
|
||||||
circuit (:class:`qibo.models.circuit.Circuit`): Circuit to execute.
|
circuit (:class:`qibo.models.circuit.Circuit`): Circuit to execute.
|
||||||
initial_state (:class:`qibo.models.circuit.Circuit`): Circuit to prepare the initial state.
|
initial_state (:class:`qibo.models.circuit.Circuit`): Circuit to prepare the initial state.
|
||||||
If ``None`` the default ``|00...0>`` state is used.
|
If ``None`` the default ``|00...0>`` state is used.
|
||||||
|
|
||||||
Returns:
|
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
|
import qibotn.eval as eval
|
||||||
|
|||||||
@@ -26,9 +26,12 @@ 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
|
"""Create the operands for dense vector computation in the interleave
|
||||||
format.
|
format.
|
||||||
|
|
||||||
|
Parameters:
|
||||||
|
None
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
Operands for the contraction in the interleave format.
|
Operands for the contraction in the interleave format.
|
||||||
"""
|
"""
|
||||||
@@ -85,8 +88,14 @@ class QiboCircuitToEinsum:
|
|||||||
return mode_labels, operands
|
return mode_labels, operands
|
||||||
|
|
||||||
def op_shape_from_qubits(self, nqubits):
|
def op_shape_from_qubits(self, nqubits):
|
||||||
"""Modify tensor to cuQuantum shape (qubit_states,input_output) *
|
"""Modify tensor to cuQuantum shape
|
||||||
qubits_involved."""
|
|
||||||
|
Parameters:
|
||||||
|
nqubits (int): The number of qubits in quantum circuit.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
(qubit_states,input_output) * nqubits
|
||||||
|
"""
|
||||||
return (2, 2) * nqubits
|
return (2, 2) * nqubits
|
||||||
|
|
||||||
def init_intermediate_circuit(self, circuit):
|
def init_intermediate_circuit(self, circuit):
|
||||||
@@ -175,7 +184,7 @@ class QiboCircuitToEinsum:
|
|||||||
def get_pauli_gates(self, pauli_map, dtype="complex128", backend=cp):
|
def get_pauli_gates(self, pauli_map, dtype="complex128", backend=cp):
|
||||||
"""Populate the gates for all pauli operators.
|
"""Populate the gates for all pauli operators.
|
||||||
|
|
||||||
Args:
|
Parameters:
|
||||||
pauli_map: A dictionary mapping qubits to pauli operators.
|
pauli_map: A dictionary mapping qubits to pauli operators.
|
||||||
dtype: Data type for the tensor operands.
|
dtype: Data type for the tensor operands.
|
||||||
backend: The package the tensor operands belong to.
|
backend: The package the tensor operands belong to.
|
||||||
@@ -202,7 +211,7 @@ class QiboCircuitToEinsum:
|
|||||||
"""Create the operands for pauli string expectation computation in the
|
"""Create the operands for pauli string expectation computation in the
|
||||||
interleave format.
|
interleave format.
|
||||||
|
|
||||||
Args:
|
Parameters:
|
||||||
pauli_string: A string representating the list of pauli gates.
|
pauli_string: A string representating the list of pauli gates.
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
|
|||||||
@@ -9,14 +9,31 @@ from qibotn.mps_contraction_helper import MPSContractionHelper
|
|||||||
|
|
||||||
def dense_vector_tn(qibo_circ, datatype):
|
def dense_vector_tn(qibo_circ, datatype):
|
||||||
"""Convert qibo circuit to tensornet (TN) format and perform contraction to
|
"""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)
|
myconvertor = QiboCircuitToEinsum(qibo_circ, dtype=datatype)
|
||||||
return contract(*myconvertor.state_vector_operands())
|
return contract(*myconvertor.state_vector_operands())
|
||||||
|
|
||||||
|
|
||||||
def expectation_pauli_tn(qibo_circ, datatype, pauli_string_pattern):
|
def expectation_pauli_tn(qibo_circ, datatype, pauli_string_pattern):
|
||||||
"""Convert qibo circuit to tensornet (TN) format and perform contraction to
|
"""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)
|
myconvertor = QiboCircuitToEinsum(qibo_circ, dtype=datatype)
|
||||||
return contract(
|
return contract(
|
||||||
*myconvertor.expectation_operands(
|
*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
|
the least costly contraction path. This is sped up with multi
|
||||||
thread. After pathfinding the optimal path is used in the actual
|
thread. After pathfinding the optimal path is used in the actual
|
||||||
contraction to give a dense vector representation of the TN.
|
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
|
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
|
the least costly contraction path. This is sped up with multi
|
||||||
thread. After pathfinding the optimal path is used in the actual
|
thread. After pathfinding the optimal path is used in the actual
|
||||||
contraction to give a dense vector representation of the TN.
|
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 cupy.cuda import nccl
|
||||||
from cuquantum import Network
|
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
|
select the least costly contraction path. This is sped up with multi
|
||||||
thread. After pathfinding the optimal path is used in the actual
|
thread. After pathfinding the optimal path is used in the actual
|
||||||
contraction to give an expectation value.
|
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 cupy.cuda import nccl
|
||||||
from cuquantum import Network
|
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
|
select the least costly contraction path. This is sped up with multi
|
||||||
thread. After pathfinding the optimal path is used in the actual
|
thread. After pathfinding the optimal path is used in the actual
|
||||||
contraction to give an expectation value.
|
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 cuquantum import Network
|
||||||
from mpi4py import MPI # this line initializes MPI
|
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):
|
def dense_vector_mps(qibo_circ, gate_algo, datatype):
|
||||||
"""Convert qibo circuit to matrix product state (MPS) format and perform
|
"""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)
|
myconvertor = QiboCircuitToMPS(qibo_circ, gate_algo, dtype=datatype)
|
||||||
mps_helper = MPSContractionHelper(myconvertor.num_qubits)
|
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
|
"""Used internally to generate the string based on given pattern and number
|
||||||
of qubit.
|
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
|
Example: pattern: "XZ", number of qubit: 7, output = XZXZXZX
|
||||||
"""
|
"""
|
||||||
if nqubits <= 0:
|
if nqubits <= 0:
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ class MPSContractionHelper:
|
|||||||
|
|
||||||
Reference: https://github.com/NVIDIA/cuQuantum/blob/main/python/samples/cutensornet/tn_algorithms/mps_algorithms.ipynb
|
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 norm of the MPS.
|
||||||
- the equivalent state vector from the MPS.
|
- the equivalent state vector from the MPS.
|
||||||
|
|||||||
Reference in New Issue
Block a user