PyTree Utilities¶
Core Utilities¶
fdtdx.core.jax.pytrees.extended_autoinit(klass)
¶
Wrapper around tc.autoinit that preserves parameter requirement information
Source code in src/fdtdx/core/jax/pytrees.py
fdtdx.core.jax.pytrees.field(*, default=NULL, init=True, repr=True, kind='POS_OR_KW', metadata=None, on_setattr=(), on_getattr=(), alias=None)
¶
Creates a field that automatically freezes on set and unfreezes on get.
This field behaves like a regular pytreeclass field but ensures values are frozen when stored and unfrozen when accessed.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
default
|
Any
|
The default value for the field |
NULL
|
init
|
bool
|
Whether to include the field in init |
True
|
repr
|
bool
|
Whether to include the field in repr |
True
|
kind
|
ArgKindType
|
The argument kind (POS_ONLY, POS_OR_KW, etc.) |
'POS_OR_KW'
|
metadata
|
dict[str, Any] | None
|
Additional metadata for the field |
None
|
on_setattr
|
Sequence[Any]
|
Additional setattr callbacks (applied after freezing) |
()
|
on_getattr
|
Sequence[Any]
|
Additional getattr callbacks (applied after unfreezing) |
()
|
alias
|
str | None
|
Alternative name for the field in init |
None
|
Returns:
Type | Description |
---|---|
Any
|
A Field instance configured with freeze/unfreeze behavior |
Source code in src/fdtdx/core/jax/pytrees.py
fdtdx.core.jax.pytrees.frozen_field(*, default=NULL, init=True, repr=True, kind='POS_OR_KW', metadata=None, on_setattr=(), on_getattr=(), alias=None)
¶
Creates a field that automatically freezes on set and unfreezes on get.
This field behaves like a regular pytreeclass field but ensures values are frozen when stored and unfrozen when accessed.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
default
|
Any
|
The default value for the field |
NULL
|
init
|
bool
|
Whether to include the field in init |
True
|
repr
|
bool
|
Whether to include the field in repr |
True
|
kind
|
ArgKindType
|
The argument kind (POS_ONLY, POS_OR_KW, etc.) |
'POS_OR_KW'
|
metadata
|
dict[str, Any] | None
|
Additional metadata for the field |
None
|
on_setattr
|
Sequence[Any]
|
Additional setattr callbacks (applied after freezing) |
()
|
on_getattr
|
Sequence[Any]
|
Additional getattr callbacks (applied after unfreezing) |
()
|
alias
|
str | None
|
Alternative name for the field in init |
None
|
Returns:
Type | Description |
---|---|
Any
|
A Field instance configured with freeze/unfreeze behavior |
Source code in src/fdtdx/core/jax/pytrees.py
fdtdx.core.jax.pytrees.frozen_private_field(*, default=None, init=False, repr=True, kind='POS_OR_KW', metadata=None, on_setattr=(), on_getattr=(), alias=None)
¶
Creates a field that automatically freezes on set and unfreezes on get, sets the default to None and init to False.
This field behaves like a regular pytreeclass field but ensures values are frozen when stored and unfrozen when accessed.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
default
|
Any
|
The default value for the field |
None
|
init
|
bool
|
Whether to include the field in init |
False
|
repr
|
bool
|
Whether to include the field in repr |
True
|
kind
|
ArgKindType
|
The argument kind (POS_ONLY, POS_OR_KW, etc.) |
'POS_OR_KW'
|
metadata
|
dict[str, Any] | None
|
Additional metadata for the field |
None
|
on_setattr
|
Sequence[Any]
|
Additional setattr callbacks (applied after freezing) |
()
|
on_getattr
|
Sequence[Any]
|
Additional getattr callbacks (applied after unfreezing) |
()
|
alias
|
str | None
|
Alternative name for the field in init |
None
|
Returns:
Type | Description |
---|---|
Any
|
A Field instance configured with freeze/unfreeze behavior |
Source code in src/fdtdx/core/jax/pytrees.py
Tree Classes and Fields¶
fdtdx.core.jax.pytrees.ExtendedTreeClassIndexer
¶
Bases: TreeClassIndexer
Extended indexer for tree class that preserves type information.
Extends TreeClassIndexer to properly handle type hints and return Self type.
Source code in src/fdtdx/core/jax/pytrees.py
__getitem__(where)
¶
Gets item at specified index while preserving type information.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
where
|
Any
|
Index or key to access |
required |
Returns:
Name | Type | Description |
---|---|---|
Self |
Self
|
The indexed item with proper type information preserved |
Source code in src/fdtdx/core/jax/pytrees.py
fdtdx.core.jax.pytrees.ExtendedTreeClass
¶
Bases: TreeClass
Extended tree class with improved attribute setting functionality.
Extends TreeClass to provide more flexible attribute setting capabilities, particularly for handling non-recursive attribute updates.
Source code in src/fdtdx/core/jax/pytrees.py
at: ExtendedTreeClassIndexer
property
¶
Gets the extended indexer for this tree.
Returns:
Name | Type | Description |
---|---|---|
ExtendedTreeClassIndexer |
ExtendedTreeClassIndexer
|
Indexer that preserves type information |
aset(attr_name, val)
¶
Sets an attribute directly without recursive application.
Similar to Self.at[attr_name].set(val), but without recursively applying to each tree leaf. Instead, replaces the full attribute with the new value.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
attr_name
|
str
|
Name of attribute to set |
required |
val
|
Any
|
Value to set the attribute to |
required |
Returns:
Name | Type | Description |
---|---|---|
Self |
Self
|
Updated instance with new attribute value |