https://mathplus.de/topic-development-lab/tes-summer-2024/qoc-workshop/
Please make sure to follow the installation instructions below carefully. You must set up these prerequisites on your own laptop before the start of the tutorial. During the two hours of the tutorial session, there will not be time for solving technical issues.
There is also a YouTube playlist to walk you through this installation:
- Installation on a Windows system
- Installation on a macOS system. These would be mostly applicable to other Unix/Linux systems as well.
On Windows, it is easiest if you have full administrative privileges. On macOS or Linux, everything will install into your home directory by default, so "root access" is not required.
This tutorial is a collection of Jupyter notebooks. To view and run them, you must have the Jupyter application installed on your system. We recommend using Miniforge to install Jupyter (or some other conda
-based distribution like Miniconda or the original Anaconda, but we recommend installing all packages from the conda-forge channel).
⚠️ ⚠️ ⚠️ Even if you already have Jupyter installed, you are probably missing thepython-localvenv-kernel
package. Make sure to install its latest version into the same environment that containsjupyter
. You may also need to installipympl
in the correct version. See the FAQ for details.
Assuming you have a Miniforge installation (or you have set up conda-forge
as your default channel), running the following command line instruction should install Jupyter into your base
environment:
conda install jupyterlab python-localvenv-kernel=0.1.7 ipympl=0.9.3
Note the python-localvenv-kernel
package, which is available only in conda-forge
. If you cannot use the conda-forge
channel, the package can also be installed into an existing environment via pip
. When installing on Windows, it is important that the python-localvenv-kernel
package is in the latest version (pip install python-localvenv-kernel==0.1.7
.)
The ipympl
package is used in some of the notebooks for interactive plots (%matplotlib widget
). For this to work properly, ipympl
must be installed both in the environment providing the Jupyter application and in the project environment used by the notebook (defined in environment.yml
), in the same version 0.9.3
. If there is a mismatch, you may see errors when generating plots. However, you will still be able to follow the tutorial with non-interactive plots by removing the %matplotlib widget
line in any notebook.
To make sure that your Jupyter is set up correctly, run
jupyter kernelspec list
on the command line and check that the output contains an entry for python-localvenv
. In case python-localvenv
does not appear in the kernel list try to reinstall the package with pip
, see also the package FAQ, or with %pip
inside a notebook cell inside a running jupyter
instance, see the tutorial FAQ.
You should now be able to launch Jupyter by running
jupyter lab
on the command line, from the folder containing this tutorial.
We also recommend that you install the JuliaMono font on your system. If possible, set it as the default monospace font in your terminal as well as your browser (e.g, via the URL chrome://settings/fonts
in Chrome) and in Jupyter Lab ("Settings", "Settings Editor", "Theme", set "code-font-family" to "JuliaMono" for your "Selected Theme").
If you would like to complete this tutorial in the Julia language, you must install Julia onto your system. Use the Juliaup installer and follow the installation instructions.
If you have problems with juliaup
, you can also manually install the official binaries.
Check that you get a Julia REPL ("Read-Evaluate-Print-Loop", the thing where you can type in code, press enter, and see the result) if you start julia
on the command line, or if you click the appropriate Julia application icon in your start menu (Windows) or the Applications folder (macOS).
Once you have julia
installed, you also need IJulia to make Julia available in Jupyter. Run the following on the command line:
julia -e 'using Pkg; Pkg.add("IJulia")'
Or, if you are already in a Julia REPL,
] add IJulia
would be the equivalent command (]
activates Pkg
mode, press backspace to get back to the standard REPL mode).
Although this should happen automatically, in some situations you may have to to manually (re-)install the IJulia kernel. In a Julia REPL in the default environment, run
using IJulia
installkernel("Julia", "--threads=auto", "--project=@.")
See the FAQ for details.
Even though you already have python
installed by virtue of having the Jupyter applications, you must still initialize the project environment in which the Python notebooks are executed. If you intend to follow this tutorial only in Julia, you can skip this setup. Because we will use Python packages that wrap around compiled C++ code, initializing the environment requires the conda
executable, see the installation instructions for Jupyter above.
On the command line, from the folder containing this tutorial, run
conda env create -p .venv -f environment.yml
Similarly, to execute any of the Julia notebooks, you must initialize a Julia project environment. If you intend to follow this tutorial only in Python, you can skip this setup. Assuming you have Julia installed on your system (see above), run the following on the command line, from the folder containing this tutorial:
julia --project=. -e "using Pkg; Pkg.instantiate()"
Or, from inside a Julia REPL with the tutorial folder as the current working directory
using Pkg
Pkg.activate(".") # equivalent to starting Julia with `--project=."
Pkg.instantiate()
The first time you do this, it will precompile a lot of packages. This can take a while (10-15 minutes, maybe more on a older Windows computer). Grab a coffee.
If you are on a Unix system and have some basic development tools installed, you can also run
make init
to initialize both the Python and Julia project configuration. Note that this will fail unless both Python and Julia are installed on your system.
This concludes the setup instructions for the tutorial. To verify the installation, run jupyter lab
and find the "Hello World" notebooks in the Python and Julia subfolders. Run these to completely to make sure that everything is working, and please ask for help if it is not.
Assuming you have set up all the prerequisites as described above, start jupyter lab
from the folder containing this tutorial. If you are on a Unix system and have make
installed, you may also run make jupyter-lab
.
⚠️ ⚠️ ⚠️ You are not expected to work though all of the notebooks below.
- Population Inversion in a Two-Level-System (Python, Julia)
- Population Transfer in a Three-Level-System with STIRAP (Python, Julia)
- Interaction of a Two-Level-System with a Chirped Laser Pulse (Python, Julia)
- Population Inversion in a Two-Level-System using Parameter Optimization (Python, Julia)
- Parameter Optimization for STIRAP (Python, Julia)
- Parameter Optimization of Three-Wave Mixing in a Three-Level System (Python, Julia)
Note that optimization with GRAPE is available only in the Julia version of these exercises.
- Population Inversion in a Two-Level-System using Krotov's Method and GRAPE (Python, Julia)
- Optimal Control for STIRAP (Python, Julia)
- Chiral Three-Wave Mixing (Python, Julia)
- Entangling Quantum Gates for Coupled Transmon Qubits (Python, Julia). The Julia version of this notebook demonstrates logical subspaces embedded in a larger physical Hilbert space, and show the use of semi-automatic differentiation to optimize arbitrary, even non-analytical functionals like the gate concurrence with both GRAPE and Krotov's method.
The notebooks span a wide variety of examples and target different levels of expertise. You are encouraged to choose your own path through the tutorial. During the two hours of the tutorial session, you will probably only be able to go through two or so notebooks superficially, and one notebook in full detail. Follow your interests; there are many possible paths through the tutorial.
- If you want to stick to a simple two-level system, look at Exercises I.1, II.1, II.3 (Python, or Julia I.1, II.1, II.3)
- If you you want to develop a basic understanding of light-matter-interaction from a numerical perspective without much optimal control, look at Part 1 (Python/Julia), and maybe Exercise II.1 as a follow-up (Python, Julia)
- If you want to follow along the control of a three-level system ("STIRAP") consider Exercises I.2, II.2, II.3, maybe with I.1 as a quick "warm-up" (Python, or Julia, I.1, I.2, II.2, II.3)
- If you are interested in chiral molecules and some more advanced examples of parameter optimization, follow Exercises I.1 (as warm-up), II.3, III.3 (Python, or Julia I.1, II.3, III.3)
- If you want to learn specifically about parameter optimization, go through the Exercises in Part II (Python, or Julia), with maybe III.2 (Python, Julia) as an outlook
- If you want to learn about Krotov's method, go through Exercises I.1 (prep), III.2, III.4 (Python, or Julia I.1, III.2, III.4). Note that later Julia Exercises dive into some more advanced topics compared to their Python counterparts. Specifically, the Julia versions support optimization both with Krotov's method and GRAPE.
- If you are interested in quantum information, briefly go through Exercises II.1 and III.1 and then mainly III.4 (Python, or Julia II.1, III.1, III.4)
You can go through earlier notebooks quickly until you reach on that is is challenging or of particular interest to you. Also, the notebooks will remain available after the end of the workshop so you can always come back, or explore other topics.
You may find further example beyond the scope of this tutorial in the documentation of
the Python krotov
package and the documentation of the Julia QuantumControl
framework. These both include examples for the optimization of open quantum systems; it is worth noting that the techniques illustrated in this tutorial apply quite directly to both closed and open quantum systems.