Update docstrings and further refinement

This commit is contained in:
tankya2
2024-03-04 16:08:59 +08:00
parent 07f433f24e
commit e6a3060c81
3 changed files with 37 additions and 7 deletions

View File

@@ -7,6 +7,17 @@ from qibotn.mps_utils import apply_gate, initial
class QiboCircuitToMPS:
"""A helper class to convert Qibo circuit to MPS.
Parameters:
circ_qibo: The quantum circuit object.
gate_algo(dict): Dictionary for SVD and QR settings.
datatype (str): Either single ("complex64") or double (complex128) precision.
rand_seed(int): Seed for random number generator.
Return:
None.
"""
def __init__(
self,
circ_qibo,

View File

@@ -17,8 +17,11 @@ class MPSContractionHelper:
- the expectation value for a given operator.
- the equivalent state vector after multiplying an MPO to an MPS.
Args:
Parameters:
num_qubits: The number of qubits for the MPS.
Return:
None.
"""
def __init__(self, num_qubits):
@@ -33,7 +36,7 @@ class MPSContractionHelper:
"""Contract the corresponding tensor network to form the norm of the
MPS.
Args:
Parameters:
mps_tensors: A list of rank-3 ndarray-like tensor objects.
The indices of the ith tensor are expected to be bonding index to the i-1 tensor,
the physical mode, and then the bonding index to the i+1th tensor.
@@ -54,7 +57,7 @@ class MPSContractionHelper:
"""Contract the corresponding tensor network to form the state vector
representation of the MPS.
Args:
Parameters:
mps_tensors: A list of rank-3 ndarray-like tensor objects.
The indices of the ith tensor are expected to be bonding index to the i-1 tensor,
the physical mode, and then the bonding index to the i+1th tensor.
@@ -76,7 +79,7 @@ class MPSContractionHelper:
"""Contract the corresponding tensor network to form the expectation of
the MPS.
Args:
Parameters:
mps_tensors: A list of rank-3 ndarray-like tensor objects.
The indices of the ith tensor are expected to be bonding index to the i-1 tensor,
the physical mode, and then the bonding index to the i+1th tensor.

View File

@@ -4,14 +4,30 @@ from cuquantum.cutensornet.experimental import contract_decompose
def initial(num_qubits, dtype):
r"""Generate the MPS with an initial state of :math:`\ket{00...00}`"""
r"""Generate the MPS with an initial state of :math:`\ket{00...00}`
Parameters:
num_qubits: Number of qubits in the Quantum Circuit.
dtype: Either single ("complex64") or double (complex128) precision.
Returns:
The initial MPS tensors.
"""
state_tensor = cp.asarray([1, 0], dtype=dtype).reshape(1, 2, 1)
mps_tensors = [state_tensor] * num_qubits
return mps_tensors
def mps_site_right_swap(mps_tensors, i, **kwargs):
"""Perform the swap operation between the ith and i+1th MPS tensors."""
"""Perform the swap operation between the ith and i+1th MPS tensors.
Parameters:
mps_tensors: Tensors representing MPS
i (int): index of the tensor to swap
Returns:
The updated MPS tensors.
"""
# contraction followed by QR decomposition
a, _, b = contract_decompose(
"ipj,jqk->iqj,jpk",
@@ -28,7 +44,7 @@ def apply_gate(mps_tensors, gate, qubits, **kwargs):
# Reference: https://github.com/NVIDIA/cuQuantum/blob/main/python/samples/cutensornet/tn_algorithms/mps_algorithms.ipynb
Args:
Parameters:
mps_tensors: A list of rank-3 ndarray-like tensor objects.
The indices of the ith tensor are expected to be the bonding index to the i-1 tensor,
the physical mode, and then the bonding index to the i+1th tensor.