Skip to content

Instantly share code, notes, and snippets.

View GiggleLiu's full-sized avatar
🎯
Focusing

Jinguo Liu (刘金国) GiggleLiu

🎯
Focusing
View GitHub Profile
@GiggleLiu
GiggleLiu / circuit_polynomial.jl
Last active August 9, 2022 16:49
Pluto notebook for finding a polynomial for a quantum circuit model
### A Pluto.jl notebook ###
# v0.19.9
using Markdown
using InteractiveUtils
# ╔═╡ 195eb152-17e7-11ed-32ab-ab200fb170af
using Yao, YaoPlots, Polynomials
# ╔═╡ f6f10336-205c-4581-9418-de6fdd9b6418
@GiggleLiu
GiggleLiu / fib2d.jl
Last active July 6, 2022 04:50
Computing two dimensional Fibonacci number with generic tensor networks + GPU in Julia
# To run this script, you need to install required packages in a Julia REPL:
# ```julia
# using Pkg; Pkg.add(["GenericTensorNetworks", "CUDA", "Comonicon", "DelimitedFiles"])
# ```
#
# Then open a terminal, go to the file folder and type
# ```bash
# $ julia fib2d.jl 20
# ```
#
@GiggleLiu
GiggleLiu / Strassen.jl
Created March 6, 2022 23:41
Compute matrix multiplication `C = A * B` using the strassen algorithm.
using LinearAlgebra: mul!
"""
strassen!(C, A, B, s0=8)
Compute matrix multiplication `C = A * B` using the strassen algorithm.
`s0` is the critical size to stop Strassen recursion, it can be slow if it recurse too deep,
then one needs to set this value larger.
!!!note
@GiggleLiu
GiggleLiu / tensorcontract_multigpu.jl
Last active April 12, 2024 20:49
Slicing + multi-GPU for contracting OMEinsum tensor contraction
# requires OMEinsum version >= 0.7
using Distributed
using OMEinsum, CUDA
println("find $(length(devices())) GPU devices")
const procs = addprocs(length(devices())-nprocs()+1)
const gpus = collect(devices())
const process_device_map = Dict(zip(procs, gpus))
@info process_device_map
@GiggleLiu
GiggleLiu / tropicalblas.jl
Last active February 24, 2021 04:04
Tropical BLAS
using TropicalNumbers, VectorizationBase
using Test
using LoopVectorization, Octavian
using VectorizationBase: OffsetPrecalc, StaticBool, Bit, static, NativeTypes, Index, gep_quote, VectorIndex
function distance(a::AbstractArray{<:Tropical}, b::AbstractArray{<:Tropical})
sum(abs.(content.(a) .- content.(b)))
end
LoopVectorization.check_args(::Type{T}, ::Type{T}) where T<:Tropical = true
@GiggleLiu
GiggleLiu / yaotutorial.jl
Created December 29, 2020 18:41
Yao tutorial, a draft
# v0.12.17
using Markdown
using InteractiveUtils
# ╔═╡ f178d9fe-49f4-11eb-0863-21e2e3934592
using Yao, YaoPlots
# ╔═╡ d59b39ec-49f5-11eb-3d4a-fb69f2505d3c
using SymEngine
@GiggleLiu
GiggleLiu / copyA.jl
Last active November 2, 2020 17:14
The copy A mma kernel
using CUDA
using CUDA.WMMA
using CUDA.WMMA: ColMajor, load_a, load_b, load_c, mma, store_d
using StaticArrays
a = rand(Float16, 16, 16)
b = rand(Float16, 16, 16)
c = zeros(Float16, 16, 16)
d = zeros(Float16, 16, 16)
a_dev = CuArray(a)
optimizer:
ip: 127.0.0.1
port: 2000
method: spsa
initial-params: specified
initial-params.random:
seed: 2
p: 5
initial-params.specified:
-
2 3
3 1
3 2
4 4
2 2
5 4
1 2
5 2
2 1
using Yao
using YaoBlocks
using YaoBlocks.ConstGate: TGate, SGate, TdagGate, SdagGate
function Base.show(io::IO, ::MIME"qasm/open", blk::AbstractBlock)
qcode = qasm(blk)
println(io, "OPENQASM 2.0")
maincode = pop!(qcode, "main")
for k in keys
println(io, qcode)