ノートブックの実行スケジュールを設定する
このページでは、Vertex AI Workbench エグゼキュータを使用して、Python ノートブック ファイルを 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.
-
In the Google Cloud console, on the project selector page, select or create a Google Cloud project.
Roles required to select or create a project
- Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
-
Create a project: To create a project, you need the Project Creator
(
roles/resourcemanager.projectCreator
), which contains theresourcemanager.projects.create
permission. Learn how to grant roles.
-
Verify that billing is enabled for your Google Cloud project.
-
Enable the Notebooks and Vertex AI APIs.
Roles required to enable APIs
To enable APIs, you need the Service Usage Admin IAM role (
roles/serviceusage.serviceUsageAdmin
), which contains theserviceusage.services.enable
permission. Learn how to grant roles. -
In the Google Cloud console, on the project selector page, select or create a Google Cloud project.
Roles required to select or create a project
- Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
-
Create a project: To create a project, you need the Project Creator
(
roles/resourcemanager.projectCreator
), which contains theresourcemanager.projects.create
permission. Learn how to grant roles.
-
Verify that billing is enabled for your Google Cloud project.
-
Enable the Notebooks and Vertex AI APIs.
Roles required to enable APIs
To enable APIs, you need the Service Usage Admin IAM role (
roles/serviceusage.serviceUsageAdmin
), which contains theserviceusage.services.enable
permission. Learn how to grant roles. -
Notebooks 実行者(
roles/notebooks.runner
) - ストレージ管理者(
roles/storage.admin
) ノートブック ファイルの最初のセルに、次のように入力します。
# Import datetime import datetime # Get the time and print it datetime.datetime.now() print(datetime.datetime.now())
ノートブック ファイルを保存するには、[File] > [Save Notebook] の順に選択します。
Google Cloud コンソールで [インスタンス] ページに移動します。
インスタンス名の横にある [JupyterLab を開く] をクリックします。
Vertex AI Workbench インスタンスで JupyterLab が表示されます。
[
File Browser] で、サンプル ノートブック ファイルをダブルクリックして開きます。[
Execute] ボタンをクリックします。[Submit notebooks to Executor] ダイアログの [Type] フィールドで、[Schedule-based recurring executions] を選択します。
デフォルトでは、エグゼキュータはノートブック ファイルを 1 時間ごとに
00
分実行します。[Advanced options] で、[Cloud Storage bucket] フィールドにバケットの名前を入力し、[Create and select] をクリックします。エグゼキュータは、この Cloud Storage バケットにノートブックの出力を保存します。
[Submit] をクリックします。
ノートブック ファイルは、設定したスケジュールで自動的に実行されます。
JupyterLab のナビゲーション メニューで [
Notebook Executor] ボタンをクリックします。[Executions] タブをクリックします。
表示する実行条件の下にある [View result] をクリックします。
エグゼキュータが新しいブラウザタブに結果を表示します。
インスタンスの JupyterLab ユーザー インターフェースで、ナビゲーション メニューの [
Notebook Executor] ボタンをクリックします。[Executions] タブをクリックします。
共有する実行の横にあるオプション メニューをクリックして、[
Share execution result] を選択します。ダイアログの指示に沿って、実行結果へのアクセス権をユーザーに付与します。
インスタンスの JupyterLab ユーザー インターフェースで、ナビゲーション メニューの [
Notebook Executor] ボタンをクリックします。[Executions] タブをクリックします。
インポートする実行の横にあるオプション メニューをクリックし、[
Import executed notebook] を選択します。[Select Kernel] ダイアログが表示されたら、ノートブックを開くカーネルを選択します。
エグゼキュータは、実行されたノートブック ファイルを JupyterLab で開きます。JupyterLab ファイル ブラウザで、このノートブック ファイルは imported_notebook_jobs フォルダに保存されています。
Google Cloud コンソールで [スケジュール] ページに移動します。
表示するスケジュールのスケジュール名をクリックします。
[スケジュールの詳細] ページに、スケジュールの直近の 5 回の実行が表示されます。
実行名の横の [結果を表示] をクリックして、実行されたノートブック ファイルを開きます。
エグゼキュータが新しいブラウザタブに結果を表示します。
インスタンスの JupyterLab ユーザー インターフェースで、ナビゲーション メニューの [
Notebook Executor] ボタンをクリックします。[Schedules] タブをクリックします。
表示する実行の下にある [View latest execution result] をクリックします。
エグゼキュータが新しいブラウザタブに結果を表示します。
Google Cloud コンソールで [スケジュール] ページに移動します。
削除するスケジュールを選択します。
[削除] をクリックします。
インスタンスの JupyterLab ユーザー インターフェースで、ナビゲーション メニューの [
Notebook Executor] ボタンをクリックします。[Schedules] タブをクリックします。
スケジュール名をクリックします。 Google Cloud コンソールで、そのスケジュールの [スケジュールの詳細] ページが開きます。
[削除] をクリックします。
Google Cloud コンソールで [インスタンス] ページに移動します。
削除するインスタンスを選択します。
[削除] をクリックします。
- In the Google Cloud console, go to the Manage resources page.
- In the project list, select the project that you want to delete, and then click Delete.
- In the dialog, type the project ID, and then click Shut down to delete the project.
必要なロール
インスタンスのサービス アカウントに Vertex AI Workbench エグゼキュータの操作に必要な権限を付与するには、プロジェクトに対する次の IAM ロールをインスタンスのサービス アカウントに付与するよう管理者に依頼してください。
ロールの付与については、プロジェクト、フォルダ、組織へのアクセス権の管理をご覧ください。
管理者は、カスタムロールや他の事前定義ロールを使用して、必要な権限をインスタンスのサービス アカウントに付与することもできます。
インスタンスとサンプル ノートブック ファイルを作成する
実行スケジュールを設定する
このドキュメントに記載されているタスクの完了後、作成したリソースを削除すると、それ以上の請求は発生しません。詳細については、クリーンアップをご覧ください。
実行されたノートブック ファイルの表示、共有、インポート
インスタンスの JupyterLab インターフェースを使用すると、実行結果の表示、他のユーザーとの共有、実行されたノートブック ファイルの JupyterLab へのインポートを行うことができます。
実行結果を表示する
実行結果を共有する
実行されたノートブックを JupyterLab にインポートする
スケジュールを表示または削除する
スケジュールを表示および削除するには、 Google Cloud コンソールまたはインスタンスの JupyterLab ユーザー インターフェースを使用します。
スケジュールを表示する
スケジュールを表示してスケジュールの頻度設定を確認します。また、ノートブック ファイル実行の直近の 5 つの結果を確認することもできます。
コンソール
JupyterLab
スケジュールを削除する
スケジュールを削除しても、そのスケジュールから生成された実行は削除されません。
コンソール
JupyterLab
クリーンアップ
このページで使用したリソースについて、 Google Cloud アカウントに課金されないようにするには、次の手順を実施します。
インスタンスの削除
プロジェクトを削除する
スケジュールの作成に必要な Cloud Storage バケットなど、Vertex AI Workbench インスタンス以外のリソースを使用した場合は、それ以上の課金が発生しないように、プロジェクトを削除することをおすすめします。