-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathflake.nix
More file actions
161 lines (137 loc) · 4.56 KB
/
flake.nix
File metadata and controls
161 lines (137 loc) · 4.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
{
description = "Esgaliant - High-performance ML/biological simulation";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
flake-utils.url = "github:numtide/flake-utils";
};
outputs = { self, nixpkgs, flake-utils }:
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = import nixpkgs {
inherit system;
config = {
allowUnfree = true; # For CUDA if needed
};
};
python = pkgs.python311;
# System dependencies for compiled extensions
systemDeps = with pkgs; [
# Build tools
gcc
gfortran
cmake
pkg-config
openblas
lapack
];
in {
devShells.default = pkgs.mkShell {
buildInputs = with pkgs; [
python
uv
git
] ++ systemDeps;
shellHook = ''
echo "===================================="
echo "Esgaliant Development Environment"
echo "===================================="
# Set up environment variables for compiled extensions
export LD_LIBRARY_PATH="${pkgs.lib.makeLibraryPath systemDeps}:$LD_LIBRARY_PATH"
export PKG_CONFIG_PATH="${pkgs.lib.makeSearchPath "lib/pkgconfig" systemDeps}:$PKG_CONFIG_PATH"
# JAX configuration
export JAX_ENABLE_X64=1
export JAX_PLATFORMS=cpu # Change to 'cuda' if GPU available
# NumPy/OpenBLAS optimization
export OPENBLAS_NUM_THREADS=1 # Let JAX/PyTorch handle threading
export MKL_NUM_THREADS=1
# Python optimization
export PYTHONHASHSEED=0 # Reproducible hash seeds
export PYTHONPATH=$PWD/src:$PYTHONPATH
# Create/activate venv
if [ ! -d .venv ]; then
echo "Creating virtual environment with uv..."
uv venv --python ${python}/bin/python
echo "Created .venv"
fi
source .venv/bin/activate
# Gitignore management
if ! grep -q ".venv/" .gitignore 2>/dev/null; then
echo ".venv/" >> .gitignore
echo "Added .venv/ to .gitignore"
fi
if ! grep -q "__pycache__/" .gitignore 2>/dev/null; then
cat >> .gitignore << 'EOF'
__pycache__/
*.py[cod]
*$py.class
*.so
.coverage
htmlcov/
.pytest_cache/
.mypy_cache/
.ruff_cache/
*.prof
*.lprof
*.egg-info/
dist/
build/
data/
.DS_Store
EOF
echo "Added Python artifacts to .gitignore"
fi
# Check if pyproject.toml exists
if [ ! -f pyproject.toml ]; then
echo "No pyproject.toml found!"
echo "Please use the comprehensive pyproject.toml provided."
exit 1
fi
# Install dependencies
echo "Installing dependencies with uv..."
uv pip install -e '.[all]'
# Install pre-commit hooks if config exists
if [ -f .pre-commit-config.yaml ]; then
if command -v pre-commit &> /dev/null; then
pre-commit install
echo "Pre-commit hooks installed"
fi
fi
# Pre-compile JAX (warmup)
echo "Warming up JAX..."
python -c "import jax; import jax.numpy as jnp; jnp.ones(1).block_until_ready()" 2>/dev/null && echo "JAX ready" || echo "JAX not installed yet"
# Verify installation
if python -c "import esgaliant" 2>/dev/null; then
ESGALIANT_VERSION=$(python -c "import esgaliant; print(esgaliant.__version__)" 2>/dev/null || echo "unknown")
echo "esgaliant v$ESGALIANT_VERSION installed"
else
echo "esgaliant not yet importable"
echo "Create src/esgaliant/__init__.py with: __version__ = '0.1.0'"
fi
'';
};
# Optional: Package the project
packages.default = python.pkgs.buildPythonPackage {
pname = "esgaliant";
version = "0.1.0";
src = ./.;
format = "pyproject";
nativeBuildInputs = with python.pkgs; [
setuptools
wheel
];
propagatedBuildInputs = with python.pkgs; [
numpy
scipy
jax
numba
torch
polars
# Add other runtime deps available in nixpkgs
];
buildInputs = systemDeps;
# Skip tests during build
doCheck = false;
};
}
);
}