archimedes.tree.struct¶
Utilities for defining custom classes that can be used with pytree transformations.
This module provides tools for creating structured data types that work seamlessly with Archimedes’ pytree functions. These tools are built on Python’s dataclasses with extensions for pytree-specific behavior.
The module re-exports several names from the dataclasses module:
- InitVarType annotation for init-only variables in dataclasses
Used to mark fields that should be passed to __post_init__ but not stored.
- fieldsFunction to retrieve fields of a dataclass
Returns a list of Field objects representing the fields of the dataclass. This is useful for introspection and validation of dataclass instances.
- replaceFunction to create a new dataclass instance with updated fields
For pytree nodes created with @pytree_node, use the .replace() method instead.
Functions
|
Decorator to mark an object as providing dataclass-like behaviour. |
|
Create a field specification with pytree-related metadata. |
|
Return a tuple describing the fields of this dataclass. |
|
Check if an object is a registered pytree node. |
|
Decorator to convert a class into a frozen dataclass registered as a pytree node. |
|
Register a dataclass as a pytree node with customized field handling. |
|
Return a new object replacing specified fields with new values. |
Classes