Builder
Fluent API for building block/scope sparsity hierarchies.
Example:
builder = (
SparsityBuilder()
.add_block(param_u, (2, 2, 2, 2), name="U")
.add_block(param_v, (2, 2, 2, 2), name="V")
.add_scope("U", scope_shape=(1, 1), name="gU")
.add_scope("V", scope_shape=(1, 4), name="gV")
.couple_scopes(
["gU", "gV"],
orders=[(0,1,2,3), (1,0,2,3)],
name="UV",
)
)
coupling = builder.get_scope("UV")
- class sparsekit.builder.SparsityBuilder[source]
Bases:
objectFluent builder for constructing BlockSpec/ScopeSpec hierarchies.
All mutating methods return
selffor method chaining.- add_block(param, block_shape, name)[source]
Register a single parameter with its block decomposition.
- couple_blocks(block_names, orders, name)[source]
Create a BlockCoupling from previously added blocks.
- get_block(name)[source]
Retrieve a BlockSpec or BlockCoupling by name.
- Parameters:
name (str)
- Return type:
- add_scope(block_name, scope_shape, name)[source]
Add a ScopeSpec over an existing block or coupling.
- couple_scopes(scope_names, orders, name)[source]
Create a ScopeCoupling from previously added scopes.
Scopes are consumed (popped) from the builder when coupled.
- get_scope(name)[source]
Retrieve a ScopeSpec or ScopeCoupling by name.
- Parameters:
name (str)
- Return type: