Helipad 1.0 has just launched with a plethora of improvements. Most importantly: you can now run Helipad models in Jupyter notebooks.
Jupyter Integration
Jupyter notebooks are interactive documents into which you can embed Python code to run in-browser. They’re popular for sharing scientific code because putting code in a document can be much more readable than putting comments in code.
Helipad can now run a full-featured instance inside a Jupyter notebook, with the same control panel experience and interactive plotting. Anything you can do with the Tkinter frontend, you can now do in the Jupyter frontend as well, with no* changes to your code. (*except that you’ll need to launch the plots explicitly with a heli.launchVisual()
line at the end)
To try out the new Jupyter frontend,
- Download one of the sample notebooks
- Install Jupyter and Ipywidgets using
pip install jupyterlab
andpip install ipywidgets
- Launch the notebook from your terminal using
jupyter notebook /path/to/notebook.ipynb
Because the code can be written and run in-browser, this should flatten the learning curve for writing a Helipad model and increase the shareability of model code.
New Decorators
The most significant API update is a set of new decorators to add hooks and reporters. Previously, it was necessary to define a function and then register it using model.addHook()
. This entailed a lot of repetition.
Starting with Helipad 1.0, you can now register hooks using a decorator syntax. Just name your function according to the hook, and add @heli.hook
at the top.
from helipad import Helipad
heli = Helipad()
@heli.hook
def modelStep(model, stage):
pass
You can also use @heli.hook('modelStep')
if you want to hook a function of any name to the modelStep
hook, for example.
There are also decorators for reporters and button shocks. Though most reporters will still be generated with the data
methods, if you’re defining your own reporter function, you can register it with the @heli.reporter
decorator. Similarly, you can add buttons easily to the control panel with @heli.button
.
API Stability
With the release of Helipad 1.0, every effort will be made to maintain backward-compatibility. Documented functions and properties will not change before six months or two 0.1 releases after the first release in which they are deprecated, whichever is longer. Undocumented functions and properties can change without notice.
Other Improvements
- Plotting is now completely independent of the control panel. So you can launch the traditional way with
model.launchCpanel()
, jump straight into plotting withmodel.launchVisual()
, or go completely GUI-less withmodel.start()
(In the latter two cases you’ll have to set parameter values, including any data post-processing, in code). Param
objects now allow you to enable and disable the GUI element.- Model control is handled in the
model
object now, rather than theCpanel
object. If you need to control the model with code, usemodel.start()
,model.stop()
, andmodel.terminate()
. - New parameter types
checkentry
andcheckgrid
can be registered withmodel.addParameter()
. - Sliders can be registered with discrete and arbitrary values by passing a list of values to the
opts
argument ofmodel.addParameter()
. - The CSV and stop-after boxes, along with the refresh rate slider and the plot list, are now proper parameters and can be accessed and set using
model.param()
under the names'csv'
,'stopafter'
,'updateEvery'
, and'plots'
, respectively. - The
stopafter
parameter can be set to a function rather than a number, in order to stop the model after an arbitrary condition is fulfilled. This can also be used in parameter sweeps. - Plots can be activated and deactivated from code with the new
Plot.active()
method.
The full list of API changes is below.
API Changes in Version 1.0
- ⚠️ HelipadRemoved
model.defaultPlots
. Select plots programmatically with theselected
argument ofmodel.addPlot()
, or after the fact withTimeSeriesPlot.active()
.
MovedCpanel.graph
andCpanel.running
to the model object.
Model control (thestart()
,stop()
, andterminate()
methods) is handled here rather than in theCpanel
object.
Removed thebuttons
property. TheaddButton()
method now aliasesShocks.register()
. - ⚠️ addButtonPass the model object to the button function, and move the display from the top to the shocks section.
- ⚠️ paramSweepRemoved the
t
parameter. Usemodel.param('stopafter')
to set a time limit or a stop condition. - ⚠️ CpanelChanged name to
Cpanel
fromGUI
.
Moved thegraph
andrunning
properties to the model object, and thelastUpdate
property to theGraph
object.
Removed theheadless
parameter and property. To run the model headless, runmodel.launchPlots()
without runningmodel.launchCpanel()
.
Thestopafter
,updateEvery
,csv
, andchecks
properties, which formerly stored Tkinter widgets relating to configuration, have been removed. Their values can be accessed through parameters of the same name withmodel.param()
exceptchecks
, which can now be accessed withmodel.param('plots')
.
Moved model control methodsrun()
,pause()
,terminate()
, andpreparePlots()
tomodel.start()
,model.stop()
,model.terminate()
, andmodel.launchPlots()
, respectively.
With the plot list being a parameter now, theCpanelAbovePlotlist
hook has been removed. - ⚠️ launchCpanelRenamed from
model.launchGUI
, and removed theheadless
parameter. To run the model headless, runmodel.launchPlots()
without calling this function. - ⚠️ launchVisualMoved from
Cpanel.preparePlots
. - ⚠️ CpanelAboveItemParamsName changed from
GUIAboveItemParams
. - ⚠️ CpanelPreLaunchName changed from
GUIPreLaunch
. - ⚠️ CpanelPostInitName changed from
GUIPostInit
. - ⚠️ CpanelTopName changed from
GUITop
. - ⚠️ CpanelBottomName changed from
GUIBottom
. - ⚠️ CpanelAboveShocksName changed from
GUIAboveShocks
. - ⚠️ CpanelAboveParamsName changed from
GUIAboveParams
. - ⚠️ modelStopTakes the model object rather than the GUI object as the first argument.
- ⚠️ terminateTakes the model object rather than the GUI object as the first argument.
- ⚠️ GUICloseNever executes in a Jupyter environment.
- launchCpanelInterrupts the 'Run All' sequence in a Jupyter environment.
- @reporterIntroduced.
- enableIntroduced.
- disableIntroduced.
- disabledIntroduced.
- @buttonIntroduced.
- @hookIntroduced.
- genDecoratorIntroduced.
- startIntroduced as part of the transfer of model control functions from
GUI
to the model object. - ParamAdded the
defaultVal
property, and split the parameter types into subclasses. - addAdded support for checkgrid, checkentry, and logslider parameters.
- checkEntryAdded the
command
argument andcallback
parameters to enable callback functions. - disabledMade the second parameter optional to allow the entire checkGrid to be enabled or disabled at once.
- addCheckNow returns the
textCheck
widget. - addAdded the
prioritize
argument. - TimeSeriesAdded the
lastUpdate
property, formerly from the GUI object. - logSliderWith the log slider now available for use in user-defined parameters, the Tkinter class now has a complement of methods:
set
,get
,enable
,disable
, anddisabled
. - TimeSeriesPlotAdded the
check
andselected
properties and theactive()
method. - activeIntroduced in the
TimeSeriesPlot
class. - visualLaunchIntroduced.