Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
fixed requested changes
  • Loading branch information
martin-klacan committed Jun 11, 2025
commit 7e586ad64ea6eae728b1d27f72694e5cff04f47f
4 changes: 0 additions & 4 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ authors = ["Aaron Trowbridge <[email protected]> and contributors"]
version = "0.7.2"

[deps]
CairoMakie = "13f3f980-e62b-5c42-98c6-ff1f3baf88f0"
DirectTrajOpt = "c823fa1f-8872-4af5-b810-2b9b72bbbf56"
Distributions = "31c24e10-a181-5473-b8eb-7969acd0382f"
ExponentialAction = "e24c0720-ea99-47e8-929e-571b494574d3"
Expand All @@ -13,7 +12,6 @@ JLD2 = "033835bb-8acc-5ee8-8aae-3f567f8a3819"
Libdl = "8f399da3-3557-5675-b5ff-fb832c97cbdb"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
NamedTrajectories = "538bc3a1-5ab9-4fc3-b776-35ca1e893e08"
Piccolo = "c4671d76-df94-11ed-2057-43d4fd632fad"
PiccoloQuantumObjects = "5a402ddf-f93c-42eb-975e-5582dcda653d"
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
Reexport = "189a3867-3050-52da-a836-e630ba90ab69"
Expand All @@ -23,15 +21,13 @@ TestItems = "1c621080-faea-4a02-84b6-bbd5e436b8fe"
TrajectoryIndexingUtils = "6dad8b7f-dd9a-4c28-9b70-85b9a079bfc8"

[compat]
CairoMakie = "0.13.7"
DirectTrajOpt = "0.2.3"
Distributions = "0.25"
ExponentialAction = "0.2"
Interpolations = "0.15"
JLD2 = "0.5"
LinearAlgebra = "1.10, 1.11"
NamedTrajectories = "0.3"
Piccolo = "0.7.2"
PiccoloQuantumObjects = "0.4"
Random = "1.10, 1.11"
Reexport = "1.2"
Expand Down
3 changes: 1 addition & 2 deletions src/problem_templates/quantum_state_minimum_time_problem.jl
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ end
@testitem "Test quantum state minimum time" begin
using NamedTrajectories
using PiccoloQuantumObjects
using QuantumCollocation

T = 51
Δt = 0.2
Expand All @@ -100,7 +99,7 @@ end

prob = QuantumStateSmoothPulseProblem(
sys, ψ_init, ψ_target, T, Δt;
piccolo_options=QuantumCollocation.Options.PiccoloOptions(verbose=false)
piccolo_options=PiccoloOptions(verbose=false)
)
initial = sum(get_timesteps(prob.trajectory))

Expand Down
6 changes: 2 additions & 4 deletions src/problem_templates/quantum_state_sampling_problem.jl
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,6 @@ end

@testitem "Sample systems with single initial, target" begin
using PiccoloQuantumObjects
using QuantumCollocation

T = 50
Δt = 0.2
Expand All @@ -162,7 +161,7 @@ end

prob = QuantumStateSamplingProblem(
[sys1, sys2], ψ_init, ψ_target, T, Δt;
piccolo_options=QuantumCollocation.Options.PiccoloOptions(verbose=false)
piccolo_options=PiccoloOptions(verbose=false)
)

state_name = :ψ̃
Expand All @@ -185,7 +184,6 @@ end

@testitem "Sample systems with multiple initial, target" begin
using PiccoloQuantumObjects
using QuantumCollocation

T = 50
Δt = 0.2
Expand All @@ -198,7 +196,7 @@ end

prob = QuantumStateSamplingProblem(
[sys1, sys2], ψ_inits, ψ_targets, T, Δt;
piccolo_options=QuantumCollocation.Options.PiccoloOptions(verbose=false)
piccolo_options=PiccoloOptions(verbose=false)
)

state_name = :ψ̃
Expand Down
6 changes: 2 additions & 4 deletions src/problem_templates/quantum_state_smooth_pulse_problem.jl
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,6 @@ end

@testitem "Test quantum state smooth pulse" begin
using PiccoloQuantumObjects
using QuantumCollocation

