Let's look at the experimental design problem of where to sample a Ramsey fringe experiment. A time-domain version of the Ramsey fringe experiment is implemented by the X90 - delay - X90 experiment and is typically used to measure the qubit frequency. If the qubit is off-resonant from the drive then the resulting the probability of seeing a $|1\rangle$ follows a $\cos^2$ pattern. The frequency $f$ and sampling time combine to give some total evolution phase $\theta$. If we know the sampling time $t$ then we can calcualte the frequency $f$. One obvious question is what sampling times will maximize the information we learn about $f$.
using Distributions: Binomial, Normal, pdf, logpdf
using DistributionsAD
using Plots
plotly() # for interactive notebook
# pyplot() # for saving SVG figures
using QuadGK: quadgk
using Zygote
┌ Info: For saving to png with the Plotly backend ORCA has to be installed. └ @ Plots /home/cryan/.julia/packages/Plots/E3MWZ/src/backends.jl:373
# probability of |1> for a given Ramsey phase evolution θ
prob(θ) = cos(θ/2)^2
τs = range(0, 2π; length=100)
p = plot(τs, prob.(τs), label=nothing)
xlabel!(p, "Phase θ (rad.)")
ylabel!(p, "Probability of |1⟩")
# savefig(p, "ramsey_fringe.svg")
Let's first look at the case of where there is no quantum shot noise but instead additive phase indepdendent Gaussian noise. This corresponds to the situation of a large ensemble. Then for any given measured probability of |1⟩ we can use the model to assess the likelihood that the true parameter was $\theta$ and gave that outcome. Let's plot the likelihood function for various measurement outcomes.
# gaussian noise with μ = 0 and σ = 0.02
noise = Normal(0.0, 0.02)
"""
Given some measured value `x` return the likelihood function evaluated at the given `θs`.
"""
function lh(x, θs)
vals = pdf.(noise, x .- prob.(θs))
end
θs = range(0, 2π; length=400)
p = plot(θs, lh(0.0, θs), label="x = 0")
plot!(p, θs, lh(1.0, θs), label="x = 1")
plot!(p, θs, lh(0.5, θs), label="x = 0.5")
xlabel!(p, "θ (rad.)")
ylabel!(p, "Likelihood")
title!(p, "Likelihood of θ given various measured probabilities")
# savefig(p, "likelihood.svg")
"""
Calculate the Fisher information about θ for a random variable X distributed according to `f(x,θ)`,
and optionally `logf(x,θ)` if available. The expectation value is evaluated over either the given
`integration_range` or discrete set of values.
"""
function fisher(θ, f, logf; integration_range=nothing, xs=nothing)
# make sure we're only passed one of an integration range or discrete set of values
@assert (integration_range != nothing) ⊻ (xs != nothing)
norm = 0.0
val = 0.0
if xs != nothing
# discrete sum version
for x in xs
l(θ) = logf(x, θ)
prob = f(x, θ)
norm += prob
val += (l'(θ))^2 * prob
end
else
# continuous integral version
function h(x)
l(θ) = logf(x, θ)
(l'(θ))^2
end
val = quadgk(x -> h(x)*f(x, θ), integration_range[1], integration_range[2])[1]
norm = quadgk(x -> f(x, θ), integration_range[1], integration_range[2])[1]
end
val/norm
end
# provide logf if not given
fisher(θ, f; integration_range=nothing, xs=nothing) = fisher(θ, f, (x,θ) -> log(f(x,θ)); integration_range=integration_range, xs=xs)
fisher (generic function with 2 methods)
# Bernoulli as a sanity check
f(x,θ) = θ^x * (1-θ)^(1-x)
θs = range(0.01, 0.99; length=101)
p = plot(θs, fisher.(θs, f; xs=(0,1)), label="Numerical")
plot!(p, θs, 1 ./ (θs.*(1 .- θs)), label="Analytic", linestyle=:dash)
xlabel!(p, "Bernoulli Parameter θ")
ylabel!(p, "Fisher Information")
# savefig(p, "fisher_information_bernoulli.svg")
# Sinusoid with additive Gaussian noise
σ = 0.01
dist(θ) = Normal(cos(θ), σ)
f(x, θ) = pdf(dist(θ), x)
logf(x, θ) = logpdf(dist(θ), x)
θs = range(0,2π;length=101)
p = plot()
p = plot!(p, θs, fisher.(θs, f, logf; integration_range=(-2, 2)), label="Numerical")
plot!(p, θs, (1/σ^2)*(sin.(θs).^2), label="Analytical", linestyle=:dash)
xlabel!(p, "Angle θ (rad)")
ylabel!(p, "Fisher Information")
title!(p, "Sinusoid Model with Gaussian Noise")
# savefig(p, "fisher_information_sinusoid_gaussian.svg")
# Ramsey fringe with spin projection noise and N shots
N = 1
f(x, θ) = pdf(Binomial(N, cos(θ/2)^2), x)
logf(x, θ) = logpdf(Binomial(N, cos(θ/2)^2), x)
θs = range(0, 2π; length=101)
p = plot(θs, fisher.(θs, f, logf; xs=0:N), label="Numerical")
plot!(p, θs, ones(length(θs)), label="Analytical", linestyle=:dash)
ylims!(p, 0, 2)
xlabel!(p, "Angle θ (rad)")
ylabel!(p, "Fisher Information")
title!(p, "Sinusoid Model with Projection Noise")
# savefig(p, "fisher_information_sinusoid_projection.svg")