Work with Jupyter notebooks in an Azure Quantum workspace

Learn how to run Q# or Python code in a Jupyter notebook in an Azure Quantum workspace. A Jupyter notebook is a document that contains both rich text and code and can run in your browser.

Prerequisites

You need the following prerequisites to use Jupyter notebooks in an Azure Quantum workspace.

Get a sample notebook

To get started, you can use use a sample from the notebook gallery.

  1. Select your Azure Quantum workspace in the Azure portal.

  2. Select Notebooks.

  3. Select Sample Gallery.

  4. Select the sample you want to use, and select Copy to My notebooks.

    Notebook gallery in Azure Quantum.

The sample notebook can be found under My notebooks and you can now run the notebook.

Run notebook

To run Q# or Python in a Jupyter notebook, follow these steps.

  1. Select your Azure Quantum workspace in the Azure portal.

  2. Select Notebooks.

  3. Select your notebook in My notebooks.

  4. Select the cell you want to run and select the run icon to execute the code in the cell, or select Run all to run all cells in the notebook.

    Run a Jupyter notebook.

Create a new notebook

Follow these steps to create a new Jupyter notebook using Q# or Python.

  1. Select your Azure Quantum workspace in the Azure portal.

  2. Select Notebooks.

  3. Select My notebooks and select Add new

    Create a new Jupyter notebook.

  4. Select either IQ# or IPython as the Kernel Type, type a File Name and select Create file.

    Select notebook kernel and file name for a new Jypter notebook.

The first cell of the notebook is populated automatically with the connection string to the Azure Quantum workspace.

For Q#, the first cell will look like this.

New Q# notebook in Azure Quantum.

For Python, the first cell will look like this.

New Python notebook in Azure Quantum.

Select + Code or + Markdown to add a code or markdown text cell.

Tip

Notebooks auto-saves every 30 seconds. You can also manually save by pressing CTRL + S.

Upload notebooks

You can upload one or more existing Jupyter notebooks to an Azure Quantum workspace.

Caution

You should only upload and run Jupyter notebooks from trusted sources and only install packages from trusted sources. While notebooks in Azure Quantum protects you by sandboxing outputs, Jupyter Notebooks is built for arbitrary code execution, so there are inherent risks to uploading or running notebooks from an untrusted source.

  1. Select your Azure Quantum workspace in the Azure portal.

  2. Select Notebooks.

  3. Select My notebooks.

  4. Select Upload new.

  5. Drag and drop your notebook files, or select Browse for Files and select the notebook files you want to upload.

  6. If you want to overwrite already existing files, select Overwrite if already exists.

  7. Select Upload files.

    Upload notebook to Azure Quantum.

After the notebooks have been uploaded, you can find them under My notebooks.

Manage notebooks

You can rename, delete, duplicate, and download existing notebooks.

  1. Select your Azure Quantum workspace in the Azure portal.

  2. Select Notebooks.

  3. Select your notebook in My notebooks and select the context pane (...).

  4. Select Rename Notebook, Delete Notebook, Duplicate Notebook, or Download Notebook.

    Notebook context pane in Azure Quantum.

Isolation

Jupyter notebooks in an Azure Quantum workspace are isolated from other users' notebooks.

  • Your Jupyter Notebook instance is hosted by Azure Quantum with hypervisor-level isolation from other users' instances.
  • Notebooks are stored in your linked storage account in your subscription.
  • A Jupyter Notebook instance is scoped to you and a specific workspace. If you visit another workspace, you will get a different instance. If another user visits the same workspace, they will get a different Jupyter Notebook instance from you.
  • Notebooks are scoped to you and a specific workspace. If you visit another workspace, the same notebooks will not appear under My Notebooks. If another user visits the same workspace, they will not see your notebooks.

Storage of notebooks

Jupyter notebooks are stored in an Azure Storage account linked to your Azure Quantum workspace.

Note

When notebooks are used in a workspace, Cross-Origin Resource Sharing (CORS) in enabled on the linked Azure Storage account. If you do not want to enable CORS for your Azure Storage account, please do not visit the Notebooks blade in the portal. If you have visited the blade previously and now no longer want to enable CORS, you can directly edit your storage account to remove any existing CORS rules.

Limitations

The following are limitations with Jupyter notebooks in an Azure Quantum workspace.

  • As it is free, the Jupyter Notebook instance will live up to a max of 12 hours (after that time, your instance will be deleted/recreated, and you will need to reinstall any custom packages).
    • Azure Quantum may need to delete your Jupyter Notebook instance to apply security patches or roll out emergency changes. When possible, it will not interrupt your workflow.
  • Notebook instances have pre-allocated 2 vCPU and 4 GB of memory.
  • Idle kernels are terminated after 30 minutes. After that time, you will need to rerun the cells.
  • The location of your storage account and workspace will affect the performance of Jupyter notebooks in an Azure Quantum workspace. When possible, try to create the storage account and workspace in a region close to where you will be using your notebooks.

Next steps