T = 51
Δt = 0.2
Expand All @@ -200,7 +199,7 @@ end
# --------------------------------
prob = QuantumStateSmoothPulseProblem(
sys, ψ_init, ψ_target, T, Δt;
piccolo_options=QuantumCollocation.Options.PiccoloOptions(verbose=false)
piccolo_options=PiccoloOptions(verbose=false)
)
initial = rollout_fidelity(prob.trajectory, sys)
solve!(prob, max_iter=50, print_level=1, verbose=false)
Expand All @@ -210,7 +209,6 @@ end

@testitem "Test multiple quantum states smooth pulse" begin
using PiccoloQuantumObjects
using QuantumCollocation

T = 50
Δt = 0.2
Expand All @@ -220,7 +218,7 @@ end

prob = QuantumStateSmoothPulseProblem(
sys, ψ_inits, ψ_targets, T, Δt;
piccolo_options=QuantumCollocation.Options.PiccoloOptions(verbose=false)
piccolo_options=PiccoloOptions(verbose=false)
)
initial = rollout_fidelity(prob.trajectory, sys)
solve!(prob, max_iter=50, print_level=1, verbose=false)
Expand Down
1 change: 0 additions & 1 deletion src/problem_templates/unitary_minimum_time_problem.jl
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@ end
@testitem "Minimum time Hadamard gate" begin
using NamedTrajectories
using PiccoloQuantumObjects
using QuantumCollocation

H_drift = 0.1PAULIS[:Z]
H_drives = [PAULIS[:X], PAULIS[:Y]]
Expand Down
3 changes: 1 addition & 2 deletions src/problem_templates/unitary_sampling_problem.jl
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,6 @@ end

@testitem "Sample robustness test" begin
using PiccoloQuantumObjects
using QuantumCollocation

T = 50
Δt = 0.2
Expand All @@ -176,7 +175,7 @@ end
samples = [0.0, 0.1]
prob = UnitarySamplingProblem(
[systems(x) for x in samples], operator, T, Δt,
piccolo_options=QuantumCollocation.Options.PiccoloOptions(verbose=false)
piccolo_options=PiccoloOptions(verbose=false)
)
solve!(prob, max_iter=100, print_level=1, verbose=false)

Expand Down
9 changes: 3 additions & 6 deletions src/problem_templates/unitary_smooth_pulse_problem.jl
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,6 @@ end

@testitem "Hadamard gate" begin
using PiccoloQuantumObjects
using QuantumCollocation

sys = QuantumSystem(GATES[:Z], [GATES[:X], GATES[:Y]])
U_goal = GATES[:H]
Expand All @@ -177,7 +176,7 @@ end
prob = UnitarySmoothPulseProblem(
sys, U_goal, T, Δt;
da_bound=1.0,
piccolo_options=QuantumCollocation.Options.PiccoloOptions(verbose=false)
piccolo_options=PiccoloOptions(verbose=false)
)

initial = unitary_rollout_fidelity(prob.trajectory, sys)
Expand All @@ -188,7 +187,6 @@ end

@testitem "Hadamard gate with bound states and control norm constraint" begin
using PiccoloQuantumObjects
using QuantumCollocation

sys = QuantumSystem(GATES[:Z], [GATES[:X], GATES[:Y]])
U_goal = GATES[:H]
Expand All @@ -197,7 +195,7 @@ end

