Skip to content

Commit

Permalink
add review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
soranjh committed Dec 4, 2024
1 parent 069ea7e commit b7f16ea
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 15 deletions.
23 changes: 22 additions & 1 deletion demonstrations/tutorial_how_to_spin_hamiltonian.metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,28 @@
"seoDescription": "Learn how to build spin Hamiltonians with PennyLane.",
"doi": "",
"canonicalURL": "/qml/demos/tutorial_how_to_spin_hamiltonian",
"references": [],
"references": [
{
"id": "ashcroft",
"type": "book",
"title": "Solid State Physics",
"authors": "N. W. Ashcroft, D. N. Mermin",
"year": "1976",
"publisher": "New York: Saunders College Publishing",
"url": "https://en.wikipedia.org/wiki/Ashcroft_and_Mermin"
},
{
"id": "jovanovic",
"type": "article",
"title": "Refraction and band isotropy in 2D square-like Archimedean photonic crystal lattices",
"authors": "D. Jovanovic, R. Gajic, K. Hingerl",
"journal": "Opt. Express",
"volume": "16",
"pages": "4048--4058",
"year": "2008",
"url": "https://opg.optica.org/oe/fulltext.cfm?uri=oe-16-6-4048&id=154856"
}
],
"basedOnPapers": [],
"referencedByPapers": [],
"relatedContent": [
Expand Down
32 changes: 18 additions & 14 deletions demonstrations/tutorial_how_to_spin_hamiltonian.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
Systems of interacting spins provide simple but powerful models for studying problems in physics,
chemistry, and quantum computing. PennyLane offers a comprehensive set of tools that enables users
to intuitively construct a broad range of spin Hamiltonians. Here we show you how to use these tools
to easily construct spin Hamiltonians for the `Fermi–Hubbard <https://en.wikipedia.org/wiki/Hubbard_model>`__ model,
the `Heisenberg <https://en.wikipedia.org/wiki/Quantum_Heisenberg_model>`__ model,
the `transverse-field Ising <https://en.wikipedia.org/wiki/Transverse-field_Ising_model>`__ model,
the `Kitaev's honeycomb <https://arxiv.org/abs/cond-mat/0506438>`__ model,
the `Haldane <https://journals.aps.org/prl/abstract/10.1103/PhysRevLett.61.2015>`__ model,
the `Emery <https://journals.aps.org/prl/abstract/10.1103/PhysRevLett.58.2794>`__ model,
to easily construct spin Hamiltonians for the `Fermi–Hubbard model <https://en.wikipedia.org/wiki/Hubbard_model>`__,
the `Heisenberg model <https://en.wikipedia.org/wiki/Quantum_Heisenberg_model>`__,
the `transverse-field Ising model <https://en.wikipedia.org/wiki/Transverse-field_Ising_model>`__,
the `Kitaev's honeycomb model <https://arxiv.org/abs/cond-mat/0506438>`__,
the `Haldane model <https://journals.aps.org/prl/abstract/10.1103/PhysRevLett.61.2015>`__,
the `Emery model <https://journals.aps.org/prl/abstract/10.1103/PhysRevLett.58.2794>`__,
and more!
.. figure:: ../_static/demo_thumbnails/opengraph_demo_thumbnails/OGthumbnail_how_to_build_spin_hamiltonians.png
Expand All @@ -31,7 +31,7 @@
# ^^^^^^^^^^^^^^^^^^^
# The `Fermi–Hubbard model Hamiltonian <https://docs.pennylane.ai/en/latest/code/api/pennylane.spin.fermi_hubbard.html>`__
# has a kinetic energy component, which is parameterized by a hopping parameter :math:`t`, and a
# potential energy component which is parameterized by the on-site interaction strength, :math:`U`.
# potential energy component which is parameterized by the on-site interaction strength, :math:`U`:
#
# .. math::
#
Expand All @@ -46,7 +46,8 @@
# The Fermi–Hubbard Hamiltonian can be
# constructed in PennyLane by passing the hopping and interaction parameters to the
# :func:`~.pennylane.spin.fermi_hubbard` function. We also need to specify the shape of the lattice
# that describes the positions of the spin sites. A full list of supported lattice shapes is
# that describes the positions of the spin sites. We will show an example here, and the full list of
# supported lattice shapes is
# provided in the :func:`~.pennylane.spin.generate_lattice` documentation.
#
# We can also define the
Expand All @@ -69,18 +70,20 @@

######################################################################
# Let's also visualize the square lattice we created. To do that, we need to
# create a simple plotting function and also the helper function
# create a simple plotting function, as well as the helper function
# :func:`~.pennylane.spin.generate_lattice`, which you will learn more about in the next sections.

import matplotlib.pyplot as plt

def plot(lattice, figsize=None, showlabel=True):

# initialize the plot
if not figsize:
figsize = lattice.n_cells[::-1]

plt.figure(figsize=figsize)

# get lattice nodes and edges and plot them
nodes = lattice.lattice_points

for edge in lattice.edges:
Expand Down Expand Up @@ -287,8 +290,8 @@ def plot(lattice, figsize=None, showlabel=True):
# our transverse-field Ising model Hamiltonian. For instance, we can access the number of sites
# with ``lattice.n_sites`` and the indices that define each edge with ``lattice.edges_indices``. For
# the full list of attributes, please see the documentation of the :class:`~.pennylane.spin.Lattice`
# class. We also need to define the coupling, :math:`J`, and onsite :math:`h` parameters of the
# Hamiltonian.
# class. We also need to define the coupling, :math:`J`, and onsite parameters of the
# Hamiltonian, :math:`h`.

from pennylane import X, Y, Z

Expand Down Expand Up @@ -388,7 +391,8 @@ def plot(lattice, figsize=None, showlabel=True):
#
# Conclusion
# ----------
# The spin module in PennyLane provides a set of powerful tools for constructing spin Hamiltonians.
# The `spin module <https://docs.pennylane.ai/en/latest/code/qml_spin.html>`__ in PennyLane provides
# a set of powerful tools for constructing spin Hamiltonians.
# Here we learned how to use these tools to construct predefined Hamiltonian templates such as the
# Fermi–Hubbard Hamiltonian. This can be done with our built-in functions that currently support
# several commonly used spin models and a variety of lattice shapes. More importantly, PennyLane
Expand All @@ -402,8 +406,8 @@ def plot(lattice, figsize=None, showlabel=True):
#
# .. [#ashcroft]
#
# Neil W. Ashcroft, David N. Mermin,
# "Solid state physics", Chapter 4, New York: Saunders College Publishing, 1976.
# N. W. Ashcroft, D. N. Mermin,
# "Solid State Physics", Chapter 4, New York: Saunders College Publishing, 1976.
#
# .. [#jovanovic]
#
Expand Down

0 comments on commit b7f16ea

Please sign in to comment.