-
Notifications
You must be signed in to change notification settings - Fork 184
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 MCState.local_estimators #1179
Conversation
Codecov Report
@@ Coverage Diff @@
## master #1179 +/- ##
==========================================
- Coverage 82.26% 82.21% -0.06%
==========================================
Files 207 207
Lines 12512 12519 +7
Branches 1902 1907 +5
==========================================
- Hits 10293 10292 -1
- Misses 1776 1779 +3
- Partials 443 448 +5
Continue to review full report at Codecov.
|
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.
As far as the operators we define go, this looks good to me.
As for user-defined operators, I'm not sure about restricting ourselves to vstate.samples
. I mean, it makes sense in context, but for most common kernels, nothing depends on s==vstate.samples
. Also, relaxing this would allow implementing a local_estimators
for VariationalState
largely the same way (probably with some more elaborate dispatch rules). That would be nice, because you can reasonably ask for local estimators on an ExactState
(it still has a model with parameters, so there's no lower level to do that), but there isn't a default set of samples for that.
I guess the minimal change would be adding an optional σ
argument to get_local_kernel_arguments
, but this might be too breaking. Other ideas?
Co-authored-by: Attila Szabó <33730178+attila-i-szabo@users.noreply.github.com>
@attila-i-szabo I agree this would be nice and I think it could potentially be solved with dispatch in a backwards-compatible way: We extend the |
@PhilipVinc would something like @dispatch
def get_local_kernel_arguments(vstate: VariationalState, Ô: DiscreteOperator, σ: Optional[Array] = None): be found by dispatch if you call |
Yes. When you have a default value it gets converted into two functions: def get_local_kernel_arguments(vstate: VariationalState, Ô: DiscreteOperator, σ: Optional[Array] = None):
blabla becomes def get_local_kernel_arguments(vstate: VariationalState, Ô: DiscreteOperator):
return get_local_kernel_arguments(vstate, Ô, None)
def get_local_kernel_arguments(vstate: VariationalState, Ô: DiscreteOperator, σ: Optional[Array]):
blabla |
I was going through this PR.
I think we can restrict ourselves to the purposes of the
To give some context, the reason I put the logic taking the samples there is that for the specific combinations of mixed states + Standard Operators the samples must be manipulated before passing them to the kernel.
I agreee.
The third argument is already taken to be an (optional) -- In general, I'd like the guiding design principle of the internals to be done so that those things could be eventually used in conjunction with |
my suggestion would be to limit this to |
I agree with @gcarleo. The extensions we are discussing here can still be done after this PR is merged, as the only user-facing change at that point should be an added optional argument In the meantime, we can already use the local estimators for Any comments on this specific implementation? Or can it be megred? @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.
I would (for now) not support chunk_size
here.
The method is missing a jitting.
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.
Looks good assuming you un-nest the if statements
This reverts commit 2a7dded.
* Add MCState.local_estimators * Pass arbitrary `extra_args` Co-authored-by: Attila Szabó <33730178+attila-i-szabo@users.noreply.github.com> * JIT-compile local_estimators * Implement suggestions from code review
This PR adds an
MCState.local_estimators
method, addressing point 2 of #1178 (and superseding the previous PR #1154).It only supports computing the estimate for the current
vstate.samples
. That is a restriction because of the way the interface described in https://netket.readthedocs.io/en/latest/advanced/custom_operators.html allows extending operators in a way that depends on theVariationalState
, making it non-trivial to decouple that logic. Doing it this way should ensure that the same code path is used to compute the local estimators that is also used forexpect
.