prob = UnitarySmoothPulseProblem(
sys, U_goal, T, Δt,
piccolo_options=QuantumCollocation.Options.PiccoloOptions(
piccolo_options=PiccoloOptions(
verbose=false,
bound_state=true,
complex_control_norm_constraint_name=:a
Expand All @@ -213,7 +211,6 @@ end

@testitem "EmbeddedOperator Hadamard gate" begin
using PiccoloQuantumObjects
using QuantumCollocation

a = annihilate(3)
sys = QuantumSystem([(a + a')/2, (a - a')/(2im)])
Expand All @@ -223,7 +220,7 @@ end

prob = UnitarySmoothPulseProblem(
sys, U_goal, T, Δt,
piccolo_options=QuantumCollocation.Options.PiccoloOptions(verbose=false)
piccolo_options=PiccoloOptions(verbose=false)
)

initial = unitary_rollout_fidelity(prob.trajectory, sys, subspace=U_goal.subspace)
Expand Down
3 changes: 1 addition & 2 deletions src/problem_templates/unitary_variational_problem.jl
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,6 @@ end
@testitem "Sensitive and robust" begin
using LinearAlgebra
using PiccoloQuantumObjects
using QuantumCollocation

system = QuantumSystem([PAULIS.X, PAULIS.Y])
varsys = VariationalQuantumSystem([PAULIS.X, PAULIS.Y], [PAULIS.X] )
Expand All @@ -199,7 +198,7 @@ end
varsys, GATES.X, T, Δt,
variational_scales=[sense_scale],
sensitive_times=[[T]],
piccolo_options=QuantumCollocation.Options.PiccoloOptions(verbose=false)
piccolo_options=PiccoloOptions(verbose=false)
)
solve!(sense_prob, max_iter=20, print_level=1, verbose=false)

Expand Down
3 changes: 1 addition & 2 deletions src/quantum_system_templates/rydberg.jl
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,6 @@ end

@testitem "Rydberg system test" begin
using PiccoloQuantumObjects
using QuantumCollocation

@test QuantumCollocation.RydbergChainSystem(N=3,cutoff_order=2,all2all=false) isa QuantumSystem
@test RydbergChainSystem(N=3,cutoff_order=2,all2all=false) isa QuantumSystem
end
40 changes: 16 additions & 24 deletions src/quantum_system_templates/transmons.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
export TransmonSystem
export TransmonDipoleCoupling
export MultiTransmonSystem
using QuantumCollocation

@doc raw"""
TransmonSystem(;
Expand Down Expand Up @@ -135,13 +134,12 @@ where `a_i` is the annihilation operator for the `i`th transmon.
"""
function TransmonDipoleCoupling end

function lift(op::AbstractMatrix, which::Int, dims::Vector{Int})
ops = [i == which ? op : Matrix{eltype(op)}(I, d, d) for (i, d) in enumerate(dims)]
result = ops[1]
for i in 2:length(ops)
result = kron(result, ops[i])
end
return result
# TODO: this function is already difined in PiccoloQuantumObjects.jl so should be used from there, but it is not in a module
function lift_operator(operator::AbstractMatrix{T}, i::Int, subsystem_levels::AbstractVector{Int}) where T <: Number
@assert size(operator, 1) == subsystem_levels[i] "Operator must match subsystem level."
Is = [Matrix{T}(I(l)) for l ∈ subsystem_levels]
Is[i] = operator
return reduce(kron, Is)
end

struct QuantumSystemCoupling
Expand All @@ -162,9 +160,10 @@ function TransmonDipoleCoupling(
lab_frame::Bool=false,
mulitply_by_2π::Bool=true,
)

i, j = pair
a_i = lift(annihilate(subsystem_levels[i]), i, subsystem_levels)
a_j = lift(annihilate(subsystem_levels[j]), j, subsystem_levels)
a_i = lift_operator(annihilate(subsystem_levels[i]), i, subsystem_levels)
a_j = lift_operator(annihilate(subsystem_levels[j]), j, subsystem_levels)

if lab_frame
op = g_ij * (a_i + a_i') * (a_j + a_j')
Expand Down Expand Up @@ -267,7 +266,6 @@ end

@testitem "TransmonSystem: default and custom parameters" begin
using PiccoloQuantumObjects
using QuantumCollocation
sys = TransmonSystem()
@test typeof(sys) == QuantumSystem
@test haskey(sys.params, :ω)
Expand All @@ -284,7 +282,6 @@ end

@testitem "TransmonSystem: lab_frame_type variations" begin
using PiccoloQuantumObjects
using QuantumCollocation
sys_duffing = TransmonSystem(lab_frame=true, lab_frame_type=:duffing)
sys_quartic = TransmonSystem(lab_frame=true, lab_frame_type=:quartic)
sys_cosine = TransmonSystem(lab_frame=true, lab_frame_type=:cosine)
Expand All @@ -294,39 +291,35 @@ end
end

@testitem "TransmonSystem: error on invalid lab_frame_type" begin
using PiccoloQuantumObjects
using QuantumCollocation
@test_throws AssertionError TransmonSystem(lab_frame=true, lab_frame_type=:invalid)
end

@testitem "TransmonDipoleCoupling: both constructors and frames" begin
using PiccoloQuantumObjects
using QuantumCollocation
levels = [3, 3]
g = 0.01

c1 = TransmonDipoleCoupling(g, (1,2), levels, lab_frame=false)
c2 = TransmonDipoleCoupling(g, (1,2), levels, lab_frame=true)
@test typeof(c1) == QuantumCollocation.QuantumSystemCoupling
@test typeof(c2) == QuantumCollocation.QuantumSystemCoupling
@test typeof(c1) == QuantumSystemCoupling
@test typeof(c2) == QuantumSystemCoupling

sys1 = TransmonSystem(levels=3)
sys2 = TransmonSystem(levels=3)
c3 = TransmonDipoleCoupling(g, (1,2), [sys1, sys2], lab_frame=false)
@test typeof(c3) == QuantumCollocation.QuantumSystemCoupling
@test typeof(c3) == QuantumSystemCoupling
end

@testitem "MultiTransmonSystem: minimal and custom" begin
using PiccoloQuantumObjects
using QuantumCollocation
using LinearAlgebra: norm
using PiccoloQuantumObjects

ωs = [4.0, 4.1]
δs = [0.2, 0.21]
gs = [0.0 0.01; 0.01 0.0]

comp = MultiTransmonSystem(ωs, δs, gs)
@test typeof(comp) == PiccoloQuantumObjects.CompositeQuantumSystem
@test typeof(comp) == CompositeQuantumSystem
@test length(comp.subsystems) == 2
@test !iszero(comp.H(zeros(comp.n_drives)))

Expand All @@ -337,14 +330,13 @@ end
subsystems=[1],
subsystem_drive_indices=[1]
)
@test typeof(comp2) == PiccoloQuantumObjects.CompositeQuantumSystem
@test typeof(comp2) == CompositeQuantumSystem
@test length(comp2.subsystems) == 1
@test !isapprox(norm(comp2.H(zeros(comp2.n_drives))), 0.0; atol=1e-12)
end

@testitem "MultiTransmonSystem: edge cases" begin
using PiccoloQuantumObjects
using QuantumCollocation
ωs = [4.0, 4.1, 4.2]
δs = [0.2, 0.21, 0.22]
gs = [0.0 0.01 0.02; 0.01 0.0 0.03; 0.02 0.03 0.0]
Expand All @@ -354,7 +346,7 @@ end
subsystems=[1,3],
subsystem_drive_indices=[3]
)
@test typeof(comp) == PiccoloQuantumObjects.CompositeQuantumSystem
@test typeof(comp) == CompositeQuantumSystem
@test length(comp.subsystems) == 2
# Only one drive
@test comp.subsystems[1].params[:drives] == false
Expand Down
19 changes: 11 additions & 8 deletions src/trajectory_initialization.jl
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,6 @@ function initialize_trajectory(
Δt_bounds::ScalarBound=(0.5 * Δt, 1.5 * Δt),
drive_derivative_σ::Float64=0.1,
a_guess::Union{AbstractMatrix{<:Float64}, Nothing}=nothing,
system::Union{OpenQuantumSystem, Nothing}=nothing,
phase_name::Symbol=:ϕ,
phase_data::Union{AbstractVector{<:Real}, Nothing}=nothing,
verbose=false,
Expand Down Expand Up @@ -349,7 +348,6 @@ function initialize_trajectory(
drive_derivative_σ
)
else
@assert !isnothing(system) "System must be provided if a_guess is provided."
# Use provided controls and take derivatives
a_values = initialize_control_trajectory(a_guess, Δt, n_control_derivatives)
end
Expand Down Expand Up @@ -773,12 +771,17 @@ end
@test_throws MethodError TrajectoryInitialization.initialize_control_trajectory(
n_drives, 2, T, "notabounds", 0.1
)
# a_guess provided but system missing
a_guess = randn(n_drives, T)
@test_throws AssertionError TrajectoryInitialization.initialize_trajectory(
state_data, state_inits, state_goals, state_names, T, Δt, n_drives, control_bounds;
a_guess=a_guess
)
end

@testitem "linear_interpolation for matrices" begin
X = [1.0 2.0; 3.0 4.0]
Y = [5.0 6.0; 7.0 8.0]
n = 3
result = linear_interpolation(X, Y, n)
@test size(result) == (2, 2 * n)
@test result[:, 1:2] ≈ X
@test result[:, 5:6] ≈ Y
@test result[:, 3:4] ≈ (X + Y) / 2
end


Expand Down
1 change: 0 additions & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using Test
using TestItemRunner
using QuantumCollocation

# Run all testitem tests in package
@run_package_tests
Loading