-
Notifications
You must be signed in to change notification settings - Fork 188
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
Make nk more extensible, pt 1: use dispatch in netket.hilbert.random #734
Conversation
Hello and thanks for your Contribution! Once the PR is closed or merged, the preview will be automatically deleted. |
Codecov Report
@@ Coverage Diff @@
## master #734 +/- ##
==========================================
+ Coverage 70.80% 71.25% +0.45%
==========================================
Files 230 231 +1
Lines 13370 13333 -37
Branches 1881 1870 -11
==========================================
+ Hits 9466 9500 +34
+ Misses 3388 3331 -57
+ Partials 516 502 -14
Continue to review full report at Codecov.
|
This is ready to be reviewed. It gives a stable API to override the default behaviour of random state generation. I'd like to write a section of the manual about it, but I won't do it now. |
|
||
|
||
@singledispatch | ||
@dispatch | ||
def flip_state_scalar(hilb, key, state, indx): |
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.
would it be possible to remove scalar and batch versions and replace them with a dispatch? or is it sci fi?
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 a sane language yes.
In an insane language like python sometimes.
I did it for random_state
because one of the inputs specifies the size of the output.
Here we should dispatch on the number of dimensions of state
which is not doable yet.
Apparently it might be doable in Python 3.10. but that's still off.
I'll try to think alternatives.
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's ok, this is still somehow an implementation detail but yeah if python 10 supports that we should go for it...!
Don't merge yet because maybe i have a solution... |
This is part 1 in making netket more easy to extend by moving to use dispatch in functions that might be extended and overridden by an user.
This PR does 2 things:
netket.utils.dispatch
instead offrom plum import dispatch
(even if they are identical) just for the sake that if, at some point, we need to change something in the dispatch, we just need to change it in one place.netket.hilbert.random
.The next step of this PR would be to make
DoubledHilbert
andTensorHilbert
parametric classes in order to create special dispatches (for example, ifDoubledHilbert[<:HomogeneousHilbert]
, there is no need to split the rows and columns because they all are identical).But I think this can be done in a second moment.
The next step would be to do the same for
MCState.expect
and.expect_and_grad
so an user could use his own, custom operators or anything with those two functions.