-
Notifications
You must be signed in to change notification settings - Fork 186
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
base: dev
Are you sure you want to change the base?
Conversation
👋 Hey, looks like you've updated some demos! 🐘 Don't forget to update the Please hide this comment once the field(s) are updated. Thanks! |
Thank you for opening this pull request. You can find the built site at this link. Deployment Info:
Note: It may take several minutes for updates to this pull request to be reflected on the deployed site. |
There was a problem hiding this 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 |
There was a problem hiding this comment.
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
# 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>` |
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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]) |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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]] |
There was a problem hiding this comment.
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)) |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
# 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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
# how to use this tools by constructing the Hamiltonian for the | |
# how to use these tools by constructing the Hamiltonian for the |
There was a problem hiding this 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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
# 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 |
n = [2] | ||
t = 0.2 | ||
u = 0.3 |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
# 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 |
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
# 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. |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
# 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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
# Let's plot the lattice to see how it looks like. | |
# Let's plot the lattice to see how it looks. |
# 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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
# 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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
# 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. |
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 thenrun
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)