Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat rebased robust gateset #136

Merged
merged 36 commits into from
Jul 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
a838da5
Objectives scalar multiplication
andgoldschmidt Jun 17, 2024
dce1c0b
Plotting layout helper
andgoldschmidt Jun 17, 2024
4771e74
bug fix: verbose passed to constrain
andgoldschmidt Jun 17, 2024
f8a3fa8
quantum system is_reachable and is_reachable arg swap
andgoldschmidt Jun 17, 2024
3c99880
bug fix: Δt vector in kwargs
andgoldschmidt Jun 21, 2024
443e566
Merge remote-tracking branch 'origin/main' into dev_homotopy
andgoldschmidt Jun 24, 2024
2e1d7ab
Merge remote-tracking branch 'open/main' into dev_homotopy
andgoldschmidt Jun 24, 2024
d4f5042
change smooth pulse template to use piccolo options
andgoldschmidt Jun 25, 2024
ed376c1
state smooth pulse piccolo options
andgoldschmidt Jun 25, 2024
aad3915
state minimum time refactor for options
andgoldschmidt Jun 25, 2024
b8f62bd
refactor tests to testitems; move traj init to new file from rollout
andgoldschmidt Jun 25, 2024
e0c3800
unitary min time with piccolo params
andgoldschmidt Jun 25, 2024
5d3e618
unitary robustness update to piccolo options
andgoldschmidt Jun 25, 2024
21d246f
adapt direct sum to piccolo_options
andgoldschmidt Jun 25, 2024
a6d349a
unitary sampling problem uses piccolo options
andgoldschmidt Jun 25, 2024
667a3e7
fix tests
andgoldschmidt Jun 25, 2024
8477303
clean up kwargs
andgoldschmidt Jun 26, 2024
2c46adb
docstrings
andgoldschmidt Jun 26, 2024
b08ba5f
bug fix: merge! to merge
andgoldschmidt Jun 26, 2024
88c8a16
objective addition udpate
andgoldschmidt Jun 26, 2024
17ee4da
trajectory initialization fixed and free time converters
andgoldschmidt Jun 26, 2024
dcbc7ec
bug fix: Δt filled inside initialize controls
andgoldschmidt Jun 26, 2024
378e845
bug fix: save and load robust objectives, fidelity constaints
andgoldschmidt Jun 26, 2024
9afcc51
embedded ops in robust problems
andgoldschmidt Jun 26, 2024
5d6657d
fill init free time data
andgoldschmidt Jun 26, 2024
3dbbb5d
embedded op kron
andgoldschmidt Jun 27, 2024
b54d519
add test skips
andgoldschmidt Jun 27, 2024
92978ef
fix params for robustness objs
andgoldschmidt Jun 27, 2024
6f742be
embedded op for fidelity
andgoldschmidt Jun 27, 2024
937bf69
print_level in solve!
andgoldschmidt Jun 27, 2024
056d889
track main on NT
andgoldschmidt Jul 1, 2024
20e268a
adjust tests to avoid good seed failures
andgoldschmidt Jul 2, 2024
c9e821e
refactor for arbitary control derivative traj initializers
andgoldschmidt Jul 2, 2024
ba3714f
bang-bang unitary template
andgoldschmidt Jul 2, 2024
b20f026
preserve slack vars after solve, add bang-bang test
andgoldschmidt Jul 2, 2024
3abfeba
bug fix: tests match initialize signature change
andgoldschmidt Jul 2, 2024
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
12 changes: 7 additions & 5 deletions Manifest.toml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# This file is machine-generated - editing it directly is not advised

julia_version = "1.10.3"
julia_version = "1.10.0"
manifest_format = "2.0"
project_hash = "0af13b9126caf21a7349df842fd536f87be35b2f"
project_hash = "9419b1dd2f369832109faffc09e4c5a2ace40768"

[[deps.ADTypes]]
git-tree-sha1 = "fc02d55798c1af91123d07915a990fbb9a10d146"
Expand Down Expand Up @@ -338,7 +338,7 @@ weakdeps = ["Dates", "LinearAlgebra"]
[[deps.CompilerSupportLibraries_jll]]
deps = ["Artifacts", "Libdl"]
uuid = "e66e0078-7015-5450-92f7-15fbd957f2ae"
version = "1.1.1+0"
version = "1.0.5+1"

