Krotov’s Method in quantum control

Hello everybody. I’m looking for a krotov method in Julia, but I’ve been having doubts with the search result. What is the recommended package for the krotov optimization method? I’m going to use it with quantum control. Thank you all.

You can try Krotov.jl, which is a port of the krotov Python package.

But I can’t even test Krotov because there is no Shapes method in QuantumControl (package installed).

ϵ(t) = 0.2 * QuantumControl.Shapes.flattop(t, T=5, t_rise=0.3, func=:blackman);

I was typing ϵ(t), but without the (t):

ϵ = 0.2 * QuantumControl.Shapes.flattop(t, T=5, t_rise=0.3, func=:blackman);

and getting the error: ERROR: UndefVarError: Shapes not defined

It doesn’t work for me. When I execute the commands in example 1, I still get an error message when I run :
julia> fig = plot_control(H[2][2], tlist)
ERROR: UndefVarError: Shapes not defined

It was not immediately obvious you are talking about the Julia package QuantumControl.jl (which seems to use Krotov.jl internally).

I would suggest asking on their issue tracker GitHub - JuliaQuantumControl/QuantumControl.jl: Julia Framework for Quantum Optimal Control or pining some of the package authors that are also on this forum, e.g. @goerz

QuantumControl.jl (which contains Krotov.jl) is definitely the package you’re looking for.

@marllos I just doubled-checked the Example from a clean environment, and it should work just fine. If you’re missing QuantumControl.Shapes, my best guess would be that you’re not running the latest release of QuantumControl or its sub-packages. There was some re-organization a month ago or so that would have affected QuantumControl.Shapes. Maybe you dev-installed packages from the JuliaQuantumControl organization at some point in the past? Make sure that you’re running the latest release (or the latest master branch, equivalently).

If you’re running into any problems, feel free to ask here (tag me), in the #quantumcontrol channel on Slack, or by opening an issue on Github. There might still be a few rough edges in QuantumControl.jl: I’d say it’s not quite ready for “production” yet, although everything in the examples definitely works as described (most notably, optimizations with Krotov and GRAPE of standard quantum control problems). Other stuff is still on the roadmap, like better integration with packages such as QuantumOptics.jl and a better API for the time propagation (QuantumPropagators.jl)

1 Like

Hi Goerz, you are right about the versioning of the packages. But I always install with “pkg> add” and update Julia almost daily. So do I need to install manually?

The versions are:

pkg> st
[b05dcdc7] Krotov v0.0.1
[8a270532] QuantumControl v0.0.1
[429524aa] Optim v1.7.0
[3c0b384b] QuantumInformation v0.4.9
… (+23)

julia> versioninfo()
Julia Version 1.7.2
Commit bf53498635 (2022-02-06 15:21 UTC)
Platform Info:
OS: Linux (x86_64-pc-linux-gnu)
CPU: Intel(R) Core™ i3-7020U CPU @ 2.30GHz
WORD_SIZE: 64
LIBM: libopenlibm
LLVM: libLLVM-12.0.1 (ORCJIT, skylake)

Linux fedora 5.15.8-200.fc35.x86_64 #1 SMP Tue Dec 14 14:26:01 UTC 2021 x86_64 x86_64 x86_64 GNU/Linu

The latest version of QuantumControl is 0.2.0. You have 0.0.1, which was basically a placeholder release and will not be useable for anything.

If you start with a new Project and install QuantumControl into that, you should be fine.

You can do this, e.g., with the following, in some (new) project folder:

julia --project=.
julia> ]add QuantumControl

Then you can run all the command from the Example in the same REPL (you’ll also want to install Plots, and probably skip the “DrWatson” cell, unless you’ve set up your project with DrWatson)

I think you can also just run ] update in your base environment (the REPL you get if you just run julia), but I strongly recommend against installing anything into your base environment. For reproducibility, you’ll always want to work with a project folder, or even use something like DrWatson. Maybe start afresh by deleting your ~./julia folder (make a backup fist: you might have dev-installs are in there, but otherwise that folder doesn’t contain anything that’s not re-generated automatically)

Interesting, I never used Julia as you showed. Just curious, in QuantumControl you solve the Liouville Equation using Chebyshev derivative matrices?

(krotov) pkg> st
Status ~/Documentos/tmp/krotov/Project.toml
[b05dcdc7] Krotov v0.2.1
[8a270532] QuantumControl v0.2.0
(all)

Chebychev polynomials are only defined for real numbers, which means they can only expand the exponential for Hermitian Hamiltonians (real eigenvalues). For open system dynamics, you can use an expansion into Newton polynomials instead (:newton prop-method in QuantumPropagators). For some reason, my Julia implementation of the Newton expansion is a bit slower than I’d like (about a factor of 10 slower compared to Cheby), but still much better than an ODE solver. Maybe I’ll be able to bring that down in the future.

In any case, the optimization should automatically pick the right propagation method, in most cases, so you probably don’t have to worry about it too much.

Thank you very much Goerz.

1 Like