Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
3 changes: 1 addition & 2 deletions CONTEXT.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@ solve!(qcp; options=IpoptOptions(max_iter=200))

# 5. Extract results
traj = get_trajectory(qcp)
U_final = iso_vec_to_operator(traj[end][:Ũ⃗])
fid = unitary_fidelity(U_final, U_goal)
fid = fidelity(qcp)
```

### State Transfer (Ket)
Expand Down
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "QuantumCollocation"
uuid = "0dc23a59-5ffb-49af-b6bd-932a8ae77adf"
version = "0.10.0"
version = "0.10.1"
authors = ["Aaron Trowbridge <aaron.j.trowbridge@gmail.com> and contributors"]

[deps]
Expand Down
21 changes: 6 additions & 15 deletions docs/literate/man/piccolo_options.jl
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,13 @@ opts_custom = PiccoloOptions(
# Pass to any problem template:
system = QuantumSystem(0.1 * PAULIS.Z, [PAULIS.X, PAULIS.Y], [1.0, 1.0])
U_goal = EmbeddedOperator(GATES.H, system)
N = 51

prob = UnitarySmoothPulseProblem(
system, U_goal, N;
T = 10.0
qtraj = UnitaryTrajectory(system, U_goal, T)

N = 51
prob = SmoothPulseProblem(
qtraj, N;
piccolo_options = opts_custom
)

Expand Down Expand Up @@ -115,15 +118,6 @@ opts_leakage = PiccoloOptions(

opts_equal_dt = PiccoloOptions(timesteps_all_equal = true)

# ## Advanced Dynamics

# ### `rollout_integrator::Symbol = :pade`
# Integration method for evaluating fidelity.
# - `:pade`: Padé approximation (default, fast)
# - `:exp`: Matrix exponential (more accurate)

opts_exp = PiccoloOptions(rollout_integrator = :exp)

# ## Derivative Constraints

# ### `zero_initial_and_final_derivative::Bool = false`
Expand All @@ -145,7 +139,6 @@ opts_hifi = PiccoloOptions(
verbose = true,
bound_state = true,
geodesic = true,
rollout_integrator = :exp
)

# ### Multilevel system with leakage suppression
Expand Down Expand Up @@ -193,5 +186,3 @@ opts_robust = PiccoloOptions(
# - `:pade` is fast and usually sufficient
# - `:exp` more accurate for sensitive systems
# - Both give same result for well-conditioned problems

println("PiccoloOptions configured!")
86 changes: 33 additions & 53 deletions docs/literate/man/problem_templates_overview.jl
Original file line number Diff line number Diff line change
@@ -1,25 +1,15 @@
# # Problem Templates Overview

# QuantumCollocation.jl provides **8 problem templates** that cover common quantum optimal control scenarios. These templates make it easy to set up and solve problems without manually constructing objectives, constraints, and integrators.

# QuantumCollocation.jl provides **4 problem templates** that cover common quantum optimal control scenarios. These templates make it easy to set up and solve problems without manually constructing objectives, constraints, and integrators.
# ## Template Comparison

# | Template | State Type | Objective | Time | Use Case |
# |:---------|:-----------|:----------|:-----|:---------|
# | [`UnitarySmoothPulseProblem`](@ref) | Unitary | Minimize control effort + infidelity | Fixed | Standard gate synthesis with smooth pulses |
# | [`UnitaryMinimumTimeProblem`](@ref) | Unitary | Minimize duration | Variable | Fastest gate given fidelity constraint |
# | [`UnitarySamplingProblem`](@ref) | Unitary | Minimize control effort + infidelity | Fixed | Robust control over multiple systems |
# | [`UnitaryFreePhase Problem`](@ref) | Unitary | Minimize control effort + infidelity | Fixed | Gate synthesis with free global phase |
# | [`UnitaryVariationalProblem`](@ref) | Unitary | Minimize control effort + infidelity ± sensitivity | Fixed | Sensitivity/robustness to Hamiltonian terms |
# | [`QuantumStateSmoothPulseProblem`](@ref) | Ket | Minimize control effort + infidelity | Fixed | State transfer with smooth pulses |
# | [`QuantumStateMinimumTimeProblem`](@ref) | Ket | Minimize duration | Variable | Fastest state transfer |
# | [`QuantumStateSamplingProblem`](@ref) | Ket | Minimize control effort + infidelity | Fixed | Robust state transfer over multiple systems |

# ## Key Differences

# ### Unitary vs Ket (Quantum State)
# - **Unitary problems**: Optimize gate operations (full unitary matrices), commonly used for universal quantum control
# - **Ket problems**: Optimize state-to-state transfers, useful for initialization and specific state preparation
# | Template | Objective | Time | Use Case |
# |:---------|:-----------|:-----|:---------|
# | [`SmoothPulseProblem`](@ref) | Minimize control effort + infidelity | Fixed | Standard gate/state synthesis with smooth pulses |
# | [`MinimumTimeProblem`](@ref) | Minimize duration | Variable | Fastest gate/state synthesis given fidelity constraint |
# | [`SplinePulseProblem`](@ref) | Minimize control effort + infidelity | Fixed | Gate/state synthesis with spline-based pulses where the derivative variables (`du`) are the actual spline coefficients or slopes. |
# | [`SamplingProblem`](@ref) | Minimize control effort + weighted sum of infidelity objectives | Fixed | Robust gate/state synthesis where the controls are shared across all systems, with differing dynamics. |

# ### Smooth Pulse vs Minimum Time
# - **Smooth Pulse**: Fixed total time `T × Δt`, minimizes control effort with regularization on `u`, `u̇`, `ü`
Expand All @@ -30,51 +20,41 @@
# - Useful for robustness against parameter uncertainties or manufacturing variations
# - Examples: different coupling strengths, detunings, or environmental conditions

# ### Free Phase & Variational
# - **Free Phase**: Optimizes global phase of target unitary (sometimes easier to reach)
# - **Variational**: Uses sensitivity analysis to find controls that are robust or sensitive to specific Hamiltonian terms

# ## Quick Selection Guide

# **I want to implement a quantum gate:**
# - Start simple? → `UnitarySmoothPulseProblem`
# - Need speed? → `UnitaryMinimumTimeProblem`
# - Need robustness? → `UnitarySamplingProblem`
# - Start simple? → [`SmoothPulseProblem`](@ref) + `UnitaryTrajectory`
# - Need speed? → [`MinimumTimeProblem`](@ref) + `UnitaryTrajectory`
# - Need robustness? → [`SamplingProblem`](@ref) + `UnitaryTrajectory`

# **I want to prepare a quantum state:**
# - Standard case? → `QuantumStateSmoothPulseProblem`
# - Speed critical? → `QuantumStateMinimumTimeProblem`
# - Robust preparation? → `QuantumStateSamplingProblem`

# **I'm tuning my solution:**
# - Struggling with convergence? → Try `UnitaryFreePhase Problem`
# - Need parameter sensitivity? → Use `UnitaryVariationalProblem`
# - Standard case? → [`SmoothPulseProblem`](@ref) + `KetTrajectory`
# - Speed critical? → [`MinimumTimeProblem`](@ref) + `KetTrajectory`
# - Robust preparation? → [`SamplingProblem`](@ref) + `KetTrajectory`

# ## Common Parameters

# All templates share these key parameters:

# ```julia
# prob = UnitarySmoothPulseProblem(
# system, # QuantumSystem defining H(u)
# U_goal, # Target unitary or state
# N, # Number of timesteps
#
# # Derivative bounds (smoothness)
# du_bound = 0.01, # |u̇| ≤ du_bound
# ddu_bound = 0.001, # |ü| ≤ ddu_bound
#
# # Regularization weights
# R_u = 0.01, # Penalize u²
# R_du = 0.01, # Penalize u̇²
# R_ddu = 0.01, # Penalize ü²
#
# # Initial guess
# u_guess = nothing, # Optional initial controls
#
# # Advanced options
# piccolo_options = PiccoloOptions(...)
# )
# ```
using QuantumCollocation # hide
using PiccoloQuantumObjects # hide
H_drift = 0.1 * PAULIS.Z # hide
H_drives = [PAULIS.X, PAULIS.Y] # hide
drive_bounds = [1.0, 1.0] # hide
sys = QuantumSystem(H_drift, H_drives, drive_bounds) # hide
U_goal = GATES[:H] # hide
T = 10.0 # hide
qtraj = UnitaryTrajectory(sys, U_goal, T) # hide
N = 51 # hide

prob = SmoothPulseProblem(
qtraj, # QuantumTrajectory wrapping system information, Unitary/Ket/MultiKet problem type
N; # Number of timesteps

Q=100.0, # Objective weighting coefficient for the infidelity
R=1e-2, # Objective weighting coefficient for the controls regularization

piccolo_options = PiccoloOptions(verbose = true), # PiccoloOptions for solver configuration
)

# See the individual template pages for parameter details and examples.
12 changes: 6 additions & 6 deletions docs/literate/man/working_with_solutions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@ using NamedTrajectories

system = QuantumSystem(0.1 * PAULIS.Z, [PAULIS.X, PAULIS.Y], [1.0, 1.0])
U_goal = EmbeddedOperator(GATES.H, system)
N = 51
T = 10.0 # time duration
qtraj = UnitaryTrajectory(system, U_goal, T)

prob = UnitarySmoothPulseProblem(system, U_goal, N)
N = 51 # number of timesteps
prob = SmoothPulseProblem(qtraj, N)

# The `solve!` function accepts several key options:

Expand Down Expand Up @@ -86,7 +88,7 @@ println("Total gate time: ", duration, " (arbitrary units)")

# **Direct fidelity** - Compare final state to goal:
U_final = iso_vec_to_operator(prob.trajectory.Ũ⃗[:, end])
fid_direct = unitary_fidelity(U_final, U_goal)
fid_direct = unitary_fidelity(U_final, U_goal.operator)
println("Direct fidelity: ", fid_direct)

