sample_builder.sample_generator
User level functions for generating samples.
FIXME: write proper doc-string
@private
Copyright © 2022-2025 HQS Quantum Simulations GmbH. All Rights Reserved.
Generate a mask.
Arguments:
- positions (np.ndarray): Sites' positions.
- attrs (dict): dictionary specifying the mask to generate.
Raises:
- ValueError: if attrs["shape"] is not valid.
- ValueError: if the shape of the positions is not valid.
Returns:
np.ndarray: array of the same shape of r, selecting the wanted sites.
Generate a modulation from a provided sampled distribution profile.
Arguments:
- positions (np.ndarray): Sites positions.
- direction (Union[list[float], np.ndarray]): Direction in which to generate the stacks.
- sampled_distributions (Union[list, np.ndarray]): sampled distribution profile for each species. Columns should contain the sampled distribution for each species.
- x_distribution: (Optional[Union[list, np.ndarray]]): The x-coordinates of the data points of the sampled distributions. The same x-coordinates will be used for all distributions.
- order: (int): The order of the interpolation. Defaults to 1 (linear interpolation).
Returns:
np.ndarray: modulation according to the provided sampled profiles.
Generate a uniform modulation.
Arguments:
- positions (np.ndarray): Sites positions.
- distribution (Union[list, np.ndarray]): Distribution to be assigned to each site.
Returns:
np.ndarray: Uniform modulation.
Generate a stacks modulation.
The system will be divided in different stacks along the selected direction and each stack will have the probability distribution defined in the homonymous argument.
Arguments:
- positions (np.ndarray): Sites' positions.
- direction (Union[list, np.ndarray]): Direction in which to generate the stacks.
- widths (Union[list, np.ndarray]): Widths of the different stacks.
- distributions (Union[list, np.ndarray]): Distributions for each stack in a nested list, e.g., [[0.5, 0.5], [1, 0]] for two stacks and two species.
- transition_width (float): Width of the smooth transition between stacks. Defaults to 0.
Returns:
np.ndarray: Stacks modulation.
Generate linear modulation.
The probability of the selected species will be modulated linearly along the specified direction according to the arguments passed. The rest of the probability (up to a total of 1) will be distributed uniformly among the other species.
Arguments:
- positions (np.ndarray): Sites' positions.
- direction (Union[list, np.ndarray]): Direction of the linear modulation.
- selected_species (int): Species which should be linearly modulated.
- n_species (int): Total number of species to be generated.
- start_value (float): Starting modulation value, should be in [0, 1].
- stop_value (float): Final modulation value, should be in [0, 1].
- from_unit_cell_idx (Optional[Union[list, np.ndarray]]): Unit cell index from which to start the linear modulation. Should have format [x_idx, y_idx, z_idx].
- to_unit_cell_idx (Optional[Union[list, np.ndarray]]): Last unit cell index of the linear modulation. Should have format [x_idx, y_idx, z_idx].
Raises:
- ValueError: If startValue or stopValue are not within [0, 1].
Returns:
np.ndarray: linear modulation.
Generate sinusoidal modulation of one or more species.
The probability of the selected species (single or multiple) will be modulated as
.. math: y0 + amplitude sin(\frac{2 \pi}{wavelength} (pp - phi))
where pp are the positions projected in the selected direction. The rest of the probability (up to a total of 1) will be distributed uniformly among the rest of the species.
Arguments:
- positions (np.ndarray): Sites' positions.
- direction (Union[list, np.ndarray]): Direction of the sinusoidal modulation.
- selected_species (Union[list, int]): Single or multiple species to modulate.
- n_species (int): Total number of species to be generated.
- y0 (Union[list, float]): Average value(s) of the modulation(s).
- amplitude (Union[list, float]): Amplitude(s) of the modulation(s).
- wavelength (Union[list, float]): Wavelength(s) of the modulation(s).
- phi (Optional[Union[list, int]]): Phase shift(s) of the modulation(s).
Raises:
- ValueError: if any inconsistency with the input is detected.
Returns:
np.ndarray: Sinusoidal modulation.
Generate cosinusoidal modulation of one or more species.
The probability of the selected species (single or multiple) will be modulated as
.. math: y0 + amplitude cos(\frac{2 \pi}{wavelength} (pp - phi))
where pp are the positions projected in the selected direction. The rest of the probability (up to a total of 1) will be distributed uniformly among the rest of the species.
Arguments:
- positions (np.ndarray): Sites' positions.
- direction (Union[list, np.ndarray]): Direction of the sinusoidal modulation.
- selected_species (Union[list, int]): Single or multiple species to modulate.
- n_species (int): Total number of species to be generated.
- y0 (Union[list, float]): Average value(s) of the modulation(s).
- amplitude (Union[list, float]): Amplitude(s) of the modulation(s).
- wavelength (Union[list, float]): Wavelength(s) of the modulation(s).
- phi (Optional[Union[list, int]]): Phase shift(s) of the modulation(s).
Raises:
- ValueError: if any inconsistency with the input is detected.
Returns:
np.ndarray: Cosinusoidal modulation.
Generate random choice given the probability distribution.
Generates an integer between 0 and N, with the given probabilities. N is the number of probabilities passed.
Arguments:
- site_dist (np.ndarray): probability distribution for the choice
- rng (np.random.Generator): random number generator to be used.
Returns:
int: random choice given the probabilities.
Generate random sample given the probability distribution.
For each site, generates an integer between 0 and N, with the given probabilities. N is the number of probabilities for each site.
Arguments:
- site_dist (np.ndarray): probability distribution for the whole sample.
- rng (np.random.Generator): random number generator to be used.
Returns:
np.ndarray: random choice given the probabilities.
Combine masks and modulations while performing consistency checks.
Arguments:
- mods (list): list of modulations to combine.
- masks (list): list of corresponing masks.
Raises:
- ValueError: if the masks are not complementary.
Returns:
np.ndarray: combined modulation.
Combine modulations according to the specified operation.
Arguments:
- mods (list): list of modulations to combine.
- operation (str): type of operation used for mixing.
- default (Optional[list]): default distribution for cases where NaNs appear.
Raises:
- ValueError: if the operation is not valid.
Returns:
np.ndarray: combined modulation.
Generate a view of the provided sample.
NOTE: not the most general. Silently assumes sample is of the shape (x, y, z, unit_cell).
Arguments:
- sample (np.ndarray): Sample.
- window_pos (Union[list, np.ndarray]): Position (x, y, z) of the selecting window.
- window_size (Union[list, np.ndarray]): Size of the window.
Raises:
- ValueError: if the provided window parameters result in an out-of-bounds window.
Returns:
np.ndarray: View over the original sample.