From beab8612f3db225dfefa1679d9b2d9bd71670a49 Mon Sep 17 00:00:00 2001 From: PabloAndresCQ Date: Wed, 23 Oct 2024 14:38:50 +0000 Subject: [PATCH] More fixes to docs --- docs/modules/general_state.rst | 2 - .../general_state/tensor_network_state.py | 71 +++++++++---------- 2 files changed, 32 insertions(+), 41 deletions(-) diff --git a/docs/modules/general_state.rst b/docs/modules/general_state.rst index 3d996e20..b0e2620f 100644 --- a/docs/modules/general_state.rst +++ b/docs/modules/general_state.rst @@ -5,7 +5,6 @@ General state (exact) simulation .. autoclass:: pytket.extensions.cutensornet.general_state.GeneralState() - .. automethod:: __init__ .. automethod:: get_statevector .. automethod:: get_amplitude .. automethod:: expectation_value @@ -14,7 +13,6 @@ General state (exact) simulation .. autoclass:: pytket.extensions.cutensornet.general_state.GeneralBraOpKet() - .. automethod:: __init__ .. automethod:: contract .. automethod:: destroy diff --git a/pytket/extensions/cutensornet/general_state/tensor_network_state.py b/pytket/extensions/cutensornet/general_state/tensor_network_state.py index 65ef3c27..0eaaf730 100644 --- a/pytket/extensions/cutensornet/general_state/tensor_network_state.py +++ b/pytket/extensions/cutensornet/general_state/tensor_network_state.py @@ -39,9 +39,22 @@ class GeneralState: """Wrapper of cuTensorNet's NetworkState for exact simulation of states. + Constructs a tensor network for the output state of a pytket circuit. + The qubits are assumed to be initialised in the ``|0>`` state. + The object stores the *uncontracted* tensor network. + Note: Preferably used as ``with GeneralState(...) as state:`` so that GPU memory is automatically released after execution. + The ``circuit`` must not contain any ``CircBox`` or non-unitary command. + + Args: + circuit: A pytket circuit to be converted to a tensor network. + attributes: Optional. A dict of cuTensorNet ``TNConfig`` keys and + their values. + scratch_fraction: Optional. Fraction of free memory on GPU to allocate as + scratch space; value between 0 and 1. Defaults to ``0.8``. + loglevel: Internal logger output level. """ def __init__( @@ -51,22 +64,6 @@ def __init__( scratch_fraction: float = 0.8, loglevel: int = logging.WARNING, ) -> None: - """Constructs a tensor network for the output state of a pytket circuit. - - The qubits are assumed to be initialised in the ``|0>`` state. - The resulting object stores the *uncontracted* tensor network. - - Note: - The ``circuit`` must not contain any ``CircBox`` or non-unitary command. - - Args: - circuit: A pytket circuit to be converted to a tensor network. - attributes: Optional. A dict of cuTensorNet ``TNConfig`` keys and - their values. - scratch_fraction: Optional. Fraction of free memory on GPU to allocate as - scratch space; value between 0 and 1. Defaults to ``0.8``. - loglevel: Internal logger output level. - """ self._logger = set_logger("GeneralState", loglevel) # Remove end-of-circuit measurements and keep track of them separately @@ -332,11 +329,29 @@ def __exit__(self, exc_type: Any, exc_value: Any, exc_tb: Any) -> None: class GeneralBraOpKet: - """Wrapper of cuTensorNet's NetworkState for exact simulation of ````. + """Constructs a tensor network for ````. + + The qubits in ``ket`` and ``bra`` are assumed to be initialised in the ``|0>`` + state. The object stores the *uncontracted* tensor network. Note: Preferably used as ``with GeneralBraOpKet(...) as braket:`` so that GPU memory is automatically released after execution. + The ``circuit`` must not contain any ``CircBox`` or non-unitary command. + The operator is provided when ``contract`` is called. + + Args: + bra: A pytket circuit describing the |bra> state. + ket: A pytket circuit describing the |ket> state. + attributes: Optional. A dict of cuTensorNet ``TNConfig`` keys and + their values. + scratch_fraction: Optional. Fraction of free memory on GPU to allocate as + scratch space; value between 0 and 1. Defaults to ``0.8``. + loglevel: Internal logger output level. + + Raises: + ValueError: If the circuits for ``ket`` or ``bra`` contain measurements. + ValueError: If the set of qubits of ``ket`` and ``bra`` do not match. """ def __init__( @@ -347,28 +362,6 @@ def __init__( scratch_fraction: float = 0.8, loglevel: int = logging.WARNING, ) -> None: - """Constructs a tensor network for ````. - - The qubits in ``ket`` and ``bra`` are assumed to be initialised in the ``|0>`` - state. The resulting object stores the *uncontracted* tensor network. - - Note: - The ``circuit`` must not contain any ``CircBox`` or non-unitary command. - The operator is provided when ``contract`` is called. - - Args: - bra: A pytket circuit describing the |bra> state. - ket: A pytket circuit describing the |ket> state. - attributes: Optional. A dict of cuTensorNet ``TNConfig`` keys and - their values. - scratch_fraction: Optional. Fraction of free memory on GPU to allocate as - scratch space; value between 0 and 1. Defaults to ``0.8``. - loglevel: Internal logger output level. - - Raises: - ValueError: If the circuits for ``ket`` or ``bra`` contain measurements. - ValueError: If the set of qubits of ``ket`` and ``bra`` do not match. - """ self._logger = set_logger("GeneralBraOpKet", loglevel) # Check that the circuits have the same qubits