Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
f0af49e
moving otimes to isomorphisms
aarontrowbridge Nov 1, 2024
e7aacc4
manifest update
aarontrowbridge Nov 1, 2024
c0a550e
integrator signature refactor -- removes sys dependence
aarontrowbridge Nov 1, 2024
eeac85a
problem template fixes (tests passing)
aarontrowbridge Nov 1, 2024
f2dd861
moved isomorphisms to core
aarontrowbridge Nov 1, 2024
e634cc3
big rip
aarontrowbridge Nov 4, 2024
d07420d
big rip 2: quantum objects
aarontrowbridge Nov 6, 2024
e3412e4
traj init for unitary
andgoldschmidt Nov 6, 2024
c0cdbbf
state sampling problem template
andgoldschmidt Nov 6, 2024
d54f53c
refactored system to integrator interface
aarontrowbridge Nov 6, 2024
4708228
density operators
aarontrowbridge Nov 10, 2024
f66b443
traj init for unitary
andgoldschmidt Nov 6, 2024
c7bdccc
state sampling problem template
andgoldschmidt Nov 6, 2024
b69af1d
bug fix: a_guess option
andgoldschmidt Nov 7, 2024
c215e41
bug fix: free phase obj
andgoldschmidt Nov 7, 2024
edde00e
phase rollout fidelity
andgoldschmidt Nov 7, 2024
43e73d9
free phase initialization
andgoldschmidt Nov 7, 2024
f5d943e
Tests for free phases
andgoldschmidt Nov 9, 2024
2ab761f
free phase incr
andgoldschmidt Nov 9, 2024
b4d5eea
bug fix: mintime and robprob fidelity subspace
andgoldschmidt Nov 9, 2024
d26420c
bug fix: drop drive_sigma arg, fix subspace nothing
andgoldschmidt Nov 9, 2024
3a34581
problem template fixes (tests passing)
aarontrowbridge Nov 1, 2024
98800fd
big rip
aarontrowbridge Nov 4, 2024
1bdd6a4
refactored system to integrator interface
aarontrowbridge Nov 6, 2024
6705653
density operators
aarontrowbridge Nov 10, 2024
91fd3a5
rebase fixes (broken)
aarontrowbridge Nov 11, 2024
a6aae3b
Merge remote-tracking branch 'origin/main' into 163-feature-peel-off-…
aarontrowbridge Nov 11, 2024
c8621ac
rebase complete (fixes free phase loss)
aarontrowbridge Nov 11, 2024
bfb6ff8
docs uopdates
aarontrowbridge Nov 12, 2024
0d2efae
renaming OperatorType -> AbstractPiccoloOperator
aarontrowbridge Nov 19, 2024
560c857
adding quantum system templates + cleaning
aarontrowbridge Nov 19, 2024
fbcbb1b
update system type from AbstractQuantumSystem to OpenQuantumSystem an…
aarontrowbridge Dec 2, 2024
5c4d06f
refactor trajectory initialization to use density_to_iso_vec for init…
aarontrowbridge Dec 5, 2024
881e083
refactor rollout_fidelity to have sys as arg
aarontrowbridge Dec 23, 2024
eac5100
passing tests (except for direct sum prob)
aarontrowbridge Jan 6, 2025
cbeebbb
refactor add_suffix and remove_suffix functions to eliminate sys para…
aarontrowbridge Jan 9, 2025
5199435
bump version to 0.5.0 and update dependencies for compatibility
aarontrowbridge Jan 9, 2025
601cd2d
Merge branch 'main' into 163-feature-peel-off-core-functionality-into…
jack-champagne Jan 13, 2025
6107ce4
remove operatortype
jack-champagne Jan 13, 2025
09a3143
add back in zero initial and final
jack-champagne Jan 13, 2025
45b6d36
revert removing list of state names
jack-champagne Jan 13, 2025
f72f5fd
refactor callbacks and problem templates to use rollout fidelity and …
aarontrowbridge Jan 14, 2025
ae3a31f
update Project.toml dependencies and refactor drive length references…
aarontrowbridge Jan 14, 2025
19004b3
fix callbacks except for new tol
jack-champagne Jan 15, 2025
8211e7c
remove fidelity test from callback test suite - see PR comment #173
jack-champagne Jan 15, 2025
cc602dc
add qualified path for get_datavec
jack-champagne Jan 15, 2025
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
Next Next commit
Merge branch 'main' into 163-feature-peel-off-core-functionality-into…
…-quantumcollocationcorejl-package
  • Loading branch information
