symmray.utils_test¶
Utility functions specifically for testing.
Attributes¶
Functions¶
|
Hash a set of keyword arguments to a deterministic integer, which can be |
|
Generate two random symmetric arrays and valid contraction |
|
Create a general, hermitian, or positive definite matrix (with conjugate |
Module Contents¶
- symmray.utils_test.hash_kwargs_to_int(**kwargs) int[source]¶
Hash a set of keyword arguments to a deterministic integer, which can be used for seeding random number generators in tests, for example, allowing a varying but reproducible seed.
- symmray.utils_test.rand_valid_tensordot(symmetry, ndim_a=None, ndim_b=None, ncon=None, charge_a=None, charge_b=None, min_ndim=1, max_ndim=5, min_d=1, max_d=3, dimension_multiplier=1, subsizes=None, seed=None, **kwargs)[source]¶
Generate two random symmetric arrays and valid contraction
axes. For testing purposes.- Parameters:
ndim_a (int or None) – Number of dimensions for the first array. If None, a random number is chosen between min_ndim and max_ndim (inclusive).
ndim_b (int or None) – Number of dimensions for the second array. If None, a random number is chosen between min_ndim and max_ndim (inclusive).
ncon (int or None) – Number of axes to contract. If None, a random number is chosen between 0 and min(ndim_a, ndim_b) (inclusive).
charge_a (charge_like or None) – Charge for the first array. If None, a random charge is chosen.
charge_b (charge_like or None) – Charge for the second array. If None, a random charge is chosen.
min_ndim (int) – Minimum number of dimensions for each array.
max_ndim (int) – Maximum number of dimensions for each array.
min_d (int) – Minimum dimension for each index. This is multiplied by dimension_multiplier if that is not None.
max_d (int) – Maximum dimension for each index. This is multiplied by dimension_multiplier if that is not None.
dimension_multiplier (int, optional) – Each index will have dimension d * dimension_multiplier where d is a random integer in [min_d, max_d]. Useful for generating flat arrays with exactly equally distributed charge sizes.
subsizes (str or None) – Passed to rand_index. If “equal”, all sectors will have equal size, required for flat arrays.
seed (int or np.random.Generator or None) – Random seed or generator. If None, a new generator is created.
**kwargs – Additional arguments passed to get_rand.
- Returns:
a (AbelianArray) – First random array.
b (AbelianArray) – Second random array.
axes (tuple[tuple[int, …], tuple[int, …]]) – Axes to contract.
- symmray.utils_test.rand_matrix(symmetry, d, seed=None, subsizes='equal', dtype='float64', fermionic=False, flat=False, matrix_type='general', d_per_charge=False)[source]¶
Create a general, hermitian, or positive definite matrix (with conjugate indices) with the given symmetry and shape (d, d). For testing purposes.
- Parameters:
d (int) – Dimension of each index. If d_per_charge is True, this is the dimension per charge sector, else it is the total dimension.
seed (int or np.random.Generator or None) – Random seed or generator. If None, a new generator is created.
subsizes (str or None) – Passed to rand_index. If “equal”, all sectors will have equal size, required for flat arrays.
fermionic (bool) – Whether the array should be fermionic.
flat (bool) – Whether to return a flat array (with a single index) instead of a block array. If True, subsizes must be “equal”.
matrix_type ({"general", "hermitian", "posdef"}) – Type of matrix to generate. “general” generates a general matrix, “hermitian” generates a hermitian matrix, and “posdef” generates a positive definite matrix.
d_per_charge (bool) – Whether d specifies the dimension per charge sector (True) or the total dimension (False). If True, the total dimension is determined by the symmetry and d, only valid for ZN.
- symmray.utils_test.rand_herm¶
- symmray.utils_test.rand_posdef¶