Forgive this silly question: how important is it that the passed in block is under the same namespace? I’ve done this kind of thing a bunch of times and usually it’s fine if they’re different namespaces.
If the concern is that the autogenerated parameter names of the passed in block change depending on runtime creation, then the simple solution to that is simply passing in a prefix when you create the encoder block so that it always has the same namespace regardless of creation time.
If there is some reason the namespace is really important, then there are maybe three options. One is the one you’re doing with a factory. The second is not to pass it in at construction, but with a setter where you create the child with the set, quite similarly to how Sequential works.
parent = MyParentBlock()
Naturally, the limitation here is that the encoder has to be created in a similar code space as the parent block, and if your encoder is coming in as an argument to a function that won’t work.
The third option is to use a prefix when you create the encoder that will match the parent. This option is pretty brittle though.
Actually I guess there is a fourth option, which is you reassign the parameter dict of your encoder to a new with with a proper name space, but simply give it the same
Parameter object references as the original parameter dict. Feels ugly, but I think that would work.