Quickstart
This quickstart guide will help you get up and running with PiccoloQuantumObjects.jl.
Installation
using Pkg
Pkg.add("PiccoloQuantumObjects")Basic Usage
using PiccoloQuantumObjects
using LinearAlgebra
using SparseArrays
using NamedTrajectoriesCreating a Quantum System
Define Hamiltonian components
H_drift = PAULIS[:Z]
H_drives = [PAULIS[:X], PAULIS[:Y]]2-element Vector{Matrix{ComplexF64}}:
[0.0 + 0.0im 1.0 + 0.0im; 1.0 + 0.0im 0.0 + 0.0im]
[0.0 + 0.0im 0.0 - 1.0im; 0.0 + 1.0im 0.0 + 0.0im]Specify time and control bounds
T_max = 10.0 # Maximum evolution time
drive_bounds = [(-1.0, 1.0), (-1.0, 1.0)] # Control bounds for each drive2-element Vector{Tuple{Float64, Float64}}:
(-1.0, 1.0)
(-1.0, 1.0)Create the quantum system
system = QuantumSystem(H_drift, H_drives, T_max, drive_bounds)QuantumSystem: levels = 2, n_drives = 2Working with Quantum States
Create quantum states
ψ_ground = ket_from_string("g", [2]) # Ground state2-element Vector{ComplexF64}:
1.0 + 0.0im
0.0 + 0.0imψ_excited = ket_from_string("e", [2]) # Excited state2-element Vector{ComplexF64}:
0.0 + 0.0im
1.0 + 0.0imCalculate fidelity
fidelity(ψ_ground, ψ_excited)0.0Simulating Evolution (Rollouts)
Initial state
ψ_init = ComplexF64[1.0, 0.0]2-element Vector{ComplexF64}:
1.0 + 0.0im
0.0 + 0.0imDefine control sequence
T = 10 # Number of time steps
controls = rand(2, T) # Random controls for two drives
Δt = fill(0.1, T) # Time step duration10-element Vector{Float64}:
0.1
0.1
0.1
0.1
0.1
0.1
0.1
0.1
0.1
0.1Perform rollout
ψ̃_rollout = rollout(ψ_init, controls, Δt, system)4×10 Matrix{Float64}:
1.0 0.990995 0.96372 0.927133 … 0.634647 0.556804 0.448841
0.0 0.0695055 0.111637 0.127104 0.276985 0.339543 0.327869
0.0 -0.0996997 -0.200748 -0.300139 -0.610341 -0.654135 -0.72681
0.0 -0.0561917 -0.135947 -0.184891 -0.38469 -0.383129 -0.403474Check final state fidelity
ψ_goal = ComplexF64[0.0, 1.0]
rollout_fidelity(ψ_init, ψ_goal, controls, Δt, system)0.27028928051207124Open Quantum Systems
Add dissipation operators
a = annihilate(2)
dissipation_operators = [a'a, a]2-element Vector{Matrix{ComplexF64}}:
[0.0 + 0.0im 0.0 + 0.0im; 0.0 + 0.0im 1.0 + 0.0im]
[0.0 + 0.0im 1.0 + 0.0im; 0.0 + 0.0im 0.0 + 0.0im]Create open quantum system
open_system = OpenQuantumSystem(
H_drives,
T_max,
drive_bounds,
dissipation_operators=dissipation_operators
)OpenQuantumSystem: levels = 2, n_drives = 2Composite Systems
Create subsystems
sys1 = QuantumSystem([PAULIS[:X]], 10.0, [(-1.0, 1.0)])
sys2 = QuantumSystem([PAULIS[:Y]], 10.0, [(-1.0, 1.0)])QuantumSystem: levels = 2, n_drives = 1Define coupling
H_coupling = 0.1 * kron(PAULIS[:Z], PAULIS[:Z])4×4 Matrix{ComplexF64}:
0.1+0.0im 0.0+0.0im 0.0+0.0im 0.0+0.0im
0.0+0.0im -0.1+0.0im 0.0+0.0im -0.0+0.0im
0.0+0.0im 0.0+0.0im -0.1+0.0im -0.0+0.0im
0.0+0.0im -0.0+0.0im -0.0+0.0im 0.1-0.0imCreate composite system
composite_sys = CompositeQuantumSystem(
H_coupling,
Matrix{ComplexF64}[],
[sys1, sys2],
10.0,
Float64[]
)CompositeQuantumSystem: levels = 4, n_drives = 2Visualization
PiccoloQuantumObjects.jl integrates with NamedTrajectories.jl for plotting trajectories.
using CairoMakiePlotting Controls and States
Create a trajectory with controls and states
T_plot = 50
controls_plot = 0.5 * sin.(2π * (1:T_plot) / T_plot)
Δt_plot = fill(T_max / T_plot, T_plot)50-element Vector{Float64}:
0.2
0.2
0.2
0.2
0.2
0.2
0.2
0.2
0.2
0.2
⋮
0.2
0.2
0.2
0.2
0.2
0.2
0.2
0.2
0.2Perform a rollout to get the state evolution
ψ̃_traj = rollout(ψ_init, hcat(controls_plot, -controls_plot)', Δt_plot, system)4×50 Matrix{Float64}:
1.0 0.979911 0.919701 0.82018 … -0.306636 -0.118921 0.0726682
0.0 -0.0124493 -0.0388295 -0.0791013 0.13996 0.166036 0.198433
0.0 -0.198659 -0.389215 -0.563388 0.894051 0.947331 0.957062
0.0 -0.0124493 -0.0339619 -0.0603398 -0.295058 -0.246687 -0.198433Create a NamedTrajectory for plotting
traj = NamedTrajectory(
(
ψ̃ = ψ̃_traj,
a = hcat(controls_plot, -controls_plot)',
Δt = Δt_plot
);
timestep=:Δt,
controls=:a,
initial=(ψ̃ = ket_to_iso(ψ_init),),
goal=(ψ̃ = ket_to_iso(ψ_goal),)
)N = 50, (ψ̃ = 1:4, a = 5:6, → Δt = 7:7)Plot the trajectory
plot(traj)
Plotting State Populations
Use transformations to plot populations directly from isomorphic states
plot(
traj,
[:a],
transformations=[
:ψ̃ => (ψ̃ -> abs2.(iso_to_ket(ψ̃)))
],
transformation_labels=["Populations"]
)
Next Steps
- Explore the Quantum Systems manual for detailed system construction
- Learn about Quantum Objects for working with states and operators
- See Rollouts for simulation and fidelity calculations
- Understand Isomorphisms for the underlying mathematical transformations
This page was generated using Literate.jl.