From aae152a0d9e9f9088554953da5f088f177d42ed7 Mon Sep 17 00:00:00 2001 From: yangliwei Date: Mon, 4 Mar 2024 00:32:18 +0800 Subject: [PATCH 01/18] Fix the rendering issue --- doc/source/getting-started/quickstart.rst | 34 +++++++++++++---------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/doc/source/getting-started/quickstart.rst b/doc/source/getting-started/quickstart.rst index 7c58a03c..32d59749 100644 --- a/doc/source/getting-started/quickstart.rst +++ b/doc/source/getting-started/quickstart.rst @@ -3,27 +3,32 @@ Quick start Setting the backend """"""""""""""""""" -QiboTN supports two backends cutensornet (using CuQuantum library) and Quimbbackend (using Quimb library) for tensor network based simulations. The backend can be set using the following command line. -For CuQuantum library, +QiboTN supports two backends: cutensornet (using cuQuantum library) and QuimbBackend (using Quimb library) for tensor network based simulations. The backend can be set using the following command line. -.. testcode:: - qibo.set_backend(backend="qibotn", platform="cutensornet", runcard=computation_settings) -.. +To use cuQuantum library, cutensornet can be specified as follows: -and for Quimb library +.. code-block:: bash + + qibo.set_backend( + backend="qibotn", platform="cutensornet", runcard=computation_settings + ) + +Similarly, to use Quimb library, QuimbBackend can be as follows: + +.. code-block:: bash -.. testcode:: qibo.set_backend( backend="qibotn", platform="QuimbBackend", runcard=computation_settings ) -.. Setting the runcard """"""""""""""""""" -Basic structure of runcard is -.. testcode:: +The basic structure of the runcard is as follows: + +.. code-block:: bash + computation_settings = { "MPI_enabled": False, "MPS_enabled": False, @@ -32,14 +37,17 @@ Basic structure of runcard is "pauli_string_pattern": "IXZ", }, } -.. Basic example """"""""""""" -.. testcode:: +The following is a basic example: + +.. code-block:: bash + # Construct the circuit c = Circuit(2) + # Add some gates c.add(gates.H(0)) c.add(gates.H(1)) @@ -48,5 +56,3 @@ Basic example result = c() print(result.state()) - -.. From f8058d5398faaeab27774e18126492450d71bf1f Mon Sep 17 00:00:00 2001 From: Alessandro Candido Date: Sun, 3 Mar 2024 18:42:26 +0100 Subject: [PATCH 02/18] fix: Switch API docs entry point name --- doc/source/index.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/source/index.rst b/doc/source/index.rst index 79ff8d52..9353fc8c 100644 --- a/doc/source/index.rst +++ b/doc/source/index.rst @@ -50,10 +50,10 @@ Contents getting-started/index .. toctree:: - :maxdepth: 2 + :maxdepth: 1 :caption: Main documentation - api-reference/modules + api-reference/qibotn Developer guides .. toctree:: From bd4f71edf8792afe9222f339b2a270c6d10ae1e4 Mon Sep 17 00:00:00 2001 From: Alessandro Candido Date: Sun, 3 Mar 2024 18:44:23 +0100 Subject: [PATCH 03/18] fix: Use default Python code blocks, instead of Bash highlight --- doc/source/getting-started/quickstart.rst | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/doc/source/getting-started/quickstart.rst b/doc/source/getting-started/quickstart.rst index 32d59749..13eae172 100644 --- a/doc/source/getting-started/quickstart.rst +++ b/doc/source/getting-started/quickstart.rst @@ -6,17 +6,13 @@ Setting the backend QiboTN supports two backends: cutensornet (using cuQuantum library) and QuimbBackend (using Quimb library) for tensor network based simulations. The backend can be set using the following command line. -To use cuQuantum library, cutensornet can be specified as follows: - -.. code-block:: bash +To use cuQuantum library, cutensornet can be specified as follows:: qibo.set_backend( backend="qibotn", platform="cutensornet", runcard=computation_settings ) -Similarly, to use Quimb library, QuimbBackend can be as follows: - -.. code-block:: bash +Similarly, to use Quimb library, QuimbBackend can be as follows:: qibo.set_backend( backend="qibotn", platform="QuimbBackend", runcard=computation_settings @@ -25,9 +21,7 @@ Similarly, to use Quimb library, QuimbBackend can be as follows: Setting the runcard """"""""""""""""""" -The basic structure of the runcard is as follows: - -.. code-block:: bash +The basic structure of the runcard is as follows:: computation_settings = { "MPI_enabled": False, @@ -41,9 +35,7 @@ The basic structure of the runcard is as follows: Basic example """"""""""""" -The following is a basic example: - -.. code-block:: bash +The following is a basic example:: # Construct the circuit c = Circuit(2) From 4029f483993c20320608876e50595df8f315ae2e Mon Sep 17 00:00:00 2001 From: scarrazza Date: Mon, 4 Mar 2024 01:51:45 +0100 Subject: [PATCH 04/18] adding missing navbar entries and fixing external links --- doc/source/index.rst | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/doc/source/index.rst b/doc/source/index.rst index 9353fc8c..e30d36dc 100644 --- a/doc/source/index.rst +++ b/doc/source/index.rst @@ -25,8 +25,8 @@ The supported HPC configurations are: Currently, the supported tensor network libraries are: -- [cuQuantum](https://github.com/NVIDIA/cuQuantum), an NVIDIA SDK of optimized libraries and tools for accelerating quantum computing workflows. -- [quimb](https://quimb.readthedocs.io/en/latest/), an easy but fast python library for ‘quantum information many-body’ calculations, focusing primarily on tensor networks. +- `cuQuantum `_, an NVIDIA SDK of optimized libraries and tools for accelerating quantum computing workflows. +- `quimb `_, an easy but fast python library for ‘quantum information many-body’ calculations, focusing primarily on tensor networks. How to Use the Documentation ============================ @@ -64,6 +64,9 @@ Contents Qibolab docs Qibocal docs Qibosoq docs + Qibochem docs + Qibotn docs + Qibo-cloud-backends docs Indices and tables ================== From 0fb0800491004cc497a9b70755e521b8f5bc2ae6 Mon Sep 17 00:00:00 2001 From: vinitha-balachandran Date: Mon, 4 Mar 2024 11:04:00 +0800 Subject: [PATCH 05/18] adding more details to quickstart file --- doc/source/getting-started/quickstart.rst | 39 +++++++++++++++++++---- 1 file changed, 33 insertions(+), 6 deletions(-) diff --git a/doc/source/getting-started/quickstart.rst b/doc/source/getting-started/quickstart.rst index 13eae172..9d28b074 100644 --- a/doc/source/getting-started/quickstart.rst +++ b/doc/source/getting-started/quickstart.rst @@ -1,10 +1,12 @@ Quick start =========== +In this section, we provide an example of two qubit ciruit simulation using qibotn package in Qibo simulator. First, the backend is to be set with appropriate run card settings, followed by the circuit simulation using Qibo documentation. + Setting the backend """"""""""""""""""" -QiboTN supports two backends: cutensornet (using cuQuantum library) and QuimbBackend (using Quimb library) for tensor network based simulations. The backend can be set using the following command line. +QiboTN offers two backends: cutensornet (using cuQuantum library) and qutensornet (using Quimb library) for tensor network based simulations. At present, cutensornet backend works only for GPUs whereas qutensornet for CPUs. The backend can be set using the following command line. To use cuQuantum library, cutensornet can be specified as follows:: @@ -12,10 +14,10 @@ To use cuQuantum library, cutensornet can be specified as follows:: backend="qibotn", platform="cutensornet", runcard=computation_settings ) -Similarly, to use Quimb library, QuimbBackend can be as follows:: +Similarly, to use Quimb library, qutensornet can be set as follows:: qibo.set_backend( - backend="qibotn", platform="QuimbBackend", runcard=computation_settings + backend="qibotn", platform="qutensornet", runcard=computation_settings ) Setting the runcard @@ -32,19 +34,44 @@ The basic structure of the runcard is as follows:: }, } + +**MPI_enabled:** Setting this option *True* results in parallel execution of circuit using MPI (Message Passing Interface). At present, only works for cutensornet platform. + +**MPS_enabled:** This option is set *True* for Matrix Product State (MPS) based calculations where as general tensor network structure is used for *False* value. + +**NCCL_enabled:** This is set *True* for cutensoret interface for further acceleration while using Nvidia Collective Communication Library (NCCL). + +**expectation_enabled:** This option is set *True* while calculating expecation value of the circuit. Observable whose expectation value is to be calculated is passed as a string in the dict format as {"pauli_string_pattern": "observable"}. When the option is set *False*, the dense vector state of the circuit is calculated. + + Basic example """"""""""""" -The following is a basic example:: +The following is a basic example to execute a two qubit circuit and print the final state in dense vector form using quimb backend:: - # Construct the circuit + # Set the quimb backend + qibo.set_backend( + backend="qibotn", platform="qutensornet", runcard=computation_settings + ) + + # Set the runcard + computation_settings = { + "MPI_enabled": False, + "MPS_enabled": False, + "NCCL_enabled": False, + "expectation_enabled": False, + } + + # Construct the circuit with two qubits c = Circuit(2) - # Add some gates + # Apply Hadamard gates on first and second qubit c.add(gates.H(0)) c.add(gates.H(1)) # Execute the circuit and obtain the final state result = c() + # Print the final state print(result.state()) + From fb5b755fe48102b00a155e9fbfa702d91096543e Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 4 Mar 2024 03:04:14 +0000 Subject: [PATCH 06/18] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- doc/source/getting-started/quickstart.rst | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/doc/source/getting-started/quickstart.rst b/doc/source/getting-started/quickstart.rst index 9d28b074..4e9c1a59 100644 --- a/doc/source/getting-started/quickstart.rst +++ b/doc/source/getting-started/quickstart.rst @@ -54,7 +54,7 @@ The following is a basic example to execute a two qubit circuit and print the fi backend="qibotn", platform="qutensornet", runcard=computation_settings ) - # Set the runcard + # Set the runcard computation_settings = { "MPI_enabled": False, "MPS_enabled": False, @@ -74,4 +74,3 @@ The following is a basic example to execute a two qubit circuit and print the fi # Print the final state print(result.state()) - From db315d5a4884a9b75410a4d9e6750382f6cca66a Mon Sep 17 00:00:00 2001 From: vinitha-balachandran Date: Mon, 4 Mar 2024 14:35:15 +0800 Subject: [PATCH 07/18] Adding docstring to quimb.py and eval_qu.py --- src/qibotn/backends/quimb.py | 2 +- src/qibotn/eval_qu.py | 22 +++++++++++++++++++--- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/src/qibotn/backends/quimb.py b/src/qibotn/backends/quimb.py index 0a34eefe..e697a58f 100644 --- a/src/qibotn/backends/quimb.py +++ b/src/qibotn/backends/quimb.py @@ -59,7 +59,7 @@ def execute_circuit( If ``None`` the default ``|00...0>`` state is used. Returns: - xxx. + list: Final state in the dense vector form after simulation of the circuit. """ import qibotn.eval_qu as eval diff --git a/src/qibotn/eval_qu.py b/src/qibotn/eval_qu.py index d6064e95..83e3a4ef 100644 --- a/src/qibotn/eval_qu.py +++ b/src/qibotn/eval_qu.py @@ -3,7 +3,15 @@ def init_state_tn(nqubits, init_state_sv): - """Create a matrix product state directly from a dense vector.""" + """Create a matrix product state directly from a dense vector. + + Args: + nqubits (int): Total number of qubits in the circuit. + init_state_sv (list): Initial state in the dense vector form. + + Returns: + list: Matrix product state representation of the dense vector. + """ dims = tuple(2 * np.ones(nqubits, dtype=int)) @@ -11,9 +19,17 @@ def init_state_tn(nqubits, init_state_sv): def dense_vector_tn_qu(qasm: str, initial_state, mps_opts, backend="numpy"): - """Evaluate QASM with Quimb. + """Evaluate circuit in QASM format with Quimb. + + Args: + qasm (str): QASM program. + initial_state (list): Initial state in the dense vector form. If ``None`` the default ``|00...0>`` state is used. + mps_opts (dict): Parameters to tune the gate_opts for mps settings in ``class quimb.tensor.circuit.CircuitMPS``. + backend (str): Backend to perform the contraction with, e.g. ``numpy``, ``cupy``, ``jax``. Passed to ``opt_einsum``. - backend (quimb): numpy, cupy, jax. Passed to ``opt_einsum``. + Returns: + list: Amplitudes of final state after the simulation of the circuit. + """ if initial_state is not None: From a8c93cc726fcf2f24bdbb6289a20bddb79d7f830 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 4 Mar 2024 06:35:29 +0000 Subject: [PATCH 08/18] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- src/qibotn/eval_qu.py | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/src/qibotn/eval_qu.py b/src/qibotn/eval_qu.py index 83e3a4ef..6cb9f395 100644 --- a/src/qibotn/eval_qu.py +++ b/src/qibotn/eval_qu.py @@ -5,12 +5,12 @@ def init_state_tn(nqubits, init_state_sv): """Create a matrix product state directly from a dense vector. - Args: - nqubits (int): Total number of qubits in the circuit. - init_state_sv (list): Initial state in the dense vector form. + Args: + nqubits (int): Total number of qubits in the circuit. + init_state_sv (list): Initial state in the dense vector form. - Returns: - list: Matrix product state representation of the dense vector. + Returns: + list: Matrix product state representation of the dense vector. """ dims = tuple(2 * np.ones(nqubits, dtype=int)) @@ -21,15 +21,14 @@ def init_state_tn(nqubits, init_state_sv): def dense_vector_tn_qu(qasm: str, initial_state, mps_opts, backend="numpy"): """Evaluate circuit in QASM format with Quimb. - Args: - qasm (str): QASM program. - initial_state (list): Initial state in the dense vector form. If ``None`` the default ``|00...0>`` state is used. - mps_opts (dict): Parameters to tune the gate_opts for mps settings in ``class quimb.tensor.circuit.CircuitMPS``. - backend (str): Backend to perform the contraction with, e.g. ``numpy``, ``cupy``, ``jax``. Passed to ``opt_einsum``. + Args: + qasm (str): QASM program. + initial_state (list): Initial state in the dense vector form. If ``None`` the default ``|00...0>`` state is used. + mps_opts (dict): Parameters to tune the gate_opts for mps settings in ``class quimb.tensor.circuit.CircuitMPS``. + backend (str): Backend to perform the contraction with, e.g. ``numpy``, ``cupy``, ``jax``. Passed to ``opt_einsum``. - Returns: - list: Amplitudes of final state after the simulation of the circuit. - + Returns: + list: Amplitudes of final state after the simulation of the circuit. """ if initial_state is not None: From bcacd9dc572766cdf7e9de2ea8ccd2d0aae7b1fb Mon Sep 17 00:00:00 2001 From: tankya2 Date: Mon, 4 Mar 2024 14:52:47 +0800 Subject: [PATCH 09/18] Add docstring --- src/qibotn/backends/cutensornet.py | 17 +++++++++-- src/qibotn/circuit_convertor.py | 47 ++++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+), 2 deletions(-) diff --git a/src/qibotn/backends/cutensornet.py b/src/qibotn/backends/cutensornet.py index fc010e97..05f45afc 100644 --- a/src/qibotn/backends/cutensornet.py +++ b/src/qibotn/backends/cutensornet.py @@ -18,7 +18,9 @@ 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 @@ def set_precision(self, precision): 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 @@ def cuda_type(self, dtype="complex64"): 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 @@ def execute_circuit( 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 diff --git a/src/qibotn/circuit_convertor.py b/src/qibotn/circuit_convertor.py index 14af79de..a15e533e 100644 --- a/src/qibotn/circuit_convertor.py +++ b/src/qibotn/circuit_convertor.py @@ -26,6 +26,11 @@ def __init__(self, circuit, dtype="complex128"): 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 @@ def op_shape_from_qubits(self, nqubits): 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 @@ def init_intermediate_circuit(self, circuit): 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 @@ def init_basis_map(self, backend, dtype): 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 @@ def get_pauli_gates(self, pauli_map, dtype="complex128", backend=cp): 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) From d3a1f4f7bcbe26469a0ab88d4bd90b957b81f8bc Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 4 Mar 2024 06:53:00 +0000 Subject: [PATCH 10/18] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- src/qibotn/backends/cutensornet.py | 5 ++--- src/qibotn/circuit_convertor.py | 6 ++++-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/qibotn/backends/cutensornet.py b/src/qibotn/backends/cutensornet.py index 05f45afc..f7d12700 100644 --- a/src/qibotn/backends/cutensornet.py +++ b/src/qibotn/backends/cutensornet.py @@ -18,9 +18,8 @@ class CuTensorNet(NumpyBackend): # pragma: no cover # CI does not test for GPU - """Creates CuQuantum backend for QiboTN. + """Creates CuQuantum backend for QiboTN.""" - """ def __init__(self, runcard): super().__init__() from cuquantum import cutensornet as cutn # pylint: disable=import-error @@ -94,7 +93,7 @@ def set_precision(self, precision): super().set_precision(precision) def cuda_type(self, dtype="complex64"): - """Get CUDA Type + """Get CUDA Type. Args: dtype (str, optional): Either single ("complex64") or double (complex128) precision. Defaults to "complex64". diff --git a/src/qibotn/circuit_convertor.py b/src/qibotn/circuit_convertor.py index a15e533e..46e7c81b 100644 --- a/src/qibotn/circuit_convertor.py +++ b/src/qibotn/circuit_convertor.py @@ -26,7 +26,8 @@ def __init__(self, circuit, dtype="complex128"): self.circuit = circuit def state_vector_operands(self): - """Create the operands for expectation computation in the interleave format. + """Create the operands for expectation computation in the interleave + format. Returns: Operands for the contraction in the interleave format. @@ -198,7 +199,8 @@ def get_pauli_gates(self, pauli_map, dtype="complex128", backend=cp): return gates def expectation_operands(self, pauli_string): - """Create the operands for pauli string expectation computation in the interleave format. + """Create the operands for pauli string expectation computation in the + interleave format. Args: pauli_string: A string representating the list of pauli gates. From 8c164707b79ffc631fc9bac01c2253ff81c2b64d Mon Sep 17 00:00:00 2001 From: tankya2 Date: Mon, 4 Mar 2024 15:01:53 +0800 Subject: [PATCH 11/18] Add docstrings --- src/qibotn/mps_contraction_helper.py | 17 ++--------------- src/qibotn/mps_utils.py | 7 ++++--- 2 files changed, 6 insertions(+), 18 deletions(-) diff --git a/src/qibotn/mps_contraction_helper.py b/src/qibotn/mps_contraction_helper.py index e4d827a4..a3dc32d8 100644 --- a/src/qibotn/mps_contraction_helper.py +++ b/src/qibotn/mps_contraction_helper.py @@ -7,17 +7,8 @@ class MPSContractionHelper: """A helper class to compute various quantities for a given MPS. Interleaved format is used to construct the input args for `cuquantum.contract`. - A concrete example on how the modes are populated for a 7-site MPS is provided - below:: - - 0 2 4 6 8 10 12 14 - bra -----A-----B-----C-----D-----E-----F-----G----- - | | | | | | | - 1| 3| 5| 7| 9| 11| 13| - | | | | | | | - ket -----a-----b-----c-----d-----e-----f-----g----- - 15 16 17 18 19 20 21 22 - + + Reference: https://github.com/NVIDIA/cuQuantum/blob/main/python/samples/cutensornet/tn_algorithms/mps_algorithms.ipynb The follwing compute quantities are supported: @@ -26,10 +17,6 @@ class MPSContractionHelper: - the expectation value for a given operator. - the equivalent state vector after multiplying an MPO to an MPS. - Note that for the nth MPS tensor (rank-3), the modes of the tensor are expected to be `(i,p,j)` - where i denotes the bonding mode with the (n-1)th tensor, p denotes the physical mode for the qubit and - j denotes the bonding mode with the (n+1)th tensor. - Args: num_qubits: The number of qubits for the MPS. """ diff --git a/src/qibotn/mps_utils.py b/src/qibotn/mps_utils.py index f0fa811c..62c3f938 100644 --- a/src/qibotn/mps_utils.py +++ b/src/qibotn/mps_utils.py @@ -2,11 +2,10 @@ from cuquantum import contract from cuquantum.cutensornet.experimental import contract_decompose -# Reference: https://github.com/NVIDIA/cuQuantum/blob/main/python/samples/cutensornet/tn_algorithms/mps_algorithms.ipynb def initial(num_qubits, dtype): - r"""Generate the MPS with an initial state of :math:`\ket{00...00}`""" + """Generate the MPS with an initial state of :math:`\ket{00...00}`""" state_tensor = cp.asarray([1, 0], dtype=dtype).reshape(1, 2, 1) mps_tensors = [state_tensor] * num_qubits return mps_tensors @@ -27,7 +26,9 @@ def mps_site_right_swap(mps_tensors, i, **kwargs): def apply_gate(mps_tensors, gate, qubits, **kwargs): """Apply the gate operand to the MPS tensors in-place. - + + # Reference: https://github.com/NVIDIA/cuQuantum/blob/main/python/samples/cutensornet/tn_algorithms/mps_algorithms.ipynb + Args: 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, From cda817faf97d33556d89d8b497e19bd00ac06644 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 4 Mar 2024 07:02:09 +0000 Subject: [PATCH 12/18] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- src/qibotn/mps_contraction_helper.py | 2 +- src/qibotn/mps_utils.py | 7 +++---- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/qibotn/mps_contraction_helper.py b/src/qibotn/mps_contraction_helper.py index a3dc32d8..3cfdf608 100644 --- a/src/qibotn/mps_contraction_helper.py +++ b/src/qibotn/mps_contraction_helper.py @@ -7,7 +7,7 @@ class MPSContractionHelper: """A helper class to compute various quantities for a given MPS. Interleaved format is used to construct the input args for `cuquantum.contract`. - + Reference: https://github.com/NVIDIA/cuQuantum/blob/main/python/samples/cutensornet/tn_algorithms/mps_algorithms.ipynb The follwing compute quantities are supported: diff --git a/src/qibotn/mps_utils.py b/src/qibotn/mps_utils.py index 62c3f938..f37f1df5 100644 --- a/src/qibotn/mps_utils.py +++ b/src/qibotn/mps_utils.py @@ -3,9 +3,8 @@ from cuquantum.cutensornet.experimental import contract_decompose - def initial(num_qubits, dtype): - """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}`""" state_tensor = cp.asarray([1, 0], dtype=dtype).reshape(1, 2, 1) mps_tensors = [state_tensor] * num_qubits return mps_tensors @@ -26,9 +25,9 @@ def mps_site_right_swap(mps_tensors, i, **kwargs): def apply_gate(mps_tensors, gate, qubits, **kwargs): """Apply the gate operand to the MPS tensors in-place. - + # Reference: https://github.com/NVIDIA/cuQuantum/blob/main/python/samples/cutensornet/tn_algorithms/mps_algorithms.ipynb - + Args: 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, From ac9fa2106ed98855f1103d17e496fc392663cb2b Mon Sep 17 00:00:00 2001 From: tankya2 Date: Mon, 4 Mar 2024 15:49:06 +0800 Subject: [PATCH 13/18] Update docstrings and refine --- src/qibotn/backends/cutensornet.py | 9 ++-- src/qibotn/circuit_convertor.py | 21 +++++--- src/qibotn/eval.py | 73 ++++++++++++++++++++++++++-- src/qibotn/mps_contraction_helper.py | 2 +- 4 files changed, 89 insertions(+), 16 deletions(-) diff --git a/src/qibotn/backends/cutensornet.py b/src/qibotn/backends/cutensornet.py index f7d12700..c8341bde 100644 --- a/src/qibotn/backends/cutensornet.py +++ b/src/qibotn/backends/cutensornet.py @@ -95,12 +95,9 @@ def set_precision(self, precision): 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 @@ def execute_circuit( ): # 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 46e7c81b..f05eb499 100644 --- a/src/qibotn/circuit_convertor.py +++ b/src/qibotn/circuit_convertor.py @@ -26,9 +26,12 @@ def __init__(self, circuit, dtype="complex128"): 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 @@ def _parse_gates_to_mode_labels_operands( 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 @@ def init_inverse_circuit(self, circuit): 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 @@ def expectation_operands(self, pauli_string): """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 6375aa6a..42d5ec85 100644 --- a/src/qibotn/eval.py +++ b/src/qibotn/eval.py @@ -9,14 +9,31 @@ 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 a3dc32d8..fbf02850 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. From 014a39c006cfa50cbb9b3d0ce2b942e75c0ad414 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 4 Mar 2024 07:49:20 +0000 Subject: [PATCH 14/18] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- src/qibotn/circuit_convertor.py | 10 +++++----- src/qibotn/eval.py | 30 +++++++++++++++--------------- 2 files changed, 20 insertions(+), 20 deletions(-) diff --git a/src/qibotn/circuit_convertor.py b/src/qibotn/circuit_convertor.py index f05eb499..441273e9 100644 --- a/src/qibotn/circuit_convertor.py +++ b/src/qibotn/circuit_convertor.py @@ -28,10 +28,10 @@ def __init__(self, circuit, dtype="complex128"): def state_vector_operands(self): """Create the operands for dense vector computation in the interleave format. - + Parameters: None - + Returns: Operands for the contraction in the interleave format. """ @@ -88,11 +88,11 @@ def _parse_gates_to_mode_labels_operands( return mode_labels, operands def op_shape_from_qubits(self, nqubits): - """Modify tensor to cuQuantum shape - + """Modify tensor to cuQuantum shape. + Parameters: nqubits (int): The number of qubits in quantum circuit. - + Returns: (qubit_states,input_output) * nqubits """ diff --git a/src/qibotn/eval.py b/src/qibotn/eval.py index 42d5ec85..245aa5ea 100644 --- a/src/qibotn/eval.py +++ b/src/qibotn/eval.py @@ -10,7 +10,7 @@ def dense_vector_tn(qibo_circ, datatype): """Convert qibo circuit to tensornet (TN) format and perform contraction to dense vector. - + Parameters: qibo_circ: The quantum circuit object. datatype (str): Either single ("complex64") or double (complex128) precision. @@ -25,12 +25,12 @@ def dense_vector_tn(qibo_circ, datatype): 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. - + 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. """ @@ -52,12 +52,12 @@ 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. """ @@ -127,12 +127,12 @@ 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. """ @@ -216,13 +216,13 @@ 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. """ @@ -308,13 +308,13 @@ 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. """ @@ -378,12 +378,12 @@ 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. - + 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. """ @@ -402,10 +402,10 @@ def pauli_string_gen(nqubits, pauli_string_pattern): 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: From e6a3060c81c39b7143e79235f092e6f6835a3530 Mon Sep 17 00:00:00 2001 From: tankya2 Date: Mon, 4 Mar 2024 16:08:59 +0800 Subject: [PATCH 15/18] Update docstrings and further refinement --- src/qibotn/circuit_to_mps.py | 11 +++++++++++ src/qibotn/mps_contraction_helper.py | 11 +++++++---- src/qibotn/mps_utils.py | 22 +++++++++++++++++++--- 3 files changed, 37 insertions(+), 7 deletions(-) diff --git a/src/qibotn/circuit_to_mps.py b/src/qibotn/circuit_to_mps.py index af8acd5a..3027a75f 100644 --- a/src/qibotn/circuit_to_mps.py +++ b/src/qibotn/circuit_to_mps.py @@ -7,6 +7,17 @@ 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, diff --git a/src/qibotn/mps_contraction_helper.py b/src/qibotn/mps_contraction_helper.py index ccdc0fa8..c29dc921 100644 --- a/src/qibotn/mps_contraction_helper.py +++ b/src/qibotn/mps_contraction_helper.py @@ -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 @@ def contract_norm(self, mps_tensors, options=None): """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 @@ def contract_state_vector(self, mps_tensors, options=None): """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 @@ def contract_expectation( """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. diff --git a/src/qibotn/mps_utils.py b/src/qibotn/mps_utils.py index f37f1df5..f29685bd 100644 --- a/src/qibotn/mps_utils.py +++ b/src/qibotn/mps_utils.py @@ -4,14 +4,30 @@ 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. From 631231f9335ee926bb54b568d1036e5b1321d55f Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 4 Mar 2024 08:09:34 +0000 Subject: [PATCH 16/18] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- src/qibotn/circuit_to_mps.py | 3 ++- src/qibotn/mps_contraction_helper.py | 2 +- src/qibotn/mps_utils.py | 8 ++++---- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/qibotn/circuit_to_mps.py b/src/qibotn/circuit_to_mps.py index 3027a75f..48ebde7f 100644 --- a/src/qibotn/circuit_to_mps.py +++ b/src/qibotn/circuit_to_mps.py @@ -8,7 +8,7 @@ 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. @@ -18,6 +18,7 @@ class QiboCircuitToMPS: Return: None. """ + def __init__( self, circ_qibo, diff --git a/src/qibotn/mps_contraction_helper.py b/src/qibotn/mps_contraction_helper.py index c29dc921..e5628504 100644 --- a/src/qibotn/mps_contraction_helper.py +++ b/src/qibotn/mps_contraction_helper.py @@ -19,7 +19,7 @@ class MPSContractionHelper: Parameters: num_qubits: The number of qubits for the MPS. - + Return: None. """ diff --git a/src/qibotn/mps_utils.py b/src/qibotn/mps_utils.py index f29685bd..878a5aaf 100644 --- a/src/qibotn/mps_utils.py +++ b/src/qibotn/mps_utils.py @@ -5,11 +5,11 @@ def initial(num_qubits, dtype): 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. """ @@ -20,11 +20,11 @@ def initial(num_qubits, dtype): def mps_site_right_swap(mps_tensors, i, **kwargs): """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. """ From 16aef2b3f28bc9849a8a4863c1b34f969b9f3dc1 Mon Sep 17 00:00:00 2001 From: vinitha-balachandran Date: Mon, 4 Mar 2024 16:12:50 +0800 Subject: [PATCH 17/18] Minor fix to docstring in quimb.py --- src/qibotn/backends/quimb.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qibotn/backends/quimb.py b/src/qibotn/backends/quimb.py index e697a58f..1c861202 100644 --- a/src/qibotn/backends/quimb.py +++ b/src/qibotn/backends/quimb.py @@ -59,7 +59,7 @@ def execute_circuit( If ``None`` the default ``|00...0>`` state is used. Returns: - list: Final state in the dense vector form after simulation of the circuit. + 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_qu as eval From a9730aaeabd317a86d2605557ad6e317905b54bb Mon Sep 17 00:00:00 2001 From: tankya2 Date: Mon, 4 Mar 2024 18:29:35 +0800 Subject: [PATCH 18/18] Remove none type from docstring --- src/qibotn/circuit_convertor.py | 12 ------------ src/qibotn/circuit_to_mps.py | 3 --- src/qibotn/mps_contraction_helper.py | 3 --- 3 files changed, 18 deletions(-) diff --git a/src/qibotn/circuit_convertor.py b/src/qibotn/circuit_convertor.py index 441273e9..03e96fa7 100644 --- a/src/qibotn/circuit_convertor.py +++ b/src/qibotn/circuit_convertor.py @@ -29,9 +29,6 @@ def state_vector_operands(self): """Create the operands for dense vector computation in the interleave format. - Parameters: - None - Returns: Operands for the contraction in the interleave format. """ @@ -106,9 +103,6 @@ def init_intermediate_circuit(self, circuit): Parameters: circuit (object): The quantum circuit object. - - Returns: - None """ self.gate_tensors = [] gates_qubits = [] @@ -139,9 +133,6 @@ def init_basis_map(self, backend, dtype): 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) @@ -157,9 +148,6 @@ def init_inverse_circuit(self, circuit): Parameters: circuit (object): The quantum circuit object. - - Returns: - None """ self.gate_tensors_inverse = [] gates_qubits_inverse = [] diff --git a/src/qibotn/circuit_to_mps.py b/src/qibotn/circuit_to_mps.py index 48ebde7f..9d98c194 100644 --- a/src/qibotn/circuit_to_mps.py +++ b/src/qibotn/circuit_to_mps.py @@ -14,9 +14,6 @@ class QiboCircuitToMPS: 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__( diff --git a/src/qibotn/mps_contraction_helper.py b/src/qibotn/mps_contraction_helper.py index e5628504..c4370044 100644 --- a/src/qibotn/mps_contraction_helper.py +++ b/src/qibotn/mps_contraction_helper.py @@ -19,9 +19,6 @@ class MPSContractionHelper: Parameters: num_qubits: The number of qubits for the MPS. - - Return: - None. """ def __init__(self, num_qubits):