qewton.data.dataloaders package

Module contents

Subpackages

Submodules

qewton.data.dataloaders.base module

Base classes for data loading and node-based data sampling in the graph.

class qewton.data.dataloaders.base.PhaseBatchSize(node: DataNode)[source]

Bases: HyperParameter

The batch size of a DataNode in its current EvaluationPhase, see DataNode.current_batch_size. A dim bound to it (e.g. the batch axes of the outputs) follows the phase. It is derived from the batch sizes of the node, so it is neither tuned nor set.

Parameters:

node (DataNode) – The node whose batch size this is.

property value: int

Returns: _type_: The current value of this HyperParameter.

set_value(new_value)[source]
class qewton.data.dataloaders.base.DataNode(batch_size: int | DiscreteHyperparameter | CategoricalHyperparameter, name: str = 'DataNode', state: NodeState = NodeState.FIXED, backend: type[Backend[TensorType]] | None = <class 'qewton.backends.base.DeepLearningBackend'>, validation_batch_size: int | DiscreteHyperparameter | CategoricalHyperparameter | None = None, test_batch_size: int | DiscreteHyperparameter | CategoricalHyperparameter | None = None)[source]

Bases: Node[TensorType]

Creates a DataNode which task is to generate/load data for evaluation in the graph. This is a base class and should be subclassed for specific data loading implementations.

Parameters:
  • batch_size (int | DiscreteHyperparameter | CategoricalHyperparameter) – Number of samples per batch in training, and in every phase without a batch size of its own.

  • name (str, optional) – Display name of the node. Defaults to “DataNode”.

  • state (NodeState, optional) – Initial state of the node. Defaults to NodeState.FIXED.

  • backend (type[Backend] | None, optional) – Computing backend (e.g., TorchBackend). Defaults to DEFAULT_DL_BACKEND.

  • | (test_batch_size (int | DiscreteHyperparameter) – CategoricalHyperparameter | None, optional): Number of samples per batch in validation. Defaults to None, i.e. batch_size.

  • | – CategoricalHyperparameter | None, optional): Number of samples per batch in testing. Defaults to None, i.e. batch_size.

property batch_size: int

The number of samples per batch in training.

property validation_batch_size: int

The number of samples per batch in validation; batch_size if none was given.

property test_batch_size: int

The number of samples per batch in testing; batch_size if none was given.

property current_batch_size: int

the validation or test batch size in those phases, else batch_size.

Type:

The number of samples per batch in the current mode

property training_batches: int
property is_cached
property hyperparameters: list[HyperParameter]
cache(n_batches: int = -1)[source]
clear_cache()[source]
provides_data_in_phase(phase: EvaluationPhase) → bool[source]

Checks whether this node can provide data in the EvaluationPhase.

Parameters:

phase (EvaluationPhase) – The evaluation phase to check for data provision capability.

Returns:

If True, the node can provide data in the specified phase,

otherwise, False.

Return type:

bool

to(device: str | Device)[source]

Move the data node to the specified device.

Parameters:

device (str, Device) – The device to move the data node to (e.g., ‘cpu’, ‘cuda’).

visualize(mode: EvaluationPhase = EvaluationPhase.VALIDATION, plot_type: type[DataPlot] | None = None, controls: list[ControlAxis] = (), default_control: type[ControlAxis] | None = None, **plot_kwargs) → Layout[source]

Run this node on its own (a DataNode is always a graph source, so it needs no Graph) and build a layout showing every output port.

Parameters:
  • mode – The EvaluationPhase this node is run in; it determines which split supplies the batch.

  • plot_type – Passed to auto_plot() for every port.

  • controls – Control axes for chosen dimensions, passed to auto_plot for every port that has them.

  • default_control – Control axis class for every other dimension not drawn; None for auto_plot’s default. Every control is shared by all ports whose data has its axes or Variable (see AutoPlots).

  • **plot_kwargs – Passed to auto_plot for every port.

Returns:

The plots arranged by

auto_layout().

Return type:

Layout

Raises:

ValueError – If this node provides no data in mode.

qewton.data.dataloaders.data_loader module

The DataLoader: batches, shuffles and splits a DataSet for the graph.

class qewton.data.dataloaders.data_loader.DataLoader(data_set: DataSet, batch_size: int | DiscreteHyperparameter | CategoricalHyperparameter, splitting_ratio: tuple[float, float, float]=(1.0, 0.0, 0.0), shuffle_data: bool | CategoricalHyperparameter = True, shuffle_seed: int | None = None, backend: type[Backend[TensorType]] = <class 'qewton.backends.base.DeepLearningBackend'>, name: str = 'DataLoader', test_data_set: DataSet | None = None, validation_batch_size: int | DiscreteHyperparameter | CategoricalHyperparameter | None = None, test_batch_size: int | DiscreteHyperparameter | CategoricalHyperparameter | None = None)[source]

Bases: DataNode[TensorType]

Standard DataLoader module for batching, shuffling, and splitting datasets.

This node acts as a source in the computation graph, providing batches of data to connected algorithms.

Parameters:
  • data_set (DataSet) – The source dataset, split into Train/Validation/ Test according to splitting_ratio.

  • batch_size (int | DiscreteHyperparameter | CategoricalHyperparameter) – Number of samples per batch in training, and in every phase without a batch size of its own.

  • splitting_ratio (tuple[float, float, float], optional) – Proportions for (Train, Validation, Test) splits of data_set. Ignored for the Test split when test_data_set is given. Defaults to (1.0, 0.0, 0.0).

  • shuffle_data (bool | CategoricalHyperparameter, optional) – Whether to shuffle the indices at the start of an epoch.. Defaults to True.

  • shuffle_seed (int | None, optional) – Random seed for reproducibility. Defaults to None.

  • backend (type[Backend] | None, optional) – The backend used for data types and device transfers.. Defaults to DEFAULT_DL_BACKEND.

  • name (str, optional) – Name of this data loader. Defaults to “DataLoader”.

  • test_data_set (DataSet | None, optional) – A separate dataset used for the Test split instead of the portion of data_set that splitting_ratio would otherwise reserve for it. Must provide the same variables as data_set. Defaults to None.

  • | (test_batch_size (int | DiscreteHyperparameter) – CategoricalHyperparameter | None, optional): Number of samples per batch in the Validation split. Defaults to None, i.e. batch_size.

  • | – CategoricalHyperparameter | None, optional): Number of samples per batch in the Test split. Defaults to None, i.e. batch_size.

property training_batches: int
property input_ports: list[InputPort]
property output_ports: list[OutputPort]
property hyperparameters: list[HyperParameter]
set_mode(new_mode)[source]

Set the current evaluation phase.

Some nodes behave differently depending on the phase, e.g. dropout is disabled during validation.

Parameters:

new_mode – The new evaluation phase.

build() → None[source]

Create what the node computes with, e.g. the weights or the inner graph of a network, from the current hyperparameter values.

Called by setup() for a node that is not built yet; a tuner makes a node unbuilt again (reset()) before trying other hyperparameter values. Does nothing by default.

forward()[source]

Executes the data loading for one batch.

This method handles split indexing, batch slicing, and moving data to the appropriate device.

cache(n_batches=-1)[source]
provides_data_in_phase(phase: EvaluationPhase) → bool[source]

Checks whether this node can provide data in the EvaluationPhase.

Parameters:

phase (EvaluationPhase) – The evaluation phase to check for data provision capability.

Returns:

If True, the node can provide data in the specified phase,

otherwise, False.

Return type:

bool