Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
f0af49e
moving otimes to isomorphisms
aarontrowbridge Nov 1, 2024
e7aacc4
manifest update
aarontrowbridge Nov 1, 2024
c0a550e
integrator signature refactor -- removes sys dependence
aarontrowbridge Nov 1, 2024
eeac85a
problem template fixes (tests passing)
aarontrowbridge Nov 1, 2024
f2dd861
moved isomorphisms to core
aarontrowbridge Nov 1, 2024
e634cc3
big rip
aarontrowbridge Nov 4, 2024
d07420d
big rip 2: quantum objects
aarontrowbridge Nov 6, 2024
e3412e4
traj init for unitary
andgoldschmidt Nov 6, 2024
c0cdbbf
state sampling problem template
andgoldschmidt Nov 6, 2024
d54f53c
refactored system to integrator interface
aarontrowbridge Nov 6, 2024
4708228
density operators
aarontrowbridge Nov 10, 2024
f66b443
traj init for unitary
andgoldschmidt Nov 6, 2024
c7bdccc
state sampling problem template
andgoldschmidt Nov 6, 2024
b69af1d
bug fix: a_guess option
andgoldschmidt Nov 7, 2024
c215e41
bug fix: free phase obj
andgoldschmidt Nov 7, 2024
edde00e
phase rollout fidelity
andgoldschmidt Nov 7, 2024
43e73d9
free phase initialization
andgoldschmidt Nov 7, 2024
f5d943e
Tests for free phases
andgoldschmidt Nov 9, 2024
2ab761f
free phase incr
andgoldschmidt Nov 9, 2024
b4d5eea
bug fix: mintime and robprob fidelity subspace
andgoldschmidt Nov 9, 2024
d26420c
bug fix: drop drive_sigma arg, fix subspace nothing
andgoldschmidt Nov 9, 2024
3a34581
problem template fixes (tests passing)
aarontrowbridge Nov 1, 2024
98800fd
big rip
aarontrowbridge Nov 4, 2024
1bdd6a4
refactored system to integrator interface
aarontrowbridge Nov 6, 2024
6705653
density operators
aarontrowbridge Nov 10, 2024
91fd3a5
rebase fixes (broken)
aarontrowbridge Nov 11, 2024
a6aae3b
Merge remote-tracking branch 'origin/main' into 163-feature-peel-off-…
aarontrowbridge Nov 11, 2024
c8621ac
rebase complete (fixes free phase loss)
aarontrowbridge Nov 11, 2024
bfb6ff8
docs uopdates
aarontrowbridge Nov 12, 2024
0d2efae
renaming OperatorType -> AbstractPiccoloOperator
aarontrowbridge Nov 19, 2024
560c857
adding quantum system templates + cleaning
aarontrowbridge Nov 19, 2024
fbcbb1b
update system type from AbstractQuantumSystem to OpenQuantumSystem an…
aarontrowbridge Dec 2, 2024
5c4d06f
refactor trajectory initialization to use density_to_iso_vec for init…
aarontrowbridge Dec 5, 2024
881e083
refactor rollout_fidelity to have sys as arg
aarontrowbridge Dec 23, 2024
eac5100
passing tests (except for direct sum prob)
aarontrowbridge Jan 6, 2025
cbeebbb
refactor add_suffix and remove_suffix functions to eliminate sys para…
aarontrowbridge Jan 9, 2025
5199435
bump version to 0.5.0 and update dependencies for compatibility
aarontrowbridge Jan 9, 2025
601cd2d
Merge branch 'main' into 163-feature-peel-off-core-functionality-into…
jack-champagne Jan 13, 2025
6107ce4
remove operatortype
jack-champagne Jan 13, 2025
09a3143
add back in zero initial and final
jack-champagne Jan 13, 2025
45b6d36
revert removing list of state names
jack-champagne Jan 13, 2025
f72f5fd
refactor callbacks and problem templates to use rollout fidelity and …
aarontrowbridge Jan 14, 2025
ae3a31f
update Project.toml dependencies and refactor drive length references…
aarontrowbridge Jan 14, 2025
19004b3
fix callbacks except for new tol
jack-champagne Jan 15, 2025
8211e7c
remove fidelity test from callback test suite - see PR comment #173
jack-champagne Jan 15, 2025
cc602dc
add qualified path for get_datavec
jack-champagne Jan 15, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
integrator signature refactor -- removes sys dependence
  • Loading branch information
aarontrowbridge committed Nov 1, 2024
commit c0a550edcab875e19b4c6f398cf00133bf6028bd
10 changes: 6 additions & 4 deletions src/integrators/_integrators.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ export QuantumStateExponentialIntegrator

export DerivativeIntegrator

export G_bilinear

