Random number helpers (varipeps.utils.random)

Utility functions for initialize tensors randomly

class varipeps.utils.random.PEPS_Jax_Random(seed: int | None = None)[source]

Bases: PEPS_Random_Impl

Jax implementation for the random number generator.

Parameters:

seed (int, optional) – Seed for the generator.

Default: None

block(dim: Sequence[int], dtype: Type[number], *, normalize: bool = True) Array[source]

Generate a tensor with random numbers.

Parameters:
Keyword Arguments:

normalize (bool, optional) – Flag if the generated tensors are normalized. Defaults to True.

Default: True

Returns:

Tensor with random numbers and the specified shape.

Return type:

jax.numpy.ndarray or numpy.ndarray

positive_block(dim: Sequence[int], dtype: Type[number], *, normalize: bool = True) Array[source]
class varipeps.utils.random.PEPS_Numpy_Random(seed: int | None = None)[source]

Bases: PEPS_Random_Impl

Numpy implementation for the random number generator.

Parameters:

seed (int, optional) – Seed for the generator.

Default: None

block(dim: Sequence[int], dtype: Type[number], *, normalize: bool = True) ndarray[source]

Generate a tensor with random numbers.

Parameters:
Keyword Arguments:

normalize (bool, optional) – Flag if the generated tensors are normalized. Defaults to True.

Default: True

Returns:

Tensor with random numbers and the specified shape.

Return type:

jax.numpy.ndarray or numpy.ndarray

class varipeps.utils.random.PEPS_Random_Impl[source]

Bases: ABC

Abstract base class for random number generator implementation.

abstractmethod block(dim: Sequence[int], dtype: Type[number], *, normalize: bool = True) ndarray | Array[source]

Generate a tensor with random numbers.

Parameters:
Keyword Arguments:

normalize (bool, optional) – Flag if the generated tensors are normalized. Defaults to True.

Default: True

Returns:

Tensor with random numbers and the specified shape.

Return type:

jax.numpy.ndarray or numpy.ndarray

class varipeps.utils.random.PEPS_Random_Number_Generator[source]

Bases: object

Class to maintain a global instance of random number generators

classmethod destroy_state() None[source]

Destroy the current state of the random number generator.

classmethod get_generator(seed: int | None = None, *, backend: str = 'jax') PEPS_Random_Impl[source]

Class method to obtain the instance of the random number generator for the specific backend

Parameters:

seed (int, optional) – Seed for the random number generator. If there is already a instance of the generator, this parameter is ignored.

Default: None

Keyword Arguments:

backend (str, optional) – Backend which should be used as random number generator. May be jax or numpy. Defaults to jax.

Default: 'jax'

Returns:

Instance of random number generator implementation.

Return type:

PEPS_Jax_Random or PEPS_Numpy_Random