Package: ipypetrinet
ipypetrinetA custom petrinet widget.InstallationYou can install the package usingpip:pipinstallipypetrinetYou may also need to installpm4py,time,datetime,numpy,pandasandcopy!If you are using Jupyter Notebook 5.2 or earlier, you may also need to enable
the nbextension:jupyternbextensionenable--py[--sys-prefix|--user|--system]ipypetrinetIf the widget is not displayed, make sure you havenotebookinstalled with the latest version.
You can update it by typing:pipinstall--upgradenotebookUsagefromipypetrinetimportPetriWidgetwidget=PetriWidget()The Widget consists of 18 buttons and a resizable canvas. The functionality of each button is briefly described below.
After adding cells (places or transitions) to the canvas, you can connect them via a link by clicking and holdingalt-keyand then dragging the source-cell to the destination-cell. You can only add links between places and transitions. Note that you can assign labels to places and transitions and probabilities to links. By double-clicking a cell or a link you can modify the label or probability respectively. Transitions can be enriched with custom conditions by clicking the attached add-button. Please also note that the canvas can be resized by dragging the lower-right corner up or down.Graphswill show a dropdown of two example graphs, which can be selected to play around with.Save Graphwill save the currently displayed graph in theGraphsdropdown. (CAUTION: It will only be stored temporarily in the local storage of the browser)Import Graphallows you to import a JSON- or PNML-file as a graph to be displayed in the widget. This also restores available conditions, case- and event-attributes of the imported model. If the PNML-file does not provide proper position-attributes, its approximate layout will be restored automatically.Download SVGallows you to download the current graph as SVG.Download Graphallows you to download the current graph as JSON- or PNML-file, which may be imported in another session to resume working. It also stores the corresponding conditions, case- and event-attributes.Zoom inandZoom outwill enlarge or shrink the graph.+ Placewill add a new place to the canvas.+ Transitionwill add a new transition to the canvas. Please keep in mind that transitions always need a label. Within the transitions, conditions can be added using the attached add-button.+will add a token to a previously selected place. You can select places or transitions by simply left-clicking them. Note that transitions cannot contain any tokens, while places may contain any positive number of tokens.-will subtract a token of a previously selected place. Note that a place cannot contain a negative number of tokens.Layoutgives the user the possibility, to automatically generate a layout for the given graph. There are four parameters that can be customized in order to obtain the desired result.Clearwill delete the whole graph off the canvas. You can now start over with a fresh canvas. (CAUTION: at this point in time this cannot be revoked)Lockwill freeze the whole model, so cells can't be moved around or deleted anymore. However, you can still modify the properties of cells by double-clicking them.Playwill simulate the Petri net. Please mind that this simulation-mode doesn't take any conditions, case- and event-attributes or probabilities into account.Stopwill stop the current simulation. (CAUTION: clickingPlaytwice without clickingStopin between will cause undefined behavior.)Resetwill reset the model to the state it had the last time a token was added or removed. Moreover, the graph is set back to its initial position and the zoom-level is reset.+ Attributeswill open a popup which allows you to add and delete both case- and event-attributes. A few options for the dynamic generation of variables are already supported (static list with probabilities, normal-, binomial-, gamma- and exponential-distribution). Please note, that you have to choose a certain transition to be extended by the respective event-attribute.Beyond that, you can implement a custom Python method, defining data-attributes and pass them to thegenerate_eventlogfunction. The function should provide these attributes in the following form:datadict={"resource":"Emma","costs":{"A":10,"B":20}}Here, the "resource" is handled as a case-attribute whereas the "costs" are defined as a event- or shared-attribute.
Furthermore, the PetriWidget comes with two attributes and a readily implemented simulation functionality. The attributes may be obtained by typingwidget.graphandwidget.caseAttrs. If you want to draw the net once again using gviz, you can runwidget.drawPetriNet(widget.graph). However, the main and most interesting function iswidget.generate_eventlog(graph=widget.graph, case_attrs=widget.caseAttrs)which will simulate an event log as a pandas DataFrame and compute the respective event-attributes and case-attributes dynamically. There are several optional parameters that can be modified. Additionally, some basic methods are included to subsequently contaminate the event log with noise like silent or double activities, missing start/end or randomly switching timestamps.
Hint: by typingwidget??in a jupyter notebook, all implemented methods (including helper methods) can be inspected.Development InstallationCreate a dev environment:condacreate-nipypetrinet-dev-cconda-forgenodejsyarnpythonjupyterlab
condaactivateipypetrinet-devInstall the python. This will also build the TS package.pipinstall-e".[test, examples]"When developing your extensions, you need to manually enable your extensions with the
notebook / lab frontend. For lab, this is done by the command:jupyter labextension develop --overwrite .
yarn run buildFor classic notebook, you need to run:jupyter nbextension install --sys-prefix --symlink --overwrite --py ipypetrinet
jupyter nbextension enable --sys-prefix --py ipypetrinetNote that the--symlinkflag doesn't work on Windows, so you will here have to run
theinstallcommand every time that you rebuild your extension. For certain installations
you might also need another flag instead of--sys-prefix, but we won't cover the meaning
of those flags here.How to see your changesTypescript:If you use JupyterLab to develop then you can watch the source directory and run JupyterLab at the same time in different
terminals to watch for changes in the extension's source and automatically rebuild the widget.# Watch the source directory in one terminal, automatically rebuilding when neededyarnrunwatch# Run JupyterLab in another terminaljupyterlabAfter a change wait for the build to finish and then refresh your browser and the changes should take effect.Python:If you make a change to the python code then you will need to restart the notebook kernel to have it take effect.