Notebook Lab

Updated at:

Notebook Lab provides a lightweight editor that lets you preview and edit Notebook files stored on OSS without starting any compute resources. When you're ready to run code, connect the Notebook to a DSW instance. Multiple Notebooks can share a single instance, improving resource utilization.

Notebook Lab vs. DSW

Feature

Notebook Lab

DSW Instance

Core concept

Lightweight Notebook editor; multiple Notebooks share one instance

Full AI development environment

File storage

Stored on OSS; decoupled from compute

Bound to the instance working directory

Billing model

No charge for editing

Billed from the moment the instance starts

Toolset

Focused on Notebook authoring

Includes Notebook, WebIDE, and Terminal

Constraints

Notebook Lab is currently available in the following regions: China (Hangzhou), China (Shanghai), China (Beijing), China (Ulanqab), and China (Shenzhen).

Quick Start

Step 1: Open Notebook

  1. Log on to the PAI console, and select the target Region in the upper-left corner.

  2. In the left navigation pane, choose Workspaces, then click the target workspace name to enter the workspace.

  3. In the left navigation pane, choose Model Training > Data Science Workshop (DSW), then click the Notebook tab.

Step 2: Select a Code Directory

Click Select Code Directory, select an OSS bucket, and create a directory (for example, notebook_test) to use as the storage location for your Notebook files. Once configured, the Notebook list scans this directory and displays all Notebook files (*.ipynb) found under the OSS path.

Step 3: Create a Notebook and Write Code

  1. Click Create Notebook. This opens the Notebook development environment and creates a new Notebook file.

  2. Write your code. Click +Python to add a Python cell, then start writing code in the cell.

    The following is a sample code snippet:

    Sample code

    # Include dependency installation logic in the Notebook file so the environment
    # is set up correctly whenever you switch DSW instances.
    !pip install pandas
    # 1. Import the pandas library and alias it as pd
    import pandas as pd
    # 2. Prepare the raw data
    data = {
        'fruit': ['apple', 'banana', 'orange', 'strawberry', 'blueberry'],
        'sales_kg': [120, 200, 150, 80, 50],
        'price_per_kg': [8.5, 3.2, 5.0, 15.0, 25.0]
    }
    # 3. Create a DataFrame
    df = pd.DataFrame(data)
    # 4. Display the data
    print(df.head())
    Note
    • Install dependencies first: Because Notebook files and DSW instances are decoupled, include dependency installation commands in the Notebook file so the environment is set up correctly whenever you switch DSW instances.

    • Save your work regularly: Notebook Lab does not auto-save by default. Make sure to save your changes promptly.

Step 4: Link a DSW Instance and Run Code

  1. Click Link DSW, then select an instance that is in the Running state. Multiple Notebooks can be linked to the same DSW instance, which improves resource utilization.

  2. Click the Run icon to run the code.

    # Include dependency installation in the Notebook file to support any DSW instance.
    !pip install pandas
    import pandas as pd

    If the kernel fails to load in the Select Kernel area in the upper-right corner of the Notebook, try refreshing your browser to reload the environment.

    Sample output:

            fruit  sales_kg  price_per_kg
    0       apple       120           8.5
    1      banana       200           3.2
    2      orange       150           5.0
    3  strawberry        80          15.0
    4   blueberry        50          25.0
Important

Stop your DSW instance when not in use: If you are using a pay-as-you-go instance, billing begins as soon as the instance enters the Running state — even if you are not using WebIDE or running any code. Stop or delete the instance when it is no longer needed to avoid unexpected charges. After you delete an instance, the data on its system disk is cleared. Back up your data before deleting the instance.

Use Copilot for AI-Assisted Coding

You can use Copilot to assist with coding. To activate it:

  • Option 1: Click Generate in the Notebook Lab toolbar.

  • Option 2: Select a cell and use the following keyboard shortcut:

    • Windows: Ctrl+I

    • macOS: Command+I

Run MaxCompute SQL

  1. Install the required dependencies. Add a Python cell and run the following command:

    !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-binary
  2. Bind a MaxCompute resource.

    1. Click +SQL in the top toolbar to create an SQL node, or click the toggle button at the bottom-right corner of an existing Python cell to switch it to MaxCompute SQL.

    2. Bind a compute resource. Click Select Compute Resource, then click Bind Compute Resource to be redirected to DataWorks to complete Associate a computing resource.

  3. Write and run an SQL cell. The following is a sample SQL query using a public dataset:

    SET odps.namespace.schema=true; 
    SELECT * 
    FROM bigdata_public_dataset.default.employee_raw_scores
    limit 10;

    Sample output:

    SET odps.namespace.schema=true;
    SELECT *
    FROM bigdata_public_dataset.default.employee_raw_scores
    limit 10;
    There's a new dataworks-magic version available (0.1.11.2), you're running 0.1.5. To upgrade:
    pip install https://dataworks-notebook-cn-shanghai.oss-cn-shanghai.aliyuncs.com/public-datasets/pypi/dataworks-magic/datawor...
    MaxCompute LogView Address: http://logview.odps.aliyun.com/logview/?h=http://service.cn-hangzhou.maxcompute.aliyun-inc.com/a...
       index  employee_id  period_name  score_item_code  item_score
    0    0      19039043     2023-09       ItemP16          10
    1    1      19039043     2023-09       ItemG7            6
    2    2      19039043     2023-09       ItemC3            1
    3    3      19039043     2023-09       ItemT20           2

Billing

Writing code in Notebook Lab is free. When a Notebook is linked to a running DSW instance, DSW billing rules apply. For details, see DSW billing.

If you run SQL using MaxCompute resources, MaxCompute billing rules apply. For details, see MaxCompute Billing Overview.