Rollouts and fidelity

using PiccoloQuantumObjects
using NamedTrajectories
using SparseArrays # for visualization
using LinearAlgebra

Rollouts are simulations of a quantum system. In a rollout, controls are integrated forward in time using the dynamics implied by a provided quantum systems. The defualt is to use zero-order hold integration to simulate the evolution–-that is, the controls are held constant between time steps. For quantum states, the Schrödinger equation is used:

\[\psi(t + \Delta t) = \exp\left(-i H(\mathbf{a}(t)) \Delta t\right) \psi(t)\]

The visited states are collected into a matrix of size (2n, T), for the isomorphic Hilbert space dimension 2n and timesteps T.

Note

All of the returned rollout are assumed to be real valued. It is helpful to use the appropriate isomorphisms to convert between real and complex quantum objects, and eachcol to iterate over the rollout columns.

There are rollouts for each kind of quantum object: quantum states, unitary operators, and density operators.

A fidelity function is also provided for each kind of quantum objectand a rollout fidelity function compares the final state of a rollout to a goal state.

Fidelity functions

The fidelity functions are used to measure how close two quantum states or operators are to each other.

  • fidelity calculates the fidelity between two quantum states.
  • unitary_fidelity calculates the fidelity between two unitary operators.

State fidelity.

ψ = GATES.X * [1.0, 0.0]
ψ_goal = [0.0, 1.0]
fidelity(ψ, ψ_goal)
1.0

Unitary fidelity of orthogonal operations.

U = GATES.Y
U_goal = GATES.X
unitary_fidelity(U, U_goal)
0.0

Quantum State Rollouts

The rollout function simulates the evolution of a real valued quantum state under given controls and quantum system.

PiccoloQuantumObjects.Rollouts.rolloutFunction
rollout(
    ψ̃_init::AbstractVector{<:Real},
    controls::AbstractMatrix{<:Real},
    Δt::AbstractVector,
    system::AbstractQuantumSystem
)
rollout(
    ψ_init::AbstractVector{<:Complex},
    controls::AbstractMatrix{<:Real},
    Δt::AbstractVector,
    system::AbstractQuantumSystem
)
rollout(
    inits::AbstractVector{<:AbstractVector},
    controls::AbstractMatrix{<:Real},
    Δt::AbstractVector,
    system::AbstractQuantumSystem
)

Rollout a quantum state ψ̃_init under the control controls for a time Δt using the system system.

If exp_vector_product is true, the integrator is expected to have a signature like the exponential action, expv. Otherwise, it is expected to have a signature like exp.

Types should allow for autodifferentiable controls and times.

source
PiccoloQuantumObjects.Rollouts.rollout_fidelityFunction
rollout_fidelity(
    ψ̃_init::AbstractVector{<:Real},
    ψ̃_goal::AbstractVector{<:Real},
    controls::AbstractMatrix{<:Real},
    Δt::AbstractVector,
    system::AbstractQuantumSystem
)
rollout_fidelity(
    ψ_init::AbstractVector{<:Complex},
    ψ_goal::AbstractVector{<:Complex},
    controls::AbstractMatrix{<:Real},
    Δt::AbstractVector,
    system::AbstractQuantumSystem
)
rollout_fidelity(
    trajectory::NamedTrajectory,
    system::AbstractQuantumSystem
)

Calculate the fidelity between the final state of a rollout and a goal state.

source

The rollout is a matrix of size (2n, T).

T = 10
ψ_init = ComplexF64[1.0, 0.0]
controls = rand(2, T)
Δt = fill(0.1, T)
system = QuantumSystem(PAULIS[:Z], [PAULIS[:X], PAULIS[:Y]])
ψ̃_rollout = rollout(ψ_init, controls, Δt, system)
ψ̃_rollout |> size
(4, 10)

Quantum State Rollout Fidelity

States must be cast to complex for the rollout to know the difference between real and isomorphic states.

ψ_goal = ComplexF64[0.0, 1.0]
rollout_fidelity(ψ_init, ψ_goal, controls, Δt, system)
0.28308429852052486
Warning

Don't forget to convert the quantum state to the appropriate isomorphism before calculating the fidelity.

fidelity(iso_to_ket(ψ̃_rollout[:, end]), ψ_goal)
0.28308429852052486

The initial state and goal are often inferred from the properly configured trajectory of a control problem.

components = (ψ̃ = zeros(Float64, size(ψ̃_rollout)), a = controls, Δt = Δt)
traj = NamedTrajectory(
    components;
    timestep=:Δt,
    controls=:a,
    initial=(ψ̃ = ket_to_iso(ψ_init),),
    goal=(ψ̃ = ket_to_iso(ψ_goal),),
)
rollout_fidelity(traj, system)
0.28308429852052486
Note

The rollout fidelity is not the same thing as the fidelity of the final trajectory state.

fidelity(iso_to_ket(traj.ψ̃[:, end]), ψ_goal)
0.0

Unitary Rollouts

PiccoloQuantumObjects.Rollouts.unitary_rolloutFunction
unitary_rollout(
    Ũ⃗_init::AbstractVector{<:Real},
    controls::AbstractMatrix{<:Real},
    Δt::AbstractVector,
    system::AbstractQuantumSystem;
    kwargs...
)

Rollout a isomorphic unitary operator Ũ⃗_init under the control controls for a time Δt using the system system.

Arguments

  • Ũ⃗_init::AbstractVector{<:Real}: Initial unitary vector
  • controls::AbstractMatrix{<:Real}: Control matrix
  • Δt::AbstractVector: Time steps
  • system::AbstractQuantumSystem: Quantum system

Keyword Arguments

  • show_progress::Bool=false: Show progress bar
  • integrator::Function=expv: Integrator function
  • exp_vector_product::Bool: Infer whether the integrator is an exponential-vector product
source
PiccoloQuantumObjects.Rollouts.unitary_rollout_fidelityFunction
unitary_rollout_fidelity(
    Ũ⃗_init::AbstractVector{<:Real},
    Ũ⃗_goal::AbstractVector{<:Real},
    controls::AbstractMatrix{<:Real},
    Δt::AbstractVector,
    system::AbstractQuantumSystem;
    kwargs...
)
unitary_rollout_fidelity(
    Ũ⃗_goal::AbstractVector{<:Real},
    controls::AbstractMatrix{<:Real},
    Δt::AbstractVector,
    system::AbstractQuantumSystem;
    kwargs...
)
unitary_rollout_fidelity(
    U_init::AbstractMatrix{<:Complex},
    U_goal::AbstractMatrix{<:Complex},
    controls::AbstractMatrix{<:Real},
    Δt::AbstractVector,
    system::AbstractQuantumSystem;
    kwargs...
)
unitary_rollout_fidelity(
    U_goal::AbstractMatrix{<:Complex},
    controls::AbstractMatrix{<:Real},
    Δt::AbstractVector,
    system::AbstractQuantumSystem;
    kwargs...
)
unitary_rollout_fidelity(
    U_goal::EmbeddedOperator,
    controls::AbstractMatrix{<:Real},
    Δt::AbstractVector,
    system::AbstractQuantumSystem;
    subspace::AbstractVector{Int}=U_goal.subspace,
    kwargs...
)
unitary_rollout_fidelity(
    traj::NamedTrajectory,
    sys::AbstractQuantumSystem;
    kwargs...
)

Calculate the fidelity between the final state of a unitary rollout and a goal state. If the initial unitary is not provided, the identity operator is assumed. If phases and phase_operators are provided, the free phase unitary fidelity is calculated.

source
Ũ⃗_rollout = unitary_rollout(controls, Δt, system)
Ũ⃗_rollout |> size
(8, 10)

Convert to unitary operators, and have a look at the initial unitary.

iso_vec_to_operator.(eachcol(Ũ⃗_rollout[:, 1])) |> first
2×2 Matrix{ComplexF64}:
 1.0+0.0im  0.0+0.0im
 0.0+0.0im  1.0+0.0im

Open Quantum System Rollouts

PiccoloQuantumObjects.Rollouts.open_rolloutFunction
open_rollout(
    ρ⃗₁::AbstractVector{<:Complex},
    controls::AbstractMatrix{<:Real},
    Δt::AbstractVector,
    system::OpenQuantumSystem;
    kwargs...
)

Rollout a quantum state ρ⃗₁ under the control controls for a time Δt

Arguments

  • ρ⃗₁::AbstractVector{<:Complex}: Initial state vector
  • controls::AbstractMatrix{<:Real}: Control matrix
  • Δt::AbstractVector: Time steps
  • system::OpenQuantumSystem: Quantum system

Keyword Arguments

  • show_progress::Bool=false: Show progress bar
  • integrator::Function=expv: Integrator function
  • exp_vector_product::Bool: Infer whether the integrator is an exponential-vector product
source
PiccoloQuantumObjects.Rollouts.open_rollout_fidelityFunction
open_rollout_fidelity(
    ρ⃗₁::AbstractVector{<:Complex},
    ρ⃗₂::AbstractVector{<:Complex},
    controls::AbstractMatrix{<:Real},
    Δt::AbstractVector,
    system::OpenQuantumSystem
)
open_rollout_fidelity(
    ρ₁::AbstractMatrix{<:Complex},
    ρ₂::AbstractMatrix{<:Complex},
    controls::AbstractMatrix{<:Real},
    Δt::AbstractVector,
    system::OpenQuantumSystem
)
open_rollout_fidelity(
    traj::NamedTrajectory,
    system::OpenQuantumSystem;
    state_name::Symbol=:ρ⃗̃,
    control_name::Symbol=:a,
    kwargs...
)

Calculate the fidelity between the final state of an open quantum system rollout and a goal state.

source

Open rollouts require open quantum systems.

open_system = OpenQuantumSystem(system)

ρ_init = ψ_init * ψ_init'
ρ̃⃗_rollout = open_rollout(ρ_init, controls, Δt, open_system)
ρ̃⃗_rollout |> size
(8, 10)

This page was generated using Literate.jl.