Skip to main content

Covalent Patterns

This guide describes some best practices for use with Covalent. Most are coding best practices to be followed when writing workflows. Others include server configuration and runtime considerations.


The coding best practices are illustrated examples using Jupyter notebook files (formerly IPython files; they have an ipynb file extension). You can open a file and run the example on your local machine. To run an example:

  1. Install Jupyter.
  2. Install Covalent.
  3. Download the IPython (.ipynb) file by selecting the "go to the source" button present next to the heading.
  4. Open the IPython (.ipynb) file in a Jupyter notebook.

The coding practices described here fall into two categories:

  • Patterns and techniques that improve Covalent implementations in some way. These improvements can be in efficiency, performance, code maintainability, or any of a number of other attributes considered desireable in a development project.

  • Techniques that must be followed when using Covalent. These usually reflect requirements for server-based dispatch and execution of workflows. The consequences of violating these requirements are demonstrated in the individual entries; in most cases, they cause the workflow to fail.

Coding Best Practices

Implementing Dynamic Workflows

Use sublattices to encapsulate dynamic code.

Creating One Executor per Resource

Create one executor object per compute resource and assign the executor to electrons as needed.

Transferring Large Data Objects

Save large data objects to a data store and read the object to electrons as needed.

Containing Computations in Tasks

Use an electron to generate the return value of a workflow.

Writing Result-Dependent Branch Decisions

Encapsulate result-dependent if/else statements in an electron.

Writing Result-Dependent Loops

Encapsulate result-dependent loops in an electron.

Returning Multiple Values from a Function

To avoid needlessly proliferating functions, return multiple values from a task in an array.

Deploying a Covalent Server

Follow these guidelines when running Covalent on a server.