[[deps.CompositeTypes]]
git-tree-sha1 = "bce26c3dab336582805503bed209faab1c279768"
Expand Down Expand Up @@ -1467,7 +1467,9 @@ version = "1.0.2"

[[deps.NamedTrajectories]]
deps = ["CairoMakie", "JLD2", "LaTeXStrings", "Latexify", "OrderedCollections", "Random", "Reexport", "Revise", "Unidecode"]
git-tree-sha1 = "a109d8dee4055adb47bb435fd479dd67a50776af"
git-tree-sha1 = "2be818959933a47c511d4f4ce7df035a256386e0"
repo-rev = "main"
repo-url = "https://github.com/aarontrowbridge/NamedTrajectories.jl.git"
uuid = "538bc3a1-5ab9-4fc3-b776-35ca1e893e08"
version = "0.1.5"

Expand Down Expand Up @@ -1542,7 +1544,7 @@ version = "0.3.24+0"
[[deps.OpenBLAS_jll]]
deps = ["Artifacts", "CompilerSupportLibraries_jll", "Libdl"]
uuid = "4536629a-c528-5b80-bd46-f80d51c5b363"
version = "0.3.23+4"
version = "0.3.23+2"

[[deps.OpenEXR]]
deps = ["Colors", "FileIO", "OpenEXR_jll"]
Expand Down
2 changes: 1 addition & 1 deletion docs/src/contribution_guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ Tests are implemented using the [`TestItemRunner.jl`](https://github.com/julia-v

prob = UnitarySmoothPulseProblem(
H_drift, H_drives, U_goal, T, Δt,
ipopt_options=Options(print_level=1)
ipopt_options=IpoptOptions(print_level=1)
)

solve!(prob, max_iter=100)
Expand Down
4 changes: 2 additions & 2 deletions src/QuantumCollocation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ include("dynamics.jl")
include("evaluators.jl")
@reexport using .Evaluators

include("ipopt_options.jl")
@reexport using .IpoptOptions
include("options.jl")
@reexport using .Options

include("problems.jl")
@reexport using .Problems
Expand Down
42 changes: 18 additions & 24 deletions src/constraints.jl
Original file line number Diff line number Diff line change
Expand Up @@ -122,15 +122,15 @@ minimum allowed fidelity.
"""

function FinalFidelityConstraint(;
fidelity_function::Union{Function,Nothing}=nothing,
fidelity_function::Union{Symbol,Function,Nothing}=nothing,
value::Union{Float64,Nothing}=nothing,
comps::Union{AbstractVector{Int},Nothing}=nothing,
goal::Union{AbstractVector{Float64},Nothing}=nothing,
statedim::Union{Int,Nothing}=nothing,
zdim::Union{Int,Nothing}=nothing,
T::Union{Int,Nothing}=nothing,
subspace::Union{AbstractVector{<:Integer}, Nothing}=nothing,
hessian::Bool=true
eval_hessian::Bool=true
)
@assert !isnothing(fidelity_function) "must provide a fidelity function"
@assert !isnothing(value) "must provide a fidelity value"
Expand All @@ -140,7 +140,12 @@ function FinalFidelityConstraint(;
@assert !isnothing(zdim) "must provide a z dimension"
@assert !isnothing(T) "must provide a T"

fidelity_function_symbol = Symbol(fidelity_function)
if fidelity_function isa Symbol
fidelity_function_symbol = fidelity_function
fidelity_function = eval(fidelity_function)
else
fidelity_function_symbol = Symbol(fidelity_function)
end

if isnothing(subspace)
fid = x -> fidelity_function(x, goal)
Expand All @@ -153,18 +158,20 @@ function FinalFidelityConstraint(;
params = Dict{Symbol, Any}()

if fidelity_function_symbol ∉ names(QuantumUtils)
@warn "fidelity function is not exported by QuantumUtils: will not be able to save this constraint"
@warn "Fidelity function :$(string(fidelity_function_symbol)) is not exported by QuantumUtils. Unable to save this constraint."
params[:type] = :FinalFidelityConstraint
params[:fidelity_function] = :not_saveable
else
params[:type] = :FinalFidelityConstraint
params[:fidelity_function] = fidelity_function_symbol
params[:value] = value
params[:comps] = comps
params[:goal] = goal
params[:statedim] = statedim
params[:zdim] = zdim
params[:T] = T
params[:subspace] = subspace
params[:eval_hessian] = eval_hessian
end

state_slice = slice(T, comps, zdim)
Expand Down Expand Up @@ -194,7 +201,7 @@ function FinalFidelityConstraint(;
end
end

if hessian
if eval_hessian
∂²ℱ(x) = ForwardDiff.hessian(fid, x)

∂²ℱ_structure = hessian_of_lagrangian_structure(∂²ℱ, statedim, 1)
Expand Down Expand Up @@ -242,7 +249,7 @@ function FinalUnitaryFidelityConstraint(
val::Float64,
traj::NamedTrajectory;
subspace::Union{AbstractVector{<:Integer}, Nothing}=nothing,
hessian::Bool=true
eval_hessian::Bool=true
)
@assert statesymb ∈ traj.names
return FinalFidelityConstraint(;
Expand All @@ -254,7 +261,7 @@ function FinalUnitaryFidelityConstraint(
zdim=traj.dim,
T=traj.T,
subspace=subspace,
hessian=hessian
eval_hessian=eval_hessian
)
end

Expand All @@ -268,7 +275,8 @@ is the NamedTrajectory symbol representing the unitary.
function FinalQuantumStateFidelityConstraint(
statesymb::Symbol,
val::Float64,
traj::NamedTrajectory,
traj::NamedTrajectory;
kwargs...
)
@assert statesymb ∈ traj.names
return FinalFidelityConstraint(;
Expand All @@ -278,26 +286,12 @@ function FinalQuantumStateFidelityConstraint(
goal=traj.goal[statesymb],
statedim=traj.dims[statesymb],
zdim=traj.dim,
T=traj.T
T=traj.T,
kwargs...
)
end



# function FinalStateFidelityConstraint(
# val::Float64,
# statesymb::Symbol,
# statedim::Int;
# fidelity_function::Function=fidelity
# )
# return FinalFidelityConstraint(;
# fidelity_function=fidelity_function,
# value=val,
# statesymb=statesymb,
# statedim=statedim
# )
# end

"""
ComplexModulusContraint(<keyword arguments>)

Expand Down
8 changes: 1 addition & 7 deletions src/direct_sums.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module DirectSums
export add_suffix
export get_suffix
export direct_sum
export merge_outer

using ..Integrators
using ..Problems
Expand Down Expand Up @@ -132,13 +133,6 @@ function direct_sum(
)
end


function get_components(components::Union{Tuple, AbstractVector}, traj::NamedTrajectory)
symbs = Tuple(c for c in components)
vals = [traj[name] for name ∈ components]
return NamedTuple{symbs}(vals)
end

Base.endswith(symb::Symbol, suffix::AbstractString) = endswith(String(symb), suffix)
Base.endswith(integrator::UnitaryPadeIntegrator, suffix::String) = endswith(integrator.unitary_symb, suffix)
Base.endswith(integrator::DerivativeIntegrator, suffix::String) = endswith(integrator.variable, suffix)
Expand Down
29 changes: 15 additions & 14 deletions src/dynamics.jl
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ end
function QuantumDynamics(
integrators::Vector{<:AbstractIntegrator},
traj::NamedTrajectory;
hessian_approximation=false,
eval_hessian=true,
jacobian_structure=true,
verbose=false
)
Expand Down Expand Up @@ -235,10 +235,10 @@ function QuantumDynamics(

∂f = dynamics_jacobian(integrators, traj)

if hessian_approximation
μ∂²f = nothing
else
if eval_hessian
μ∂²f = dynamics_hessian_of_lagrangian(integrators, traj)
else
μ∂²f = nothing
end

if verbose
Expand All @@ -247,13 +247,7 @@ function QuantumDynamics(

dynamics_dim = dim(integrators)

if hessian_approximation
∂f_structure, ∂F_structure = dynamics_structure(∂f, traj, dynamics_dim;
verbose=verbose,
jacobian=jacobian_structure,
)
μ∂²F_structure = nothing
else
if eval_hessian
∂f_structure, ∂F_structure, μ∂²f_structure, μ∂²F_structure =
dynamics_structure(∂f, μ∂²f, traj, dynamics_dim;
verbose=verbose,
Expand All @@ -263,6 +257,12 @@ function QuantumDynamics(
)
)
μ∂²f_nnz = length(μ∂²f_structure)
else
∂f_structure, ∂F_structure = dynamics_structure(∂f, traj, dynamics_dim;
verbose=verbose,
jacobian=jacobian_structure,
)
μ∂²F_structure = nothing
end

∂f_nnz = length(∂f_structure)
Expand Down Expand Up @@ -294,9 +294,7 @@ function QuantumDynamics(
return ∂s
end

if hessian_approximation
μ∂²F = nothing
else
if eval_hessian
@views μ∂²F = (Z⃗::AbstractVector{<:Real}, μ⃗::AbstractVector{<:Real}) -> begin
μ∂²s = Vector{eltype(Z⃗)}(undef, length(μ∂²F_structure))
Threads.@threads for t = 1:traj.T-1
Expand All @@ -310,7 +308,10 @@ function QuantumDynamics(
end
return μ∂²s
end
else
μ∂²F = nothing
end

return QuantumDynamics(
integrators,
F,
Expand Down
12 changes: 12 additions & 0 deletions src/embedded_operators.jl
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,16 @@ function Base.:*(
)
end

function Base.kron(op1::EmbeddedOperator, op2::EmbeddedOperator)
levels = [size(op1, 1), size(op2, 2)]
indices = get_subspace_indices(
[op1.subspace_indices, op2.subspace_indices], levels
)
return EmbeddedOperator(unembed(op1) ⊗ unembed(op2), indices, levels)
end

QuantumUtils.:⊗(A::EmbeddedOperator, B::EmbeddedOperator) = kron(A, B)

function EmbeddedOperator(
op::AbstractMatrix{<:Number},
system::QuantumSystem;
Expand Down Expand Up @@ -157,6 +167,8 @@ function EmbeddedOperator(
return *(ops_embedded...)
end

# function LinearAlgebra

# ====================

basis_labels(subsystem_levels::AbstractVector{Int}; baseline=1) =
Expand Down
4 changes: 2 additions & 2 deletions src/evaluators.jl
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ mutable struct PicoEvaluator <: MOI.AbstractNLPEvaluator
trajectory::NamedTrajectory,
objective::Objective,
dynamics::QuantumDynamics,
nonlinear_constraints::Vector{<:NonlinearConstraint},
eval_hessian::Bool
nonlinear_constraints::Vector{<:NonlinearConstraint};
eval_hessian::Bool=true
)
n_dynamics_constraints = dynamics.dim * (trajectory.T - 1)
n_nonlinear_constraints = sum(con.dim for con ∈ nonlinear_constraints; init=0)
Expand Down
8 changes: 3 additions & 5 deletions src/integrators/pade_integrators.jl
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ struct UnitaryPadeIntegrator <: QuantumPadeIntegrator
unitary_symb::Union{Symbol,Nothing}=nothing,
drive_symb::Union{Symbol,Tuple{Vararg{Symbol}},Nothing}=nothing;
order::Int=4,
autodiff::Bool=false,
G::Union{Function, Nothing}=nothing,
autodiff::Bool=order != 4,
G::Function=G_bilinear,
)
@assert order ∈ [4, 6, 8, 10] "order must be in [4, 6, 8, 10]"
@assert !isnothing(unitary_symb) "must specify unitary symbol"
Expand All @@ -111,7 +111,6 @@ struct UnitaryPadeIntegrator <: QuantumPadeIntegrator

G_drift = sys.G_drift
G_drives = sys.G_drives
G = isnothing(G) ? G_bilinear : G

drive_anticomms, drift_anticomms =
order == 4 ? build_anticomms(G_drift, G_drives, n_drives) : (nothing, nothing)
Expand Down Expand Up @@ -189,7 +188,7 @@ struct QuantumStatePadeIntegrator <: QuantumPadeIntegrator
drive_symb::Union{Symbol,Tuple{Vararg{Symbol}},Nothing}=nothing;
order::Int=4,
autodiff::Bool=order != 4,
G::Union{Function, Nothing}=nothing,
G::Function=G_bilinear,
)
@assert order ∈ [4, 6, 8, 10] "order must be in [4, 6, 8, 10]"
@assert !isnothing(state_symb) "state_symb must be specified"
Expand All @@ -201,7 +200,6 @@ struct QuantumStatePadeIntegrator <: QuantumPadeIntegrator

G_drift = sys.G_drift
G_drives = sys.G_drives
G = isnothing(G) ? G_bilinear : G

drive_anticomms, drift_anticomms =
order == 4 ? build_anticomms(G_drift, G_drives, n_drives) : (nothing, nothing)
Expand Down
Loading
Loading