Skip to content

Instantly share code, notes, and snippets.

View lgarrison's full-sized avatar

Lehman Garrison lgarrison

View GitHub Profile
@lgarrison
lgarrison / condition.ipynb
Last active February 22, 2024 23:31
finufft condition number with small inputs
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@lgarrison
lgarrison / check_bispectrum_pylians.ipynb
Created October 3, 2023 18:15
zeldovich-PLT f_NL validation notebook
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@lgarrison
lgarrison / compress.py
Created June 7, 2022 20:03
Compress a density grid with lossy + lossless compression
#!/usr/bin/env python3
'''
Compress a density grid.
Usage: ./compress.py --help
'''
from pathlib import Path
import click
@lgarrison
lgarrison / optimize_fenv.ipynb
Created February 25, 2022 18:29
optimize calc_fenv
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@lgarrison
lgarrison / potential.ipynb
Created July 13, 2021 15:54
simple N^2 gravitational potential calculator in numba
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@lgarrison
lgarrison / multithreaded_reader.py
Created May 13, 2021 19:27
Simple, blocking multithreaded reader
import numpy as np
import threading
import queue
def multithreaded_read(fns, nthreads=2):
'''
A simple multithreaded reader that spins up N threads
to read a list of files, returning the result in a list.
Reads in Numpy format by default.
@lgarrison
lgarrison / numba_ecdf.py
Last active March 29, 2021 17:44
Fast N-dimensional empirical CDF
import numba as nb
import numpy as np
def nb_ecdf(X,Rmax,ngrid=64,nthreads=1):
'''Compute the empirical CDF of points X (shape (N,D))
in domain [0,Rmax) using a histogram with `ngrid` cells
per dimension.
Rmax and ngrid can also be length D arrays.
'''
@lgarrison
lgarrison / multithreaded_io_queue.py
Created March 25, 2021 20:40
A simple multi-threaded Python file writer
'''
A simple multi-threaded Python file writer.
Author: Lehman Garrison (lgarrison.github.io)
'''
import threading
import queue
import numpy as np
@lgarrison
lgarrison / globus.py
Last active September 24, 2020 17:17
Abacus Globus script
#!/usr/bin/env python3
'''
This script facilitates Globus transfers of Abacus simulation data.
In particular, for AbacusSummit we want to transfer particle data and
halo catalogs from OLCF to NERSC after each simulation is done.
Both sites already have Globus endpoints, so the job of this script
is to initiate a transfer between the two, saving the transfer ID
number so we can query the transfer status later.
The intention of this script is primarily to do disk-to-disk
@lgarrison
lgarrison / corrfunc_bug_gh193.c
Created September 29, 2019 20:50
GCC Bug (Corrfunc #193)
/*
This is a "minimal" reproducer for an apparent GCC-7 bug related to AVX-512.
It has a 100% reproduction rate on my machine (Cascade Lake).
A simple loop that copies the values from a double array to a float array
sometimes gives the wrong answer in the first few elements (zero, nan, or garbage).
The bug seems correlated with alignment values of the input and output
arrays, but it's not a one-to-one relationship.