Programming in Grapycal
Start Grapycal
First, run grapycal run
in a terminal to start Grapycal. It will open a blank editor in a browser, where you’ll be programming on.
Before running Grapycal, remember to activate the Python environment where Grapycal is installed. Otherwise, the grapycal command doesn’t work.
The Example Files
We provide example files to show the usage of Grapycal. Please navigate to the file view (the upper-left 📁 button) and open the “Welcome” file. The file contains basic programs that implements essential concepts in Grapycal. It’s both good either to pause to play with them, or to continue reading this page.
Hello World
Let’s create a simple program that prints “Hello World!”.
- From the node list (the left sidebar), drag an
ExecNode
and aPrintNode
into the editor and connect them together. The connections between nodes are called “edges”. - Enter
"Hello world!"
into theExecNode
. - Double-click on the
ExecNode
to run the program. TheExecNode
evaluates the string and passes it to thePrintNode
as expected.
Note that if you change the expression, an ExecNode
will not evaluate it until being double-clicked again.
Try to add more nodes to the program to make it more complex. A quicker way to add nodes is via commands: type the node’s name you want in the editor, then select it from the search result.
Commonly Used Nodes
There are plenty of types of nodes in Grapycal. Some are common, such as ExecNode
, ForNode
, and DisplayImageNode
, while others are domain-specific, such as MSELossNode
, provided by various Extensions.
PrintNode
Equivalent to Python’s print
. It can print anything, from numbers to arrays.
PasteImageNode and DisplayImageNode
Paste an image from clipboard to Grapycal with ctrl+V
then a PasteImageNode
will hold the image. Double click the node to pass the image to other nodes. You can manipulate the image in any way, such as pixel-wise transformations.
The image is treated as a numpy array (or torch tensor) in Grapycal. On the edges, the shape of the image is shown, which is beneficial for debugging.
Neural networks? No problem.
ForNode
ForNode
is equivalent to for
in Python. It receives an iterable (like an array) and output them one by one.
If you try the above code, you won’t see 1,2, and 3 displayed in the PrintNode
because they are passed to the PrintNode
almost at the same time. To fix that, make Grapycal sleep 1 second after each iteration.
A similar node, RepeatNode
, is a shortcode for range
and ForNode
.
ExecNode
ExecNode
runs a piece of text-based Python code normally. It’s useful to try something out quickly or do something that you know its Python code but it is hard or unnecessary to be represented with graph-based code.
ExecNode
lets you escape graph-based coding (which is the main feature of Grapycal), but it’s totally okay. By using ExecNode
so much you can twist the user experience of Grapycal into Jupyter Notebook.
Often, a program consists of text-based code (ExecNode
) and graph-based code, interleaved.
LinePlotNode
What’s Next?
By going through this page, you’ve been programming in Grapycal.
Next, add more and more nodes to make exciting stuff: fractals, image-generating models, PID control simulations, and Discord bots,…. The best thing is that you can combine them all by connecting them with edges!
To reach out to various domains, you may need some Extension to access domain-specific nodes.
Want to be inspired? The Tutorials chapter introduces various applications that can be created easily with native Grapycal nodes.