Notebook Engine Examples
This guide will walk you through the Notebook Engine client usage in a few examples.
See the module documentation for full client reference.
Starting a Notebook engine
import h2o_engine_manager
from h2o_engine_manager.clients.notebook_engine.engine import NotebookEngine
# Initialize clients.
aiem = h2o_engine_manager.login()
notebook_engine_client = aiem.notebook_engine_client
notebook_engine_profile_client = aiem.notebook_engine_profile_client
notebook_engine_image_client = aiem.notebook_engine_image_client
# You can list available profiles.
profiles = notebook_engine_profile_client.list_all_notebook_engine_profiles(parent="workspaces/global")
print("Profiles:")
for profile in profiles:
print("\t", profile.name)
# You can list available images.
images = notebook_engine_image_client.list_all_notebook_engine_images(parent="workspaces/global")
print("Images:")
for image in images:
print("\t", image.name)
# Create Notebook engine with required parameters.
eng = notebook_engine_client.create_notebook_engine(
parent="workspaces/default", # You can use alias 'default' for your personal workspace.
notebook_engine=NotebookEngine(
profile="workspaces/global/notebookEngineProfiles/default", # One of the listed profiles.
notebook_image="workspaces/global/notebookEngineImages/default", # One of the listed images.
display_name="My Basic Notebook engine",
),
notebook_engine_id="my-engine"
)
# Wait until the engine is ready.
notebook_engine_client.wait(name=eng.name)
# You can access the running Notebook engine in browser via the access URI.
print("Notebook engine access URI: ", notebook_engine_client.access_notebook_engine(name=eng.name))
Advanced Notebook engine
# Create Notebook engine with customized parameters (cpu, gpu, memory, storage, ...).
eng = notebook_engine_client.create_notebook_engine(
parent="workspaces/default", # You can use alias 'default' for your personal workspace.
notebook_engine=NotebookEngine(
profile="workspaces/global/notebookEngineProfiles/default", # One of the listed profiles.
notebook_image="workspaces/global/notebookEngineImages/default", # One of the listed images.
display_name="My Advanced Notebook engine",
cpu=4,
gpu=1,
memory_bytes="2Gi",
storage_bytes="4Gi",
max_idle_duration="2h",
max_running_duration="2h",
),
notebook_engine_id="my-engine",
)
Fetching a Notebook engine
This fetches an existing engine from the previous example.
import h2o_engine_manager
notebook_engine_client = h2o_engine_manager.login().notebook_engine_client
engine = notebook_engine_client.get_engine(name="workspaces/default/notebookEngines/my-engine")
print(engine)
Listing Notebook engines
The list_engine
method supports pagination.
Following example shows basic listing usages.
import h2o_engine_manager
notebook_engine_client = h2o_engine_manager.login().notebook_engine_client
# By default, engines are ordered by their time of creation in descending order
# and limited to 50 items per page.
page1 = notebook_engine_client.list_notebook_engines(parent="workspaces/default")
# To list a second page, pass the next_page_token from the previous page.
# This example increases the page size to 100.
page2 = notebook_engine_client.list_notebook_engines(
parent="workspaces/default",
page_size=100,
page_token=page1.next_page_token
)
# You can use a convenience function for listing all notebook engines from a specified workspace.
all_engines = notebook_engine_client.list_all_notebook_engines(parent="workspaces/default")
Pausing a Notebook engine
You should pause your engines when you are not using them to save costs. Pausing terminates all running jobs but all other state is persisted.
import h2o_engine_manager
notebook_engine_client = h2o_engine_manager.login().notebook_engine_client
# Pause the engine.
notebook_engine_client.pause_notebook_engine(name="workspaces/default/notebookEngines/my-engine")
# You may wait for the engine to get into PAUSED state.
# This is a blocking call.
notebook_engine_client.wait(name="workspaces/default/notebookEngines/my-engine")
An engine can be automatically paused after exceeding the max_idle_duration or max_running_duration.
Resuming a Notebook engine
A paused engine can be resumed to continue using it.
import h2o_engine_manager
notebook_engine_client = h2o_engine_manager.login().notebook_engine_client
# Resume a paused engine.
notebook_engine_client.resume_notebook_engine(name="workspaces/default/notebookEngines/my-engine")
# You may wait for the engine to get into RUNNING state.
# This is a blocking call.
notebook_engine_client.wait(name="workspaces/default/notebookEngines/my-engine")
# You can access the again-running Notebook engine in browser via the access URI.
access_uri = notebook_engine_client.access_notebook_engine(name="workspaces/default/notebookEngines/my-engine")
print("Notebook engine access URI: ", access_uri)
Updating a Driverless AI engine
You can modify an existing engine with the update method. The engine is only updatable when paused.
import h2o_engine_manager
notebook_engine_client = h2o_engine_manager.login().notebook_engine_client
# Get the engine first.
engine = notebook_engine_client.get_notebook_engine(name="workspaces/default/notebookEngines/my-engine")
# Change selected engine fields to new values.
engine.cpu = 2
# Perform the update.
notebook_engine_client.update_notebook_engine(notebook_engine=engine)
Deleting a Notebook engine
Engine deletion is a destructive operation that immediately terminates the engine and deletes all data contained within. It cannot be undone.
import h2o_engine_manager
notebook_engine_client = h2o_engine_manager.login().notebook_engine_client
# Delete engine.
notebook_engine_client.delete_notebook_engine(name="workspaces/default/notebookEngines/my-engine")
# You may wait for the engine to finish deleting.
notebook_engine_client.wait(name="workspaces/default/notebookEngines/my-engine")
- Submit and view feedback for this page
- Send feedback about AI Engine Manager to cloud-feedback@h2o.ai