Extend Phlex algorithm lifecycle to include pre- and post-execution phases "initialize" and "finalize". #764
Replies: 1 comment 3 replies
The barriers are conceptual: adding these entry points would mean that graph execution would need to be informed by not only data dependencies and the available concurrency, but it would also depend on algorithms that are used (presumably) only for establishing state...making some of the dependencies implicit. We are very hesitant to go this route until we can understand specifically what necessitates it. We have not yet seen a compelling case to add such hooks (although they have been considered). Some options you might consider are below. Those options assume that the purpose of the "initialize" and "finalize" are to handle state used by the algorithm1. Happy to follow up on anything. Phlex support for functions bound to stateful objectsFunctions bound to stateful objects can be registered with the framework. See here for an example of calling This approach means no changes to Phlex proper, and it keeps stateful classes local to the Phlex module. Recasting the "initialize" and "finalize" as data dependenciesDepending on what the initialize and finalize are for, it may be possible to introduce algorithms that prepare the state and pass that state explicitly as an in-memory-only data product to a downstream algorithm that requires it. This keeps the data dependencies explicit, thus making it easier to understand the flow of the program. How a "finalize" is implemented would depend on what it is for. ResourcesWe have a reasonably mature design for Phlex resources. These can be helpful when needing to coordinate the execution of algorithms that depend on a shared resource that may not be thread-safe. Depending on what you need to do with the "initialize" and "finalize", these may be reasonable approaches. Footnotes
|
Uh oh!
There was an error while loading. Please reload this page.
I'd like Phlex to consider to add support for calling two methods on an algorithm:
initialize()andfinalize()before and after the DFP graph execution (just after start and just before end of job) and from the main thread.A templated compile-time check can be used so that algorithms that are simple functions or classes that lack one or both of these methods could be exempt from attempting to call their non-existent methods and without the need for inheritance.
This would help support Wire-Cell Toolkit and Geant4 in Phlex and probably other future integrations.
Are there any barriers to adding these two algorithm entry points?
All reactions