Skip to content

Instantly share code, notes, and snippets.

View jebej's full-sized avatar

Jérémy jebej

  • Institute for Quantum Computing
  • Waterloo
View GitHub Profile
@jebej
jebej / abstractdispatch.jl
Created February 13, 2021 17:09
julia abstract dispatch tests
using BenchmarkTools
abstract type AbstrType end
struct ConcrType1 <: AbstrType; x::Int; end
struct ConcrType2 <: AbstrType; x::Int; end
@noinline f(a::ConcrType1)::Int = a.x
@noinline f(a::ConcrType2)::Int = a.x
n = 1_000_000
@jebej
jebej / expim-tests.jl
Created December 18, 2019 19:05
Complex Exponential of Hermitian
using LinearAlgebra, BenchmarkTools
using LinearAlgebra: RealHermSymComplexHerm
import Base: cis
cis(H::RealHermSymComplexHerm) = cis!(Matrix{complex(eltype(H))}(H),copy(H))
cis!(H::RealHermSymComplexHerm) = cis!(Matrix{complex(eltype(H))}(H),H)
function cis!(R::Matrix{<:Complex},H::RealHermSymComplexHerm)
# First decompose H into U*Λ*Uᴴ
Λ,U = eigen!(H)
# Calculate the imaginary exponential of each eigenvalue and multiply
@jebej
jebej / SymmetricSparseTests.jl
Last active June 3, 2017 12:49
Symmetric Sparse Implementation Benchmarks
module SymmetricSparseTests
using BenchmarkTools
import Base: Symmetric, *, A_mul_B!, LinAlg.checksquare
function Symmetric(A::SparseMatrixCSC, uplo::Symbol=:U)
checksquare(A)
Symmetric{eltype(A), typeof(A)}(A, Base.LinAlg.char_uplo(uplo)) # preserve A
end
(*)(A::Symmetric{TA,SparseMatrixCSC{TA,S}}, x::StridedVecOrMat{Tx}) where {TA,S,Tx} = A_mul_B(A, x)
@jebej
jebej / punchout.jl
Created May 30, 2017 23:31
Julia Error
# Punchout measurement example
using Schrodinger
const n = 4 # number of qubit states
const N = 5 # number of cavity fock states
function JC_gen(fc=5, Ej=14, Ec=0.4, ϕ=0)
ωc = fc * 2π # cavity frequency
Ej′ = Ej*abs(cos(π*ϕ)) # Biased Ej
ωq = √(8*Ej′*Ec)*2π # transmon "base" frequency
@jebej
jebej / drivebench.jl
Created April 21, 2017 22:12
Broadcast performance problem in 0.6
using BenchmarkTools
const ⊗ = kron
const ħ = 1.054571800E-34 # in Joules*seconds, 2014 CODATA
const ln2 = 0.6931471805599453
function liouvillian(H)
Id = eye(H)
return -1im/ħ * (Id⊗H - H.'⊗Id)
end
function gaussian(x,w)
return exp(-4ln2*(x/w)^2)
@jebej
jebej / eigbench.jl
Created March 23, 2016 23:18
Comparison of eig solution between MATLAB and Julia for the TFIM
using ProfileView, Gadfly
function TFIM_1D_PBC(N,J,H)
# Hilbert Space Dimension
dim = 2^N
# Hamiltonian Matrix
ham = zeros(dim,dim)
# Build the diagonal part of the Hamiltonian
# First loop through the hilbert space
for bra in 0:dim-1
@jebej
jebej / quickbench.jl
Last active March 8, 2016 23:27
TFIM Performance Comparison
using DataFrames
using Gadfly
using PyCall
@pyimport timeit
include("tfim_1D_OBC.jl")
# Max number of sites, large values might run out of memory
maxN = 15
# Time python code