Quantum information science has changed our perception of quantum physics from passive understanding to a source of technological advances [1]. By way of actively exploiting the two essential elements of quantum physics, coherence and entanglement, technologies such as quantum computing [2] or quantum sensing [3] hold the promise for solving computationally hard problems or reaching unprecedented sensitivity. These technologies rely on the ability to accurately perform quantum operations for increasingly complex quantum systems. Quantum optimal control allows to address this challenge by providing a set of tools to devise and implement shapes of external fields that accomplish a given task in the best way possible [4]. Originally developed in the context of molecular physics [5][6] and nuclear magnetic resonance [7][8], quantum optimal control theory has been adapted to the specific needs of quantum information science in recent years [4][9]. Calculation of optimized external field shapes for tasks such as state preparation or quantum gate implementation have thus become standard [4], even for large Hilbert space dimensions as encountered in e.g. Rydberg atoms [10][11]. Experimental implementation of the calculated field shapes, using arbitrary waveform generators, has been eased by the latter becoming available commercially. Successful demonstration of quantum operations in various experiments [4][12][13][14][15][16][17][18][19][20] attests to the level of maturity that quantum optimal control in quantum technologies has reached.

In order to calculate optimized external field shapes, two choices need to be made – about the optimization functional and about the optimization method. The functional consists of the desired figure of merit, such as a gate or state preparation error, as well as additional constraints, such as amplitude or bandwidth restrictions [4][9]. Optimal control methods in general can be classified into gradient-free and gradient-based algorithms that either evaluate the optimization functional alone or together with its gradient [4]. Gradient-based methods typically converge faster, unless the number of optimization parameters can be kept small. Most gradient-based methods rely on the iterative solution of a set of coupled equations that include forward propagation of initial states, backward propagation of adjoint states, and the control update [4]. A popular representative of concurrent update methods is GRadient Ascent Pulse Engineering (GRAPE) [21]. Krotov’s method, in contrast, requires sequential updates [5][22]. This comes with the advantage of guaranteed monotonic convergence and obviates the need for a line search in the direction of the gradient [23].

The choice of Python as an implementation language is due to Python’s easy-to-learn syntax, expressiveness, and immense popularity in the scientific community. Moreover, the QuTiP library exists, providing a general purpose tool to numerically describe quantum systems and their dynamics. QuTiP already includes basic versions of other popular quantum control algorithms such as GRAPE and the gradient-free CRAB [24]. The Jupyter notebook framework is available to provide an ideal platform for the interactive exploration of the krotov package’s capabilities, and to facilitate reproducible research workflows.

The krotov package targets both students wishing to enter the field of quantum optimal control, and researchers in the field. By providing a comprehensive set of Examples, we enable users of our package to explore the formulation of typical control problems, and to understand how Krotov’s method can solve them. These examples are inspired by recent publications [25][26][27][28][29][30], and thus show the use of the method in the purview of current research. In particular, the package is not restricted to closed quantum systems, but can fully address open system dynamics, and thus aide in the development of Noisy Intermediate-Scale Quantum (NISQ) technology [31]. Optimal control is also increasingly important in the design of experiments [4][12][13][14][15][16][17][18][19][20], and we hope that the availability of an easy-to-use implementation of Krotov’s method will facilitate this further.

Large Hilbert space dimensions [32][33][10][11] and open quantum systems [27] in particular require considerable numerical effort to optimize. Compared to the Fortran and C/C++ languages traditionally used for scientific computing, and more recently Julia [34], pure Python code usually performs slower by two to three orders of magnitude [35][36]. Thus, for hard optimization problems that require several thousand iterations to converge, the Python implementation provided by the krotov package may not be sufficiently fast. In this case, it may be desirable to implement the entire optimization and time propagation in a single, more efficient (compiled) language. Our Python implementation of Krotov’s method puts an emphasis on clarity, and the documentation provides detailed explanations of all necessary concepts, especially the correct Time discretization and the possibility to parallelize the optimization. Thus, the krotov package can serve as a reference implementation, leveraging Python’s reputation as “executable pseudocode”, and as a foundation against which to test other implementations.