Skip to content

amm-optimizer 0.6.0

Choose a tag to compare

@github-actions github-actions released this 30 Oct 13:44
· 6 commits to main since this release
Immutable release. Only release title and notes can be modified.

Bug fixes, a SciPy-compatible API and early stopping, with the research options deprecated. The default algorithm is unchanged: every configuration that ships runs bit for bit as in 0.5.0 on inputs that worked before, the default and c46 reproduce the paper's benchmark runs exactly, and c46's config hash is still 2153948ebed51150.

Added

  • Early stopping. minimize(..., callback=, ftarget=): callback(intermediate_result) is called after every evaluation that improves the best value, with an OptimizeResult holding x, fun, nfev and nit; raising StopIteration from it ends the run. ftarget ends the run once the best value is at or below it. Either way the best point so far is returned, with status 2 or 1, and no evaluation follows the stop. catch_interrupt=True (opt-in) turns Ctrl-C into a result too (status 3, success=False, a RuntimeWarning). Without these arguments every run is bit for bit as before: the callback path draws no random numbers and changes no evaluation.

  • rng accepts a numpy.random.Generator (the run's seed is one draw, rng.integers(2**32)), and seed accepts a numpy.random.SeedSequence. A run without a seed draws one from the operating system and records it, so result.seed repeats any run (seed=result.seed); it is None only when a RandomState was continued.

  • Preset names in config=: config="default" (AMM, the default preset, frozen as c46), "c46", "atm" (ATMConfig()), "composite" (ATMConfig.composite()) or a research preset; presets.get takes the same names. Anything else that is not an ATMConfig is a TypeError.

  • examples/ with three short scripts: quickstart.py, scipy_migration.py and early_stopping.py.

  • docs/HISTORY.md: how the research composites c23 to c46 came about (from the presets module docstring, which is now a short list).

  • A documentation site, for https://amm-optimizer.readthedocs.io: getting started, a user
    guide (bounds, budgets, seeds, the anytime mode, profiling), the presets, the API reference
    generated from the docstrings, the changelog, the deprecation policy and how to cite AMM
    (mkdocs.yml, .readthedocs.yaml, a docs extra). CI builds it with mkdocs build --strict,
    and the package metadata links it as Documentation.

  • Each release tag gets a GitHub Release once PyPI has the files: its notes are the version's
    CHANGELOG section, and it carries the wheel, the sdist and a CycloneDX SBOM.

  • CI: a floor leg with the oldest supported NumPy and SciPy (2.0 and 1.18.0, Python 3.12), and
    coverage reports on Codecov.

Changed

  • The result is a scipy.optimize.OptimizeResult (amm_optimizer.OptimizeResult subclasses it): r.x works as before, and r["x"], r.keys() and dict(r) work as in SciPy. New fields: nit (the number of evaluations that improved the best value, the times callback is called), success, status (0 budget used or plan finished, 1 ftarget reached, 2 stopped by the callback, 3 interrupted), message and seed. It is no longer a dataclass, so code that called dataclasses.replace or dataclasses.asdict on a result needs dict(r) or item assignment instead.
  • A non-finite value at the starting point is a failed evaluation, like a non-finite value anywhere else: the run carries on, and any finite value beats it. It used to raise ValueError, so only runs that failed before behave differently; an objective undefined at the centre of the box now works. A run in which every value fails returns fun=inf at the starting point.
  • presets.names() lists the presets on display, ("default", "c46", "atm", "composite"); presets.names(research=True) adds the research composites c23 to c45, which all stay loadable with presets.get.
  • minimize's docstring documents the new arguments and recommends callback or ftarget, not an exception raised inside fun, for cutting an anytime run short.
  • An x0 outside bounds is clipped onto the box, with a UserWarning, on every box. On the bbob box [-5, 5] it used to be evaluated as given; on any other box it was already clipped, silently, so those runs are unchanged. amm_optimizer.api.minimize, the engine, does not check x0.

Deprecated

  • 92 research-only Variant fields and 29 research-only values of the other fields emit a
    FutureWarning when set and will be removed in 0.7.0 (warnings.filterwarnings("ignore", "Variant", FutureWarning) silences them meanwhile). No shipped configuration (c23-c46,
    ATMConfig(), ATMConfig.composite(), anytime=True) uses them, so none of those warns,
    and their config hashes and results are unchanged. The lists are config.RESEARCH_FIELDS and
    config.RESEARCH_CHOICES, measured by tools/research_fields.py. Fields: targeted_gate,
    targeted_amplitude, reset_on_success, sr_eta, sr_targets, sr_widths,
    sr_max_width, es_init_factor, es_small_dim, es_small_max_budget_per_dim,
    scale_learning, scale_rate, scale_cap, cov_cap, cov_steps, cov_path,
    cov_max_dim, local_force, fork_seed, prefix_plateau_rugged, chain_min_per_dim,
    sep_route_min_per_dim, additive_min_dim, basin_max_dim, basin_min_per_dim,
    basin_descents_max_per_dim, small_engine_max_per_dim, small_engine_radius,
    rugged_try_cap_per_dim, rugged_try_max_per_dim, prefix_ridge_radius,
    small_switch_max_dim, small_switch_max_per_dim, small_switch_cos,
    small_switch_radius, small_switch_rest, sampled_polish_per_dim, qn_false_success,
    qn_floor, probe_faces, eval_memo, step_box_check, box_steps,
    prefix_nan_min_per_dim, prefix_nan_clip, prefix_nan_reprobe, prefix_plateau_ties,
    prefix_fractal_min_dim, prefix_fractal_min_per_dim, stage_extend_restart,
    stage_extend_max_per_dim, sep_route_low, sep_route_low_dim, centre_point,
    centre_point_min_dim, smooth_bfgs_second, cma_restart, cma_model_max_dim,
    cma_lq_max_dim, cma_model_sigma, cma_handoff_cap_min_dim,
    cma_handoff_cap_low_per_dim, cma_handoff_cap_low_max_per_dim, es_lean_start,
    cma_regimes, cma_placement, cma_placement_max_dim, cma_local_nonsep_min_dim,
    sep_parabolic, sep_parabolic_late, sep_parabolic_scope, sep_share,
    sep_min_budget_per_dim, width_units, crossover, noise, skip_starved, width_mode,
    sr_shared_target, restart_mode, stag_tolfun, stag_tolx, ipop_factor,
    ipop_max_pool, local_method, simplex_max_dim, nm_refine_max_dim, refine_fraction,
    refine_min_budget_per_dim, refine_max_dim, pool_max, pool_divisor. Values:
    amplitude_control "success_rate"; es_kind "slsqplq10", "slsqplq10hk";
    cma_local_nonsep "ipop", "population", "qn", "qn2", "qn5", "qn6", "qn10",
    "qn11", "qn13", "qn13n", "qn15"; nm_stage "qnprefix", "qnprefix30g";
    cma_model "lq"; cma_restart_rule "economy"; cma_local "population", "ipop";
    sep_check "pair"; pop_lambda "cap4", "budget", "steps", "ipop4", "stepsgrow";
    pop_switch_start "carry"; rugged_try_rest "cut"; prefix_nan_reading "smooth".

Fixed

  • fun gets its own copy of every point, as in SciPy. It used to receive writeable views of the optimizer's buffers, so an objective that wrote into x changed the search, and one that kept x saw it change.
  • Bad inputs fail before any evaluation, with plain errors: a non-finite x0 (ValueError); a config that is neither an ATMConfig nor a preset name (TypeError), or names no preset (ValueError); an rng that is not a NumPy Generator or RandomState (TypeError naming seed=); a seed that is not an integer or a SeedSequence (TypeError) or is outside [0, 2**32) (ValueError); a bool budget (TypeError, it was taken as 1). A fun that returns an array, a list, a complex number or None gets a TypeError that says what it returned.
  • The value at the starting point is a float like every other value; a fun returning Fraction no longer crashes.
  • Warnings raised by fun reach the caller on the COBYQA and basin routes, which used to ignore every warning. SciPy's own overflow warnings from finite differences over a failed evaluation are no longer shown.
  • The diagnostic logs stay bounded. anytime.LAST_STAGES (alias STAGE_LOG) holds the stages of the most recent anytime run only; cma_phase.PROBE_LOG records only while cma_phase.RECORD_PROBES is true.
  • Runs in separate threads no longer share the step unit of Variant.box_steps. It was the module global qn_phase.X_UNIT, which every call wrote, so two threads on different boxes used whichever unit was written last; it is now a context variable (qn_phase.set_x_unit / qn_phase.x_unit()), one per thread. Every run is bit for bit as before.