Tutorial
Quickstart
Add the QBase.jl Package:
julia> using Pkg; Pkg.add("QBase")
Import the QBase module
using QBase
Algebra with Bras and Kets
See the Bras and Kets section for details.
Create a Ket
ψ = Ket([1,0])
2-element Ket{Int64}:
1
0
Create a Bra
by taking the adjoint.
ψ'
1×2 Bra{Int64}:
1 0
Inner product between Bra
and Ket
ψ'ψ
1
Outer product between Ket
and Bra
ψ*ψ'
2×2 Matrix{Int64}:
1 0
0 0
Quantum States
See States section for details.
Constructing States
ρ_0 = State( [1 0;0 0] )
2×2 State{Int64}:
1 0
0 0
ρ_1 = State( [0 0;0 1] )
2×2 State{Int64}:
0 0
0 1
Create Product States
kron( ρ_0, ρ_1 )
4×4 State{Int64}:
0 0 0 0
0 1 0 0
0 0 0 0
0 0 0 0
Create a Bloch Qubit State
bloch_qubit_state( π/3, 7π/6 )
2×2 State{ComplexF64}:
0.75+0.0im -0.375+0.216506im
-0.375-0.216506im 0.25+0.0im
Create a State from a Ket
pure_state(ψ)
2×2 State{Int64}:
1 0
0 0
Create a Mixed State
mixed_state( [0.6, 0.4], [ρ_0, ρ_1] )
2×2 State{Float64}:
0.6 0.0
0.0 0.4
Evolution of Quantum States
See Evolution section for details.
Pauli Constants
[σI, σx, σy, σz]
4-element Vector{Unitary}:
[1 0; 0 1]
[0 1; 1 0]
[0 + 0im 0 - 1im; 0 + 1im 0 + 0im]
[1 0; 0 -1]
Unitary Evolution
evolve(σx, ρ_0)
2×2 State{Int64}:
0 0
0 1
evolve(σx, ψ)
2-element Ket{Int64}:
0
1
Channel Evolution
depolarizing_channel(ρ_0, 0.5)
2×2 State{Float64}:
0.75 0.0
0.0 0.25
Measurement of Quantum States
See Measurements section for details.
Constructing POVM Measurements
# measurement in z-basis
Π_Z = POVM([ [1 0;0 0], [0 0;0 1] ])
2-element POVM{Int64}
Π[1] : 2×2 POVMel{Int64}:
1 0
0 0
Π[2] : 2×2 POVMel{Int64}:
0 0
0 1
# measurement in x-basis
Π_X = POVM([ [0.5 0.5;0.5 0.5], [0.5 -0.5;-0.5 0.5] ])
2-element POVM{Float64}
Π[1] : 2×2 POVMel{Float64}:
0.5 0.5
0.5 0.5
Π[2] : 2×2 POVMel{Float64}:
0.5 -0.5
-0.5 0.5
Measurement Probabilities
Outcome Probabilities
are obtained with the measure
method.
measure( Π_Z, ρ_0 )
2-element Probabilities{Int64}:
1
0
measure( Π_X, ρ_0 )
2-element Probabilities{Float64}:
0.5
0.5
measure( Π_Z, [ρ_0, ρ_1] )
2×2 Conditionals{Int64}:
1 0
0 1
Quantum Information
See the Information Theory section for a complete list of methods.
Von Neumann Entropy of Bell state
# maximally entangled bipartite qubit state
ρ_bell = bell_states()[1]
von_neumann_entropy( ρ_bell )
3.2034265038149176e-16
# maximally mixed two-qubit state
ρ_bell_mix = mixed_state( [1,1,1,1]/4, bell_states() )
von_neumann_entropy( ρ_bell_mix )
2.0
Advanced Examples
Absolute Tolerance
In some cases, it may be desirable to relax or tighten the tolerated numerical error. This example demonstrates how to pass the atol
parameter to the State
constructor. This parameter can be used for any type defined in this project. The absolute tolerance should be used with caution as it may delegitimize computed results.
ϵ = 1e-5 # introducing a small error
# state creation fails due to non-hermiticity
try
State([1 ϵ;-ϵ 0])
catch err
println( err )
end
DomainError([1.0 1.0e-5; -1.0e-5 0.0], "Density matrix `ρ` is not hermitian.")
# the atol parameter overrides the non-hermiticity failure
State([1 ϵ;-ϵ 0], atol=1e-4)
2×2 State{Float64}:
1.0 1.0e-5
-1.0e-5 0.0
Random States
# Create a 5x5 random unitary
U_rand = random_unitary( 5 )
5×5 Unitary{ComplexF64}:
0.413635-0.369018im 0.273568-0.67956im … 0.257068+0.0450523im
0.165528+0.38666im 0.0991758-0.210902im -0.276638-0.0293374im
-0.272689-0.137399im 0.314998+0.0405367im 0.0151134+0.0256582im
-0.272175+0.101341im -0.147227-0.0481443im 0.27775+0.873617im
0.57571+0.0824464im -0.459871+0.269633im -0.0779082+0.0847905im
# evolve the |0> Ket
ψ_rand = U_rand * Ket( [1, 0, 0, 0, 0] )
5-element Ket{ComplexF64}:
0.413635021883039 - 0.3690176425647414im
0.16552760879873218 + 0.38665957280785834im
-0.2726892180596612 - 0.1373991980570071im
-0.27217515091613725 + 0.10134056418968022im
0.575710394434449 + 0.08244636662779628im
# create a pure state from the random ket
ρ_rand = pure_state(ψ_rand)
5×5 State{ComplexF64}:
0.307268+0.0im -0.0742162-0.221019im … 0.20771-0.24655im
-0.0742162+0.221019im 0.176905+0.0im 0.127175+0.208957im
-0.0620911-0.15746im -0.0982643+0.0826945im -0.168318-0.0566199im
-0.149978-0.0585194im -0.0058682+0.122014im -0.148339+0.0807827im
0.20771+0.24655im 0.127175-0.208957im 0.33824+0.0im
Noisy Quantum Channel
Computing measurement probabilities in a noiseless channel:
# create bipartite Bell states
ρ_bell_states = bell_states()
# create a measurement in the same Bell basis
Π_bell_basis = POVM( ρ_bell_states )
# compute the ideal measurement probabilities
measure( Π_bell_basis, ρ_bell_states )
4×4 Conditionals{Float64}:
1.0 0.0 0.0 0.0
0.0 1.0 0.0 0.0
0.0 0.0 1.0 0.0
0.0 0.0 0.0 1.0
Computing measurement probabilities with a noisy channel:
# create a depolarizing channel which mixes in 50% white noise
𝒩(ρ) = depolarizing_channel(ρ, 0.5)
# Add noise to quantum states
ρ_noisy_bell_states = 𝒩.(ρ_bell_states)
# compute the noisy measurement probabilities
measure( Π_bell_basis, ρ_noisy_bell_states )
4×4 Conditionals{Float64}:
0.625 0.125 0.125 0.125
0.125 0.625 0.125 0.125
0.125 0.125 0.625 0.125
0.125 0.125 0.125 0.625
Reduced Density States
The reduced density matrix of a Bell state is a maximally mixed state.
# bipartite entangled qutrit states
ρ = generalized_bell_states( 3 )[1]
# tracing out the first qutrit subsystem
# creates a reduced density matrix State
partial_trace(ρ, [3,3], 1)
3×3 State{ComplexF64}:
0.333333+0.0im 0.0+0.0im 0.0+0.0im
0.0+0.0im 0.333333+0.0im 0.0+0.0im
0.0+0.0im 0.0+0.0im 0.333333+0.0im