Package: unipolator
unipolatorUnitary Interpolation, allows for the fast repeated exponentiation of parametric Hamiltonians[1]. Construct propagators (and their derivatives) of time dependent quantum systems of the form $H(t) = H_0 + \sum_{i=1} c_i(t) H_i$ (for example in optimal control problems) or quantum circuits with parametric gates. We utilize a grid based interpolation scheme to calculate propagators from cached matrix decompositions. The computation of a propagator for a time step is as fast as a single Trotter step, but with the ability to achieve machine precision.Install and ImportInstall viapip install unipolatorand then simply import into a project viafrom unipolator import *Initialize the Unitary Interpolation Object:Describe a system with a double complex array of HamiltoniansH_s, withH_s[i,...] = H_i ∆t, so that for $n$ control HamiltoniansH_sis a $(n+1) \times d \times d$ array for a $d$ dimensional Hilbert space. Define the bounds of the interpolation (hyper-) volume via $n$ dimensional double arraysc_minsandc_maxsand define the number of bins for every dimension via the $n$ dimensional int64 arrayc_bins, to initialize the unitary interpolation cacheui = UI(H_s, c_mins, c_maxs, c_bins)Equivalently if we wish to propagate only wavevectors $\ket{\psi(t)} = U(t) \ket{\psi(0)}$ we initialize the unitary interpolation cache viaui_vector = UI_vector(H_s, c_mins, c_maxs, c_bins, m)wheremis the number of wavevectors that are calculated in parallel.
The package contains further methods listed at the bottom of this document.Automatic BinningThe methodUI_binsautomatically calculates the optimal binning for a target infidelity (defaultI_tar=1e-10). Use viabins = UI_bins(H_s, c_mins, c_maxs, I_tar=1e-10)By callingui = UI_auto(H_s, c_mins, c_maxs, I_tar=1e-10)orui_vector = UI_vector_auto(H_s, c_mins, c_maxs, I_tar=1e-10, m)this method is called automatically during the initialization of the unitary interpolation cache.Calculate:We can now useuito calculate matrix exponentials, their derivatives, pulse sequences, and their gradients via the following methods:expmHcalculates the unitary $U = \exp(-i H(c) \Delta t)$ for a given set of coefficientsc(double array of length $n$), passU_uito the method to store the result (this avoids allocating new memory for every call, and allows reusing the same arrays)ui.expmH( c, U_ui)Similarly we pass two $d \times m$ arraysV_inandV_out, with the $m$ input wavevectors and for the propagated wavevectors, viaui_vector.expmH( c, V_in, V_out)dexpmHalso outputs the derivatives of the unitaris (wavevectors) with respect to the control paractersc. This requires the additional passing of a $n \times d \times d$ arraydUto store the derivatives inui.dexpmH( c, U, dU)During the initalization we can also select which dervatives we wish to compute, via the additional argumentwhich_diffswhich requires an int64 array with the indexes of the control parameters for which we wish to compute the derivatives.In the wavevector case, we replace the output variabledUwith an additional $n \times m \times n$ arraysdV_out, so thatui_vector.dexpmH( c, V_in, V_out, dV_out)expmH_pulsecalculates the propagator of a piecewise constant pulse for a given set of coefficientsc_s, now a 2d array of shape $N \times n$, where $N$ is the number of timestepsui.expmH_pulse(cs, U)grapecalculates the infidelity of such a pulse with respect to a arget unitaryU_target(using the indexestarget_indexesofU_target), as well as the gradients of the control parameters along the pulse by using the GRAPE trick. We pass an arraydI_djof shape $n \times N$ to store the gradients at every time step for every control parameterui.grape(cs, U_target, target_indexes, U, dU, dI_dj)Other Methods:The package also contains classes for eigenvalue based exponentiations, Krylov based exponentiations and (symmetric-)  Trotterisations, namelyHamiltonian_System(H_s),Hamiltonian_System_vector(H_s, m), wheremis the number of wavevectors that are calculated in parallel,Trotter_System=(H_s, m_times), wherem_timesis the number of doublings $2^\mathrm{m}$ Trotter steps,Symmetric_Trotter_System=(H_s, m_times),Trotter_System_vector(H_s, n_times)wheren_timesis the number of performed Trotter steps ,Symmetric_Trotter_System_vector(H_s, n_times).In the test Subdirectory we provide additional functions to generate Random Hamiltonians, construct infidelities and more.Author:Michael SchillingReferences:[1] Schilling, Michael, et al. Exponentiation of Parametric Hamiltonians via Unitary Interpolationarxiv.org/abs/2402.01498