Skip to content

Improve Hilbert space random_state interface

Vicentini Filippo requested to merge github/fork/femtobit/hilbert-random into master

Created by: femtobit

This PR contains the following:

(a) Add an optional batch argument to AbstractHilbert.random_state. It is then possible to generate a batch of random states at once for convenience.

>>> hi = Spin(s=1/2, N=8)
>>> hi.random_state(batch=4)
array([[-1., -1.,  1.,  1.,  1.,  1., -1.,  1.],
       [-1., -1., -1., -1.,  1.,  1.,  1.,  1.],
       [ 1., -1., -1.,  1., -1., -1.,  1.,  1.],
       [-1., -1.,  1., -1.,  1.,  1.,  1., -1.]])

By default, random_state still returns a ndim=1 single configuration, to get a single conf with batch dim one has to call random_state(batch=1).

>>> hi.random_state()
array([-1., -1.,  1., -1., -1.,  1.,  1.,  1.])
>>> hi.random_state(batch=1)
array([[ 1., -1.,  1.,  1., -1.,  1.,  1., -1.]])

(b) Remove random_vals in favor of random_state (as the former is deprecated and equivalent to the later). We could alternatively keep it as an alias with a FutureWarning for now, if desired.

(c) Some minor interface changes (such as making the random_state arguments kw-only).

(d) Add optional n_max to Boson.random_state, which might be useful for unconstrained Boson spaces (where otherwise the method defaults to uniformly picking boson numbers in range(INT_MAX) which is rarely sensible).

Merge request reports