Skip to content

Instantly share code, notes, and snippets.

View wangleiphy's full-sized avatar

Lei Wang wangleiphy

View GitHub Profile
@GiggleLiu
GiggleLiu / sci-brainstorm.md
Created February 25, 2026 07:00
Brain storming strategy tailored for scientific discovery
name sci-brainstorm
description Use when exploring a research idea, starting from a paper, concept, or question — conducts deep literature survey via arxiv and web search, discovers cross-field connections, then challenges the idea through Socratic and adversarial discussion

Scientific Research Brainstorming

Research-first brainstorming. Every phase begins with autonomous search — never ask the human what the literature says; go find out. Staged posture: Socratic while the idea is forming, adversarial once it has shape. Produces a research direction document.

Entry

@karpathy
karpathy / microgpt.py
Last active August 28, 2026 02:13
microgpt
"""
The most atomic way to train and run inference for a GPT in pure, dependency-free Python.
This file is the complete algorithm.
Everything else is just efficiency.
@karpathy
"""
import os # os.path.exists
import math # math.log, math.exp
@antirez
antirez / codex_skill.md
Last active August 23, 2026 08:18
CLAUDE_CODEX_SKILL.md
name codex
description Use OpenAI Codex CLI for complex debugging, code analysis, or when stuck on difficult problems. Invokes Codex with a file-based question/answer pattern.
disable-model-invocation true

Using Codex for Complex Debugging

When you encounter a difficult problem that would benefit from a second perspective or deep analysis, use Codex via the file-based pattern.

@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
@francois-rozet
francois-rozet / flow_matching.py
Last active January 24, 2026 23:48
Flow Matching in 100 LOC
#!/usr/bin/env python
import math
import matplotlib.pyplot as plt
import torch
import torch.nn as nn
from sklearn.datasets import make_moons
from torch import Tensor
from tqdm import tqdm
@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
# zhangqiaorjc@google.com
# `jax.distributed.initialize` is available in jax-0.2.25.
# $ pip install --upgrade "jax[cuda]" -f https://storage.googleapis.com/jax-releases/jax_releases.html # Note: wheels only available on linux.
# Run this script on 2 GPU nodes, assuming 10.128.0.6 is the master node
# python nvidia_gpu_pjit.py --server_addr="10.128.0.6:1456" --num_hosts=2 --host_idx=0
# python nvidia_gpu_pjit.py --server_addr="10.128.0.6:1456" --num_hosts=2 --host_idx=1
from absl import app
from absl import flags
@jackd
jackd / README.md
Last active January 24, 2021 14:43
Generalized eigenvalue jvp implementation in jax

After installing jax, run with:

git clone https://gist.github.com/jackd/99e012090a56637b8dd8bb037374900e
cd 99e012090a56637b8dd8bb037374900e
python dirty_test.py
@Roger-luo
Roger-luo / tiny_yao.jl
Created December 20, 2020 07:05
Implement your own (full amplitude) top performance quantum circuit emulator in ONE day!
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
@shoyer
shoyer / jax-harmonic-oscillator-odeint.ipynb
Last active December 11, 2021 16:43
JAX harmonic oscillator odeint.ipynb
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.