Skip to content

Instantly share code, notes, and snippets.

Avatar
🍭
casting spells

Rogerluo Roger-luo

🍭
casting spells
View GitHub Profile
View expand.jl
using Expronicon
using MLStyle
function expand_mlstyle(m::Module, ex)
@switch ex begin
@case Expr(:macrocall, Symbol("@match"), xs...) || Expr(:macrocall, Symbol("@switch"), xs...) ||
Expr(:macrocall, Symbol(""), xs...)
return expand_mlstyle(m, macroexpand(m, ex))
@case ::Expr
return Expr(ex.head, map(x->expand_mlstyle(m, x), ex.args)...)
View threaded_subspace_mm.jl
using YaoLocations
using BenchmarkTools
using BQCESubroutine
using StrideArrays
using BQCESubroutine.Utilities
using LoopVectorization
using ThreadingUtilities
using ArrayInterface
using BQCESubroutine.Utilities: BitSubspace
View entropy.jl
using Random
using Yao
using Plots
using LinearAlgebra
using QuantumInformation
function run_circuit!(r::AbstractRegister, θs::Matrix, p::Real=0.0)
n = nqubits(r)
for j in 1:size(θs, 2) # each layer
for i in 1:size(θs, 1)÷2 # each wire
@Roger-luo
Roger-luo / tiny_yao.jl
Created Dec 20, 2020
Implement your own (full amplitude) top performance quantum circuit emulator in ONE day!
View tiny_yao.jl
macro _threads(ex)
return quote
if (Threads.nthreads() > 1) && (length(st) > 4096)
$(Expr(:macrocall, Expr(:(.), :Threads, QuoteNode(Symbol("@threads"))), __source__, ex))
else
$ex
end
end |> esc
end
View typeinf.jl
using YaoCompiler
using YaoCompiler.Intrinsics
qasm"""OPENQASM 2.0;
include "qelib1.inc";
gate post q {x q;}
"""
@device function circuit()
View workhours.jl
using Dates
function count_hours(m)
days = filter(Date(2020, m, 14): Day(1):Date(2020, m+1, 13)) do day
!(dayname(day) in ["Saturday", "Sunday"])
end
return length(days) * 8
end
count_hours(7) * 30
View cuda_expv.jl
using CUDA
using ExponentialUtilities
using LinearAlgebra
using BenchmarkTools
using ExponentialUtilities: getV, getH, get_cache, _exp!
using LinearAlgebra: BlasReal, BlasComplex
using SparseArrays
using CUDA: CUBLAS
CUDA.allowscalar(false)
View newlayer.jl
using Flux
struct Linear{T, WT <: AbstractMatrix{T}, BT <: AbstractVector{T}}
W::WT
b::BT
end
Flux.functor(m::Linear) = (m.W, m.b), (W, b) -> Linear(W, b)
m = Linear(rand(2, 2), rand(2))
@Roger-luo
Roger-luo / patch.jl
Created Mar 2, 2020
AutoPreallocation patch
View patch.jl
using Zygote: @adjoint, _pullback, Context, cache
using AutoPreallocation
using Cassette
export expect, ∇expect, exact_expect, ∇exact_expect
using AutoPreallocation: RecordingCtx, ReplayCtx
# https://github.com/oxinabox/AutoPreallocation.jl/pull/9
@inline Cassette.overdub(ctx::RecordingCtx, ::typeof(Base.haskey), collection, key) = haskey(collection, key)
@inline Cassette.overdub(ctx::ReplayCtx, ::typeof(Base.haskey), collection, key) = haskey(collection, key)
@Roger-luo
Roger-luo / preallocation.jl
Created Feb 19, 2020
Cassette slow down the program?
View preallocation.jl
using LinearAlgebra
using LinearAlgebra: promote_op, matprod
# multiply 2x2 matrices
function matmul2x2(tA, tB, A::AbstractArray{T, 3}, B::AbstractArray{S, 3}) where {T,S}
matmul2x2!(similar(B, promote_op(matprod, T, S), 2, 2, size(A, 3)), tA, tB, A, B)
end
function matmul2x2!(C::AbstractArray{T1, 3}, tA, tB, A::AbstractArray{T2, 3}, B::AbstractArray{T3, 3}) where {T1,T2,T3}
if !(size(A) == size(B) == size(C) == (2,2, size(A, 3)))