Schedule a notebook run

This page shows you how to use the Vertex AI Workbench executor to run a Python notebook file on an hourly schedule.

Before you begin

  1. Sign in to your Google Cloud account. If you're new to Google Cloud, create an account to evaluate how our products perform in real-world scenarios. New customers also get $300 in free credits to run, test, and deploy workloads.
  2. In the Google Cloud console, on the project selector page, select or create a Google Cloud project.

    Go to project selector

  3. Make sure that billing is enabled for your Google Cloud project.

  4. Enable the Notebooks and Vertex AI APIs.

    Enable the APIs

  5. In the Google Cloud console, on the project selector page, select or create a Google Cloud project.

    Go to project selector

  6. Make sure that billing is enabled for your Google Cloud project.

  7. Enable the Notebooks and Vertex AI APIs.

    Enable the APIs

Required roles

To ensure that your instance's service account has the necessary permissions to interact with the Vertex AI Workbench executor, ask your administrator to grant your instance's service account the Notebooks Viewer (roles/notebooks.viewer) IAM role on the project. For more information about granting roles, see Manage access to projects, folders, and organizations.

This predefined role contains the permissions required to interact with the Vertex AI Workbench executor. To see the exact permissions that are required, expand the Required permissions section:

Required permissions

The following permissions are required to interact with the Vertex AI Workbench executor:

  • To list executions: notebooks.executions.list

Your administrator might also be able to give your instance's service account these permissions with custom roles or other predefined roles.

Create an instance and example notebook file

  1. Create an instance.

  2. Open JupyterLab.

  3. Open a new notebook file.

  4. In the first cell of the notebook file, enter the following:

    # Import datetime
    import datetime
    
    # Get the time and print it
    datetime.datetime.now()
    print(datetime.datetime.now())
    
  5. To make sure your notebook file is saved, select File > Save Notebook.

Schedule a run

  1. In the Google Cloud console, go to the Instances page.

    Go to Instances

  2. Next to your instance's name, click Open JupyterLab.

    Your Vertex AI Workbench instance opens JupyterLab.

  3. In the  File Browser, double-click the example notebook file to open it.

  4. Click the  Execute button.

  5. In the Submit notebooks to Executor dialog, in the Type field, select Schedule-based recurring executions.

    By default, the executor runs your notebook file every hour at the 00 minute of the hour.

  6. In Advanced options, enter a name for your bucket in the Cloud Storage bucket field, and then click Create and select. The executor stores your notebook output in the Cloud Storage bucket.

  7. Click Submit.

    Your notebook file runs automatically on the schedule that you set.

When you finish the tasks that are described in this document, you can avoid continued billing by deleting the resources that you created. For more information, see Clean up.

View, share, and import an executed notebook file

By using your instance's JupyterLab interface, you can view your notebook output, share the results with others, and import the executed notebook file into JupyterLab.

View the execution results

  1. In JupyterLab's navigation menu, click the  Notebook Executor button.

  2. Click the Executions tab.

  3. Under the execution that you want to view, click View result.

    The executor opens your result in a new browser tab.

Share the execution results

  1. In your instance's JupyterLab user interface, in the navigation menu, click the  Notebook Executor button.

  2. Click the Executions tab.

  3. Next to the execution that you want to share, click the  options menu, and select Share execution result.

  4. Follow the directions in the dialog to grant users access to the execution result.

Import the executed notebook into JupyterLab

  1. In your instance's JupyterLab user interface, in the navigation menu, click the  Notebook Executor button.

  2. Click the Executions tab.

  3. Next to the execution that you want to import, click the  options menu, and select Import executed notebook.

  4. If the Select Kernel dialog appears, select the kernel that you want to open the notebook.

    The executor opens the executed notebook file in JupyterLab, and stores this notebook file in the JupyterLab File Browser in a folder named imported_notebook_jobs.

View or delete a schedule

You can view and delete schedules by using either the Google Cloud console or your instance's JupyterLab user interface.

View a schedule

View a schedule to see the frequency settings of the schedule or to view the five most recent results of the notebook file execution.

Console

  1. In the Google Cloud console, go to the Schedules page.

    Go to Schedules

  2. For the schedule that you want to view, click its schedule name.

    On the Schedule details page, you can view the schedule's last five executions.

  3. Next to an execution name, click View result to open the executed notebook file.

    The executor opens your result in a new browser tab.

JupyterLab

  1. In your instance's JupyterLab user interface, in the navigation menu, click the  Notebook Executor button.

  2. Click the Schedules tab.

  3. Under the execution that you want to view, click View latest execution result.

    The executor opens your result in a new browser tab.

Delete a schedule

Deleting a schedule doesn't delete the executions that were generated from that schedule.

Console

  1. In the Google Cloud console, go to the Schedules page.

    Go to Schedules

  2. Select the schedule that you want to delete.

  3. Click  Delete.

JupyterLab

  1. In your instance's JupyterLab user interface, in the navigation menu, click the  Notebook Executor button.

  2. Click the Schedules tab.

  3. Click the schedule name. The Schedule details page for that schedule opens in the Google Cloud console.

  4. Click  Delete.

Clean up

To avoid incurring charges to your Google Cloud account for the resources used on this page, follow these steps.

Delete the instance

  1. In the Google Cloud console, go to the Instances page.

    Go to Instances

  2. Select the instance that you want to delete.

  3. Click  Delete.

Delete the project

If you used resources outside of your Vertex AI Workbench instance, such as the Cloud Storage bucket required for creating a schedule, you might want to delete your project to avoid incurring additional charges.

  1. In the Google Cloud console, go to the Manage resources page.

    Go to Manage resources

  2. In the project list, select the project that you want to delete, and then click Delete.
  3. In the dialog, type the project ID, and then click Shut down to delete the project.

What's next