Skip to content

Commit

Permalink
Merge pull request #6 from aarontrowbridge/generalize
Browse files Browse the repository at this point in the history
  • Loading branch information
aarontrowbridge committed Aug 13, 2022
2 parents 5b19aea + d15610f commit af3838a
Show file tree
Hide file tree
Showing 25 changed files with 651 additions and 780 deletions.
21 changes: 10 additions & 11 deletions experiments/multimode/g0_to_g1.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,14 @@ using HDF5

hf_path = "notebooks/g0_to_g1_multimode_sys_data.h5"

sys = MultiModeQubitSystem(hf_path)
system = QuantumSystem(hf_path, control_bounds = a_bounds)
# bounds on controls

qubit_a_bounds = [0.018 * 2π, 0.018 * 2π]

cavity_a_bounds = fill(0.03, sys.ncontrols - 2)

a_bounds = [qubit_a_bounds; cavity_a_bounds]

T = parse(Int, ARGS[1])
Δt = parse(Float64, ARGS[2])
Expand All @@ -18,14 +25,6 @@ options = Options(
max_cpu_time = 100000.0,
)

# bounds on controls

qubit_a_bounds = [0.018 * 2π, 0.018 * 2π]

cavity_a_bounds = fill(0.03, sys.ncontrols - 2)

a_bounds = [qubit_a_bounds; cavity_a_bounds]

