diff --git a/src/constraints.jl b/src/constraints.jl index 5284028f..72c09e56 100644 --- a/src/constraints.jl +++ b/src/constraints.jl @@ -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 @@ -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 """ @@ -104,14 +104,14 @@ end FinalFidelityConstraint() -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 @@ -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( @@ -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( @@ -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 @@ -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. """ diff --git a/src/problem_templates.jl b/src/problem_templates.jl index 4571357a..ab9769f0 100644 --- a/src/problem_templates.jl +++ b/src/problem_templates.jl @@ -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, diff --git a/test/dynamics_tests.jl b/test/dynamics_test.jl similarity index 100% rename from test/dynamics_tests.jl rename to test/dynamics_test.jl diff --git a/test/losses_tests.jl b/test/losses_test.jl similarity index 100% rename from test/losses_tests.jl rename to test/losses_test.jl diff --git a/test/objectives_tests.jl b/test/objectives_test.jl similarity index 100% rename from test/objectives_tests.jl rename to test/objectives_test.jl diff --git a/test/problem_templates_test.jl b/test/problem_templates_test.jl new file mode 100644 index 00000000..eb6af881 --- /dev/null +++ b/test/problem_templates_test.jl @@ -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 diff --git a/test/problems_tests.jl b/test/problems_test.jl similarity index 100% rename from test/problems_tests.jl rename to test/problems_test.jl diff --git a/test/quantum_systems_tests.jl b/test/quantum_systems_test.jl similarity index 100% rename from test/quantum_systems_tests.jl rename to test/quantum_systems_test.jl diff --git a/test/runtests.jl b/test/runtests.jl index 0102179f..880f5b52 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -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