Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

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 test runs the solver package’s integration tests, unit tests and doctests;
  • cargo test --workspace additionally runs the benchmark, native-reference and extension packages; the native-reference tests need CMake and a C compiler;
  • --release rechecks numerical tests in an optimized build;
  • clippy covers 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
OptionMeaning
--suite smoke|smooth|globalProblem group
--algorithms ...Algorithm registry: bfgs, lbfgs, de, pso, pattern-search, nelder-mead, external-pattern
--seeds 0..30Optimizer seed interval, with the right endpoint exclusive
--dimension NDimension for variable-dimension problems; fixed-dimension problems keep their own dimension
--budget-per-dimension NObjective budget = this value × actual dimension
--output path.jsonl|.csvRecord file; an existing file stays intact
--summarize pathOffline summary, accepting both formats

Transform and noise switches:

OptionDefaultEffect
--shift on|offoffTranslate the known minimizer to a seed-selected interior point
--rotate on|offoffApply a seed-selected orthogonal rotation
--instance-seed N0Problem-instance seed, independent of optimizer seeds
--noise none|gaussian|uniform|laplacenoneObservation-noise distribution
--noise-level SIGMA0Standard deviation in objective units
--noise-seed N0Noise-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 to book/en/;
  • the site root http://localhost:8000/ serves Chinese, http://localhost:8000/en/ serves English;
  • the top-bar language button switches between /x.html and /en/x.html while keeping the anchor;
  • previewing one language alone works through mdbook serve books/zh or mdbook 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:

  1. open Actions → Deploy nlopt4r book to GitHub Pages → Run workflow in the repository;
  2. the workflow installs mdBook 0.5.4, builds both languages and uploads book/;
  3. deploy-pages publishes 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/zh and mdbook build books/en succeed;
  • 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_dispatch as its single trigger.

22.7 Documentation index

FileContent
docs/BENCHMARKS.mdBenchmark protocol, options, error semantics
docs/BENCHMARK_RESULTS.mdMeasured baseline, pairing experiments, coverage and validation counts
docs/NIST.mdCertified least-squares validation
docs/THEORY.mdMethod selection, assumptions, costs and references
docs/SCALABLE_LOCAL.mdL-BFGS, Newton-CG, Steihaug
docs/FOUNDATIONS.mdBudgets, observers and external algorithm examples
docs/ROBUSTNESS.mdAdaptive QR LM, projected gradient, SQP restoration
docs/GLOBAL.mdDE/PSO parameters and seed protocol
docs/ROADMAP.mdFollow-up extension items

Theory background