softboiler / boilercv

Computer vision routines suitable for nucleate pool boiling bubble analysis
https://softboiler.org/boilercv/
MIT License
0 stars 2 forks source link

Stabilize `ContextMorph` with unique contexts #197

Closed blakeNaccarato closed 4 months ago

blakeNaccarato commented 4 months ago

Please use this form appropriately

Please check that this internal matter hasn't already been raised

Description

Context keys are unique on concrete types, but they could be unique IDs allowing for the same type to have different contexts at different tree positions. That would require a unique ID assigned per position, or to use stacks of contexts somehow.

A flat mapping of position to context could be composed with minimal duplication by sharing inner contexts across members, or stacks could be composed that uniquely associate with branches of the model tree.

But it's not immediately clear how branches of stacks would be handled, so maybe this needs fleshing out. Need to look into DAG node addressing literature to figure this out.

ID assignment at runtime might entail each ContextMorph to check its class against an index class stored in context, incrementing the address and storing itself as the new index class if different from the current index, or equivalently by operating on the context stacks, popping off the appropriate stack.

Could build a context by creating a stack for each field in a ContextBase or for each direct call to ContextMorph.context_model_validate.

Possibly when building, during each context merge, check if the class passed in during merging differs from a running context and assign a new ID, flattening the entire tree of contexts to a linear mapping. This would motivate get_context_id as an actual classmethod, called by get_context to increment the context key at model build time.

I don't think that the finitely recursive model definition requires a finitely recursive context shape, since the nodal network can be flattened to a unique mapping of addresses. This is probably already solved in other DAG-handling libraries, maybe there's a low-level tree handler to help with this.

But this problem is not adequately defined to be worked on now, and class-unique indexing of contexts will suffice for now.

blakeNaccarato commented 4 months ago

This was done in #196.