Drawing Network Diagrams - PetaVision/OpenPV GitHub Wiki
This page contains instructions on using the 'draw' tool to parse params files and automatically generate network diagrams.
Get Dependencies
Drawings are generated by the open-source script language mermaid, created by Knut Sveidqvist. The following commands use package manager npm, bundled as part as of javascript environment node.js. This is available as a .pkg file here, and should be downloaded and installed before entering the following commands at a terminal prompt:
sudo npm install -g [email protected]
sudo npm install -g phantomjs
Note the explicit version for mermaid; as of July 2017, the most recent version 7.0.3 has a bug where arrowheads are not drawn.
Mermaid should now be installed and usable as a command which outputs .png images of the network described by an input text file.
If you get an error from npm about a node/nodejs conflict, create a softlink from nodejs to node in /usr/bin:
sudo ln -s /usr/bin/nodejs /usr/bin/node
which node
Make sure the output points to /usr/bin/node (I had it point to /usr/sbin/node, so I added /usr/bin to the beginning of my $PATH)
Set Up the 'draw' Tool
The bash script 'draw' should now produce diagrams of params files directly from the command line. To be able to use this command globally, open your .bash_profile file in your home directory and look for the line that begins “export PATH”— This is an environmental variable that can take a colon-separated list of paths to look for bash commands. Add the path to OpenPV’s python folder to this list, or simply add the following line to the end of the .bash_profile file:
export PATH=$PATH:[/your/path/to]/OpenPV/python
From a command line, make sure the change your bash profile has been sourced by running:
source .bash_profile
You might have to change permissions on the script. To make it executable, enter:
chmod 500 [/your/path/to]/OpenPV/python/draw
If this setup has worked and everything is in place, entering:
which draw
Should yield "[/your/path/to/]/OpenPV/python/draw".
Using 'draw'
To generate a diagram, cd to any directory containing a params file and enter:
draw [-a][-l][-f][-p] your_file.params
The available options are:
- -a: Sort objects alphabetically for mermaid input. In some cases this can help make the diagram more legible, especially if the params file has been generated from a lua script.
- -l: Print a legend in the corner of the diagram, explaining notation.
- -f: Keep (do not rm) the intermediate mermaid_input file used to generate the diagram.
- -p: Color-code layers by phase rather than by nx-ny scale.