Override parent backend optimizer passes with derived backend passes #597
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Opening this PR for discussion, with the solution if agreed.
In #509 we noticed that if a base and derived
Backend
class both define an optimizer pass of the same name, it is the base backend pass that remains registered to the derived backend set of passes. This is a bit counterintuitive - I think you'd expect the derived class to override passes in the same way it might override methods. I put the change in a separate branch since it touches something deeper in the framework.A concrete example from #509:
Notice I get the pass registered to
vivadoaccelerator
backend, which returns an object inhls4ml.backends.vivado
.With this PR I changed the behaviour to register the base class passes first, which are then updated with the current class.
So now it yields:
As expected, getting the pass from
vivadoaccelerator
returns the pass fromhls4ml.backends.vivado_accelerator
.I think this case is our only example of the derived class defining a pass of the same name as the parent class. The backends that derive from
FPGABackend
only add passes, they don't override (I think).