Skip to content

Instantly share code, notes, and snippets.

View GiggleLiu's full-sized avatar
🎯
Focusing

Jinguo Liu (刘金国) GiggleLiu

🎯
Focusing
View GitHub Profile
### A Pluto.jl notebook ###
# v0.11.14
using Markdown
using InteractiveUtils
# This Pluto notebook uses @bind for interactivity. When running this notebook outside of Pluto, the following 'mock version' of @bind gives bound variables a default value (instead of an error).
macro bind(def, element)
quote
local el = $(esc(element))
@GiggleLiu
GiggleLiu / stateful_pluto.jl
Last active October 30, 2020 21:04
Pluto as a state machine
### A Pluto.jl notebook ###
# v0.11.14
using Markdown
using InteractiveUtils
# This Pluto notebook uses @bind for interactivity. When running this notebook outside of Pluto, the following 'mock version' of @bind gives bound variables a default value (instead of an error).
macro bind(def, element)
quote
local el = $(esc(element))
using NiLang, NiLang.AD
function f!(du, u, p, t)
y₁, y₂, y₃ = u
k₁, k₂, k₃ = p
du[1] = -k₁*y₁ + k₃*y₂*y₃
du[2] = k₁*y₁ - k₃*y₂*y₃ - k₂*y₂^2
du[3] = y₁ + y₂ + y₃ - 1
return nothing
end
@GiggleLiu
GiggleLiu / plutouitips.jl
Last active February 17, 2021 20:04
Make pluto UI feel real!
### A Pluto.jl notebook ###
# v0.11.14
using Markdown
using InteractiveUtils
# This Pluto notebook uses @bind for interactivity. When running this notebook outside of Pluto, the following 'mock version' of @bind gives bound variables a default value (instead of an error).
macro bind(def, element)
quote
local el = $(esc(element))
@GiggleLiu
GiggleLiu / spinglass_yao.jl
Created May 16, 2020 09:43
Solving spinglass ground state with Yao, Tropical numbers and ForwardDiff.
# References
# * Yao: https://arxiv.org/abs/1912.10877
# * ForwardDiff: https://arxiv.org/abs/1607.07892
# * Tropical Numbers: https://en.wikipedia.org/wiki/Tropical_geometry
using ForwardDiff, Yao, LinearAlgebra
# define tropical numbers with the following property.
# x ⊕ y := max(x ,y)
# x ⊗ y := x + y
struct Tropical{T} <: Number
@GiggleLiu
GiggleLiu / cueinsum.jl
Last active July 27, 2019 21:50
CUDAnative implementation of einsum
# `]add OMEinsum#master`
# `]add TupleTools`
using OMEinsum
using CuArrays
using CUDAdrv
using CUDAnative, TupleTools
using OMEinsum: index_map, map_prod
using Base.Cartesian
using GPUArrays
@GiggleLiu
GiggleLiu / test_einsum_trait.jl
Last active June 18, 2019 07:12
dispatching einsum by traits
using OMEinsum, LinearAlgebra
using TupleTools
import OMEinsum: einsum!
"""The rule type used for dispatch."""
struct EinRule{S} end
EinRule(S) = EinRule{S}()
global einsum_rules = NTuple{2, Any}[]
@GiggleLiu
GiggleLiu / naive_einsum.jl
Last active January 20, 2020 09:16
CUDAnative based einsum! on GPU - the prototype
using TupleTools
using Base.Cartesian
using CuArrays, CUDAnative
"""
A naive implementation of `einsum!`
* `ixs`: input tensor indices,
* `xs`: input tensors,
* `iy`: output tensor indices,
* `y`: accumulated tensor, notice it is initialized to 0 as output!
@GiggleLiu
GiggleLiu / trg_autodiff.jl
Last active April 2, 2019 10:11
Automatic Differentiation over Tensor Renormalization Group
#=
To use this script, please install Flux.jl first by typing `]add Flux` in a Julia REPL.
=#
import LinearAlgebra
using Flux.Tracker: @grad, data, track, TrackedTuple, TrackedArray
using Flux
import Flux.Tracker: _forward
"""
backward function for svd.
@GiggleLiu
GiggleLiu / j1j2_groundstate.jl
Last active March 11, 2019 15:22
Get the groundstate for a Hamiltonian (not VQE!) using Yao.jl
using KrylovKit, Yao
"""
J1J2{D}
J1J2(size::Int...; J2::Real, periodic::Bool) -> J1J2
D ∈ {1, 2} is the dimension target system.
"""
struct J1J2{D}
size::NTuple{D, Int}