u_bounds = BoundsConstraint(
1:T,
sys.n_wfn_states .+
Expand All @@ -34,8 +33,8 @@ u_bounds = BoundsConstraint(
sys.vardim
)

prob = QubitProblem(
sys,
prob = QuantumControlProblem(
system,
T;
Δt=Δt,
R=R,
Expand Down
4 changes: 2 additions & 2 deletions experiments/multimode/g0_to_g1_from_init_guess.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ using HDF5
hf_path = "notebooks/g0_to_g1_multimode_system_data.h5"

system, data =
MultiModeQubitSystem(hf_path; return_data=true)
QuantumSystem(hf_path; return_data=true)

Δt = data["Δt"]
T = data["T"]
Expand Down Expand Up @@ -49,7 +49,7 @@ init_traj = Trajectory(system, data["controls"], Δt)

# define problem

prob = QubitProblem(
prob = QuantumControlProblem(
system,
init_traj;
R=R,
Expand Down
4 changes: 2 additions & 2 deletions experiments/multimode/g0_to_g1_mintime_from_init_guess.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ using HDF5
hf_path = "notebooks/g0_to_g1_multimode_system_data.h5"

system, data =
MultiModeQubitSystem(hf_path; return_data=true)
QuantumSystem(hf_path; return_data=true)

Δt = data["Δt"]
T = data["T"]
Expand Down Expand Up @@ -50,7 +50,7 @@ init_traj = Trajectory(system, data["controls"], Δt)

# define problem

prob = QubitProblem(
prob = QuantumControlProblem(
system,
init_traj;
R=R,
Expand Down
32 changes: 20 additions & 12 deletions experiments/multimode/multimode.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ function cavity_state(level)
end
#const TRANSMON_ID = I(TRANSMON_LEVELS)

const TRANSMON_G = [1; zeros(TRANSMON_LEVELS - 1)]
const TRANSMON_E = [zeros(1); 1; zeros(TRANSMON_LEVELS - 2)]
TRANSMON_G = [1; zeros(TRANSMON_LEVELS - 1)]
TRANSMON_E = [zeros(1); 1; zeros(TRANSMON_LEVELS - 2)]


const CHI = 2π * -0.5469e-3
const KAPPA = 2π * 4e-6
CHI = 2π * -0.5469e-3
KAPPA = 2π * 4e-6

H_drift = 2 * CHI * kron(TRANSMON_E*TRANSMON_E', number(CAVITY_LEVELS)) +
(KAPPA/2) * kron(I(TRANSMON_LEVELS), quad(CAVITY_LEVELS))
Expand All @@ -38,11 +38,20 @@ H_drives = [transmon_driveR, transmon_driveI, cavity_driveR, cavity_driveI]
ψ1 = kron(TRANSMON_G, cavity_state(0))
ψf = kron(TRANSMON_G, cavity_state(1))

sys = MultiModeQubitSystem(
# bounds on controls

qubit_a_bounds = [0.018 * 2π, 0.018 * 2π]

cavity_a_bounds = fill(0.03, sys.ncontrols - 2)

a_bounds = [qubit_a_bounds; cavity_a_bounds]

system = QuantumSystem(
H_drift,
H_drives,
ψ1,
ψf
ψf,
control_bounds = a_bounds
)

T = parse(Int, ARGS[1])
Expand All @@ -57,13 +66,7 @@ options = Options(
max_cpu_time = 100000.0,
)

# bounds on controls

qubit_a_bounds = [0.018 * 2π, 0.018 * 2π]

cavity_a_bounds = fill(0.03, sys.ncontrols - 2)

a_bounds = [qubit_a_bounds; cavity_a_bounds]

u_bounds = BoundsConstraint(
1:T,
Expand All @@ -82,8 +85,13 @@ data_dir = "data/multimode/fixed_time/no_guess/problems"

resolves = parse(Int, ARGS[end])

<<<<<<< HEAD
prob = QuantumControlProblem(
system,
=======
prob = QubitProblem(
sys,
>>>>>>> origin
T;
Δt=Δt,
R=R,
Expand Down
108 changes: 56 additions & 52 deletions experiments/single_qubit/mintime.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,73 +7,77 @@ using QubitControl
H_drift = σz / 2
H_drives = [σx / 2, σy / 2]

gate = Symbol(ARGS[1])
gate = Symbol(:X)

ψ0 = [1, 0]
ψ1 = [0, 1]

ψ = [ψ0, ψ1, (ψ0 + im * ψ1) / 2, (ψ0 - ψ1) / 2]
ψf = apply.(gate, ψ)
a_bound = [1.0, 0.5]

system = SingleQubitSystem(H_drift, H_drives, gate, ψ)
system = QuantumSystem(
H_drift,
H_drives,
ψ1 = ψ,
ψf = ψf,
control_bounds = a_bound
)

T = parse(Int, ARGS[2])
T = 1000
Δt = 0.01
Q = 500.0
R = 0.001

Q = 200.0
R = 0.01
Rᵤ = 1e-5
Rₛ = Rᵤ
cost = infidelity_cost

a_bound = [1.0, 0.5]

iter = 3500
tol = 1e-5

options = Options(
max_iter = parse(Int, ARGS[end-1]),
tol = 1e-6
max_iter = iter,
tol = tol,
max_cpu_time = 10000.0,
)

iter = parse(Int, ARGS[end])

tol = 1e-5

plot_dir = "plots/single_qubit/min_time/two_controls"
plot_file = "$(gate)_gate_Ru_$(Rᵤ)_Rs_$(Rₛ)_tol_$(tol)_iter_$(iter)_pinned.png"
plot_path = joinpath(plot_dir, plot_file)

min_time_options = Options(
max_iter = 14000,
tol = tol,
max_cpu_time = 27000.0,
)

prob = QuantumMinTimeProblem(
system,
T;
Δt=Δt,
Q=Q,
R=R,
Rᵤ=Rᵤ,
Rₛ=Rₛ,
cost=cost,
options=options,
mintime_options=min_time_options
)

plot_single_qubit(
system,
prob.subprob.trajectory,
plot_path
)

solve!(prob)

plot_single_qubit(
system,
prob.subprob.trajectory,
plot_path
)

for Rᵤ in [1e-3, 1e-5]

Rₛ = Rᵤ

plot_file = "$(gate)_gate_Ru_$(Rᵤ)_Rs_$(Rₛ)_tol_$(tol)_iter_$(iter)_pinned.png"

plot_path = joinpath(plot_dir, plot_file)

min_time_options = Options(
max_iter = iter,
tol = tol
)

prob = MinTimeProblem(
system,
T;
Δt=Δt,
Q=Q,
R=R,
Rᵤ=Rᵤ,
Rₛ=Rₛ,
a_bound=a_bound,
cost=cost,
options=options,
min_time_options=min_time_options
)

plot_single_qubit(
system,
prob.subprob.trajectory,
plot_path
)

solve!(prob)

plot_single_qubit(
system,
prob.subprob.trajectory,
plot_path
)
end
16 changes: 10 additions & 6 deletions experiments/single_qubit/test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,16 @@ iter = 100
# ψ = (ψ0 + ψ1) / √2

ψ = [ψ0, ψ1, (ψ0 + im * ψ1) / 2, (ψ0 - ψ1) / 2]
ψf = apply.(gate, ψ)

system = SingleQubitSystem(
a_bounds = [1.0, 0.5]

system = QuantumSystem(
H_drift,
H_drive,
gate, ψ
ψ1 = ψ,
ψf = ψf,
control_bounds = a_bounds
)

T = 1000
Expand All @@ -35,7 +40,7 @@ R = 2.0
cost = infidelity_cost
hess = true

a_bounds = [1.0, 0.5]


pin_first_qstate = false

Expand All @@ -55,16 +60,15 @@ options = Options(
# linear_solver="pardiso",
)

prob = QubitProblem(
prob = QuantumControlProblem(
system,
T;
Δt=Δt,
Q=Q,
R=R,
eval_hessian=hess,
a_bound=a_bounds,
cost=cost,
pin_first_qstate = true,
pin_first_qstate = pin_first_qstate,
options=options,
integrator=integrator,
)
Expand Down
28 changes: 14 additions & 14 deletions experiments/transmon/transmon.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,8 @@ plot_path = generate_file_path("png", EXPERIMENT_NAME * "_iter_$(iter)", "plots/

#system parameters

qubit_frequency = 2π * 4.96 #GHz
anharmonicity = -2π * 0.143 #GHz
amax = 2π*19e-3

ω = 2π * 4.96 #GHz
α = -2π * 0.143 #GHz
levels = 3

ψg = [1. + 0*im, 0 , 0]
Expand All @@ -20,21 +18,24 @@ levels = 3
ψ1 = [ψg, ψe]
ψf = [-im*ψe, -im*ψg]

system = TransmonSystem(
levels = levels,
rotating_frame = true,
ω = qubit_frequency,
α = anharmonicity,
H_drift = α/2 * quad(levels)
H_drive = [create(levels) + annihilate(levels),
1im * (create(levels) - annihilate(levels))]

system = QuantumSystem(
H_drift,
H_drive,
ψ1 = ψ1,
ψf = ψf
ψf = ψf,
control_bounds = [2π * 19e-3, 2π * 19e-3]
)

#T is number of time steps, not total time
T = 400
Δt = 0.1
Q = 200.
R = 0.1
cost = amplitude_cost
cost = infidelity_cost
hess = true
pinqstate = true

Expand All @@ -45,15 +46,14 @@ options = Options(
tol = 1e-5
)

prob = QubitProblem(
prob = QuantumControlProblem(
system,
T;
Δt = Δt,
Q = Q,
R = R,
eval_hessian = hess,
cost = cost,
a_bound = amax,
pin_first_qstate = pinqstate,
options = options
)
Expand Down Expand Up @@ -83,7 +83,7 @@ result = Dict(
"eval_hessian" => hess,
"a_bound" => 19e-3,
# "trajectory" => prob.trajectory,
"a_max" => amax,
#"a_max" => amax,
"pin_first_qstate" => pinqstate,
"controls" => controls,
"infidelity" => infidelity
Expand Down
Loading

0 comments on commit af3838a

Please sign in to comment.