Skip to content
Snippets Groups Projects
README.md 14.8 KiB
Newer Older
# Quantum Optimization ISC 2025 Tutorial

## Abstract
Lourens van Niekerk's avatar
Lourens van Niekerk committed
<!-- 
Quantum computing is a rapidly evolving technology with significant potential, particularly for solving optimization problems. Hard-to-solve classical challenges, such as graph-based problems, hold high practical relevance. A notable example is task mapping, where quantum approaches could provide groundbreaking solutions. Currently, hybrid methods such as the Quantum Approximate Optimization Algorithm (QAOA) are especially promising as they circumvent some of the disadvantages of noisy intermediate-scale quantum (NISQ) computers.

This tutorial has two main parts. The first part is an introduction to quantum computing, which familiarizes beginners with the concepts and programming of gate-based quantum computers. A focus is put on explanations and tutorials that can be easily understood by attendees without any prior knowledge of quantum mechanics. The Qiskit programming framework will be used in the hands-on tutorials to deepen the understanding of quantum computing. Quantum simulators will be used to simulate, analyze, and understand the action of quantum gates and how typical quantum algorithms are designed.

The second part provides an introduction to solving optimization problems with the QAOA approach, a quantum algorithm designed for solving combinatorial optimization problems by integrating gate-based quantum circuits and classical optimization. It will show how the QAOA approach is rooted in the variational quantum eigensolver framework and how it can leverage parameterized quantum circuits to tackle NP-hard problems with potential quantum speedups. The interplay between cost and mixer Hamiltonians and the optimization of circuit parameters will be discussed. 

Overall this tutorial will equip participants with a practical understanding of quantum computing, its challenges, and limitations. Furthermore, they will be able to identify if optimization problems they come across might be more efficiently solvable with the  Quantum Approximate Optimization Algorithm.  -->



Leveraging quantum algorithms holds the potential for exponential advancements in classical machine learning. In this ISC tutorial, we present an introductory tutorial to quantum computing
aimed at computer- and data scientists and HPC users of any scientific domain. Our focus is
to show how quantum computers are programmed today while providing the essential math and
Lourens van Niekerk's avatar
Lourens van Niekerk committed
physics background required to develop quantum algorithms. 
This is the 3rd tutorial to be presented at ISC by the team, following on the 'Introduction to quantum machine learning' tutorial the previous two years; 
this year with 'Introduction to quantum optimization'.
The first part introduces basic ideas and examples of gate-based quantum computing designed for participants without prior knowledge. The second part explains in detail the Quantum Approximate Optimization Algorithm (QAOA), a use case thereof, and the comparison of it to the classical approach. 
Experienced individuals in quantum computing can join both sessions to refresh their knowledge or participate
in the afternoon session alone. The tutorial will use the Qiskit framework to show how complex
quantum algorithms can be constructed from available building blocks. As participants progress
Lourens van Niekerk's avatar
Lourens van Niekerk committed
through this tutorial, they will acquire practical insights into the complexities of quantum computing, equipping them with knowledge and skills to explore the potential of quantum algorithms
in their respective fields.

## Target Audience
This tutorial is a beginner-level tutorial aimed at computer and data scientists of any degree of skill
with an interest in what quantum computers can provide and how they are programmed. HPC
users of any scientific domain interested in utilizing new approaches would find the integration
Lourens van Niekerk's avatar
Lourens van Niekerk committed
of classical and quantum computation in a heterogeneous approach exciting and helpful. Young programmers would find the tutorial beneficial to approach a fast-emerging market.
Lourens van Niekerk's avatar
Lourens van Niekerk committed
### Section 1: Quantum Computing Basics (3h30m):
* Introduction and basic concepts (60m)
* Exercises on qubit systems (45m)
* Implementation of quantum algorithms (30m)
* Exercises on quantum circuits (45m)
* Practical consideration on real quantum computers (15m)
* Exercises on aspects of real quantum computers (15m)

### Section 2: Quantum Machine Learning (3h30m):
* Introduction to QAOA (30m)
* Solving the task-mapping problem with QAOA (30m)
* Exercises on solving the task-mapping problem (60m)
* Deeper dive and context (30m)
* Exercises on error checking and analysis (30m)
* Exercises on benchmarking and the classical comparison (30m)

## Presenters
* Christian Boehme - christian.boehme@gwdg.de
Lourens van Niekerk's avatar
Lourens van Niekerk committed
* Dhiraj Kumar - dhiraj.kumar@gwdg.de
* Mehmet Niyazi Kayi - mehmetniyazi.kayi@gwdg.de
* Robert Schade - robert.schade@uni-paderborn.de
* Patrick Gelß - gelss@zib.de


