class penzai.core.selectors.SelectionHole[source]#

Bases: Struct

A hole in a structure, taking the place of a selected subtree.

When building a selection, the nodes that are selected are moved out of the original tree for easier processing. They are replaced by a SelectionHole, which points to the node that was here originally.

A SelectionHole is a PyTree with no children. This ensures that the selected elements are actually “removed” from the tree from JAX’s point of view.

Users should not need to create a SelectionHole directly, and should instead use the select(...) function and other selector traversals. However, you may see a SelectionHole if inspecting the contents of a Selection object.

Note that the Selection machinery assumes that the selected PyTree nodes do not require their children to be a specific type, so that we can insert SelectionHole in arbitrary places in the tree. If a node makes strong assumptions about the types of its children, it may not be possible to select those children, since rebuilding that node with a SelectionHole may fail.

See for more information on how to implement your PyTrees to avoid this problem.


path (KeyPath) – Keypath to this hole. Used to index back into the selected components.





Inherited Methods

(expand to view inherited methods)


Constructs a dictionary with all of the fields in the class.


Directly instantiates a struct given all of its fields.


Generates a JAX PyTree key for a given field name.


Wraps this struct in a selection, enabling functional-style mutations.


Flattens this tree node.


Flattens this tree node with keys.

tree_unflatten(aux_data, children)

Unflattens this tree node.


Computes a CSS color to display for this object in treescope.