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

How to build spin hamiltonians #1230

Open
wants to merge 5 commits into
base: dev
Choose a base branch
from
Open

How to build spin hamiltonians #1230

wants to merge 5 commits into from

Conversation

soranjh
Copy link
Contributor

@soranjh soranjh commented Oct 4, 2024

Before submitting

Please complete the following checklist when submitting a PR:

  • Ensure that your tutorial executes correctly, and conforms to the
    guidelines specified in the README.

  • Remember to do a grammar check of the content you include.

  • All tutorials conform to
    PEP8 standards.
    To auto format files, simply pip install black, and then
    run black -l 100 path/to/file.py.

When all the above are checked, delete everything above the dashed
line and fill in the pull request template.


Title:
How to build spin hamiltonians [sc-74419]

Summary:
This how-to explains the features added to the qml.spin module for constructing spin Hamiltonians.

Relevant references:

Possible Drawbacks:

Related GitHub Issues:


If you are writing a demonstration, please answer these questions to facilitate the marketing process.

  • GOALS — Why are we working on this now?

    Eg. Promote a new PL feature or show a PL implementation of a recent paper.

  • AUDIENCE — Who is this for?

    Eg. Chemistry researchers, PL educators, beginners in quantum computing.

  • KEYWORDS — What words should be included in the marketing post?

  • Which of the following types of documentation is most similar to your file?
    (more details here)

  • Tutorial
  • Demo
  • How-to

Copy link

github-actions bot commented Oct 4, 2024

👋 Hey, looks like you've updated some demos!

🐘 Don't forget to update the dateOfLastModification in the associated metadata files so your changes are reflected in Glass Onion (search and recommendations).

Please hide this comment once the field(s) are updated. Thanks!

Copy link

github-actions bot commented Oct 7, 2024

Thank you for opening this pull request.

You can find the built site at this link.

Deployment Info:

  • Pull Request ID: 1230
  • Deployment SHA: f9d66d90011a5195b513948dc43e925c37b02b93
    (The Deployment SHA refers to the latest commit hash the docs were built from)

Note: It may take several minutes for updates to this pull request to be reflected on the deployed site.

Copy link
Contributor

@KetpuntoG KetpuntoG left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This new functionality really seems to make the job easier 🚀

# spin-down particle. The Hamiltonian describing this model has two components: the kinetic energy
# component which is parameterized by a hopping parameter and the potential energy component
# parameterized by the on-site interaction strength. The Fermi-Hubbard Hamiltonian can then be
# constructed in PennyLane by passing the hoping and interaction parameters to the fermi_hubbard
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

even if the link doesn't work now, I would add this

Suggested change
# constructed in PennyLane by passing the hoping and interaction parameters to the fermi_hubbard
# constructed in PennyLane by passing the hoping and interaction parameters to the :func:`fermi_hubbard <pennylane.spin.fermi_hubbard>`

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the same for all other functions. Another option is to put ``function name``, so that it is not seen in plain text

#
# PennyLane has a range of functions for constructing spin model Hamiltonians with minimal input
# data needed from the user. Let’s look at the
# `Fermi-Hubbard <https://pennylane.ai/datasets/qspin/fermi-hubbard-model>`__ model as an example.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was confused by your pointing to the dataset as I thought we were using it but they are different things


######################################################################
# Similarity, a broad range of other well-investigated spin model Hamiltonians can be constructed
# with the dedicated functions available in the spin module, by just providing the lattice
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know if we can link it now but it would be good to add a link here to the spin module

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we can't link it, we can maybe provide a list of spin-Hamiltonians we can construct.

# Hamiltonian templates
# ---------------------
#
# PennyLane has a range of functions for constructing spin model Hamiltonians with minimal input
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you mention a couple of different Hamiltonian examples?

# examples of both methods. First we use generate_lattice to construct a square lattice containing 9
# sites which are all connected to their nearest neighbor.

lattice = qml.spin.lattice._generate_lattice('square', [3, 3])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

curious about why this is a private function

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It will become public in a WIP PR.

# manually is more flexible while generate_lattice only works for some predefined lattice shapes.
#
# Now that we have the lattice, we can use its attributes, e.g., edges and vertices, to construct
# our transverse field Ising model Hamiltonian. We just need to define the coupling and onsite
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You might remember the reader that these are J and h

# nodes and the unit cell translation vector and then define the number of unit cells in each
# direction.

nodes = [[0.5, 0.5 / 3 ** 0.5], [1, 1 / 3 ** 0.5]]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure I understand what the nodes are here

######################################################################
# Let's plot the lattice to see how it looks like.

plot(Lattice(n_cells, vectors, nodes), figsize=(5, 3))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😮