jack-champagne committed Jan 13, 2025
commit 601cd2dc82475976151983d43c77b8d1383756ba
3 changes: 3 additions & 0 deletions docs/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,6 @@ NamedTrajectories = "538bc3a1-5ab9-4fc3-b776-35ca1e893e08"
QuantumCollocation = "0dc23a59-5ffb-49af-b6bd-932a8ae77adf"
QuantumCollocationCore = "2b384925-53cb-4042-a8d2-6faa627467e1"
Revise = "295af30f-e4ad-537b-8983-00126c2a3abe"

[compat]
NamedTrajectories = "0.2.4"
88 changes: 88 additions & 0 deletions docs/literate/man/ipopt_callbacks.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
# ```@meta
# CollapsedDocStrings = true
# ```
# # IpOpt Callbacks

# This page describes the callback functions that can be used with the IpOpt solver (in the future, may describe more general callback behavior).

# ## Callbacks

using QuantumCollocation
using NamedTrajectories

import ..QuantumStateSmoothPulseProblem
import ..Callbacks

# By default, IpOpt callbacks are called at each optimization step with the following signature:
function full_argument_list_callback(
alg_mod::Cint,
iter_count::Cint,
obj_value::Float64,
inf_pr::Float64,
inf_du::Float64,
mu::Float64,
d_norm::Float64,
regularization_size::Float64,
alpha_du::Float64,
alpha_pr::Float64,
ls_trials::Cint,
)
return true
end

# This gives the user access to some of the optimization state internals at each iteration.
# A callback function with any subset of these arguments can be passed into the `solve!` function via the `callback` keyword argument see below.

# The callback function can be used to stop the optimization early by returning `false`. The following callback when passed to `solve!` will stop the optimization after the first iteration:
my_callback = (kwargs...) -> false

# Single initial and target states
# --------------------------------
T = 50
Δt = 0.2
sys = QuantumSystem(0.1 * GATES[:Z], [GATES[:X], GATES[:Y]])
ψ_init = Vector{ComplexF64}([1.0, 0.0])
ψ_target = Vector{ComplexF64}([0.0, 1.0])

prob = QuantumStateSmoothPulseProblem(
sys, ψ_init, ψ_target, T, Δt;
ipopt_options=IpoptOptions(print_level=1),
piccolo_options=PiccoloOptions(verbose=false)
)


# The callback function can be used to monitor the optimization progress, save intermediate results, or modify the optimization process.
# For example, the following callback function saves the optimization trajectory at each iteration - this can be useful for debugging or plotting the optimization progress.
# `trajectory_history_callback` from the `Callbacks` module
callback, trajectory_history = QuantumCollocation.Callbacks.trajectory_history_callback(prob)
solve!(prob, max_iter=20, callback=callback)

# Save trajectory images into files which can be used to create a gif like the following:
for (iter, traj) in enumerate(trajectory_history)
str_index = lpad(iter, length(string(length(trajectory_history))), "0")
plot("./iteration-$str_index-trajectory.png", traj, [:ψ̃, :a], xlims=(-Δt, (T+5)*Δt), ylims=(ψ̃1 = (-2, 2), a = (-1.1, 1.1)))
end

# ![pulse optimization animation](../../assets/animation.gif)

# Using a callback to get the best trajectory from all the optimization iterations
sys2 = QuantumSystem(0.15 * GATES[:Z], [GATES[:X], GATES[:Y]])
ψ_init2 = Vector{ComplexF64}([0.0, 1.0])
ψ_target2 = Vector{ComplexF64}([1.0, 0.0])

# Using other callbacks from the callback library
# --------------------------------
# Callback used here is `best_rollout_fidelity_callback` which appends the best trajectories based on monotonically increasing fidelity of the rollout
prob2 = QuantumStateSmoothPulseProblem(
sys2, ψ_init2, ψ_target2, T, Δt;
ipopt_options=IpoptOptions(print_level=1),
piccolo_options=PiccoloOptions(verbose=false)
)

best_trajectory_callback, best_trajectory_list = best_rollout_fidelity_callback(prob2)
solve!(prob2, max_iter=20, callback=best_trajectory_callback)
# fidelity of the last iterate
@show Losses.fidelity(prob2)

