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

Add lattice and Fermi-Hubbard model #365

Merged
merged 67 commits into from
Dec 9, 2021

Conversation

k-tamuraphys
Copy link
Contributor

@k-tamuraphys k-tamuraphys commented Sep 16, 2021

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

  • improve adjacency_matrix
  • add the defaults position of the draw method
  • add unit tests
  • add release note

image

Added by @ikkoham

@CLAassistant
Copy link

CLAassistant commented Sep 16, 2021

CLA assistant check
All committers have signed the CLA.

@ikkoham ikkoham changed the title add lattice and Fermi-Hubbard model [WIP] add lattice and Fermi-Hubbard model Sep 16, 2021
Copy link
Collaborator

@mtreinish mtreinish left a 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

@k-tamuraphys
Copy link
Contributor Author

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

Thank you for the comment. I added retworkx to requirements.txt and .pylintrc.

@ikkoham ikkoham marked this pull request as ready for review September 28, 2021 10:30
@ikkoham ikkoham marked this pull request as draft September 28, 2021 10:30
Copy link
Member

@mrossinek mrossinek left a 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 👍

Copy link
Member

@mrossinek mrossinek left a comment

Choose a reason for hiding this comment

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

It's getting increasingly difficult to find remaining unresolved conversations. I included two screenshots below. Other than that, this lgtm now 👍

screenshot_1638266407
screenshot_1638266419

@ikkoham
Copy link
Contributor

ikkoham commented Dec 2, 2021

@pbark
Copy link
Contributor

pbark commented Dec 6, 2021

I think that now this LGTM except the minor naming change that we discussed above.

@ikkoham
Copy link
Contributor

ikkoham commented Dec 6, 2021

I changed the file path according to @pbark's comment. 138de92

Comment on lines 149 to 151
def copy(self) -> "Lattice":
"""Return a copy of the lattice."""
return Lattice(self.graph.copy())
Copy link
Member

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

Copy link
Member

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.

Copy link
Contributor

@ikkoham ikkoham Dec 7, 2021

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.

Copy link
Member

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.

Copy link
Contributor

@pbark pbark Dec 7, 2021

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.

Copy link
Contributor

@ikkoham ikkoham Dec 8, 2021

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.

Copy link
Member

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.

@ikkoham
Copy link
Contributor

ikkoham commented Dec 8, 2021

Oh my... Python 3.6 hasn't been removed yet.

@pbark pbark self-requested a review December 8, 2021 09:38
@mrossinek mrossinek merged commit 25c72a0 into qiskit-community:main Dec 9, 2021
Anthony-Gandon pushed a commit to Anthony-Gandon/qiskit-nature that referenced this pull request May 25, 2023
* 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 <Manoel.Marques@ibm.com>
Co-authored-by: ikkoham <ikkoham@users.noreply.github.com>
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.