symmray.utils¶
Utility functions, mostly for generating random symmray indices and arrays
Attributes¶
Classes¶
Simple wrapper to make numpy.random.RandomState have the same |
Functions¶
|
|
|
Mark a method as one that must be implemented in a subclass, but only |
|
|
|
|
|
Get a function that produces numpy arrays of random numbers with the |
|
Randomly partition d into n sizes each of size at least 1. |
|
Get a list of |
|
Generate a random ZN index with the given dimension and order. |
|
|
|
Get a list of |
|
Generate a random U1 index with the given dimension. |
|
Get a list of |
|
|
|
Get a random index with the given symmetry. |
|
Get the array class for the given symmetry, fermionic flag, and flat |
|
|
|
Get a random symmray array, with the given symmetry and shape. The |
|
|
|
Module Contents¶
- symmray.utils.DEBUG¶
- symmray.utils.lazyabstractmethod(method)[source]¶
Mark a method as one that must be implemented in a subclass, but only enforce this when the method is called. This can be used as a decorator (if you want to demonstrate the call signature) or by directly assigning the result to a method name.
- class symmray.utils.RandomStateTranslated(rng)[source]¶
Simple wrapper to make numpy.random.RandomState have the same interface as numpy.random.Generator.
- rng¶
- symmray.utils.get_random_fill_fn(seed=None, dist='normal', dtype='float64', scale=1.0, loc=0.0)[source]¶
Get a function that produces numpy arrays of random numbers with the specified distribution, dtype, loc, and scale.
- Parameters:
seed (None, int, or numpy.random.Generator, optional) – The seed for the random number generator.
dist (str, optional) – The distribution of the random numbers. Can be “normal” or “uniform” or any other distribution supported by numpy.
dtype (str, optional) – The data type of the random numbers. If “complex”, the real and imaginary parts are generated separately and added.
scale (float, optional) – A multiplicative factor to the distribution.
loc (float, optional) – An additive offset to the distribution.
- Returns:
A function with signature fill_fn(shape) -> numpy.ndarray.
- Return type:
callable
- symmray.utils.rand_partition(d, n, seed=None)[source]¶
Randomly partition d into n sizes each of size at least 1.
- symmray.utils.get_zn_charges(ncharge, order)[source]¶
Get a list of
nchargedistinct ZN charges that are as close to 0 or |G| as possible, with a slight bias towards positive charges.
- symmray.utils.rand_zn_index(d, order, dual='random', subsizes='random', seed=None)[source]¶
Generate a random ZN index with the given dimension and order.
- Parameters:
d (int, dict[hashable, int] or sequence[(hashable, int), ...]) – The total size of the index. If a dict, an explicit chargemap. If a sequence, a linearmap.
order (int) – The order (i.e. size, N) of the cyclic group ZN.
dual (bool or "random", optional) – The dualness of the index. If “random”, it is randomly chosen.
subsizes ("random", "equal", "maximal", "minimal", or tuple[int], optional) –
The sizes of the charge sectors. The choices are as follows:
”random”: the charges and sizes are randomly determined.
”equal”: a fixed number of charges ‘close to’ zero charge are chosen, all with equal size (up to remainders).
”maximal”: as many charges as possible are chosen, each with size 1 (or more if the total number of charges is less than the total size).
”minimal”: only the zero charge sector is chosen, with full size.
tuple: the sizes of the charge sectors, a matching number of charges are chosen automatically, in sequence ‘closest to zero’.
seed (None, int, or numpy.random.Generator, optional) – The seed for the random number generator.
- Return type:
- symmray.utils.rand_z2_index¶
- symmray.utils.get_u1_charges(ncharge)[source]¶
Get a list of
nchargedistinct U1 charges that are as close to the origin as possible, with a slight bias towards positive charges.
- symmray.utils.rand_u1_index(d, dual='random', subsizes='random', seed=None)[source]¶
Generate a random U1 index with the given dimension.
- Parameters:
d (int) – The total size of the index.
dual (bool or "random", optional) – The dualness of the index. If “random”, it is randomly chosen.
subsizes ("random", "equal", "maximal", "minimal", or tuple[int], optional) –
The sizes of the charge sectors. The choices are as follows:
”random”: the charges and sizes are randomly determined.
”equal”: a fixed number of charges ‘close to’ zero charge are chosen, all with equal size (up to remainders).
”maximal”: as many charges as possible are chosen, each with size 1 (or more if the total number of charges is less than the total size).
”minimal”: only the zero charge sector is chosen, with full size.
tuple: the sizes of the charge sectors, a matching number of charges are chosen automatically, in sequence ‘closest to zero’.
seed (None, int, or numpy.random.Generator, optional) – The seed for the random number generator.
- Return type:
- symmray.utils.get_u1u1_charges(ncharge)[source]¶
Get a list of
nchargedistinct U1U1 charges that are as close to the origin as possible.
- symmray.utils.rand_index(symmetry, d, dual='random', subsizes='random', seed=None)[source]¶
Get a random index with the given symmetry.
- Parameters:
d (int, dict, sequence, or BlockIndex) – The total size of the index. If a dict, an explicit chargemap. If a sequence an explicit linearmap. If a BlockIndex, it is returned unchanged.
dual (bool or "random", optional) – The dualness of the index. If “random”, it is randomly chosen.
subsizes ("random", "equal", "maximal", "minimal", or tuple[int], optional) –
The sizes of the charge sectors. The choices are as follows:
”random”: the charges and sizes are randomly determined.
”equal”: a fixed number of charges ‘close to’ zero charge are chosen, all with equal size (up to remainders).
”maximal”: as many charges as possible are chosen, each with size 1 (or more if the total number of charges is less than the total size).
”minimal”: only the zero charge sector is chosen, with full size.
tuple: the sizes of the charge sectors, a matching number of charges are chosen automatically, in sequence ‘closest to zero’.
seed (None, int, or numpy.random.Generator, optional) – The seed for the random number generator.
- Return type:
- symmray.utils.get_array_cls(symmetry, fermionic=False, flat=False) type[source]¶
Get the array class for the given symmetry, fermionic flag, and flat flag.
- symmray.utils.get_rand(symmetry, shape, duals='random', charge=None, seed=None, dist='normal', fermionic=False, label=None, flat=False, subsizes='random', **kwargs)[source]¶
Get a random symmray array, with the given symmetry and shape. The duals, charge, and sub charge sizes can be specified or automatically or randomly generated.
- Parameters:
symmetry (str) – The symmetry of the array.
shape (tuple[int | dict | sequence | BlockIndex, ...]) – The desired overall effective shape of the array. Each element can be an int, in which case the charge sizes will be generated automatically according to subsizes, or an explicit dict of charge sizes, or an explicit linearmap, or a BlockIndex.
duals ("random", "equals", or Sequence[bool], optional) – The dualness of each index. If “random”, the dualnesses are chosen randomly. If “equal”, they are chosen so the first half of the indices have dual=False and the second half have dual=True. If shape contains BlockIndex objects, the dualness of that index takes precedence over any specification here.
charge (int or tuple[int], optional) – The total charge of the array. If not given the ‘zero’ charge is used, which depends on the symmetry.
seed (None, int, or numpy.random.Generator, optional) – The seed for the random number generator.
dist (str, optional) – The distribution of the random numbers. Can be “normal” or “uniform”.
fermionic (bool, optional) – Whether to generate a fermionic array.
label (hashable, optional) – An optional label for the array, potentially needed for ordering dummy odd fermionic modes.
flat (bool, optional) – Whether to generate a ‘flat’ backend array (True) or the default block-sparse backend array (False). If flat, then subsizes should be set to “equal” or equivalent.
subsizes ("random", "equal", "maximal", "minimal", or tuple[int], optional) –
The sizes of the charge sectors. The choices are as follows:
”random”: the charges and sizes are randomly determined.
”equal”: a fixed number of charges ‘close to’ zero charge are chosen, all with equal size (up to remainders).
”maximal”: as many charges as possible are chosen, each with size 1 (or more if the total number of charges is less than the total size).
”minimal”: only the zero charge sector is chosen, with full size.
tuple: the sizes of the charge sectors, a matching number of charges are chosen automatically, in sequence ‘closest to zero’.
If shape contains dict or BlockIndex objects, the subsizes of those indices take precedence over any specification here.
kwargs – Additional keyword arguments are passed to the random array generation function.
- Return type: