22. Validation, Benchmarks and Site Build
This chapter collects the repository check commands, benchmark runs and the build/release flow of this book. The published crate is https://crates.io/crates/nlopt4r, with API documentation at https://docs.rs/nlopt4r/1.0.1/nlopt4r/.
22.1 Routine checks
cargo test
cargo test --release
cargo fmt --check
cargo clippy --all-targets -- -D warnings
RUSTDOCFLAGS="-D warnings -D missing_docs" cargo doc -p nlopt4r --no-deps
cargo test -p nlopt4r --doc
cargo testruns the solver package’s integration tests, unit tests and doctests;cargo test --workspaceadditionally runs the benchmark, native-reference and extension packages; the native-reference tests need CMake and a C compiler;--releaserechecks numerical tests in an optimized build;clippycovers all targets with warnings treated as errors;- the rustdoc check rejects missing documentation and broken links;
- doctests compile and run the public examples.
Current 1.0.1 counts: 90 solver integration tests, 3 solver unit tests, 16 solver doctests, 10 native comparisons and 28 benchmark-tool tests. The extension example has no tests. The historical 118-test baseline for an earlier revision is recorded in docs/BENCHMARK_RESULTS.md.
22.2 Native comparison and NIST
The native comparison tests require CMake and a C compiler and build the bundled NLopt C library:
cargo test -p nlopt4r-reference
cargo test --release -p nlopt4r-reference
This dependency belongs to the unpublished comparison tool package alone; the default cargo test and downstream builds stay pure Rust.
Nonlinear least-squares validation against NIST certified data:
cargo test -p nlopt4r --test nist
22.3 Coverage measurement
cargo llvm-cov -p nlopt4r --json --output-path target/coverage-full.json
Historical baseline at the recorded benchmark revision: line coverage 90.05% (3331/3699), function coverage 93.91% (262/279), region coverage 88.34% (5546/6278), excluding doctests and the native tools. Branch coverage was not instrumented, so no branch-coverage percentage is claimed.
22.4 Benchmark driver
tools/bench is the unpublished nlopt4r-bench executable:
cargo run --release --locked -p nlopt4r-bench -- \
--suite smoke --algorithms bfgs,lbfgs,de,pso --seeds 0..30 \
--dimension 4 --budget-per-dimension 1000 --output target/smoke.jsonl
cargo run -p nlopt4r-bench -- --summarize target/smoke.jsonl
| Option | Meaning |
|---|---|
--suite smoke|smooth|global | Problem group |
--algorithms ... | Algorithm registry: bfgs, lbfgs, de, pso, pattern-search, nelder-mead, external-pattern |
--seeds 0..30 | Optimizer seed interval, with the right endpoint exclusive |
--dimension N | Dimension for variable-dimension problems; fixed-dimension problems keep their own dimension |
--budget-per-dimension N | Objective budget = this value × actual dimension |
--output path.jsonl|.csv | Record file; an existing file stays intact |
--summarize path | Offline summary, accepting both formats |
Transform and noise switches:
| Option | Default | Effect |
|---|---|---|
--shift on|off | off | Translate the known minimizer to a seed-selected interior point |
--rotate on|off | off | Apply a seed-selected orthogonal rotation |
--instance-seed N | 0 | Problem-instance seed, independent of optimizer seeds |
--noise none|gaussian|uniform|laplace | none | Observation-noise distribution |
--noise-level SIGMA | 0 | Standard deviation in objective units |
--noise-seed N | 0 | Noise-experiment seed |
Pairing experiments: same instance seed and same optimizer seed, run separately across the four switch combinations. Noise example:
cargo run --release --locked -p nlopt4r-bench -- \
--suite smoke --algorithms de,pso --seeds 0..30 \
--dimension 2 --budget-per-dimension 2000 \
--shift on --rotate on --instance-seed 42 \
--noise gaussian --noise-level 0.01 --noise-seed 17 \
--output target/noisy.jsonl
cargo run --release --locked -p nlopt4r-bench -- --summarize target/noisy.jsonl
Metric definitions:
- target value \(= f_{\text{ref}}+10^{-6}(1+|f_{\text{ref}}|)\);
- ERT = sum of first-hit evaluations over successful runs and consumed evaluations over failed runs ÷ success count;
- zero successes correspond to an infinite ERT;
- noise experiments separate “visit hits” from “returned recommendation hits”.
Summaries group by budget, target and environment metadata, and distinct configurations stay in separate groups. The full protocol is in docs/BENCHMARKS.md, and the 30-seed measured tables are in docs/BENCHMARK_RESULTS.md.
Criterion kernel checks:
cargo bench --bench kernels
CARGO_NET_OFFLINE=true cargo bench --bench kernels -- --test
22.5 Building this book
mdBook 0.5.4 is required:
cargo install mdbook --version 0.5.4 --locked
mdbook build books/zh
mdbook build books/en
python3 -m http.server 8000 -d book
- the Chinese book outputs to
book/, the English book tobook/en/; - the site root
http://localhost:8000/serves Chinese,http://localhost:8000/en/serves English; - the top-bar language button switches between
/x.htmland/en/x.htmlwhile keeping the anchor; - previewing one language alone works through
mdbook serve books/zhormdbook serve books/en.
Build checks:
mdbook build books/zh && mdbook build books/en
cargo build -p nlopt4r
for f in books/zh/src/*.md; do
rustdoc --test "$f" --extern nlopt4r=target/debug/libnlopt4r.rlib \
-L dependency=target/debug/deps --edition 2024
done
rustdoc --test compiles every code block: signature-display blocks carry ignore, and runnable examples execute against the current API. The English book uses the same command.
22.6 Manual deployment to GitHub Pages
The workflow .github/workflows/pages.yml supports manual triggering alone:
- open Actions → Deploy nlopt4r book to GitHub Pages → Run workflow in the repository;
- the workflow installs mdBook 0.5.4, builds both languages and uploads
book/; deploy-pagespublishes to GitHub Pages (Source set to GitHub Actions, HTTPS enforced).
Local rehearsal (with wrkflw installed):
WRKFLW_SKIP_ACTIONS=actions/upload-pages-artifact \
wrkflw run --runtime emulation --job build .github/workflows/pages.yml
The rehearsal covers checkout, the pinned mdBook installation and both book builds; the upload step is skipped in wrkflw and runs natively on GitHub. The rehearsal reports as partially passing.
Pre-publish checklist:
mdbook build books/zhandmdbook build books/ensucceed;- the book’s runnable code blocks pass
rustdoc --test; - under the local HTTP server the language switch and the table-of-contents links resolve;
- the workflow file keeps
workflow_dispatchas its single trigger.
22.7 Documentation index
| File | Content |
|---|---|
docs/BENCHMARKS.md | Benchmark protocol, options, error semantics |
docs/BENCHMARK_RESULTS.md | Measured baseline, pairing experiments, coverage and validation counts |
docs/NIST.md | Certified least-squares validation |
docs/THEORY.md | Method selection, assumptions, costs and references |
docs/SCALABLE_LOCAL.md | L-BFGS, Newton-CG, Steihaug |
docs/FOUNDATIONS.md | Budgets, observers and external algorithm examples |
docs/ROBUSTNESS.md | Adaptive QR LM, projected gradient, SQP restoration |
docs/GLOBAL.md | DE/PSO parameters and seed protocol |
docs/ROADMAP.md | Follow-up extension items |
Theory background
- Benchmark metrics and measured results: see chapter 13.
- Coverage measurement and validation-count interpretation: see chapter 13 and chapter 12.