Skip to main content

fcmaes_core/
lib.rs

1#![doc = include_str!("../README.md")]
2#![deny(missing_docs)]
3#![deny(rustdoc::broken_intra_doc_links)]
4// Public entry points must state how they fail. Optimizer misuse (wrong batch
5// length, ask/tell out of order, mismatched bounds) is the most common
6// integration error, so the panicking and fallible variants both document
7// their contract.
8#![warn(clippy::missing_errors_doc)]
9#![warn(clippy::missing_panics_doc)]
10
11pub mod biteopt;
12pub mod cmaes;
13pub mod crfmnes;
14pub mod da;
15pub mod de;
16pub mod fitness;
17pub mod indicators;
18pub mod mapelites;
19pub mod mode;
20pub mod moretry;
21pub mod pgpe;
22pub mod retry;
23pub mod rng;
24
25pub use biteopt::{
26    BiteOpt, BiteParams, BiteResult, DeepBiteOpt, optimize_bite, validate_bite_inputs,
27};
28pub use cmaes::{AcmaResult, Cmaes, CmaesParams};
29pub use crfmnes::{Crfmnes, CrfmnesParams, CrfmnesResult};
30pub use da::{DaParams, DaResult, optimize_da};
31pub use de::{De, DeParams, DeResult};
32pub use fitness::{Fitness, NAN_REPLACEMENT, Objective, parallel_batch};
33pub use indicators::{
34    HypervolumeEstimate, HypervolumeReport, IndicatorError, OutsidePolicy, ReferencePoint,
35    additive_epsilon, crowding_distance, gd, gd_plus, hypervolume, hypervolume_monte_carlo,
36    hypervolume_with, igd, igd_plus, nondominated_sort, spacing, spread,
37};
38pub use mapelites::{
39    Archive, DiversifierParams, GridLayout, MapElitesParams, QdBatchFitness, QdFitness, diversify,
40    diversify_batch, map_elites, map_elites_batch, map_elites_batch_with_progress,
41};
42pub use mode::{Mode, ModeParams, ModeResult};
43pub use moretry::{
44    MoRetryConfig, MoRetryEntry, MoRetryResult, MultiObjective, WeightedObjective, moretry,
45    pareto_indices, scalarize,
46};
47pub use pgpe::{Pgpe, PgpeParams, PgpeResult};
48pub use retry::{
49    AdvancedRetryConfig, RetryBounds, RetryConfig, RetryContext, RetryEntry, RetryImprovement,
50    RetryResult, RetryRunResult, advanced_retry, retry, retry_run_seed,
51};
52pub use rng::Rng;
53
54/// Version string of the core crate, surfaced through the Python build-info.
55pub const CORE_VERSION: &str = env!("CARGO_PKG_VERSION");
56
57/// Sum a slice of `f64`.
58///
59/// This exists as an installation probe: it is the smallest call that proves
60/// the Python → PyO3 → Rust path is wired end to end, and it backs
61/// `fcmaes_rust._fcmaes_ext._phase1_probe_sum`. It is not a numerical
62/// reduction API — it performs no compensated summation and applications
63/// should use [`Iterator::sum`] directly.
64///
65/// # Examples
66///
67/// ```
68/// assert_eq!(fcmaes_core::probe_sum(&[1.0, 2.0, 3.5]), 6.5);
69/// assert_eq!(fcmaes_core::probe_sum(&[]), 0.0);
70/// ```
71pub fn probe_sum(values: &[f64]) -> f64 {
72    values.iter().sum()
73}
74
75#[cfg(test)]
76mod tests {
77    use super::*;
78
79    #[test]
80    fn probe_sum_adds_values() {
81        assert_eq!(probe_sum(&[1.0, 2.0, 3.5]), 6.5);
82    }
83
84    #[test]
85    fn probe_sum_empty_is_zero() {
86        assert_eq!(probe_sum(&[]), 0.0);
87    }
88}