-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathJustfile
More file actions
591 lines (518 loc) · 19.2 KB
/
Justfile
File metadata and controls
591 lines (518 loc) · 19.2 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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
# PECOS Development Justfile
# Cross-platform command runner (Windows, macOS, Linux)
# Install: cargo install just
# Usage: just <recipe> or just --list
# Default recipe: show quick-start guide + recipe list
default:
@echo "PECOS Development"
@echo "================="
@echo ""
@echo "Quick start:"
@echo " just install-cli # Optional: install pecos CLI for direct use"
@echo " just setup # First time: detect and install dependencies"
@echo " just build # Build PECOS (runs setup if needed)"
@echo " just test # Run all tests"
@echo " just dev # Build + test (daily workflow)"
@echo " just lint # Check formatting and linting"
@echo " just doctor # Diagnose environment problems"
@echo ""
@echo "All commands:"
@just --list --list-heading ''
# =============================================================================
# Settings
# =============================================================================
# Requires bash (Windows: use Git Bash from https://git-scm.com or WSL)
set shell := ["bash", "-cu"]
# PECOS CLI - must be installed (run 'just install-cli' first)
pecos := "cargo run -p pecos-cli --"
# =============================================================================
# Getting Started
# =============================================================================
# Install or update the PECOS CLI
[group('setup')]
install-cli:
@echo "Installing PECOS CLI..."
cargo install --path crates/pecos-cli --force
@echo ""
@echo "Done! You can now run: just build"
# Set up build environment (detect and install missing dependencies)
[group('setup')]
setup:
{{pecos}} setup
# Set up build environment, accepting all prompts (for CI)
[group('setup')]
setup-ci:
{{pecos}} setup --yes
# Check development environment for common problems
[group('setup')]
doctor:
#!/usr/bin/env bash
set -euo pipefail
PROBLEMS=0
ok() { echo " [OK] $1: $2"; }
fail() { echo " [!!] $1: $2"; PROBLEMS=$((PROBLEMS + 1)); }
echo "LLVM 14:"
LLVM_DIR=""
for d in "$HOME/.pecos/deps/llvm-14" "$HOME/.pecos/deps/llvm"; do
[ -d "$d/bin" ] && LLVM_DIR="$d" && break
done
if [ -n "$LLVM_DIR" ]; then
VERSION=$("$LLVM_DIR/bin/llvm-config" --version 2>/dev/null || echo "unknown")
ok "installed" "$VERSION at $LLVM_DIR"
else
fail "installed" "not found (run: pecos setup)"
fi
if [ -f .cargo/config.toml ] && grep -q "LLVM_SYS_140_PREFIX" .cargo/config.toml 2>/dev/null; then
ok ".cargo/config.toml" "LLVM_SYS_140_PREFIX configured"
else
fail ".cargo/config.toml" "LLVM_SYS_140_PREFIX not set (run: pecos llvm configure)"
fi
echo ""
echo "Python:"
if command -v uv >/dev/null 2>&1; then
ok "uv" "$(uv --version)"
else
fail "uv" "not found (see: https://docs.astral.sh/uv/)"
fi
PECOS_VER=$(uv run python -c "import pecos; print(pecos.__version__)" 2>/dev/null) \
&& ok "import pecos" "v$PECOS_VER" \
|| fail "import pecos" "failed (run: just build)"
RSLIB_VER=$(uv run python -c "import pecos_rslib; print(pecos_rslib.__version__)" 2>/dev/null) \
&& ok "pecos_rslib" "v$RSLIB_VER" \
|| fail "pecos_rslib" "native library failed to load (run: just build)"
echo ""
echo "CUDA (optional):"
NVCC=$(command -v nvcc 2>/dev/null || echo /usr/local/cuda/bin/nvcc)
if [ -x "$NVCC" ]; then
CUDA_VER=$("$NVCC" --version 2>/dev/null | grep release | sed 's/.*release //' | sed 's/,.*//')
ok "CUDA" "$CUDA_VER"
else
echo " [--] CUDA: not found (optional)"
fi
echo ""
if [ "$PROBLEMS" -eq 0 ]; then
echo "No problems found."
else
echo "$PROBLEMS problem(s) found. See above for fixes."
fi
# Show system information
[group('setup')]
sys-info:
{{pecos}} sys-info
# List installed and cached dependencies
[group('setup')]
list-deps:
{{pecos}} list -v
# =============================================================================
# Building
# =============================================================================
# Build PECOS (profile: debug, release, native)
[group('build')]
build profile="debug": setup-quiet sync-deps build-selene
#!/usr/bin/env bash
set -euo pipefail
{{pecos}} python build --profile {{profile}}
command -v julia >/dev/null 2>&1 && just julia-build {{profile}} || true
command -v go >/dev/null 2>&1 && just go-build {{profile}} || true
# Build PECOS without dependency setup or sync (profile: debug, release, native)
[group('build')]
build-lite profile="debug": build-selene
{{pecos}} python build --profile {{profile}}
# Build PECOS with CUDA Python extras (profile: debug, release, native)
[group('build')]
build-cuda profile="debug": setup-quiet
{{pecos}} python build --profile {{profile}} --cuda
# =============================================================================
# Testing
# =============================================================================
# Run Python tests (or: just pytest <custom args>)
[group('test')]
pytest *args:
#!/usr/bin/env bash
set -euo pipefail
if [ -n "{{args}}" ]; then
uv run pytest {{args}}
else
uv run pytest python/pecos-rslib/tests -m "not performance"
uv run --group numpy-compat pytest python/pecos-rslib/tests -m "numpy and not performance"
uv run pytest python/quantum-pecos/tests -m "not optional_dependency and not slow"
uv run pytest python/selene-plugins
fi
# Run Rust tests (CUDA-aware; mode: debug or release)
[group('test')]
rstest mode="release":
#!/usr/bin/env bash
set -euo pipefail
if [ "{{mode}}" = "release" ]; then
{{pecos}} rust test --release
else
{{pecos}} rust test
fi
# Run all tests (Rust + Python + Julia + Go if available)
[group('test')]
test mode="release": (rstest mode) pytest
#!/usr/bin/env bash
set -euo pipefail
if command -v julia >/dev/null 2>&1; then
echo "Julia detected, running Julia tests..."
just julia-test
else
echo "Julia not detected, skipping Julia tests"
fi
if command -v go >/dev/null 2>&1; then
echo "Go detected, running Go tests..."
just go-test
else
echo "Go not detected, skipping Go tests"
fi
# =============================================================================
# Linting / Formatting
# =============================================================================
# Fix formatting and linting issues (or: just lint check)
[group('lint')]
lint mode="fix":
#!/usr/bin/env bash
set -euo pipefail
# Detect CUDA: only use --all-features when CUDA toolkit is available
if command -v nvcc >/dev/null 2>&1 || [ -n "${CUDA_PATH:-}" ] || [ -d /usr/local/cuda ]; then
CLIPPY_FEATURES="--all-features"
echo "(CUDA detected -- linting with all features)"
else
CLIPPY_FEATURES=""
echo "(No CUDA -- linting with default features only)"
fi
if [ "{{mode}}" = "check" ]; then
echo "==> Checking Rust formatting..."
cargo fmt --all -- --check
echo "==> Running clippy..."
cargo clippy --workspace --all-targets $CLIPPY_FEATURES -- -D warnings
echo "==> Running pre-commit..."
uv run pre-commit run --all-files
if command -v julia >/dev/null 2>&1; then
echo "==> Checking Julia formatting..."
just julia-fmt-check
just julia-lint
fi
if command -v go >/dev/null 2>&1; then
echo "==> Checking Go formatting..."
just go-fmt-check
just go-lint
fi
else
echo "==> Fixing Rust formatting and clippy..."
cargo fmt --all
cargo clippy --workspace --all-targets $CLIPPY_FEATURES --fix --allow-staged --allow-dirty -- -D warnings
echo "==> Running pre-commit..."
uv run pre-commit run --all-files || true
if command -v julia >/dev/null 2>&1; then
echo "==> Fixing Julia formatting..."
just julia-fmt
fi
if command -v go >/dev/null 2>&1; then
echo "==> Fixing Go formatting..."
just go-fmt
fi
fi
# Run cargo check
[group('lint')]
check:
cargo check --workspace --all-targets
# Run cargo clippy (CUDA-aware: uses --all-features only when CUDA is available)
[group('lint')]
clippy:
#!/usr/bin/env bash
set -euo pipefail
if command -v nvcc >/dev/null 2>&1 || [ -n "${CUDA_PATH:-}" ] || [ -d /usr/local/cuda ]; then
echo "(CUDA detected -- clippy with all features)"
cargo clippy --workspace --all-targets --all-features -- -D warnings
else
echo "(No CUDA -- clippy with default features)"
cargo clippy --workspace --all-targets -- -D warnings
fi
# Check Rust formatting
[group('lint')]
fmt:
cargo fmt --all -- --check
# Run benchmarks (profile: release/native; features: optional; pattern: filter)
[group('test')]
bench profile="release" features="" pattern="":
#!/usr/bin/env bash
set -euo pipefail
ARGS="bench -p benchmarks --bench benchmarks"
if [ "{{profile}}" = "native" ]; then
ARGS="$ARGS --profile=native"
export RUSTFLAGS="${RUSTFLAGS:-} -C target-cpu=native"
elif [ "{{profile}}" != "release" ]; then
echo "Unknown profile: {{profile}}. Use release or native."; exit 1
fi
if [ -n "{{features}}" ]; then ARGS="$ARGS --features={{features}}"; fi
if [ -n "{{pattern}}" ]; then ARGS="$ARGS -- {{pattern}}"; fi
cargo $ARGS
# =============================================================================
# Dev Workflows
# =============================================================================
# Dev cycle: build + test (lang: all, rust, python, julia, go)
[group('dev')]
dev lang="all":
#!/usr/bin/env bash
set -euo pipefail
case "{{lang}}" in
all)
just build
just test debug
;;
rust)
just rstest debug
;;
python)
just build
just pytest
;;
julia)
just julia-build
just julia-test
;;
go)
just go-build
just go-test
;;
*)
echo "Unknown language: {{lang}}. Use: all, rust, python, julia, go"
exit 1
;;
esac
# Clean build + test + lint check (run before opening a PR)
[group('dev')]
check-all: clean (build "release") (test "release") (lint "check")
# Clean build artifacts (or: just clean cache/deps/all/dry-run)
[group('clean')]
clean *target:
uv run python scripts/clean.py {{ if target == "cache" { "--cache" } else if target == "deps" { "--deps" } else if target == "all" { "--all" } else if target == "dry-run" { "--dry-run" } else { "" } }}
# =============================================================================
# Documentation
# =============================================================================
# Serve documentation locally (port: default 8000)
[group('docs')]
docs port="8000":
uv run mkdocs serve -a "127.0.0.1:{{port}}"
# Build documentation
[group('docs')]
docs-build:
uv run mkdocs build --clean
# Test Python code examples in documentation
[group('docs')]
docs-test:
uv run python scripts/docs/generate_doc_tests.py
uv run pytest python/quantum-pecos/tests/docs/generated -v -k "not rust" -m "not slow"
# =============================================================================
# Deps Management (prefer `just setup` or `pecos install <target>`)
# =============================================================================
# Install LLVM 14
[group('deps')]
install-llvm:
{{pecos}} install llvm
# Install CUDA Toolkit
[group('deps')]
install-cuda:
{{pecos}} install cuda
# Configure LLVM paths in .cargo/config.toml
[group('deps')]
configure-llvm:
{{pecos}} llvm configure
# Check LLVM 14 installation status
[group('deps')]
check-llvm:
-{{pecos}} llvm check
# Check CUDA installation status
[group('deps')]
check-cuda:
-{{pecos}} cuda check
# =============================================================================
# Julia Bindings
# =============================================================================
# Build Julia FFI library (profile: debug, release, native; rustflags: optional)
[group('julia')]
julia-build profile="release" rustflags="":
#!/usr/bin/env bash
set -euo pipefail
if [ -n "{{rustflags}}" ]; then
export RUSTFLAGS="${RUSTFLAGS:-} {{rustflags}}"
fi
case "{{profile}}" in
native) cargo build --profile native -p pecos-julia-ffi ;;
release) cargo build --release -p pecos-julia-ffi ;;
dev|debug) cargo build -p pecos-julia-ffi ;;
*) echo "Unknown profile: {{profile}}"; exit 1 ;;
esac
# Run Julia tests
[group('julia')]
julia-test: (julia-build "release")
cd julia/PECOS.jl && julia --project=. -e 'using Pkg; Pkg.instantiate(); include("test/runtests.jl")'
# Format Julia code
[group('julia')]
julia-fmt:
#!/usr/bin/env bash
set -euo pipefail
julia -e 'using Pkg; Pkg.activate(); haskey(Pkg.project().dependencies, "JuliaFormatter") || Pkg.add("JuliaFormatter")'
cd julia/PECOS.jl && julia -e 'using JuliaFormatter; format("."; verbose=true)'
# Check Julia code formatting
[group('julia')]
julia-fmt-check:
#!/usr/bin/env bash
set -euo pipefail
julia -e 'using Pkg; Pkg.activate(); haskey(Pkg.project().dependencies, "JuliaFormatter") || Pkg.add("JuliaFormatter")'
cd julia/PECOS.jl && julia -e 'using JuliaFormatter; format("."; verbose=false, overwrite=false) || (println("Run just julia-fmt to fix."); exit(1))'
# Run Aqua.jl quality checks
[group('julia')]
julia-lint: (julia-build "release")
cd julia/PECOS.jl && julia --project=. test/aqua_tests.jl
# =============================================================================
# Go Bindings
# =============================================================================
# Build Go FFI library (profile: debug, release, native; rustflags: optional)
[group('go')]
go-build profile="release" rustflags="":
#!/usr/bin/env bash
set -euo pipefail
if [ -n "{{rustflags}}" ]; then
export RUSTFLAGS="${RUSTFLAGS:-} {{rustflags}}"
fi
case "{{profile}}" in
native) cargo build --profile native -p pecos-go-ffi ;;
release) cargo build --release -p pecos-go-ffi ;;
dev|debug) cargo build -p pecos-go-ffi ;;
*) echo "Unknown profile: {{profile}}"; exit 1 ;;
esac
# Run Go tests
[group('go')]
go-test: (go-build "release")
#!/usr/bin/env bash
set -euo pipefail
LIB_DIR="$(pwd)/target/release"
export LD_LIBRARY_PATH="$LIB_DIR:${LD_LIBRARY_PATH:-}"
export DYLD_LIBRARY_PATH="$LIB_DIR:${DYLD_LIBRARY_PATH:-}"
cd go/pecos && go test -v
# Format Go code
[group('go')]
go-fmt:
gofmt -w go/pecos
# Check Go code formatting
[group('go')]
go-fmt-check:
@test -z "$(gofmt -l go/pecos)" || (gofmt -l go/pecos && exit 1)
# Run Go linting with go vet
[group('go')]
go-lint: (go-build "release")
#!/usr/bin/env bash
set -euo pipefail
LIB_DIR="$(pwd)/target/release"
export LD_LIBRARY_PATH="$LIB_DIR:${LD_LIBRARY_PATH:-}"
export DYLD_LIBRARY_PATH="$LIB_DIR:${DYLD_LIBRARY_PATH:-}"
cd go/pecos && go vet ./...
# =============================================================================
# Additional Testing
# =============================================================================
# Run performance tests with release build
[group('test')]
pytest-perf: build-release
uv run --group numpy-compat pytest python/pecos-rslib/tests -m "performance" -v
# Run tests for optional dependencies
[group('test')]
pytest-dep:
uv run pytest python/pecos-rslib/tests -m "optional_dependency"
uv run pytest python/quantum-pecos/tests -m "optional_dependency"
# Run the slower integration lane (excluded from the default fast lane)
[group('test')]
pytest-slow:
uv run pytest python/quantum-pecos/tests -m "slow and not optional_dependency"
# =============================================================================
# Private / Internal Recipes
# =============================================================================
[private]
setup-quiet:
{{pecos}} setup --quiet
# Sync Python deps (fast if already installed, skips maturin rebuilds)
[private]
sync-deps:
#!/usr/bin/env bash
set -euo pipefail
# Quick check: ensure the packages used by the default dev/test lane are importable.
# This catches newly added workspace members that an older .venv may be missing.
if uv run --frozen python -c "import importlib.util, sys; required = ('pecos', 'pecos_rslib', 'pecos_selene_stab_vec', 'pecos_selene_stabilizer', 'pecos_selene_statevec', 'pecos_selene_stab_mps', 'pecos_selene_mast'); missing = [name for name in required if importlib.util.find_spec(name) is None]; sys.exit(1 if missing else 0)" 2>/dev/null; then
exit 0
fi
echo "Python deps incomplete, running uv sync..."
uv sync --project . --all-packages
[private]
build-selene:
#!/usr/bin/env bash
set -euo pipefail
PLUGIN_DIRS=()
for DIR in python/selene-plugins/pecos-selene-*/; do
[ -d "$DIR" ] || continue
[ -f "$DIR/Cargo.toml" ] || continue
[ -f "$DIR/pyproject.toml" ] || continue
PLUGIN_DIRS+=("$DIR")
done
# Check if any selene source changed since last install
NEEDS_BUILD=false
for DIR in "${PLUGIN_DIRS[@]}"; do
PKG=$(basename "$DIR")
DEST="$DIR/python/${PKG//-/_}/_dist/lib/"
SO=$(find "$DEST" -name "*.so" 2>/dev/null | head -1 || true)
if [ -z "$SO" ]; then
NEEDS_BUILD=true
break
fi
# Check if any Rust source is newer than the installed .so
NEWER=$(find "crates/" "$DIR" -name "*.rs" -newer "$SO" 2>/dev/null | head -1 || true)
if [ -n "$NEWER" ]; then
NEEDS_BUILD=true
break
fi
done
if [ "$NEEDS_BUILD" = false ]; then
echo "Selene plugins: up to date"
exit 0
fi
echo "Building Selene plugins..."
CARGO_ARGS=""
for DIR in "${PLUGIN_DIRS[@]}"; do
CARGO_ARGS="$CARGO_ARGS -p $(basename "$DIR")"
done
if [ -n "$CARGO_ARGS" ]; then
cargo build --release $CARGO_ARGS
fi
echo "Copying libraries to Python packages..."
{{pecos}} selene install --profile release
echo "Selene plugins built and installed successfully"
# Convenience aliases
[private]
build-debug: (build "debug")
[private]
build-release: (build "release")
# Regenerate all lockfiles from scratch
[group('setup')]
updatelocks:
rm -f uv.lock Cargo.lock
uv lock --project .
cargo generate-lockfile
# Install CUDA Python packages (requires CUDA toolkit)
[private]
install-cuda-python:
{{pecos}} cuda setup-python
# Validate CUDA installation integrity
[private]
validate-cuda:
{{pecos}} cuda validate
# Run Julia examples
[private]
julia-examples: (julia-build "debug")
#!/usr/bin/env bash
set -euo pipefail
if command -v julia >/dev/null 2>&1; then
cd julia/PECOS.jl && julia --project=. examples/demo.jl
cd julia/PECOS.jl && julia --project=. examples/basic_usage.jl
else
echo "Julia not found."; exit 1
fi