hamiltonian = qml.spin.fermi_hubbard("cubic", [3, 3, 3], t, u)

######################################################################
# Similarity, a broad range of other well-investigated spin model Hamiltonians can be constructed
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# Similarity, a broad range of other well-investigated spin model Hamiltonians can be constructed
# Similarly, a broad range of other well-investigated spin model Hamiltonians can be constructed

# The Hamiltonian template functions are great and simple tools for someone who just wants to build
# a Hamiltonian quickly. However, PennyLane offers intuitive tools that can be used to construct
# spin Hamiltonians manually which are very handy for building customized Hamiltonians. Let’s learn
# how to use this tools by constructing the Hamiltonian for the
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# how to use this tools by constructing the Hamiltonian for the
# how to use these tools by constructing the Hamiltonian for the

@soranjh soranjh changed the title [WIP] how to build spin hamiltonians How to build spin hamiltonians Oct 11, 2024
Copy link
Contributor

@ddhawan11 ddhawan11 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @soranjh. I have added my first set of comments.

# spin-down particle. The Hamiltonian describing this model has two components: the kinetic energy
# component which is parameterized by a hopping parameter and the potential energy component
# parameterized by the on-site interaction strength. The Fermi-Hubbard Hamiltonian can then be
# constructed in PennyLane by passing the hoping and interaction parameters to the fermi_hubbard
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# constructed in PennyLane by passing the hoping and interaction parameters to the fermi_hubbard
# constructed in PennyLane by passing the hopping and interaction parameters to the fermi_hubbard

Comment on lines +30 to +32
n = [2]
t = 0.2
u = 0.3
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shall we add comments here to say which term describes what parameter or rename the parameters? This might get confusing as we don't provide the equation here.

# The fermi_hubbard function is general enough to go beyond the simple “chain” model and construct
# the Hamiltonian for a wide range of two-dimensional and three-dimensional lattice shapes. For
# those cases, we need to provide the number of sites in each direction of the lattice. We can
# construct the Hamiltonian for a cubic lattice with 3 sites on each direction as
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# construct the Hamiltonian for a cubic lattice with 3 sites on each direction as
# construct the Hamiltonian for a cubic lattice with 3 sites in each direction as


######################################################################
# Similarity, a broad range of other well-investigated spin model Hamiltonians can be constructed
# with the dedicated functions available in the spin module, by just providing the lattice
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we can't link it, we can maybe provide a list of spin-Hamiltonians we can construct.

# spin Hamiltonians manually which are very handy for building customized Hamiltonians. Let’s learn
# how to use this tools by constructing the Hamiltonian for the
# `transverse field Ising <https://pennylane.ai/datasets/qspin/transverse-field-ising-model>`__
# model on a two-dimension lattice.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# model on a two-dimension lattice.
# model on a two-dimensional lattice.


######################################################################
# This gives us the same lattice as we created with generate_lattice but constructing the lattice
# manually is more flexible while generate_lattice only works for some predefined lattice shapes.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can link the generate_lattice function here, so that a reader can see which pre-defined shapes are available.


######################################################################
# In this example we just used the in-built attributes of the lattice we created without further
# customising them. The lattice can be constructed in a very flexible way that allows constructing
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# customising them. The lattice can be constructed in a very flexible way that allows constructing
# customising them. The lattice can be constructed in a more flexible way that allows constructing

n_cells = [3, 3]

######################################################################
# Let's plot the lattice to see how it looks like.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# Let's plot the lattice to see how it looks like.
# Let's plot the lattice to see how it looks.

Comment on lines +207 to +209
# See how we can easily and intuitively construct the Kitaev model Hamiltonian with the tools in
# these tools. You can compare the constructed Hamiltonian with the template we already have for
# the Kitaev model and verify that the Hamiltonians are the same.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# See how we can easily and intuitively construct the Kitaev model Hamiltonian with the tools in
# these tools. You can compare the constructed Hamiltonian with the template we already have for
# the Kitaev model and verify that the Hamiltonians are the same.
# See how we can easily and intuitively construct the Kitaev model Hamiltonian with the tools available in the
# spin module. You can compare the constructed Hamiltonian with the template we already have for
# the Kitaev model and verify that the Hamiltonians are the same.

# Hamiltonians. Here we learned how to use these tools to construct pre-defined Hamiltonian
# templates, such as the Fermi-Hubbard model Hamiltonian, and use the Lattice object to construct
# more advanced and customised models such as the Kitaev honeycomb Hamiltonian. The versatility of
# the new spin functions and classes allows constructing any new spin model Hamiltonian intuitively.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# the new spin functions and classes allows constructing any new spin model Hamiltonian intuitively.
# the new spin functions and classes allows construction of any new spin model Hamiltonian intuitively.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants