Skip to content

Commit

Permalink
More fixes to docs
Browse files Browse the repository at this point in the history
  • Loading branch information
PabloAndresCQ committed Oct 23, 2024
1 parent ea12cbb commit beab861
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 41 deletions.
2 changes: 0 additions & 2 deletions docs/modules/general_state.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -14,7 +13,6 @@ General state (exact) simulation

.. autoclass:: pytket.extensions.cutensornet.general_state.GeneralBraOpKet()

.. automethod:: __init__
.. automethod:: contract
.. automethod:: destroy

Expand Down
71 changes: 32 additions & 39 deletions pytket/extensions/cutensornet/general_state/tensor_network_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__(
Expand All @@ -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
Expand Down Expand Up @@ -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 ``<bra|O|ket>``.
"""Constructs a tensor network for ``<bra|operator|ket>``.
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__(
Expand All @@ -347,28 +362,6 @@ def __init__(
scratch_fraction: float = 0.8,
loglevel: int = logging.WARNING,
) -> None:
"""Constructs a tensor network for ``<bra|operator|ket>``.
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
Expand Down

0 comments on commit beab861

Please sign in to comment.