-
Notifications
You must be signed in to change notification settings - Fork 208
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
Add lattice and Fermi-Hubbard model #365
Conversation
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.
Two quick comments here, first, you'll need to add retworkx to https://github.com/Qiskit/qiskit-nature/blob/main/requirements.txt since it's being explicitly imported by nature now. The second is the lint failures with retworkx are because pylint can't do it's own parsing and ast analysis of a compiled extension, you need to add retworkx to the extension pkg list in the pylintrc: https://github.com/Qiskit/qiskit-nature/blob/main/.pylintrc#L37 so pylint knows to not try to inspect the members
docs/apidocs/qiskit_nature.problems.secind_quantization.lattice.rst
Outdated
Show resolved
Hide resolved
docs/apidocs/qiskit_nature.problems.second_quantization.lattice.models.rst
Outdated
Show resolved
Hide resolved
fix lint and refactor
Thank you for the comment. I added retworkx to requirements.txt and .pylintrc. |
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.
Thank you @k-tamuraphys for the hard work on this! Some comments from my side (rather nitpicky at times...)
I did not look at the unittests in detail but will do so on the second iteration of my review 👍
qiskit_nature/problems/second_quantization/lattice/lattice/__init__.py
Outdated
Show resolved
Hide resolved
qiskit_nature/problems/second_quantization/lattice/lattice/hyper_cubic.py
Outdated
Show resolved
Hide resolved
qiskit_nature/problems/second_quantization/lattice/lattice/triangular_lattice.py
Outdated
Show resolved
Hide resolved
qiskit_nature/problems/second_quantization/lattice/models/fermi_hubbard_model.py
Outdated
Show resolved
Hide resolved
qiskit_nature/problems/second_quantization/lattice/models/fermi_hubbard_model.py
Outdated
Show resolved
Hide resolved
qiskit_nature/problems/second_quantization/lattice/models/fermi_hubbard_model.py
Outdated
Show resolved
Hide resolved
qiskit_nature/problems/second_quantization/lattice/models/fermi_hubbard_model.py
Outdated
Show resolved
Hide resolved
fix docs generation
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 think that now this LGTM except the minor naming change that we discussed above. |
qiskit_nature/problems/second_quantization/lattice/lattices/hyper_cubic_lattice.py
Outdated
Show resolved
Hide resolved
def copy(self) -> "Lattice": | ||
"""Return a copy of the lattice.""" | ||
return Lattice(self.graph.copy()) |
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.
Since self.graph already does a copy() this seems to be doing a copy of the copy. What is this expected to be used for - I am asking since it seems to be in this base class but not overridden (that I saw) in any derived classes. Hence if I call copy() on a derived instance, say a HyperCubicLattice, I will not get a copy of that rather I am going to get a base class Lattice instance using its graph. Since user can make a Lattice from the graph property easily themselves too, with the above observations I guess I am questioning whether having this method is useful
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.
In thinking/reviewing a little more I wondered about the sub-classes since it seemed they just created a graph for the Lattice constructor and only a couple had a little more. I was wondering if all those classes, all those types, were actually needed/useful - rather than say just have factory functions that build out a Lattice in square, triangular form etc. In a couple of the cases it seems that the parameters passed to the constructor are used in the draw without boundary. Otherwise these sub-classes do not add any new/specialized functions at for the derived types. Like for instance being able to add one more row to the lattice. Now I see there are public variables for rows, cols etc in sub-classes. While I can see reading these as properties can be useful when there are these subtypes, they are public instance vars, not properties like is done in Lattice, and thus they can be set too. Which will either have no effect (square lattice) or later mess up the draw without boundary. Should all these be private instance vars and have properties just to read them from a public API perspective. Maybe these sub-types can be expanded upon in the future so it seems more useful to have them as specific types - at present, to me, aside from draw without boundary, that maybe cannot be done in Lattice itself from the graph, their existence just adds a bunch of types/classes with no other additional specilalization/value beyond that.
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 think this is correct about copy. (or copy.deepcopy might be safer.)
8beeb63#diff-f5c282fdc2a29ac3872af2c25326ad98d8277544a967e89fb6dec888b872c5c9R151
I choose to use deepcopy here.
36367eb
For public API, I'm sure there were unnecessary setters, so I deleted it and made them getters only.
8af7388
Currently, there is no special method, but the meaning is clear from the class name, so I believe it is easier to use than, for example, creating from a class method.
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.
For public API, I'm sure there were unnecessary setters, so I deleted it and made them getters only.
For the hyper_cubic_lattice is still seems to have a dim
and size
public instance vars.
Currently, there is no special method, but the meaning is clear from the class name, so I believe it is easier to use than, for example, creating from a class method.
Ok, I was more thinking of public methods say square_lattice(.....) -> Lattice
. But perhaps, even though the various types today do not have any specialization beyond the one method in a couple of the classes, in the future that will happen and then the structure is more suitable for this than say just having methods.
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.
@woodsp-ibm thanks for the comment. In general I agree with @ikkoham that the current implementation is more user friendly where the class names correspond to the expected 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 forgot dim
and size
. I'll add them soon.
As for type hint, they are fine for returning sub classes (Liskov). If you need in the future, we can override stronger type hints in the sub class side.
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.
For copy() that's fine - what you have now is a bit different than before in that now its making a copy of the instance, and hence whatever the subclass is, not a new Lattice (possibly parent of instance) with the same graph.
qiskit_nature/problems/second_quantization/lattice/lattices/lattice.py
Outdated
Show resolved
Hide resolved
qiskit_nature/problems/second_quantization/lattice/lattices/triangular_lattice.py
Show resolved
Hide resolved
This reverts commit 71d263b.
Oh my... Python 3.6 hasn't been removed yet. |
* add lattice and FermiHubbard * minor update * update * fix lint and refactor * add unit tests * update unit tests * update unit tests * fix typo of apidocs * fix docs generation * minor update * fix docs * minor update * fix lint * minor update * updates * add comments and documentation * fix spell * minor update * Revert unnecessary changes * improves docs * dynamical annotations * add release note * minor update * update document * add DrawStyle * minor update * add tutorial * fix documentation * minor update * extract functions * edit pylintdict * add BoundaryCondition Enum * minor change * delete tutorial * fix releasenote * minor update * fix matplotlib dependency * fix mypy error * minor update * change filepath (lattice -> lattices) * remove unnecessary return docs * remove unnecessary setter * fix copy * remove unnecessary getter (dim, size, boundary_edges) * improve typehint by PEP-563 * Revert "improve typehint by PEP-563" This reverts commit 71d263b. * fix spells Co-authored-by: Manoel Marques <[email protected]> Co-authored-by: ikkoham <[email protected]>
Summary
Implement lattice and Fermi-Hubbard model
Details and comments
Gist URL of the jupyter notebook for the lattice module:
https://gist.github.com/k-tamuraphys/6da54c468fffca3b4d18d9837de81aaf
To Do
Added by @ikkoham