export jacobian
export hessian_of_the_lagrangian

Expand All @@ -23,11 +25,10 @@ export sixth_order_pade
export eighth_order_pade
export tenth_order_pade

using ..QuantumSystems
using ..Isomorphisms
using ..QuantumObjectUtils
using ..Losses
using ..QuantumSystemUtils
# using ..QuantumSystems
# using ..QuantumObjectUtils
# using ..QuantumSystemUtils

using NamedTrajectories
using TrajectoryIndexingUtils
Expand All @@ -36,6 +37,7 @@ using SparseArrays
using ForwardDiff
using TestItemRunner


abstract type AbstractIntegrator end

abstract type QuantumIntegrator <: AbstractIntegrator end
Expand Down
52 changes: 26 additions & 26 deletions src/integrators/exponential_integrators.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@ This file includes expoential integrators for states and unitaries

using ExponentialAction

function exp_eigen(G::AbstractMatrix)
Ĥ = Hermitian(Matrix(Isomorphisms.H(G)))
λ, V = eigen(Ĥ)
expG = iso(sparse(V * Diagonal(exp.(-im * λ)) * V'))
droptol!(expG, 1e-12)
return expG
end

# ----------------------------------------------------------------------------- #
# Quantum Exponential Integrators #
# ----------------------------------------------------------------------------- #
Expand All @@ -27,15 +35,14 @@ struct UnitaryExponentialIntegrator <: QuantumExponentialIntegrator
G::Function

function UnitaryExponentialIntegrator(
sys::AbstractQuantumSystem,
unitary_name::Symbol,
drive_name::Union{Symbol, Tuple{Vararg{Symbol}}},
G::Function,
traj::NamedTrajectory;
G::Function=a -> G_bilinear(a, sys.G_drift, sys.G_drives),
autodiff::Bool=false
)
ketdim = size(sys.H_drift, 1)
dim = 2ketdim^2
dim = traj.dims[unitary_name]
ketdim = Int(sqrt(dim ÷ 2))

unitary_components = traj.components[unitary_name]

Expand Down Expand Up @@ -73,7 +80,6 @@ struct UnitaryExponentialIntegrator <: QuantumExponentialIntegrator
end

function (integrator::UnitaryExponentialIntegrator)(
sys::AbstractQuantumSystem,
traj::NamedTrajectory;
unitary_name::Union{Nothing, Symbol}=nothing,
drive_name::Union{Nothing, Symbol, Tuple{Vararg{Symbol}}}=nothing,
Expand All @@ -83,11 +89,10 @@ function (integrator::UnitaryExponentialIntegrator)(
@assert !isnothing(unitary_name) "unitary_name must be provided"
@assert !isnothing(drive_name) "drive_name must be provided"
return UnitaryExponentialIntegrator(
sys,
unitary_name,
drive_name,
G,
traj;
G=G,
autodiff=autodiff
)
end
Expand Down Expand Up @@ -122,14 +127,6 @@ end
return Ũ⃗ₜ₊₁ - expv(Δtₜ, I(ℰ.ketdim) ⊗ Gₜ, Ũ⃗ₜ)
end

function hermitian_exp(G::AbstractMatrix)
Ĥ = Hermitian(Matrix(Isomorphisms.H(G)))
λ, V = eigen(Ĥ)
expG = Isomorphisms.iso(sparse(V * Diagonal(exp.(-im * λ)) * V'))
droptol!(expG, 1e-12)
return expG
end

@views function jacobian(
ℰ::UnitaryExponentialIntegrator,
zₜ::AbstractVector,
Expand All @@ -152,7 +149,7 @@ end

Id = I(ℰ.ketdim)

expĜₜ = Id ⊗ hermitian_exp(Δtₜ * Gₜ)
expĜₜ = Id ⊗ exp_eigen(Δtₜ * Gₜ)

∂Ũ⃗ₜ₊₁ℰ = sparse(I, ℰ.dim, ℰ.dim)
∂Ũ⃗ₜℰ = -expĜₜ
Expand Down Expand Up @@ -183,15 +180,14 @@ struct QuantumStateExponentialIntegrator <: QuantumExponentialIntegrator
G::Function

function QuantumStateExponentialIntegrator(
sys::AbstractQuantumSystem,
state_name::Symbol,
drive_name::Union{Symbol, Tuple{Vararg{Symbol}}},
G::Function,
traj::NamedTrajectory;
G::Function=a -> G_bilinear(a, sys.G_drift, sys.G_drives),
autodiff::Bool=false
)
ketdim = size(sys.H_drift, 1)
dim = 2ketdim
dim = traj.dims[state_name]
ketdim = dim ÷ 2

state_components = traj.components[state_name]

Expand Down Expand Up @@ -237,7 +233,6 @@ function get_comps(P::QuantumStateExponentialIntegrator, traj::NamedTrajectory)
end

function (integrator::QuantumStateExponentialIntegrator)(
sys::AbstractQuantumSystem,
traj::NamedTrajectory;
state_name::Union{Nothing, Symbol}=nothing,
drive_name::Union{Nothing, Symbol, Tuple{Vararg{Symbol}}}=nothing,
Expand All @@ -247,11 +242,10 @@ function (integrator::QuantumStateExponentialIntegrator)(
@assert !isnothing(state_name) "state_name must be provided"
@assert !isnothing(drive_name) "drive_name must be provided"
return QuantumStateExponentialIntegrator(
sys,
state_name,
drive_name,
G,
traj;
G=G,
autodiff=autodiff
)
end
Expand Down Expand Up @@ -299,7 +293,7 @@ end
# compute the generator
Gₜ = ℰ.G(aₜ)

expGₜ = hermitian_exp(Δtₜ * Gₜ)
expGₜ = exp_eigen(Δtₜ * Gₜ)

∂ψ̃ₜ₊₁ℰ = sparse(I, ℰ.dim, ℰ.dim)
∂ψ̃ₜℰ = -expGₜ
Expand Down Expand Up @@ -338,6 +332,7 @@ end

dt = 0.1


Z = NamedTrajectory(
(
Ũ⃗ = unitary_geodesic(U_goal, T),
Expand All @@ -350,7 +345,9 @@ end
goal=(Ũ⃗ = Ũ⃗_goal,)
)

ℰ = UnitaryExponentialIntegrator(system, :Ũ⃗, :a, Z)
G = a -> Integrators.G_bilinear(a, system.G_drift, system.G_drives)

ℰ = UnitaryExponentialIntegrator(:Ũ⃗, :a, G, Z)


∂Ũ⃗ₜℰ, ∂Ũ⃗ₜ₊₁ℰ, ∂aₜℰ, ∂Δtₜℰ = jacobian(ℰ, Z[1].data, Z[2].data, 1)
Expand Down Expand Up @@ -397,7 +394,10 @@ end
goal=(ψ̃ = ψ̃_goal,)
)

ℰ = QuantumStateExponentialIntegrator(system, :ψ̃, :a, Z)
G = a -> Integrators.G_bilinear(a, system.G_drift, system.G_drives)

ℰ = QuantumStateExponentialIntegrator(:ψ̃, :a, G, Z)

∂ψ̃ₜℰ, ∂ψ̃ₜ₊₁ℰ, ∂aₜℰ, ∂Δtₜℰ = jacobian(ℰ, Z[1].data, Z[2].data, 1)

∂ℰ_forwarddiff = ForwardDiff.jacobian(
Expand Down
74 changes: 30 additions & 44 deletions src/integrators/pade_integrators.jl
Original file line number Diff line number Diff line change
Expand Up @@ -222,59 +222,50 @@ struct UnitaryPadeIntegrator <: QuantumPadeIntegrator
G::Function
∂G::Function

"""
@doc raw"""
UnitaryPadeIntegrator(
sys::AbstractQuantumSystem,
unitary_name::Symbol,
drive_name::Union{Symbol,Tuple{Vararg{Symbol}}};
drive_name::Union{Symbol,Tuple{Vararg{Symbol}}},
G::Function,
∂G::Function,
traj::NamedTrajectory;
order::Int=4,
autodiff::Bool=order != 4
) where R <: Real

Construct a `UnitaryPadeIntegrator` for the quantum system `sys`.
calculate_pade_operators_structure::Bool=true,
autodiff::Bool=false
)

# Examples
Construct a `UnitaryPadeIntegrator` which computes

## a bare integrator
```julia
P = UnitaryPadeIntegrator(sys)
```math
\text{isovec}\qty(B^{(n)}(a_t) U_{t+1} - F^{(n)}(a_t) U_t)
```

## for a single drive `a`:
```julia
P = UnitaryPadeIntegrator(sys, :Ũ⃗, :a)
```

## for two drives `α` and `γ`, order `4`, and autodiffed:
```julia
P = UnitaryPadeIntegrator(sys, :Ũ⃗, (:α, :γ); order=4, autodiff=true)
```
where `U_t` is the unitary at time `t`, `a_t` is the control at time `t`, and `B^{(n)}(a_t)` and `F^{(n)}(a_t)` are the `n`th order Pade operators of the exponential of the drift operator `G(a_t)`.

# Arguments
- `sys::AbstractQuantumSystem`: the quantum system
- `unitary_name::Union{Symbol,Nothing}=nothing`: the nameol for the unitary
- `drive_name::Union{Symbol,Tuple{Vararg{Symbol}},Nothing}=nothing`: the nameol(s) for the drives
- `order::Int=4`: the order of the Pade approximation. Must be in `[4, 6, 8, 10]`. If order is not `4` and `autodiff` is `false`, then the integrator will use the hand-coded fourth order derivatives.
- `autodiff::Bool=order != 4`: whether to use automatic differentiation to compute the jacobian and hessian of the lagrangian
- `unitary_name::Symbol`: the name of the unitary in the trajectory
- `drive_name::Union{Symbol,Tuple{Vararg{Symbol}}}`: the name of the drive(s) in the trajectory
- `G::Function`: a function which takes the control vector `a_t` and returns the drive `G(a_t)`, $G(a_t) = \text{iso}(-i H(a_t))$
- `∂G::Function`: a function which takes the control vector `a_t` and returns a vector of matrices $\qty(\ldots, \pdv{G}{a^j_t}, \ldots)$
- `traj::NamedTrajectory`: the trajectory

# Keyword Arguments
- `order::Int=4`: the order of the Pade approximation. Must be in `[4, 6, 8, 10, 12, 14, 16, 18, 20]`.

"""
function UnitaryPadeIntegrator(
sys::AbstractQuantumSystem,
unitary_name::Symbol,
drive_name::Union{Symbol,Tuple{Vararg{Symbol}}},
G::Function,
∂G::Function,
traj::NamedTrajectory;
order::Int=4,
G::Function=a -> G_bilinear(a, sys.G_drift, sys.G_drives),
∂G::Function=a -> sys.G_drives,
calculate_pade_operators_structure::Bool=true,
autodiff::Bool=false
)
@assert order ∈ keys(PADE_COEFFICIENTS) "order ∉ $(keys(PADE_COEFFICIENTS))"

ketdim = size(sys.H_drift, 1)
dim = 2ketdim^2

I_2N = sparse(I(2ketdim))
dim = traj.dims[unitary_name]
ketdim = Int(sqrt(dim ÷ 2))

unitary_components = traj.components[unitary_name]

Expand Down Expand Up @@ -322,7 +313,6 @@ function get_comps(P::UnitaryPadeIntegrator, traj::NamedTrajectory)
end

function (integrator::UnitaryPadeIntegrator)(
sys::AbstractQuantumSystem,
traj::NamedTrajectory;
unitary_name::Union{Symbol, Nothing}=nothing,
drive_name::Union{Symbol, Tuple{Vararg{Symbol}}, Nothing}=nothing,
Expand All @@ -334,13 +324,12 @@ function (integrator::UnitaryPadeIntegrator)(
@assert !isnothing(unitary_name) "unitary_name must be provided"
@assert !isnothing(drive_name) "drive_name must be provided"
return UnitaryPadeIntegrator(
sys,
unitary_name,
drive_name,
G,
∂G,
traj;
order=order,
G=G,
∂G=∂G,
autodiff=autodiff
)
end
Expand Down Expand Up @@ -522,13 +511,12 @@ struct QuantumStatePadeIntegrator <: QuantumPadeIntegrator
- `autodiff::Bool=false`: whether to use automatic differentiation to compute the jacobian and hessian of the lagrangian
"""
function QuantumStatePadeIntegrator(
sys::AbstractQuantumSystem,
state_name::Symbol,
drive_name::Union{Symbol,Tuple{Vararg{Symbol}}},
G::Function,
∂G::Function,
traj::NamedTrajectory;
order::Int=4,
G::Function=a -> G_bilinear(a, sys.G_drift, sys.G_drives),
∂G::Function=a -> sys.G_drives,
autodiff::Bool=false,
)
@assert order ∈ keys(PADE_COEFFICIENTS) "order ∉ $(keys(PADE_COEFFICIENTS))"
Expand Down Expand Up @@ -583,7 +571,6 @@ function get_comps(P::QuantumStatePadeIntegrator, traj::NamedTrajectory)
end

function (integrator::QuantumStatePadeIntegrator)(
sys::AbstractQuantumSystem,
traj::NamedTrajectory;
state_name::Union{Symbol, Nothing}=nothing,
drive_name::Union{Symbol, Tuple{Vararg{Symbol}}, Nothing}=nothing,
Expand All @@ -595,13 +582,12 @@ function (integrator::QuantumStatePadeIntegrator)(
@assert !isnothing(state_name) "state_name must be provided"
@assert !isnothing(drive_name) "drive_name must be provided"
return QuantumStatePadeIntegrator(
sys,
state_name,
drive_name,
G,
∂G,
traj;
order=order,
G=G,
∂G=∂G,
autodiff=autodiff
)
end
Expand Down