Step 2: Create your first Workflow#

At this point, you should have a Codespace that is configured to securely connect to your Artificial Cloud. This tutorial will walk you through writing your first workflow.

Note

Please note that this tutorial presumes that you have already created your first Lab and first Assistant in your Artificial instance.

What is a workflow?#

Wouldn’t it be nice to be able to connect and automate the instruments, software and even people in your lab? A Workflow is a script written in Orchestration Python that runs in the Artificial Runtime in the cloud and can call Actions to run protocols on instruments, upload data to your LIMS, display Assistants for manual work, and much more.

Create a workflow#

  1. Create a new file workflow/hello_workflow.py.

  2. Copy and paste the following Orchestration Python (OP) snippet into this file, replacing lab_id with the id of the lab you created in your Artificial instance. See Finding IDs in Artificial for help with locating IDs for Labs and Assistants in Artificial.

from artificial.workflows.decorators import workflow
from artificial.workflows.runtime import show_info

@workflow('Hello Workflow',
          'hello_workflow',
          'lab_id')
async def hello_workflow() -> None:
    await show_info("Hello World")

Let’s walk through what this code does.

@workflow('Hello Workflow',
          'hello_workflow',
          'lab_id')

@workflow is called a “decorator” and marks the hello_workflow function as a workflow. It tells Artificial the workflow name ('Hello Workflow'), the workflow’s unique id ('hello_workflow'), and which lab the workflow is built for ('lab_id'–don’t forget to replace this with the id of the lab you created in your Artificial instance). The Artificial SDK provides lots of decorators; we’ll explore several more in the next few tutorials.

async def hello_workflow() -> None:

This declares the workflow function; when a user runs the workflow in LabOps, this is the function that will run. To keep things manageable, the name of the function should match the unique id of the workflow. We also mark workflow functions as async because sometimes they can take a long time to run–up to months or even years for some complicated cell culture workflows.

await show_info("Hello World")

show_info is an action that displays the given message in the LabOps console. It’s useful for sending messages to the person running the workflow and also for debugging. We prefix action calls with await because some actions can take a long time to run (e.g. a multi-hour incubation or instrument protocol).

Publish your workflow#

  1. Click the Artificial Logo in the left pane.

  2. Open the Workflow Publishing folder.

  3. Find the workflow you just created and click the “Publish Workflow” icon to the right of the workflow name.

As you continue to edit your workflow, you can also use the “Publish Workflow” quick link that appears just above the @workflow decorator in your editor window:

_images/publish_workflow_shortcut.png

Run your workflow#

Then, use LabOps to run this workflow and see the message.