vipr_reflectometry.flow_models package

Subpackages

Submodules

vipr_reflectometry.flow_models.q_generator module

Q-Generator components for VIPR reflectometry plugin.

This module contains custom Q-generators from the reflectorch fork that are not in the official reflectorch package.

class vipr_reflectometry.flow_models.q_generator.ConstantLogQ(q: Tensor | Tuple[float, float, int] = (0.01, 0.3, 128), device='cpu', dtype=torch.float32)

Bases: QGenerator

Q generator for reflectivity curves with fixed, logarithmically spaced discretization.

This generator creates Q-values with logarithmic spacing, which is useful for neutron reflectometry data where measurements are often taken on a logarithmic scale.

Parameters:
  • q (Union[Tensor, Tuple[float, float, int]], optional) – A pre-computed tensor of q-values, or a tuple (q_min, q_max, num_q) to define the log-spaced range. Defaults to (0.01, 0.3, 128).

  • device (optional) – The PyTorch device. Defaults to ‘cpu’.

  • dtype (optional) – The PyTorch data type. Defaults to torch.float32.

Example

>>> q_gen = ConstantLogQ(q=(0.005, 0.3, 256))
>>> q_batch = q_gen.get_batch(batch_size=32)
>>> print(q_batch.shape)  # torch.Size([32, 256])
get_batch(batch_size: int, context: dict | None = None) Tensor

Generate a batch of q values.

Parameters:
  • batch_size (int) – Number of samples in the batch

  • context (dict, optional) – Additional context (unused). Defaults to None.

Returns:

Batch of q-values with shape (batch_size, num_q)

Return type:

Tensor

scale_q(q: Tensor) Tensor

Scales the q values to the range [-1, 1].

This is useful for normalizing q-values for neural network inputs.

Parameters:

q (Tensor) – Unscaled q values

Returns:

Scaled q values in range [-1, 1]

Return type:

Tensor

class vipr_reflectometry.flow_models.q_generator.QGenerator

Bases: object

Base class for momentum transfer (q) generators

get_batch(batch_size: int, context: dict | None = None) Tensor

Module contents

vipr_reflectometry.flow_models.load(app)