-
Notifications
You must be signed in to change notification settings - Fork 34
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
Improve manybodyoperator
performance once more
#128
Conversation
Codecov Report
@@ Coverage Diff @@
## master #128 +/- ##
==========================================
- Coverage 93.55% 93.37% -0.18%
==========================================
Files 24 24
Lines 3055 3018 -37
==========================================
- Hits 2858 2818 -40
- Misses 197 200 +3
📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
This looks great, thank you as always! I am not too worried about the change of ordering in the returned vector. However, I think this has at least one change that probably should be considered breaking. Previously the return type for many of these functions was Vector, but now it is Occupations, and Occupations does not permit operations that users might already be relying on. master:
this pr:
I think we need to support a bit more of the Vector API before being comfortable merging this. I also pushed an empty commit to this branch to rerun the CI. Feel free to overwrite it. |
Done. The best way to support the vector API is implementing the |
I do not think that Naturally, I might be wrong about these suggestions of mine, thus please run me through your reasoning to make sure I am not missing something. Implementing formal interfaces in Julia is itself a very interesting topic with many threads on Discourse and experiments in Github repos, but no proper solution yet. |
I'm sorry I disappeared for a while :) |
No worries! I agree that implementing the AbstractVector interface would be useful, but subclassing AbstractVector does not contribute to that goal, unless there are some specific methods that are already defined for AbstractVector and that rely on methods defined for Occupations. Are you saying that your definitions of If these indeed work now, could you add a few "interface" unit tests? Checking that getting an index, getting a length, |
Sure, I'll rename Speaking of interfaces, I used this manual page which says that redefining |
Oh, I understand now! I am all on board with this. I do not envision other points to discuss and would be eager to merge this after the addition of a couple of interface tests. Thank you so much for this contribution!!! There are a couple of "correctness of interface implementation testing" packages in the ecosystem. I will add an issue to track the possible use of such a package in the future (not specifically for this contribution, rather in general). It can be a good google summer of code onboarding tasks too. |
Done. |
""" | ||
Calculate the matrix element <{m}|at_1...at_n a_1...a_n|{n}>. | ||
""" | ||
Base.@propagate_inbounds function coefficient(occ_m, occ_n, at_indices, a_indices) |
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.
given #147 , it seems some folks use this function even though it is internal. Do you mind keeping a version of it (a wrapper around your implementation) so that we do not break user code? I guess Hyrum's law strikes again https://www.hyrumslaw.com/
We should probably start keeping a changelog to make it easier for folks to notice when stuff like this happens.
Also, please go ahead and bump the version number to 0.4.18 - I will make a release immediately after merging this.
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.
Maybe also using @deprecate
to warn people they should not be using this (they should never have started, but too late for 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.
Let me backtrack on this, I misunderstood the report in #147 . No need to add anything or many any changes. I will reread and merge this soon.
state_transition!
instead ofcoefficient
allows to loop over occupations only once. The state index can be found by searching in the occupations list - but it is still way faster.These two tricks yield yet another ~300x performance boost :)
The
OccupationsIterator
interface can make it even faster, because for fermion states one can avoid storing all occupation vectors by calculating the state index using a formula - but I'd better leave it for another pull request.Before (36 modes, 3 fermions):
After:
UPD: Important detail is that the default state ordering in manybody bases is now slightly changed if
Nparticles
is a vector. Hope that does not break anything.