Skip to content

Instantly share code, notes, and snippets.

@SiLiKhon
SiLiKhon / get_density_from_diffusion.py
Created November 21, 2023 07:22
SAMOS density calculation
from typing import Iterable
import numpy as np
from ase.io import read
from ase.atoms import Atoms
from samos.trajectory import Trajectory
from samos.analysis.get_gaussian_density import get_gaussian_density
def calculate_gaussian_density(
@SiLiKhon
SiLiKhon / hello.cu
Created August 18, 2023 07:12
Dummy cuda load
#include "stdio.h"
__global__ void cuda_hello() {
printf("Hello World from GPU!\n");
}
#define N 1000000000
__global__ void vector_add(float *out, float *a, float *b, int n) {
for (int i = 0; i < n; i++) {
@SiLiKhon
SiLiKhon / parse_qe_xml.py
Created July 13, 2023 05:07
QE xml parser
import xml.etree.ElementTree as ET
from io import StringIO
import numpy as np
from ase import units, Atoms
from ase.calculators.singlepoint import SinglePointCalculator
def parse_qe_xml(filename):
tree = ET.parse(filename)
root = tree.getroot()
from time import perf_counter
class TimeMonitor:
def __enter__(self):
self.report_times = [perf_counter()]
self.report_tags = ["Start"]
return self
def tick(self, tag):
MEM_INFO=`nvidia-smi --query-compute-apps=pid,used_memory --format=csv,noheader`
output=''
while read -r line
do
PID=`echo $line | awk -F, '{print $1}'`
MEM=`echo $line | awk -F, '{print $2}'`
ELAPSED=`ps -p $PID -o etime --no-headers`
UNAME=`ps -p $PID -o user --no-headers`
@SiLiKhon
SiLiKhon / activation_monitoring_callback.py
Last active May 2, 2021 14:26
Ugly code to monitor layer activations when training tf keras models with `model.fit` or similar.
# Disclaimer: this is just an ugly solution to monitoring layer activations
# when training a model in tf keras.
# this code is executed right after the model is created.
class Callback(tf.keras.callbacks.Callback):
def __init__(self, logging_data):
super().__init__()
# `logging_data` is a namedtuple of the follwoing type:
# LoggingData = namedtuple("LoggingData", ['get_val_dataset_fn', 'get_writer_fn', 'freq'])
import numpy as np
import pydub
def audiosegment2array(segment):
return np.array(segment.get_array_of_samples()).reshape(-1, segment.channels)
def array2audiosegment(array, rate=44100):
assert array.ndim == 2
num_channels = array.shape[1]
array = bytes(array.astype(np.int16).reshape(-1).data)
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.widgets as w
from scipy.signal import convolve2d
def check(state):
base = [1] * 5
filters = [
np.array(base).reshape(5, 1),
import numpy as np
n = 40
d = 20
sigma = .05
sigma2 = sigma**2
X = np.random.normal(size=(n, d))
Y = X.sum(axis=1, keepdims=True)
import sys
import math
import random
# Auto-generated code below aims at helping you parse
# the standard input according to the problem statement.
import numpy as np
my = np.zeros(shape=(3, 3), dtype=bool)
his = np.zeros(shape=(3, 3), dtype=bool)