archimedes.tree.fieldΒΆ

archimedes.tree.field(
static: bool = False,
*,
metadata: dict[str, Any] | None = None,
**kwargs,
) FieldΒΆ

Create a field specification with struct-related metadata.

This function extends dataclasses.field() with additional metadata to control how fields are treated in tree operations. Fields can be marked as static (metadata) or dynamic (data). Except for the static argument, all other arguments are passed directly to dataclasses.field().

Parameters:
  • static (bool, default=False) – If True, the field is treated as static metadata rather than dynamic data. Static fields are preserved during tree transformations but not included in the flattened representation.

  • metadata (dict, optional) – Additional metadata to include in the field specification. This will be merged with the static setting.

  • **kwargs (dict) – Additional keyword arguments passed to dataclasses.field().

Returns:

field_object – A field specification with the appropriate metadata.

Return type:

dataclasses.Field

Examples

>>> import structree as st
>>> import numpy as np
>>>
>>> @st.struct
>>> class Vehicle:
...     position: np.ndarray
...     velocity: np.ndarray
...     mass: float = st.field(static=True, default=1000.0)

See also

struct

Decorator for creating tree-compatible dataclasses

register_dataclass

Register a dataclass as compatible with tree operations