Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update spin docs #6387

Merged
merged 28 commits into from
Oct 24, 2024
Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 37 additions & 6 deletions doc/code/qml_spin.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,43 @@ qml.spin
Overview
obliviateandsurrender marked this conversation as resolved.
Show resolved Hide resolved
--------

This module contains functions and classes for creating and manipulating Hamiltonians for the spin models.
This module contains functions and classes for creating and manipulating Hamiltonians for
spin models.

Hamiltonian functions
^^^^^^^^^^^^^^^^^^^^^

.. currentmodule:: pennylane.spin

.. autosummary::
:toctree: api

~emery
~fermi_hubbard
~haldane
~heisenberg
~kitaev
~transverse_ising
isaacdevlugt marked this conversation as resolved.
Show resolved Hide resolved


Hamiltonian custom functions
^^^^^^^^^^^^^^^^^^^^^^^^^^^^

.. currentmodule:: pennylane.spin

.. automodapi:: pennylane.spin
:no-heading:
:no-main-docstr:
:skip: Lattice
:include-all-objects:
.. autosummary::
:toctree: api

~spin_hamiltonian


Lattice classes and functions
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

.. currentmodule:: pennylane.spin

.. autosummary::
:toctree: api

~Lattice
~generate_lattice
2 changes: 1 addition & 1 deletion pennylane/spin/__init__.py
soranjh marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
This module provides the functionality to create spin Hamiltonians.
"""

from .lattice import Lattice
from .lattice import Lattice, generate_lattice
from .spin_hamiltonian import (
emery,
fermi_hubbard,
Expand Down
31 changes: 20 additions & 11 deletions pennylane/spin/lattice.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,10 @@ class Lattice:

**Example**

>>> n_cells = [2,2]
>>> n_cells = [2, 2]
>>> vectors = [[0, 1], [1, 0]]
>>> boundary_condition = [True, False]
>>> lattice = qml.spin.Lattice(n_cells, vectors,
>>> boundary_condition=boundary_condition)
>>> lattice = qml.spin.Lattice(n_cells, vectors, boundary_condition=boundary_condition)
>>> lattice.edges
[(2, 3, 0), (0, 2, 0), (1, 3, 0), (0, 1, 0)]

Expand Down Expand Up @@ -358,21 +357,31 @@ def add_edge(self, edge_indices):
self.edges.append(new_edge)


def _generate_lattice(lattice, n_cells, boundary_condition=False, neighbour_order=1):
r"""Generates the lattice object for a given shape and n_cells.
def generate_lattice(lattice, n_cells, boundary_condition=False, neighbour_order=1):
r"""Generates a :class:`~pennylane.spin.Lattice` object for a given lattice shape and number of
cells.

Args:
lattice (str): Shape of the lattice. Input values can be ``'chain'``, ``'square'``, ``'rectangle'``,
``'honeycomb'``, ``'triangle'``, ``'kagome'``, ``'lieb'``, ``'cubic'``, ``'bcc'``, ``'fcc'``,
or ``'diamond'``.
lattice (str): Shape of the lattice. Input values can be ``'chain'``, ``'square'``,
``'rectangle'``, ``'triangle'``, ``'honeycomb'``, ``'kagome'``, ``'lieb'``,
``'cubic'``, ``'bcc'``, ``'fcc'`` or ``'diamond'``.
n_cells (list[int]): Number of cells in each direction of the grid.
boundary_condition (bool or list[bool]): Defines boundary conditions in different lattice axes.
Default is ``False`` indicating open boundary condition.
Default is ``False`` indicating open boundary condition.
obliviateandsurrender marked this conversation as resolved.
Show resolved Hide resolved
neighbour_order (int): Specifies the interaction level for neighbors within the lattice.
Default is 1, indicating nearest neighbour.
Default is 1, indicating nearest neighbour.
soranjh marked this conversation as resolved.
Show resolved Hide resolved

Returns:
lattice object.
~pennylane.spin.Lattice: lattice object.

**Example**

>>> shape = 'square'
>>> n_cells = [2, 2]
>>> boundary_condition = [True, False]
>>> lattice = qml.spin.generate_lattice(shape, n_cells, boundary_condition)
>>> lattice.edges
[(2, 3, 0), (0, 2, 0), (1, 3, 0), (0, 1, 0)]
"""

lattice_shape = lattice.strip().lower()
Expand Down
Loading