Skip to content

Commit

Permalink
edits
Browse files Browse the repository at this point in the history
  • Loading branch information
aarontrowbridge committed Nov 10, 2023
1 parent fe04648 commit c15ab8f
Show file tree
Hide file tree
Showing 9 changed files with 78 additions and 28 deletions.
40 changes: 24 additions & 16 deletions src/constraints.jl
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,15 @@ end
"""
struct NonlinearEqualityConstraint
Represents a nonlinear equality constraint.
Represents a nonlinear equality constraint.
# Fields
- `g::Function`: the constraint function
- `∂g::Function`: the Jacobian of the constraint function
- `∂g_structure::Vector{Tuple{Int, Int}}`: the structure of the Jacobian
- `∂g_structure::Vector{Tuple{Int, Int}}`: the structure of the Jacobian
i.e. all non-zero entries
- `μ∂²g::Function`: the Hessian of the constraint function
- `μ∂²g_structure::Vector{Tuple{Int, Int}}`: the structure of the Hessian
- `μ∂²g_structure::Vector{Tuple{Int, Int}}`: the structure of the Hessian
- `dim::Int`: the dimension of the constraint function
- `params::Dict{Symbol, Any}`: a dictionary of parameters
Expand All @@ -81,12 +81,12 @@ Represents a nonlinear inequality constraint.
# Fields
- `g::Function`: the constraint function
- `∂g::Function`: the Jacobian of the constraint function
- `∂g_structure::Vector{Tuple{Int, Int}}`: the structure of the Jacobian
- `∂g_structure::Vector{Tuple{Int, Int}}`: the structure of the Jacobian
i.e. all non-zero entries
- `μ∂²g::Function`: the Hessian of the constraint function
- `μ∂²g_structure::Vector{Tuple{Int, Int}}`: the structure of the Hessian
- `μ∂²g_structure::Vector{Tuple{Int, Int}}`: the structure of the Hessian
- `dim::Int`: the dimension of the constraint function
- `params::Dict{Symbol, Any}`: a dictionary of parameters containing additional
- `params::Dict{Symbol, Any}`: a dictionary of parameters containing additional
information about the constraint
"""
Expand All @@ -104,14 +104,14 @@ end
FinalFidelityConstraint(<keyword arguments>)
Returns a NonlinearInequalityConstraint representing a constraint on the
Returns a NonlinearInequalityConstraint representing a constraint on the
minimum allowed fidelity.
# Arguments
- `fidelity_function::Union{Function,Nothing}=nothing`: the fidelity function
- `value::Union{Float64,Nothing}=nothing`: the minimum fidelity value allowed
- `value::Union{Float64,Nothing}=nothing`: the minimum fidelity value allowed
by the constraint
- `comps::Union{AbstractVector{Int},Nothing}=nothing`: the components of the
- `comps::Union{AbstractVector{Int},Nothing}=nothing`: the components of the
state to which the fidelity function is applied
- `goal::Union{AbstractVector{Float64},Nothing}=nothing`: the goal state
- `statedim::Union{Int,Nothing}=nothing`: the dimension of the state
Expand Down Expand Up @@ -205,14 +205,22 @@ function FinalFidelityConstraint(;
end
end

return NonlinearInequalityConstraint(g, ∂g, ∂g_structure, μ∂²g, μ∂²g_structure, 1, params)
return NonlinearInequalityConstraint(
g,
∂g,
∂g_structure,
μ∂²g,
μ∂²g_structure,
1,
params
)
end

"""
FinalUnitaryFidelityConstraint(statesymb::Symbol, val::Float64, traj::NamedTrajectory)
Returns a FinalFidelityConstraint for the unitary fidelity function where statesymb
is the NamedTrajectory symbol representing the unitary.
Returns a FinalFidelityConstraint for the unitary fidelity function where statesymb
is the NamedTrajectory symbol representing the unitary.
"""
function FinalUnitaryFidelityConstraint(
Expand All @@ -235,8 +243,8 @@ end
"""
FinalQuantumStateFidelityConstraint(statesymb::Symbol, val::Float64, traj::NamedTrajectory)
Returns a FinalFidelityConstraint for the unitary fidelity function where statesymb
is the NamedTrajectory symbol representing the unitary.
Returns a FinalFidelityConstraint for the unitary fidelity function where statesymb
is the NamedTrajectory symbol representing the unitary.
"""
function FinalQuantumStateFidelityConstraint(
Expand Down Expand Up @@ -279,7 +287,7 @@ Returns a NonlinearInequalityConstraint on the complex modulus of a complex cont
# Arguments
- `R::Union{Float64,Nothing}=nothing`: the maximum allowed complex modulus
- `comps::Union{AbstractVector{Int},Nothing}=nothing`: the components of the complex control,
- `comps::Union{AbstractVector{Int},Nothing}=nothing`: the components of the complex control,
both the real and imaginary parts
- `times::Union{AbstractVector{Int},Nothing}=nothing`: the times at which the constraint is applied
- `zdim::Union{Int,Nothing}=nothing`: the dimension of a single time step of the trajectory
Expand Down Expand Up @@ -439,7 +447,7 @@ end
trajectory_constraints(traj::NamedTrajectory)
Implements the initial and final value constraints and bounds constraints on the controls
and states as specified by traj.
and states as specified by traj.
"""

Expand Down
4 changes: 2 additions & 2 deletions src/problem_templates.jl
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ function UnitarySmoothPulseProblem(
Δt::Float64;
free_time=true,
init_trajectory::Union{NamedTrajectory, Nothing}=nothing,
a_bound::Float64=Inf,
a_bound::Float64=1.0,
a_bounds::Vector{Float64}=fill(a_bound, length(system.G_drives)),
a_guess::Union{Matrix{Float64}, Nothing}=nothing,
dda_bound::Float64=Inf,
dda_bound::Float64=1.0,
dda_bounds::Vector{Float64}=fill(dda_bound, length(system.G_drives)),
Δt_min::Float64=0.5 * Δt,
Δt_max::Float64=1.5 * Δt,
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
42 changes: 42 additions & 0 deletions test/problem_templates_test.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# ------------------------------------------------
# Test: ProblemTemplates
#
# 1. test UnitarySmoothPulseProblem
# 2. test UnitaryMinimumTimeProblem
# ------------------------------------------------


@testset "Problem Templates" begin

H_drift = GATES[:Z]
H_drives = [GATES[:X], GATES[:Y]]
U_goal = GATES[:H]
T = 50
Δt = 0.2

# --------------------------------------------
# 1. test UnitarySmoothPulseProblem
# --------------------------------------------

prob = UnitarySmoothPulseProblem(H_drift, H_drives, U_goal, T, Δt)

solve!(prob; max_iter=100)

@test unitary_fidelity(prob) > 0.99

# --------------------------------------------
# 2. test UnitaryMinimumTimeProblem
# --------------------------------------------

final_fidelity = 0.99

mintime_prob = UnitaryMinimumTimeProblem(prob; final_fidelity=final_fidelity)

solve!(mintime_prob; max_iter=100)

@test unitary_fidelity(mintime_prob) > final_fidelity

@test times(mintime_prob.trajectory)[end] < times(prob.trajectory)[end]


end
File renamed without changes.
File renamed without changes.
20 changes: 10 additions & 10 deletions test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
using Revise
using QuantumCollocation
using NamedTrajectories

using Test
using LinearAlgebra
using ForwardDiff
#using FiniteDiff
using SparseArrays
using Random
using Random; Random.seed!(1234)

using QuantumCollocation
using NamedTrajectories



Random.seed!(1234)

include("test_utils.jl")

@testset "QuantumCollocation.jl" begin
include("quantum_systems_tests.jl")
include("objectives_tests.jl")
include("dynamics_tests.jl")
include("quantum_systems_test.jl")
include("objectives_test.jl")
include("dynamics_test.jl")
include("problem_templates_test.jl")
end

0 comments on commit c15ab8f

Please sign in to comment.