Schema Mutation
Use model methods to change a live schema. They validate the edit, rebuild the runtime graph, and retain state-dictionary entries whose names, types, and tensor shapes still match. An edit can therefore retain some learned state while initializing incompatible parts anew.
Select And Update
Predicates combine with logical AND. Inspect selected addresses before making a broad change:
import relflow as rf
prices = rf.where("address") == "order/line_items/price"
selected = model.select(prices)
model.update(prices, mask=0.10)Selection is read-only. Updates are strict by default: every matched node must support each supplied option. Narrow the predicate rather than mixing unrelated node types. strict=False permits partial application to supporting nodes; an option supported by none of the selected nodes still raises.
mask=False removes the selected node’s policies; mask=True makes it an always-hidden reconstruction target. Use description for notes and declared field options for configuration.
Make A Temporary Change
with model.override(prices, active=False):
ablated = model.predict(observations)
ordinary = model.predict(observations)observations is the application’s Arrow input. The context manager restores the previous schema attributes, even on exit through an exception. It does not snapshot all weights, vocabularies, or normalizers: compatible learned-state changes inside the context remain. See Evaluation for an ablation example.
Change The Tree Or Reinitialize State
| Method | Effect |
|---|---|
extend(...) |
Add named children to exactly one selected branch. |
delete(...) |
Remove selected nodes and their descendant subtrees. |
reset(...) |
Keep the schema and reinitialize selected runtime modules. |
root = rf.where("address") == "order"
model.extend(root, expedited=rf.Boolean, region=rf.Category(size=32))
model.reset(rf.where("address") == "order/region")
model.delete(rf.where("address") == "order/expedited")An extension accepts keyword children or a fields mapping, following the same parent-owned naming rules as construction. Names must remain unique. Deletion cannot remove the generated root or leave an invalid empty tree. reset(..., descendants=True) includes a selected branch’s subtree; resetting a field discards its learned runtime state, including any owned vocabulary.
Edit Between Loops
Mutation is prohibited during active forward, inference, and Lightning loops. Change the model between complete operations. Avoid direct attribute edits that bypass graph rebuilding.
Rebuilds replace runtime modules, so recreate optimization through a factory and a new fitting loop after editing a trained model. An existing optimizer instance can refer to replaced parameters. Existing data modules keep the model reference and use its current schema; application caches and exported artifacts remain your responsibility.
A failed update that cannot rebuild restores its previous schema and graph. Successful changes clear compilation and cached output contracts. Call model.compile() again if wanted, reevaluate the changed model, and save the artifact you intend to use.
Evidence For Learned Behavior
The mutation proofs start with trained models, evaluate immediately after an edit, and measure adaptation separately:
- Neutral edits check prediction, normalization, and vocabulary retention.
- Adding a hidden target checks immediate retention and learning with continuation and scratch controls.
- Selective reset checks localized loss and relearning of one hidden output.
- Deactivation and restoration removes an informative input, then checks updates, override exits, and reactivation from an inactive checkpoint.
- Deletion and adaptation compares retraining with inactive, scratch, and continuation controls against the best prediction possible from the remaining information.
These experiments cover specific edits and synthetic tasks. Consult their recorded outcomes: retaining state entries does not establish identical predictions when a schema-derived computation changes.
The added-target experiment currently fails exact prediction retention with the default attention reduction. Adding the hidden field changes the root pool’s capacity and shifts old predictions despite preserving existing state. The new output still learns successfully during adaptation.