Skip to content

kestrelquantum/QuantumCollocation.jl

Repository files navigation

QuantumCollocation.jl

Documentation Build Status Support Paper License
Dev Build Status Coverage Unitary Fund arXiv License: MIT

QuantumCollocation.jl uses NamedTrajectories.jl to set up and solve direct collocation problems specific to quantum optimal control, i.e. generating a pulse sequence $a_{1:T-1}$ to drive a quantum system and realize a target gate $U_{\text{goal}}$. We formulate this problem as a nonlinear program (NLP) of the form

$$\begin{aligned} \underset{U, a, \Delta t}{\text{minimize}} & \quad \ell(U_T, U_{\text{goal}})\\\ \text{ subject to } & \quad U_{t+1} = \exp(-i \Delta t H(a_t)) U_t \end{aligned}$$

Where the dynamics between knot points $(U_t, a_t)$ and $(U_{t+1}, a_{t+1})$ are enforced as constraints on the states which are free variables in the solver; this optimization framework is called direct collocation. For details of our implementation please see our award-winning IEEE QCE 2023 paper, Direct Collocation for Quantum Optimal Control. If you use QuantumCollocation.jl in your work, please cite 🙌!

QuantumCollocation.jl gives the user the ability to add other constraints and objective functions to this problem and solve it efficiently using Ipopt.jl and MathOptInterface.jl under the hood.

⚠️ Notice ⚠️

This package is under active development and issues may arise -- please be patient and report any issues you find!

Installation

QuantumCollocation.jl is registered! To install:

using Pkg
Pkg.add(QuantumCollocation)

Examples

Single Qubit X-Gate

See the example script examples/scripts/single_qubit_gate.jl, which produces the following plot:

Single Qubit X-Gate

Quickstart developers guide

Install Julia Juliaup is an installer and version manager. This is one useful way to manage Julia versions and keep up with the latest changes. After installing, run julia to obtain the Julia REPL.

Julia environments (Documentation) Your project's environment is stored in Project.toml. You can interactively add packages to an environment by using the Julia command line REPL and package manager. Start Julia in the project folder. Type ] to enter the package manager. Type activate . to activate or create an environment specified by Project.toml located in the current folder. Separately, you generate a manifest (solving the versions to create a valid environment) by running instantiate; instantiate will check that the environment is correct after you add all the packages you want.

Adding packages (Documentation) The initial cell for a Piccolo notebook might look something like the following:

# Standard packages
using LinearAlgebra
using CairoMakie

# Piccolo packages
using QuantumCollocation
using NamedTrajectories
using TrajectoryIndexingUtils

First, let's install some standard packages (these are like Numpy and Matplotlib). Open the package manager in the current environment (type julia, ], and activate .), type add LinearAlgebra to install and precompile LinearAlgebra. Same with CairoMakie.

Second, let's install Piccolo. There are three packages (QuantumCollocation, NamedTrajetories, TrajectoryIndexingUtils) inside Piccolo. We could do add Piccolo to get the three as a bundle from the Julia repository. Instead of individually calling using ... for each, this approach only requires using Piccolo at the start of a file or notebook.

As a developer, we want to use the git repositories directly from the Kestrel Quantum Github page. Clone, then add the local packages to the Project file with e.g. dev ../relative/path/to/repo/QuantumCollocation. This command installs the development version of QuantumCollocation pointing to the local Github code instead of the package repository. You can repeat this for the others, also.

Developing Revise.jl will let you edit source code, update packages, and reload the changes in a notebook---automatically! This is a great tool for development. add Revise from the REPL and then include it before any packages you intend to edit:

using Revise
using QuantumCollocation

Tips for Visual Studio Code

Julia extension You can run Julia notebooks and much more with the Julia extension. Upon opening your project folder in VS code and attempting to run an .ipynb, you will see that VS Code finds the interpreters managed by juliaup and defaults to using the environment based on the Project.toml in the project directory.

Fonts VS Code will not display all characters allowed by Julia. You can change the editor font family in the settings to 'JuliaMono' to get full support. If you don't want to mix and mash, you can create a new VS Code settings profile for working in Julia at File>Preferences>Profile.

Tests Tests should automatically populate in VS Code when working with a Piccolo package. For example, just by adding the QuantumCollocation.jl folder to your workspace, you should see tests appear if you click on the Testing sidebar icon. If you run one of these tests, a new Julia kernel is spawned for the test. You can find the kernel if you click on the Julia sidebar icon (after installing the Julia extensions). Sometimes, for the tests to recognize new changes, you may need to manually kill this kernel to see your changes reflected.