# fidelity of the best iterate
@show QuantumCollocation.fidelity(best_trajectory_list[end], prob2.system)
1 change: 1 addition & 0 deletions docs/make.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ pages = [
"Manual" => [
"Problem Templates" => "generated/man/problem_templates.md",
"Embedded Operators" => "generated/man/embedded_operators.md",
"Callbacks" => "generated/man/ipopt_callbacks.md",
],
"Examples" => [
"Two Qubit Gates" => "generated/examples/two_qubit_gates.md",
Expand Down
Binary file added docs/src/assets/animation.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/src/assets/pulse-optimization.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/src/assets/smooth_pulse_animation.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
126 changes: 126 additions & 0 deletions docs/src/generated/man/ipopt_callbacks.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
```@meta
EditURL = "../../../literate/man/ipopt_callbacks.jl"
```

```@meta
CollapsedDocStrings = true
```
# IpOpt Callbacks

This page describes the callback functions that can be used with the IpOpt solver (in the future, may describe more general callback behavior).

## Callbacks

````@example ipopt_callbacks
using QuantumCollocation
using NamedTrajectories

import ..QuantumStateSmoothPulseProblem
import ..Callbacks
````

By default, IpOpt callbacks are called at each optimization step with the following signature:

````@example ipopt_callbacks
function full_argument_list_callback(
alg_mod::Cint,
iter_count::Cint,
obj_value::Float64,
inf_pr::Float64,
inf_du::Float64,
mu::Float64,
d_norm::Float64,
regularization_size::Float64,
alpha_du::Float64,
alpha_pr::Float64,
ls_trials::Cint,
)
return true
end
````

This gives the user access to some of the optimization state internals at each iteration.
A callback function with any subset of these arguments can be passed into the `solve!` function via the `callback` keyword argument see below.

The callback function can be used to stop the optimization early by returning `false`. The following callback when passed to `solve!` will stop the optimization after the first iteration:

````@example ipopt_callbacks
my_callback = (kwargs...) -> false
````

Single initial and target states
--------------------------------

````@example ipopt_callbacks
T = 50
Δt = 0.2
sys = QuantumSystem(0.1 * GATES[:Z], [GATES[:X], GATES[:Y]])
ψ_init = Vector{ComplexF64}([1.0, 0.0])
ψ_target = Vector{ComplexF64}([0.0, 1.0])

prob = QuantumStateSmoothPulseProblem(
sys, ψ_init, ψ_target, T, Δt;
ipopt_options=IpoptOptions(print_level=1),
piccolo_options=PiccoloOptions(verbose=false)
)
````

The callback function can be used to monitor the optimization progress, save intermediate results, or modify the optimization process.
For example, the following callback function saves the optimization trajectory at each iteration - this can be useful for debugging or plotting the optimization progress.
`trajectory_history_callback` from the `Callbacks` module

````@example ipopt_callbacks
callback, trajectory_history = QuantumCollocation.Callbacks.trajectory_history_callback(prob)
solve!(prob, max_iter=20, callback=callback)
````

Save trajectory images into files which can be used to create a gif like the following:

````@example ipopt_callbacks
for (iter, traj) in enumerate(trajectory_history)
str_index = lpad(iter, length(string(length(trajectory_history))), "0")
plot("./iteration-$str_index-trajectory.png", traj, [:ψ̃, :a], xlims=(-Δt, (T+5)*Δt), ylims=(ψ̃1 = (-2, 2), a = (-1.1, 1.1)))
end
````

![pulse optimization animation](../../assets/animation.gif)

Using a callback to get the best trajectory from all the optimization iterations

````@example ipopt_callbacks
sys2 = QuantumSystem(0.15 * GATES[:Z], [GATES[:X], GATES[:Y]])
ψ_init2 = Vector{ComplexF64}([0.0, 1.0])
ψ_target2 = Vector{ComplexF64}([1.0, 0.0])
````

Using other callbacks from the callback library
--------------------------------
Callback used here is `best_rollout_fidelity_callback` which appends the best trajectories based on monotonically increasing fidelity of the rollout

````@example ipopt_callbacks
prob2 = QuantumStateSmoothPulseProblem(
sys2, ψ_init2, ψ_target2, T, Δt;
ipopt_options=IpoptOptions(print_level=1),
piccolo_options=PiccoloOptions(verbose=false)
)

best_trajectory_callback, best_trajectory_list = best_rollout_fidelity_callback(prob2)
solve!(prob2, max_iter=20, callback=best_trajectory_callback)
````

fidelity of the last iterate

````@example ipopt_callbacks
@show Losses.fidelity(prob2)
````

fidelity of the best iterate

````@example ipopt_callbacks
@show QuantumCollocation.fidelity(best_trajectory_list[end], prob2.system)
````

---

*This page was generated using [Literate.jl](https://github.com/fredrikekre/Literate.jl).*

Loading
Loading
You are viewing a condensed version of this merge commit. You can view the full changes here.