With Notebook Lab, you can preview and edit any Notebook file on Object Storage Service (OSS) without launching a compute resource. To run your code, connect the Notebook to a DSW instance. Multiple Notebooks can share a single instance, improving resource utilization.
Comparison with DSW
Feature comparison | Notebook Lab | DSW instance |
Core | Lightweight Notebook editor | A complete AI development environment |
File | Stored in Object Storage Service (OSS), decoupled from compute resources | Bound to the compute instance in the same working directory |
Billing | No charge for editing | Billing starts when the instance is launched |
Tools | Focused on Notebook development | Includes JupyterLab, WebIDE, and Terminal |
Access a notebook
Log on to the PAI console.
In the upper-left corner, select the required region.
In the navigation pane on the left, choose Workspaces, and then click the name of your target workspace.
In the navigation pane on the left, choose Model Training > Data Science Workshop (DSW), then click the Notebook tab.
Configure code directory
Click Select Code Directory.

After you configure a custom code directory, Notebook Lab scans the directory and lists all Notebook files (*.ipynb) from the specified OSS path. You can then select an existing Notebook or create a new one in the configured directory.
Create and develop a notebook
Click Create Notebook. This creates a new Notebook file in the configured code directory.

On the development page, you can work in a Jupyter-style interactive environment.
Because Notebook files are decoupled from DSW instances, include the logic for downloading and installing environment dependencies directly in your Notebook file. This ensures that your code runs correctly even when you switch between different DSW instances.
Develop a notebook
Prerequisites
(Optional) To use SQL, install the SQL plugin.
!pip install https://dataworks-notebook-cn-shanghai.oss-cn-shanghai.aliyuncs.com/public-datasets/pypi/dataworks-magic/dataworks_magic-0.1.5-py3-none-any.whl jupysql tenacity sqlparse maxframe alibabacloud_emr_serverless_spark20230808 alibabacloud_ververica20220718 psycopg2-binaryProcedure
Add a cell.
Create a new cell from the Notebook Lab toolbar or by clicking the buttons that appear above or below an existing cell.
NoteTo reorder cells, hover over the blue line to the left of a cell, and then drag the cell to a new position.

(Optional) Change the cell type.
Click the cell type button in the lower-right corner of a cell to change its type. The following cell types are supported:
Markdown, Python, MaxCompute SQL, Flink SQL Batch, and Flink SQL Streaming.
NoteWhen you change the cell type, the content is preserved. You must manually adapt the code to the new cell type.

Write code in a cell.
You can edit SQL, Python, or Markdown code in the corresponding cells. Use Copilot for programming assistance. To trigger Copilot, use one of the following methods:
Method 1: Trigger Copilot from the Notebook Lab toolbar or by using the buttons that appear above or below a cell.

Method 2: Select a cell and use the following keyboard shortcuts:
Windows:
Ctrl+ImacOS:
Command+I
Debug and run Notebook
Select a DSW instance.
After you finish editing your Notebook, click the DSW instance name in the upper-right corner to select an instance to debug or run your code. By default, the list is filtered to show DSW instances in the current workspace. Choose an instance with the appropriate specifications and image.
When a Notebook is connected to a DSW instance, its working path is the same as the DSW instance's working directory (default: /mnt/workspace). This lets you interact with local files in the DSW instance by using relative paths. You can also create, delete, preview, or edit files within the DSW instance.
ImportantBilling starts as soon as an instance enters the
runningstate.(Optional) Select a compute resource, such as MaxCompute or Flink.
When developing in an SQL cell, click Select a computing resource, and then click Associate Computing Resource to go to DataWorks to associate a computing resource. When you run the cell, the specified compute resource executes the SQL code.

After you write the code in your cells, run them to test your Notebook.
Run all cells: Click the
button in the toolbar to run all cells in the Notebook.Run a single cell: Click the
button to the left of a cell to run only that cell.
View the result.
Click Ask Copilot to view the code analysis results in the right-side pane.
