qewton.config.data_configurations package¶
Module contents¶
Submodules¶
qewton.config.data_configurations.base module¶
- class qewton.config.data_configurations.base.DataConfiguration(*axes: Axes | EllipsisAxes, dtype=None, element_dtype=None)[source]¶
Bases:
SerializableA DataConfiguration describes the expected structure of the data, including the axes and their dimensions, as well as the data type. It is used to ensure that the data being passed through the graph matches the expected format for different methods/algorithms.
- Parameters:
*axes (Axes | EllipsisAxes) – The axes that describe the structure of the data.
dtype (_type_, optional) – The datatype used in this configuration. Defaults to None.
element_dtype (optional) – The dtype of the elements of a tensor, a marker of
qewton.config.dtypessuch as Float32; None leaves it open.
A configuration as such is a declaration, e.g. of a port, and never changes; matching works on its instances in a
Matching(DynamicDataConfiguration).- element_dtype: Any = None¶
The dtype of the elements of a tensor; None leaves it open.
- replace(axes: Axes, new_axes: list[Axes]) DataConfiguration[source]¶
A configuration with axes replaced by new_axes, describing the same data reshaped:
data.reshape(new.shape).- Parameters:
axes – Axes of this configuration.
new_axes – Axes with as many elements as axes, in row-major order.
- Returns:
The new configuration, with the same dtype.
- Return type:
- Raises:
ValueError – If axes is not part of this configuration or the number of elements differs.
- classmethod empty()[source]¶
Builds an empty data configuration with only an ellipsis axis. This can be used as a placeholder when no specific data configuration is needed or when the data structure is completely flexible.
- Returns:
The empty data configuration.
- Return type:
- property variables¶
Returns all variables defined in the feature axes of this data configuration.
- Returns:
The list of variables.
- Return type:
list[Variables]
- property variable_name¶
Returns the name of the variable defined in the feature axes of this data configuration. :returns:
- The name of the variable, or an empty string
if no variable is defined.
- Return type:
str
- property shape: tuple[int | None | EllipsisType, ...]¶
- property feature_axes: FeatureAxes | None¶
Returns the feature axes of this configuration.
- Returns:
The feature axes if defined, otherwise None.
- Return type:
FeatureAxes | None
- property geometry_axes: GeometryAxes | list[GeometryAxes] | None¶
Returns the geometry axes of this configuration.
- Returns:
- The geometry axes if
defined, otherwise None.
- Return type:
GeometryAxes | list[GeometryAxes] | None
- belongs_to(matching) bool[source]¶
Whether this configuration is an instance in matching; a declaration belongs to none.
- matches(other: DataConfiguration) bool[source]¶
Check if both data configurations describe the same data.
- Parameters:
other (DataConfiguration) – Other data configuration to compare with.
- Returns:
- Whether the data configurations match,
meaning they describe the same data structure and type.
- Return type:
bool
- classmethod of_value(value: Any) DataConfiguration | None[source]¶
The configuration of a given value, e.g. the default of an unconnected input: none for a Python scalar, axes of unknown kind for an array; None if nothing is known about it.
- axes_of(reference: Variable | Axes) Axes[source]¶
Find the axes of this configuration that hold a reference.
- Parameters:
reference – An Axes of this configuration, or a Variable (or a part of one) of a GeometryAxes’ geometry or of the FeatureAxes.
- Returns:
- reference itself if it is an Axes, otherwise the
FeatureAxes or GeometryAxes whose variable contains it. A Variable held by both, e.g. the coordinates of a geometry given as data, lies in the FeatureAxes: the data holds its values.
- Return type:
- Raises:
ValueError – If no axes of this configuration hold reference.
- describe() str[source]¶
What the axes of this configuration hold, by name, e.g.
"batch axes (50), the geometry of t (50), the features u, p".- Returns:
One part per axes.
- Return type:
str
- get_variable_slice(variable: Variable) tuple[source]¶
Computes the slice indices to obtain the variables along the current configuration.
- Parameters:
variable (Variable) – The variable for which to compute the slice indices.
- Returns:
- The slice indices to obtain the variable along the
current configuration.
- Return type:
tuple
- get_slice(data_config: DataConfiguration)[source]¶
- save(serializer: Serializer) None[source]¶
The save method is responsible for serializing the object’s state. It collects the object’s attributes and adds them to the serializer.
- Parameters:
serializer (Serializer) – The serializer instance that manages the serialization process.
- load(serializer: Deserializer, data_config: dict) None[source]¶
Loads the object’s state from the serialized data. It sets the object’s attributes based on the serialized data.
- Parameters:
serializer (Deserializer) – The deserializer instance that manages the loading process.
data_config (dict) – A dictionary containing the serialized data for the object.
- ready_to_load(serializer: Deserializer, data_config: dict) bool[source]¶
Checks if all dependencies of the object are ready to be loaded.
- Parameters:
serializer (Deserializer) – The deserializer instance that manages the loading process.
data_config (dict) – A dictionary containing the serialized data for the object.
- Returns:
- If the object is ready to be loaded (i.e., all its
dependencies are ready).
- Return type:
bool
qewton.config.data_configurations.dynamic module¶
Configurations at a place of a matching:
DynamicDataConfiguration.
- class qewton.config.data_configurations.dynamic.DynamicDataConfiguration(*axes, matching: Matching, dtype=None, element_dtype=None)[source]¶
Bases:
DataConfigurationThe configuration of a port at a place of a
Matching, e.g. of a node in a graph: an instance of its declaration that matching makes more concrete.Merging (
merge()) and the shape operations work through the matching: what they fix (e.g. that a dim is 1) is kept there, and their results belong to it;resolve()shows what is known so far. Node authors get configurations of this kind inrelate().- Parameters:
*axes (Axes | EllipsisAxes) – The axes that describe the structure of the data.
matching – The matching this configuration belongs to.
dtype (optional) – The datatype; None leaves it open.
element_dtype (optional) – The dtype of the elements of a tensor; None leaves it open.
- merge(other: DataConfiguration) None[source]¶
Make this configuration and other describe the same data in the matching (see
Matching.merge_configurations()): corresponding axes and dims become one group, ellipses are bound to what they stand for, the dtypes are merged. Callresolve()to see the result.- Parameters:
other – The configuration to merge with, of the matching or a declaration.
- Raises:
DataConfigMismatchError – If the configurations contradict.
- resolve() DynamicDataConfiguration[source]¶
This configuration as known so far: merged objects replaced by their representatives, bound ellipses by what they stand for (see
Matching.resolve()).- Returns:
The resolved configuration.
- Return type:
- belongs_to(matching) bool[source]¶
Whether this configuration is an instance in matching; a declaration belongs to none.
- merge_dim(index: int, dim: AxesDim) None[source]¶
Make the dim at index one with dim, e.g. to relate it to a size of the node (see
merge()).
- drop(index: int) DynamicDataConfiguration[source]¶
The configuration without the dim at index, e.g. after a sum over it without keeping it.
- squeeze(index: int) DynamicDataConfiguration[source]¶
The configuration without the dim at index, which has size 1.
- set_size(index: int, size: int | AxesDim) DynamicDataConfiguration[source]¶
The configuration with the dim at index of size, e.g. 1 after a sum over it keeping it.
- unsqueeze(index: int) DynamicDataConfiguration[source]¶
The configuration with a new dim of size 1 at index of the result.
- permute(order: list[int]) DynamicDataConfiguration[source]¶
The configuration with its dims in order, which also fixes their number.
- flatten(start: int = 0, end: int = -1) DynamicDataConfiguration[source]¶
The configuration with the dims from start to end merged into one, whose size is their product.
- unflatten(index: int, sizes: tuple[int, ...]) DynamicDataConfiguration[source]¶
The configuration with the dim at index split into dims of sizes; one of them may be -1.
- reshape(sizes: tuple[int, ...]) DynamicDataConfiguration[source]¶
The configuration of the data reshaped to sizes; one of them may be -1. The new dims belong to axes of unknown kind.
- concat(others: list[DataConfiguration], index: int) DynamicDataConfiguration[source]¶
The configuration of this data and others joined along the dim at index, whose size is their sum; all other dims are merged.
- split(index: int, sizes: list[int]) list[DynamicDataConfiguration][source]¶
The configurations of the pieces of this data split along the dim at index into sizes, whose sum is that dim.
- broadcast(other: DataConfiguration) DynamicDataConfiguration[source]¶
The configuration that this data and other broadcast to, aligned from the last dim; where one has size 1, the other’s dim (and axes) is taken. Its dtype is left open.
- Raises:
StructureUnknown – While the structure of either is unknown.
- window(index: int, kernel: int, stride: int = 1, padding: int = 0, dilation: int = 1) DynamicDataConfiguration[source]¶
The configuration after a sliding window (a convolution or pooling) over the dim at index.
qewton.config.data_configurations.grid module¶
- class qewton.config.data_configurations.grid.GridDataConfig(shape, feature_variable, geometry_variable=None, dtype=None)[source]¶
Bases:
DataConfigurationA DataConfiguration for data on a regular grid, with axes [batch, *grid, feature].
- Parameters:
shape (tuple[int, ...]) – Full data shape, as (batch_size, *grid_shape, feature_dim).
feature_variable (Variable) – The variable describing the feature axis. Its dim must equal shape[-1].
geometry_variable (Variable, optional) – The variable connected to the grid geometry. Its dim must equal len(shape) - 2. Defaults to an auto-named Variable(“grid”, …) matching the grid’s dimensionality.
dtype (optional) – The datatype used in this configuration. Defaults to None.
- Raises:
AssertionError – If feature_variable’s dim does not match shape[-1].
- qewton.config.data_configurations.grid.GridDataConfiguration¶
alias of
GridDataConfig