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 / wyckoff_assign.jl
Last active January 26, 2025 07:21
Wyckoff position assignment - Given atoms counting and Wyckoff position multiplicity
using JuMP, HiGHS, Graphs, LinearAlgebra, Test
# Find one valid assignment with integer programming
function lattice_sites(num_sites::Vector{Int}, multiplicity::Vector{Int}, num_atoms::Vector{Int})
model = Model(HiGHS.Optimizer)
JuMP.set_silent(model)
@variable(model, x[1:length(num_sites), 1:length(num_atoms)] >= 0, Int)
for (ia, na) in enumerate(num_atoms)
@constraint(model, sum(x[i, ia] * num_sites[i] for i in 1:length(num_sites)) == na)
end
@GiggleLiu
GiggleLiu / generic-tensornetwork-visualize.jl
Created October 10, 2024 02:17
Visualizing landscape of an independent set problem with GenericTensorNetworks.jl
using GenericTensorNetworks
# create a random King's subgraph
graph = random_diagonal_coupled_graph(7, 7, 0.8)
# create an independent set problem
problem = IndependentSet(graph)
# convert to tensor network
pb = GenericTensorNetwork(problem)
# solve the MIS size
@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:
-