Operations

In Graphbook, an operation is a fundamental concept that represents a single function or task. There are 4 types of operations:

  • Primitive Operation: A basic operation that performs a single, well-defined task.
  • Composite Operation: A more complex operation that allows for the expansion of a sub-graph, enabling the creation of more sophisticated workflows.
  • If Else Operation: A conditional control structure that directs the flow of execution in a graph based on the value of a conditional input variable.
  • Loop Operation: A conditional logic structure that dynamically directs the flow of execution in a graph based on the value of a conditional input variable.
Operations

Creating Operations

Creating an operation on Graphbook is incredibly easy! You can get started in two simple ways:

  • Right-click to create: Simply right-click on the graph canvas to create a blank operation, complete with a comment block.
  • Drag-and-drop simplicity: Drag pre-built operations from the Templates panel into the canvas to create a new operation instantly. This is the only way to create primitive operations.
Creating Operations

Operation Template Components

Every operation in Graphbook consists of the following essential components:

  • Name: A unique identifier for the operation, allowing for easy recognition and reference.
  • Inputs: A list of variables that define the data the operation takes as input.
  • Outputs: A list of variables that the operation generates data for.
  • Description: A natural language characterization of the operation, providing context and understanding of its purpose.
Operations Template Components

On the backend, Graphbook utilizes assertions to enforce constraints on data shape and type relationships for each variable. These assertions ensure that variables are consistent in terms of data shape and type, preventing potential errors or mismatches. Learn more about assertions.

Operation Overflow Menu Options

The Overflow Menu, accessible by clicking the button on the top right of an operation, provides a range of useful options for managing and manipulating operations in Graphbook. The menu contains the following items:

Operations Overflow Menu Options

General Options

  • Edit Operation Name
  • Duplicate Operation
  • Save Operation
  • Create Subgraph
  • Edit Dir Paths
  • Split Global Constant
  • Set Differentiate Func Output
  • Run Operation
  • Show in New Tab
  • Redo Preview*
  • Save for Serving
  • Delete Operation

*Primitive only operations

Reordering Variables for Better Organization

To improve the readability and organization of your graph, you can reorder the variables within an operation. This is particularly useful when dealing with complex operations that have multiple inputs and outputs, as it helps to minimize link criss-crosses and make the graph more intuitive.

Reordering Slots with Drag-and-Drop

To reorder slots, simply use your mouse to drag a slot to a new position. As you drag, a small integer will appear near the center of the operation, indicating the original ordering of the slot. This integer is a visual cue that helps you keep track of the slot's original position, even if the variable name changes.

Tracking Original Variable Order

For example, if you swap the positions of two slots, the integer indicator will show the original index of each slot. In the image below, the right operand is now on top, but it has a 1 next to it, indicating that it was originally at index 1. This way, you can easily identify the original function of the variable, even if its name changes.

Tracking Original Variable Order

Primitive and Composite Operations

Just like in mathematics, where arithmetic operators can be combined to form complex functions, Graphbook distinguishes between two types of operations: primitives and composites.

Primitive Operations

Primitive operations are the building blocks of Graphbook. They are basic operations that directly correspond to an executable function, such as multiplication, cosine, addition, and more. These primitive operations can be found under the Template section, represented by token icons. They are the fundamental components that can be combined to create more complex operations.

Composite Operations

Composite operations, on the other hand, are created by combining multiple primitive operations, as well as links, represented by inventory icons. They handle more complex functions that can be used to solve a wide range of problems. Composite operations are useful for encapsulating functionality and reusing it in multiple places.

Creating Composite:

Composite operations are displayed similarly to primitive operations, but they have some key differences. To create a composite operation, you can either find it in the templates or right-click on the blank graph canvas area and select Create Composite.

Creating Composite

Unboxing a Composite Operation

When you create a composite operation, you'll notice an Create Unbox symbol in the body of the rectangle. Clicking on this symbol reveals a new graph canvas, which is the sub-graph of the composite operation.

Unboxing 1
Unboxing 2

Inputs and Outputs

In the sub-graph, you'll see two special operations: Inputs on the left and Outputs on the right. These operations correspond to the input and output variables on the composite parent. As data flows into the composite operation from the parent input, it continues into the sub-graph via the Inputs operation, and vice versa for the Outputs operation.

Inputs and Outputs

Adding and Removing Variables

To add a new input or output variable, click the `+` button on the Inputs or Outputs operation, respectively. This will add a new variable to the composite operation, which will also be visible at the parent level. Note that variables can only be added to a composite operation from its sub-graph.

Input and Outputs

To remove a variable, right-click on it and select `Remove Variable Slot`. However, if the variable is connected to a link, you won't be able to remove it until it's unlinked. In this case, the menu item will be grayed out.

Adding and Removing Variables
Note after Adding and Removing Variables