def random_state( self, key=NoneType(), size: Optional[int] = NoneType(), dtype=np.float32, out: Optional[np.ndarray] = None, rgen=None, ) -> jnp.ndarray: r"""Generates either a single or a batch of uniformly distributed random states. Runs as :code:`random_state(self, key, size=None, dtype=np.float32)` by default. Args: key: rng state from a jax-style functional generator. size: If provided, returns a batch of configurations of the form :code:`(size, N)` if size is an integer or :code:`(*size, N)` if it is a tuple and where :math:`N` is the Hilbert space size. By default, a single random configuration with shape :code:`(#,)` is returned. dtype: DType of the resulting vector. out: Deprecated. Will be removed in v3.1 rgen: Deprecated. Will be removed in v3.1 Returns: A state or batch of states sampled from the uniform distribution on the hilbert space. Example: >>> import netket, jax >>> hi = netket.hilbert.Qubit(N=2) >>> k1, k2 = jax.random.split(jax.random.PRNGKey(1)) >>> print(hi.random_state(key=k1)) [1. 0.] >>> print(hi.random_state(key=k2, size=2)) [[0. 0.] [0. 1.]] """ # legacy support # TODO: Remove in 3.1 # if no positional arguments, and key is unspecified -> legacy if isinstance(key, NoneType): warn_deprecation(legacy_warn_str) # legacy sure if isinstance(size, NoneType): return self._random_state_legacy(size=None, out=out, rgen=rgen) else: return self._random_state_legacy(size=size, out=out, rgen=rgen) elif (isinstance(key, tuple) or isinstance(key, int) and isinstance(size, NoneType)): # if one positional argument legacy typee... warn_deprecation(legacy_warn_str) return self._random_state_legacy(size=key, out=out, rgen=rgen) else: from netket.hilbert import random size = size if not isinstance(size, NoneType) else None return random.random_state(self, key, size, dtype=dtype)
def random_state( self, key=NoneType(), size: Optional[int] = NoneType(), dtype=np.float32, out: Optional[np.ndarray] = None, rgen=None, ) -> jnp.ndarray: r"""Generates either a single or a batch of uniformly distributed random states. random_state(self, key, size=None, dtype=np.float32) Args: key: rng state from a jax-style functional generator. size: If provided, returns a batch of configurations of the form (size, #) if size is an integer or (*size, #) if it is a tuple and where # is the Hilbert space size. By default, a single random configuration with shape (#,) is returned. dtype: Dtype of the resulting vector. out: Deprecated. Will be removed in v3.1 rgen: Deprecated. Will be removed in v3.1 Returns: A state or batch of states sampled from the uniform distribution on the hilbert space. Example: >>> hi = netket.hilbert.Qubit(N=2) >>> hi.random_state(jax.random.PRNGKey(0)) array([0., 1.]) >>> hi.random_state(size=2) array([[0., 0.], [1., 0.]]) """ # legacy support # TODO: Remove in 3.1 # if no positional arguments, and key is unspecified -> legacy if isinstance(key, NoneType): # legacy sure if isinstance(size, NoneType): return self._random_state_legacy(size=None, out=out, rgen=rgen) else: return self._random_state_legacy(size=size, out=out, rgen=rgen) elif (isinstance(key, tuple) or isinstance(key, int) and isinstance(size, NoneType)): # if one positional argument legacy typee... return self._random_state_legacy(size=key, out=out, rgen=rgen) else: from netket.hilbert import random size = size if not isinstance(size, NoneType) else None return random.random_state(self, key, size, dtype=dtype)
def random_state( self, key=None, size: Optional[int] = None, dtype=np.float32, ) -> jnp.ndarray: r"""Generates either a single or a batch of uniformly distributed random states. Runs as :code:`random_state(self, key, size=None, dtype=np.float32)` by default. Args: key: rng state from a jax-style functional generator. size: If provided, returns a batch of configurations of the form :code:`(size, N)` if size is an integer or :code:`(*size, N)` if it is a tuple and where :math:`N` is the Hilbert space size. By default, a single random configuration with shape :code:`(#,)` is returned. dtype: DType of the resulting vector. Returns: A state or batch of states sampled from the uniform distribution on the hilbert space. Example: >>> import netket, jax >>> hi = netket.hilbert.Qubit(N=2) >>> k1, k2 = jax.random.split(jax.random.PRNGKey(1)) >>> print(hi.random_state(key=k1)) [1. 0.] >>> print(hi.random_state(key=k2, size=2)) [[0. 0.] [0. 1.]] """ from netket.hilbert import random return random.random_state(self, key, size, dtype=dtype)