## Institutes
Lourens van Niekerk's avatar
Lourens van Niekerk committed
* [GWDG](https://gwdg.de/hpc/) - Gesellschaft für Wissenschaftliche Datenverarbeitung mbH Göttingen
* [PC2](https://pc2.uni-paderborn.de/) - Paderborn Center for Parallel Computing - pc2-support@uni-paderborn.de
* [ZIB](https://www.zib.de/research) - Zuse Institute Berlin - info@zib.de

## Prerequisites
The tutorial is designed for attendees with some prior knowledge about quantum computing. People without prior experience could join the tutorial as well and would benefit still, as there will be basics covered in section 1, but the content might be covered too fast for satisfactory comprehension.

The exercises will be executed on the attendee's laptop. Attendees have two options for completing the exercises:
1. (RECOMMENDED) Temporary accounts are available for use that have been set up already on the JupyterHub of the NHR Emmy Cluster in Germany.
2. A self-installation script is provided in order to run the notebooks locally. This option requires the attendee to have python version 3.8 or later and the ability to set up virtual environments with Anaconda.

## Accessing resources options:
Lourens van Niekerk's avatar
Lourens van Niekerk committed
To prepare for the exercises, as mentioned in 'Prerequisites' above, please make use of ONLY ONE OPTION below for accessing the resources.

### OPTION 1: Jupyter-HPC Option
Each attendant has been assigned a temporary account for use on the Jupyter-HPC platform of the NHR Emmy cluster. The accounts are valid for the entire month of Novemeber, so further testing can be done after the conference. (Example: username: kurs1180 ; password: c4gI+aQ!-v)
Steps to usage:
1. Go to https://jupyter.hpc.gwdg.de/hub/login .
2. Enter your assigned username and password from your personal handout in the Academic ID login. This will direct you to the JupyterHub server spawner options page.
Christian Boehme's avatar
Christian Boehme committed
3. At 'Select a job profile', select 'Custom profile'. At 'Custom Profile ID', enter 'sc2024-quantum-machine-learning'. See image below.
   
Lourens van Niekerk's avatar
Lourens van Niekerk committed
![jupyterhub_spawner](/img/jupyterHub_spawner.png "JupyterHub Spawner Page")
4. Leave the rest of the options as is and press the 'Start' button. Once your server has been spawned and you are in the JupyterHub, open a Terminal (press the blue '+' button and click 'Terminal'), enter the JupyterHub folder and clone this repository:
    ```
    cd jupyterhub-gwdg
    git clone https://gitlab.gwdg.de/ag-compute-public/sc-2024-qml-tutorial.git
    ```
Lourens van Niekerk's avatar
Lourens van Niekerk committed
![jupyterhub_terminal](/img/jupyterHub_terminal.png "JupyterHub Terminal")
Lourens van Niekerk's avatar
Lourens van Niekerk committed
5. You should now have access to all material from the tutorial to follow along and complete the exercises. Enjoy!
Lourens van Niekerk's avatar
Lourens van Niekerk committed
### OPTION 2: Local Installation
1. Git is required for accessing the resources. In case Git isn't already available on your Computer: [Get Git](https://git-scm.com/downloads)
2. Get Anaconda (recommended) or pyflow
    - Installation instructions for your OS can be found here: [Get Anaconda](https://www.anaconda.com/download/)
    - for Ubuntu/Debian run following command in a terminal after installation:
    ```
    source ~/.bashrc
    ```
3. Create a virtual Python environment:
    - if you are using a Unix or Linux OS, use the `create_conda_env.sh`
    - else: open a command shell, or the Anaconda Navigator and open Powershell Prompt.
        - Create a new Python environment (3.12 is best if possible)
        ```
        (base) ~$ conda create --name qiskitenv python=3.12
        ```
        
        - Activate the environment
        ```
        (base) ~$ conda activate qiskitenv
        ```
        - Install required packages
        ```
        (qiskitenv) ~$ conda install notebook ipykernel 
        ```
        - Create kernel
        ```
        (qiskitenv) ~$ python -m ipykernel install --user --name qiskitenv
        ```
        - Install required qiskit packages
        ```
        (qiskitenv) ~$ pip install qiskit[visualization]==1.0.2 qiskit-machine-learning==0.7.2 qiskit-algorithms==0.3.0 qiskit-ibm-runtime==0.23.0 qiskit-aer==0.14.1 
        ```
4. Open the notebook
    - either use VScode and select the kernel `qiskitenv`,
    - or start a jupyter instance on your machine using your Web Browser: [Jupyter Notebook Documentation](https://jupyter-notebook-beginner-guide.readthedocs.io/en/latest/execute.html)
    - on Ubuntu/Debian type:
    ```
    Username@Hostname: ~$ jupyter notebook
    ```
    - on Windows use the Anaconda Navigator to start a jupyter notebook
5. Clone the repository
    - Use the below command and start enjoying the exercises.
    ```
    git clone https://gitlab.gwdg.de/ag-compute-public/sc-2024-qml-tutorial.git
    ```
<!---
### 3) Using a Virtual Machine (VM)
#### Using the VM
Install Oracle VM VirtualBox Manager for your system from https://www.virtualbox.org/wiki/Downloads . Download the VM files from https://owncloud.gwdg.de/index.php/s/X34sZ90qmSAoF1U (there should be a .vbox configuration file and a .vdi disk drive file compressed as a .zip file). Make sure the .vbox and .vdi files are together in the same folder. Open the VM Manager, then add a machine with the Add button or Machine -> Add. Navigate to the location of the .vbox file, and select it. To start the machine, just double click on it.
![vm01](/images/VM/vm-01-add_vm.png "Add a VM to VirtualBox")
Some terminology going forward: "Host" refers to your own computer/OS, where VirtualBox is installed. "Guest" refers to the VM we are using.
The VM starts with 2 processors and 4 GB of RAM allocated. If you want to increase or reduce this allocation, see the section "Expanding or Reducing VM resources".
The more useful applications have been gathered together on the desktop (file is the file explorer):
![vm02](/images/VM/vm-02-apps.png "Main available applications")
To start the Jupyter server, open the console by double clicking on its icon, then "jupyter-notebook --allow-root". This should also automatically open the server on Firefox. If it doesn't, open Firefox or another browser, and input "localhost:8888" as a URL.
![vm03](/images/VM/vm-03-jupyter.png "Console and Jupyter Server")
To terminate the server, go to the console and press Ctrl+c on your keyboard (or just close the terminal or power off the VM).
#### Changing VM resolutions
The VM should be configured to adapt the guest view port automatically if you resize the VM's window. This can lead to some graphical bugs on the guest, which are easily solved by restarting its graphical server (see section Graphical Bugs below).
If the automatic window resizing does not work, you can change the resolution from inside the guest OS, by going to Menu on the bottom left -> Setup -> Screen/Graphics Wizard -> First option (Screen Resolution/Color Depth)

![vm04](/images/VM/vm-04-resolution1.png "Resolution menu 1")
![vm05](/images/VM/vm-05-resolution2.png "Resolution menu 2")

If you experience problems with the window size adjusting on its own or not adjusting to your changes, you can change these options using the menu at the top when the VM is running. Under the View option, select Auto-Adjust Guest Display to enable or disable the automatic resizing.

#### Graphical bugs

If you notice some graphical bugs on the VM (particularly after resizing the window), click on the start menu on the bottom left, Exit, then "Restart graphical server". 

![vm06](/images/VM/vm-06-graphicalrestart.png "Restarting the graphical server")

#### The "Desktop"

The "Desktop" in this Linux version doesn't function like a normal Ubuntu/Windows Desktop, so don't expect files to show up there if you download them to a Desktop folder. It is recommended to download files to the "Downloads" folder or similar to make them easier to find.

#### Expanding or Reducing VM resources

If you find that the VM is too slow and your laptop/computer has a lot of resources (or not enough resources to run the current setup), you can expand the RAM, VRAM and CPU cores dedicated to the VM. For this purpose, stop the machine, right click on it, Settings, and change the allocated RAM (System -> Motherboard -> Base Memory), number of processors (System -> Processor -> Processors), or VRAM (Display -> Screen -> Video Memory).

![vm07](/images/VM/vm-07-ram.png "Changing RAM allocation")
![vm08](/images/VM/vm-08-cpu.png "Changing CPU allocation")
![vm09](/images/VM/vm-09-vram.png "Changing VRAM allocation")

#### Shared Clipboard

By default, the clipboard sharing between host and guest is disabled. To reenable it, either right click on the machine -> Settings -> General -> Advanced Tab -> Shared Clipboard; or while the machine is running, in the menus at the top select Devices -> Shared Clipboard. You can set the clipboard to be uni- or bi-directional.

#### Shared folder with Host

If you want to easily transfer files in or out of the machine (for example, to copy out your solved notebooks), follow these steps:

On Virtualbox:
With the machine stopped, right click on it, Settings -> Shared Folders -> Add. Select a path on your host machine, leave other options as default or empty.

On the Linux Host:
1. Open /etc/rc.d/rc.local with console (vi) or text editor
2. Modify the last command () by removing the # and changing both instances of "shared-folder" to the name you gave the shared folder in VirtualBox
3. Create the folder on the mount directory if it doesn't already exist: sudo mkdir /mnt/shared-folder (or the name you used in the previous point)
4. Restart the VM
5. Your folder will be mounted to /mnt/shared-folder in the guest, and wherever you told VirtualBox on the host. Files added here will be accesible from both machines.

If the folder does not appear, make sure it is actually shared in the VirtualBox menus.

#### Deleting/Cleaning up the VM

Before deleting the machine, right click on it and choose the option "Show in file manager". This will lead you to the location of any extra files theVirtualBox might have created for the VM. Make a note of the location. 

To delete the machine, right click on it and then Remove. You will be given the option to also delete any lingering files. To confirm all files have been cleaned, check the location mentioned in the previous paragraph, as well as the location where the .vbox and .vdi files were initially downloaded.
--->