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.
Description
Changing configuration in hls4ml requires deep understanding of the conversion process in order to be successful. New layers can be introduced, which pick up default precision definition causing problems for subsequent layers, unexpected allocation of DSPs etc. To solve this, users have to anticipate new layer names and with a meticulous trial-and-error procedure nail the initial configuration that will result in perfect conversion. This is way too cumbersome but until we have a better configuration system it is the only way. This PR proposes an alternative, to be able update the configuration of an existing hls4ml model interactively, via a GUI. It came out of a crazy idea I had last night after a few beers. See it in action:
It is very simple to use, make your changes and click "Update", the model will be updated and the changes should be reflected on the architecture plot on the left side.
This builds upon the recent automatic configuration support, by exposing only the configurable attributes (precision, strategy, RF etc). Some parts of it are a bit hacky for now, until we improve the configuration itself (ideally, we should have an
model.get_config()/model.set_config()
API).The GUI is built using
PySimpleGUI
library, you can install it withpip install pysimplegui
. Since the feature is optional, I also added an installation extra, so installation ofpip install hls4ml[gui]
will ensure the dependency is there. I considered a pure Tk implementation usingtkinter
from the standard library to avoid the new dependency, but the equivalent GUI had 400 lines of code and no support for mouse scroll events so I abandoned it.The GUI is part of the utilities, to use it, run:
A GUI should open up. If you use this through SSH or VS code server it may be slow to open. I don't know what is causing this, possibly an issue with the GUI library itself. Pure
tkinter
implementation didn't have this issue.In the future, we can expand it to support creating the initial configuration, based on Keras/PyTorch/ONNX model.
Type of change
Also fixes a minor bug in definition of the
trace
attribute (was string, should be bool) and addsstrategy
attribute to supported layers.Tests
We currently don't have any way of testing GUIs and this is a can of worms, so I suggest we skip it for now.
Checklist
pre-commit
on the files I edited or added.