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
Implementation of fermionic hilbert and operator #1090
Conversation
don't we already have some kind of support for that for fock spaces? (actually, I would tend to say we can use the already existing fock hilbert without creating a new one? maybe I am mistaken...!) |
what I mean is: can't you derive |
Good point, I'll look into that |
Can we be careful about that and discuss it briefly in person? While I know it's possible to inherit from a non abstract class, I'd be wary of it because it has been a source of bugs in the past. I'd prefer if in general non abstract things where not inherited from. |
sure, actually I just meant to construct a Fock space, not inherit from it |
What do you mean, creating a class Fermions2nd which has a self._fock as field? |
no I just suspect you can construct the object just by returning |
Codecov Report
@@ Coverage Diff @@
## master #1090 +/- ##
==========================================
+ Coverage 81.77% 81.91% +0.14%
==========================================
Files 199 208 +9
Lines 12015 12526 +511
Branches 1800 1897 +97
==========================================
+ Hits 9825 10261 +436
- Misses 1762 1817 +55
- Partials 428 448 +20
Continue to review full report at Codecov.
|
Well, the idea is mostly to (in the next step) optimize this for fixed number of fermions, since that's relevant for 99% of all cases. I guess that would be less obvious with Fock? |
but Fock is already optimized for fixed number of particles, as far as I remember (not sure why N is referred to as the number of bosonic modes in the docs though, since it's more general)
|
I would say that |
|
Should be ok now. |
By the way, if we are going to merge this in NetKet, i'd like to have this live for at least a few months in |
Fock uses the constraint function to impose the number of particles, so it enumerates them all and then removes the incorrect ones, if I understand correctly. What do we gain from inheriting from Fock and not Homogeneous? I don't see much gain... |
I will do this once we agree on the hilbert and operator concept, have a all the minimal implementations, etc. |
The problem is that the api of It goes back to netket 1 |
One thing I realized is the following: in this representation, if you do a translation operator for example, you need to define the parity of such an operator. So e.g. if you order your original sites as (0, 1, 2, 3) in some way (e.g. zigzag), then the translation brings this (on a 2x2 lattice) to (1, 0, 3, 2) for example. You then need to compute the parity of the (1, 0, 3, 2) permutation to determine the representation of this transformation in the given basis. This might be a bit annoying, but maybe it's fine if we just add some functions that can quickly compute the parity of such transformations. Alternatively, we define an additional operator type that does this. What do you think? |
Can you say something more about why you'd need me he parity? Where? |
This would be when you want to look at excitations, for example. Maybe it's not necessary to define it, but it might also be tricky because it's not a priori clear in this representation that you need such parity factors. |
@jwnys yes I understand the issue, but I am not sure why you need this to be defined in the operator itself? (as far as I know we do not support transforming operators with symmetries, even for spins?) |
what I am trying to say here is that we should think about more broadly about supporting symmetry transformations for operators/ quickly identifying the correct phase, but I think it's best to separate the discussion and do that in another PR? |
Ok, that makes sense, yeah. Thanks for the feedback. |
Still, I am a bit unconvinced by the fact that we cannot derive/ construct this directly from Fock, since both the constraints and the local occupation numbers you need are exactly the same you already have there. Aren't we just going to duplicate the code to fix the total number of particles, for example? |
I don't really have a very strong opinion on this. It might be ok to do it like that. What I had in mind for fixed particles was to construct the hilbert states in blocks of fixed number of fermions. In that case the ordering would be rather different from e.g. Fock where you list all possibilities and just delete the ones that violate the constraint. The advantage would be that you can do ED for bigger systems. However, the disadvantage would be that our matrix then looks quite different from other libraries, since the convention of ordering the states would be different. |
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.
a few points in the API I guess need to be clarified, but otherwise it's good! can we also maybe add a small example (say, Hubbard model or spinless fermions) or even (ideally, if you or Imelda have time) a tutorial with ED?
To summarize, the new version: it's a lot faster for symbolic operations and implements many more things like iadd, etc (following the new implementation of LocalOperator by @PhilipVinc ). |
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.
some more stuff
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.
Ok, there's only a few missing tests and we're ready to merge.
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.
Seems good to me now.
Assuming tests pass* |
Tests pass, so this can be merged now. |
good to squash and merge for me |
This is an implementation of discrete fermionic degrees of freedom by @imi-hub and myself. It contains the hilbert space and an operator. The operator handles the minus signs coming from the exchange symmetry, while the hilbert space stores occupation numbers only. This follows e.g. the way qiskit and openfermion would implement things. For the operator, we follow the implementation of openfermion and added an 'from_openfermion' function to create operators. This allows us to use all their hamiltonians, such as Fermi-Hubbard. Co-authored-by: Imelda Romero <imelda.romero@epfl.ch> Co-authored-by: Filippo Vicentini <filippovicentini@gmail.com>
This is an implementation of discrete fermionic degrees of freedom by @imi-hub and myself.
It contains the hilbert space and an operator. The operator handles the minus signs coming from the exchange symmetry, while the hilbert space stores occupation numbers only. This follows e.g. the way qiskit and openfermion would implement things.
For the operator, we follow the implementation of openfermion and added an 'from_openfermion' function to create operators. This allows us to use all their hamiltonians, such as Fermi-Hubbard.
The hilbert space is not optimized for fixed number of fermions (since it inherits from HomogeneousHilbert), for that we might need to add another Hilbert implementation.
FYI: formatting will fail because flake8 and flakehell are giving me hell.