Graphical Editing¶
The main interface for editing block diagrams in Lynx is a Jupyter widget, which allows interactive editing inline in Jupyter notebooks.
Basic widget functionality
This is strongly recommended over programmatic diagram construction - put simply, it is very difficult to design an inutitive API for what is fundamentally a graphical “language”. A convenient workflow is to:
Create a diagram in the interactive widget or initialize from a template
Save the diagram to JSON (can also check into git)
Edit parameters and extract subsystems using Python
Use the widget for visualization or further structural changes or visualization, saving changes to the JSON file
State Synchronization¶
The Python code and the interactive widget have bidirectional syncing:
# 1. Create diagram programmatically
diagram = lynx.Diagram()
diagram.add_block('gain', 'K', K=5.0)
diagram.add_block('transfer_function', 'G',
num=[2.0], den=[1.0, 3.0])
diagram.add_connection('c1', 'K', 'out', 'G', 'in')
# 2. Launch interactive widget
lynx.edit(diagram)
# 3. Makes changes in UI:
# - Drag blocks to new positions
# - Edit parameters in property panel
# - Add/remove connections
# - Adjust routing waypoints
# 4. The diagram object is updated automatically
print(diagram["gain"].get_parameter("K"))
This allows you to update Python variables used in expressions in the diagram and have the changes automatically propagate to the diagram, or to edit the diagram and have the changes automatically sync to the Python Diagram object.
Static Rendering¶
For documentation/publication/presentations, you can also create static renderings with lynx.render(diagram, 'diagram.png'), which supports both PNG and SVG exports.