# **Rollout fidelity** - Simulate dynamics forward:
Expand Down Expand Up @@ -165,7 +167,7 @@ using PiccoloPlots # For visualization
using CairoMakie

# Plot controls
fig = plot_controls(prob.trajectory)
fig = plot(prob.trajectory)
# save("controls.png", fig)

# Extract control data for export
Expand Down Expand Up @@ -210,5 +212,3 @@ control_data = Dict(
# 3. Use minimum time optimization for fastest gates
# 4. Apply leakage constraints for multilevel systems
# 5. Use sampling problems for robust control

println("Solution evaluation complete!")
43 changes: 24 additions & 19 deletions docs/make.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,30 @@ using PiccoloDocsTemplate

pages = [
"Home" => "index.md",
"Manual" => [
"Problem Templates Overview" => "generated/man/problem_templates_overview.md",
"Ket Problem Templates" => "generated/man/ket_problem_templates.md",
"Unitary Problem Templates" => "generated/man/unitary_problem_templates.md",
"Robust Control" => "generated/man/robust_control.md",
"Working with Solutions" => "generated/man/working_with_solutions.md",
"PiccoloOptions Reference" => "generated/man/piccolo_options.md",
],
"Customization" => [
"Custom Objectives" => "generated/man/custom_objectives.md",
"Adding Constraints" => "generated/man/adding_constraints.md",
"Initial Trajectories" => "generated/man/initial_trajectories.md",
],
"Examples" => [
"Single Qubit Gate" => "generated/examples/single_qubit_gate.md",
"Two Qubit Gates" => "generated/examples/two_qubit_gates.md",
"Minimum Time Optimization" => "generated/examples/minimum_time_problem.md",
"Robust Control" => "generated/examples/robust_control.md",
"Multilevel Transmon" => "generated/examples/multilevel_transmon.md",
# "Manual" => [
# "Problem Templates Overview" => "generated/man/problem_templates_overview.md",
# "Ket Problem Templates" => "generated/man/ket_problem_templates.md",
# "Unitary Problem Templates" => "generated/man/unitary_problem_templates.md",
# "Robust Control" => "generated/man/robust_control.md",
# "Working with Solutions" => "generated/man/working_with_solutions.md",
# "PiccoloOptions Reference" => "generated/man/piccolo_options.md",
# ],
# "Customization" => [
# "Custom Objectives" => "generated/man/custom_objectives.md",
# "Adding Constraints" => "generated/man/adding_constraints.md",
# "Initial Trajectories" => "generated/man/initial_trajectories.md",
# ],
# "Examples" => [
# "Single Qubit Gate" => "generated/examples/single_qubit_gate.md",
# "Two Qubit Gates" => "generated/examples/two_qubit_gates.md",
# "Minimum Time Optimization" => "generated/examples/minimum_time_problem.md",
# "Robust Control" => "generated/examples/robust_control.md",
# "Multilevel Transmon" => "generated/examples/multilevel_transmon.md",
# ],
"Usage Guide" => [
"Problem Templates Overview" => "generated/man/problem_templates_overview.md",
"Working with Solutions" => "generated/man/working_with_solutions.md",
"PiccoloOptions Reference" => "generated/man/piccolo_options.md",
],
"Library" => "lib.md",
]
Expand Down
42 changes: 20 additions & 22 deletions docs/src/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,25 +27,32 @@ using PiccoloQuantumObjects
# Define system: drift + 2 control Hamiltonians
H_drift = 0.1 * PAULIS.Z
H_drives = [PAULIS.X, PAULIS.Y]
sys = QuantumSystem(H_drift, H_drives, 10.0, [1.0, 1.0])
drive_bounds = [1.0, 1.0] # symmetric bounds
sys = QuantumSystem(H_drift, H_drives, drive_bounds)

# Set up problem: system, target gate, timesteps
U_goal = GATES.H
N = 51
prob = UnitarySmoothPulseProblem(sys, U_goal, N)
# 2. Create quantum trajectory. defines problem: system, target gate, timesteps
U_goal = GATES[:H]
T = 10.0
qtraj = UnitaryTrajectory(sys, U_goal, T) # creates zero pulse internally

# 3. Build optimization problem
N = 51 # number of timesteps
qcp = SmoothPulseProblem(qtraj, N; Q=100.0, R=1e-2)

# Solve!
solve!(prob; max_iter=100)
solve!(qcp; options=IpoptOptions(max_iter=100))

# Check result
println("Fidelity: ", unitary_rollout_fidelity(prob.trajectory, sys))
traj = get_trajectory(qcp)
println("Fidelity: ", fidelity(qcp))
```

That's it! You've optimized control pulses for a quantum gate.

## What Can QuantumCollocation Do?

- **Unitary gate optimization** - Find pulses to implement quantum gates
- **Open quantum systems** - Find pulses for lindladian dynamics
- **State transfer** - Drive quantum states to target states
- **Minimum time control** - Optimize gate duration
- **Robust control** - Account for system uncertainties
Expand All @@ -69,25 +76,16 @@ where $\mathbf{Z}$ is a trajectory containing states and controls from [NamedTra

We provide **problem templates** for common quantum control tasks. These templates construct a `DirectTrajOptProblem` from [DirectTrajOpt.jl](https://github.com/harmoniqs/DirectTrajOpt.jl) with appropriate objectives, constraints, and dynamics.

We provide **problem templates** for common quantum control tasks. These templates construct a `DirectTrajOptProblem` from [DirectTrajOpt.jl](https://github.com/harmoniqs/DirectTrajOpt.jl) with appropriate objectives, constraints, and dynamics.

## Problem Templates

Problem templates are organized by the type of quantum system being controlled:

### Unitary (Gate) Templates
- [`UnitarySmoothPulseProblem`](@ref) - Optimize smooth pulses for unitary gates
- [`UnitaryMinimumTimeProblem`](@ref) - Minimize gate duration
- [`UnitarySamplingProblem`](@ref) - Robust control over system variations
- [`UnitaryFreePhaseProblem`](@ref) - Optimize up to global phase
- [`UnitaryVariationalProblem`](@ref) - Variational quantum optimization
### General Problem Templates
- [`MinimumTimeProblem`](@ref) - Minimize gate duration
- [`SamplingProblem`](@ref) - Robust control over system variations
- [`SmoothPulseProblem`](@ref) - Optimize smooth pulses for unitary gates
- [`SplinePulseProblem`](@ref) - Using higher order splines to characterize pulse shape

### Quantum State Templates
- [`QuantumStateSmoothPulseProblem`](@ref) - Drive states with smooth pulses
- [`QuantumStateMinimumTimeProblem`](@ref) - Minimize state transfer time
- [`QuantumStateSamplingProblem`](@ref) - Robust state transfer

See the [Problem Templates Overview](@ref) for a detailed comparison and selection guide.

See the [Problem Templates Overview](@ref) for a detailed comparison and selection guide.

Expand Down Expand Up @@ -121,7 +119,7 @@ The dynamics between knot points $(U_k, u_k)$ and $(U_{k+1}, u_{k+1})$ become no
- 📚 [Problem Templates Overview](@ref) - Choose the right template for your problem
- 🎯 [Working with Solutions](@ref) - Extract results, evaluate fidelity, save data
- ⚙️ [PiccoloOptions Reference](@ref) - Configure solver options and constraints
- 💡 [Examples](@ref) - See complete examples from single qubits to multilevel systems
- 💡 [Two Qubit Gates](@ref), [Single Qubit Gate](@ref) - See complete examples from single qubits to multilevel systems (**MOVING TO PICCOLO DOCS**)

## Related Packages

Expand Down
15 changes: 5 additions & 10 deletions docs/src/lib.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,32 +5,27 @@
Modules = [QuantumCollocation.ProblemTemplates]
```

## Quantum System Templates
```@autodocs
Modules = [QuantumCollocation.QuantumSystemTemplates]
```

## Quantum Objectives
```@autodocs
Modules = [QuantumCollocation.QuantumObjectives]
```

## Quantum Constraints
```@autodocs
Modules = [QuantumCollocation.QuantumObjectives]
Modules = [QuantumCollocation.QuantumConstraints]
```

## Quantum Integrators
```@autodocs
Modules = [QuantumCollocation.QuantumObjectives]
Modules = [QuantumCollocation.QuantumIntegrators]
```

## Options
```@autodocs
Modules = [QuantumCollocation.Options]
```

## Trajectory Initialization
## Control Problems
```@autodocs
Modules = [QuantumCollocation.TrajectoryInitialization]
```
Modules = [QuantumCollocation.QuantumControlProblems]
```
2 changes: 1 addition & 1 deletion src/problem_templates/minimum_time_problem.jl
Original file line number Diff line number Diff line change
Expand Up @@ -627,7 +627,7 @@ end
@test duration_after <= duration_before * 1.1
end

@testitem "MinimumTimeProblem with time-dependent SamplingTrajectory (Unitary)" begin
@testitem "MinimumTimeProblem with time-dependent SamplingTrajectory (Unitary)" tags=[:experimental] begin
using QuantumCollocation
using PiccoloQuantumObjects
using DirectTrajOpt
Expand Down
Loading
Loading