Skip to content

Latest commit

 

History

History
117 lines (90 loc) · 4.89 KB

how-to-submit-jobs-with-jupyter-notebooks.md

File metadata and controls

117 lines (90 loc) · 4.89 KB
author description ms.author ms.date ms.service ms.subservice ms.topic title uid
KittyYeungQ
This document provides a basic guide to submit and run Q# applications in Azure Quantum using Q# Jupyter Notebooks.
kitty
02/01/2021
azure-quantum
core
article
Submit jobs to Azure Quantum with Q# Jupyter Notebooks
microsoft.quantum.submit-jobs.jupyter

Submit jobs to Azure Quantum with Q# Jupyter Notebooks

This document provides a basic guide to submit and run Q# applications in Azure Quantum using Q# Jupyter Notebooks.

Prerequisites

  • An Azure Quantum workspace in your Azure subscription. To create a workspace, see Create an Azure Quantum workspace.

Installation

Follow these steps to install Jupyter Notebook and the current version of the IQ# kernel, which powers the Q# Jupyter Notebook and Python experiences.

  1. Install Miniconda or Anaconda.

  2. Open an Anaconda Prompt.

    • Or, if you prefer to use PowerShell or pwsh: open a shell, run conda init powershell, then close and re-open the shell.
  3. Create and activate a new conda environment named qsharp-env with the required packages (including Jupyter Notebook and IQ#) by running the following commands:

    conda create -n qsharp-env -c quantum-engineering qsharp notebook
    
    conda activate qsharp-env
  4. Run python -c "import qsharp" from the same terminal to verify your installation and populate your local package cache with all of the required QDK components.

You are now set up to use Q# Jupyter Notebooks and Q# integration to run quantum programs on Azure Quantum.

Quantum computing with Q# Jupyter Notebooks

  1. Run jupyter notebook from the terminal where your conda environment is activated. This starts the notebook server and opens Jupyter in a browser.

  2. Create your Q# notebook (via NewQ#) and write your Q# program.

  3. If you've never used Q# with Jupyter, follow the steps in Create your first Q# notebook.

  4. Write your Q# operations directly in the notebook. Running the cells will compile the Q# code and report whether there are any errors.

    • For example, you could write a Q# operation that looks like this:

      operation GenerateRandomBit() : Result {
          use q = Qubit();
          H(q);
          let r = M(q);
          Reset(q);
          return r;
      }
  5. Once you have your Q# operations defined, use the %azure.* magic commands to connect and submit jobs to Azure Quantum. You'll use the resource ID of your Azure Quantum workspace in order to connect. (The resource ID can be found on your workspace page in the Azure Portal.)

    If your workspace was created in an Azure region other than "West US", you also need to specify this as the location parameter to %azure.connect.

    • For example, the following commands will connect to an Azure Quantum workspace and run an operation on the ionq.simulator target:

      %azure.connect "/subscriptions/.../Microsoft.Quantum/Workspaces/WORKSPACE_NAME" location="West US"
      
      %azure.target ionq.simulator
      
      %azure.execute GenerateRandomBit

      where GenerateRandomBit is the Q# operation that you have already defined in the notebook.

  6. After submitting a job, you can check its status with the command %azure.status or view its results with the command %azure.output. You can view a list of all your jobs with the command %azure.jobs.

Some helpful tips while using Q# Jupyter Notebooks:

Next steps

Now that you know how to submit jobs to Azure Quantum, you can try to run the different samples we have available or try to submit your own projects. In particular, you can view a sample written entirely in a Q# Jupyter notebook.