Perhaps not for this pass, but I wonder if a paradigm of `push_algo_instance(self)` and `pop_algo_instance()` would help legibility/maintainabitiy. (By adding some error handling when an algo already exists or doesn't exist in those functions, as well as making the add/removal of the algo context very explicit.)

Alternatively, we could do something like `with AlgoInstanceContext(self):`