How to use MetropolisSamplerNumpy #1160
-
Hello, I was trying to make a custom sampler by defining the transition rule. While it works with
gives output,
What am I doing wrong? Thank You. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 3 replies
-
The documentation of Therefore, it requires the transition kernels to be written in NumPy instead of Jax. Admittedly this is not mentioned anywhere, and we could improve the documentation. To write a NumPy Kernel, start from one of the existing numpy kernels for inspiration such as The reason for the existence of this numpy sampler is that when we started the rewrite of NetKet 3 in Jax, we could not write some transition rules in Jax efficiently (in particular As a lot happened since then, we should probably revisit whether we still need to have this dumpy-specific implementation or if this can be dropped. May I ask what transition rule you are trying to implement? |
Beta Was this translation helpful? Give feedback.
-
Thank you for the very quick answer. I have a custom Hilbert space with some symmetry related constraints and I want my transition rule to respect those constraints. I could not do this without using conditional statements. (Maybe I can create a minimum example and post here later.) I could implement that in Jax using its control flow primitives, which was not fun. The reason I am trying to go to NumPy is because for larger systems (>20 sites), the Jax sampler is very slow. For 40 sites or more, it takes hours for the optimization to start. I am still not sure what is the reason for this and wanted to compare it with a NumPy sampler. (I have narrowed it down to |
Beta Was this translation helpful? Give feedback.
The documentation of
MetropolisSamplerNumpy
says that this sampler is executed through Numpy instead of Jax that is the standard throught netket.Therefore, it requires the transition kernels to be written in NumPy instead of Jax. Admittedly this is not mentioned anywhere, and we could improve the documentation. To write a NumPy Kernel, start from one of the existing numpy kernels for inspiration such as
LocalRuleNumpy
orHamiltonianNumpy
or the very genericCustomNumpy
.The reason for the existence of this numpy sampler is that when we started the rewrite of NetKet 3 in Jax, we could not write some transition rules in Jax efficiently (in particular
HamiltonianRule
andCustom
) and therefo…