{"id":6738,"library":"nevergrad","title":"Nevergrad","description":"Nevergrad is a Python 3.6+ library for performing gradient-free optimization. Developed by Facebook AI Research, it provides a rich collection of optimization algorithms (evolutionary, bandit, Bayesian, etc.) and robust tools for parameter and hyperparameter tuning. It can optimize functions with continuous, discrete, or mixed variable types, even in noisy environments. The library maintains an active development status with regular releases.","status":"active","version":"1.0.12","language":"en","source_language":"en","source_url":"https://github.com/facebookresearch/nevergrad","tags":["optimization","gradient-free","hyperparameter tuning","machine learning","evolutionary algorithms","bayesian optimization"],"install":[{"cmd":"pip install nevergrad","lang":"bash","label":"Install stable release"}],"dependencies":[{"reason":"Fundamental package for numerical operations.","package":"numpy","optional":false},{"reason":"Used for data structures and analysis.","package":"pandas","optional":false},{"reason":"Required for advanced type hinting.","package":"typing-extensions","optional":false}],"imports":[{"note":"Standard alias for the library.","symbol":"ng","correct":"import nevergrad as ng"},{"note":"Optimizers are located under `nevergrad.optimization` as of recent versions, not a top-level `optimizers` module. `ng.optimizers.NGOpt` is also valid for registry access.","wrong":"from nevergrad.optimizers import NGOpt","symbol":"NGOpt","correct":"from nevergrad.optimization import NGOpt"},{"note":"The `parametrization` module is typically aliased as `p` for convenience and is the recommended way to access parameter types like `Scalar`, `Log`, `Choice`, `Array`.","wrong":"from nevergrad.instrumentation import Instrumentation","symbol":"Instrumentation","correct":"from nevergrad import parametrization as p\nparametrization = p.Instrumentation(...)"}],"quickstart":{"code":"import nevergrad as ng\nimport numpy as np\n\ndef objective_function(learning_rate: float, batch_size: int, architecture: str) -> float:\n    # Simulate a training process; optimal for lr=0.2, bs=4, arch='conv'\n    return (learning_rate - 0.2)**2 + (batch_size - 4)**2 + (0 if architecture == 'conv' else 10)\n\n# Define the parameter space using Instrumentation\nparametrization = ng.p.Instrumentation(\n    # Log-distributed scalar for learning_rate\n    learning_rate=ng.p.Log(lower=0.001, upper=1.0),\n    # Integer scalar for batch_size\n    batch_size=ng.p.Scalar(lower=1, upper=12).set_integer_casting(),\n    # Categorical choice for architecture\n    architecture=ng.p.Choice([\"conv\", \"fc\"]),\n)\n\n# Choose an optimizer (NGOpt is a recommended adaptive optimizer)\noptimizer = ng.optimizers.NGOpt(parametrization=parametrization, budget=100)\n\n# Minimize the objective function\nrecommendation = optimizer.minimize(objective_function)\n\nprint(f\"Optimal hyperparameters: {recommendation.kwargs}\")\nprint(f\"Best objective value: {objective_function(**recommendation.kwargs)}\")","lang":"python","description":"This quickstart demonstrates how to define a function with mixed continuous, discrete, and categorical parameters using `nevergrad.parametrization.Instrumentation` and then optimize it using `nevergrad.optimizers.NGOpt`. The `minimize` method returns the best parameter set found within the specified budget."},"warnings":[{"fix":"Ensure `nevergrad` is updated to the latest version (1.0.12 or newer) and consider pinning `numpy<2.0` if compatibility issues persist with other libraries in your environment.","message":"Nevergrad has experienced compatibility issues with NumPy 2.0 due to expired deprecations in NumPy's API, particularly affecting optimizers like `NGOpt` and `NgDS`. While fixes have been merged into the `main` branch, older versions or complex dependency trees might still encounter these problems.","severity":"breaking","affected_versions":"<=1.0.11 (and possibly some 1.0.x if indirect dependencies are not updated)"},{"fix":"Refer to the official documentation and GitHub for the most current usage patterns, especially when defining complex parameter spaces.","message":"The `parametrization` API (e.g., `ng.p.Instrumentation`, `ng.p.Scalar`, `ng.p.Choice`) is explicitly stated as a 'work in progress' and subject to future breaking changes.","severity":"gotcha","affected_versions":"All 1.x versions"},{"fix":"Explicitly add `colorama` to your project's dependencies if you require its functionality. `pip install colorama`.","message":"The `colorama` dependency was removed in version 1.0.12. If your application indirectly relied on `nevergrad` for `colorama`'s functionality (e.g., colored terminal output), it will cease to work.","severity":"deprecated","affected_versions":">=1.0.12"},{"fix":"For DE algorithms, ensure a sufficient budget. Generally, choose optimizers appropriate for your problem's complexity and available computational budget. Consult the documentation for optimizer-specific recommendations.","message":"Some optimizers, particularly Differential Evolution (DE) algorithms, can be inefficient or perform poorly when provided with very small budgets (e.g., `budget < 60`).","severity":"gotcha","affected_versions":"All versions"},{"fix":"Check the optimizer's documentation or `no_parallelization` attribute if planning parallel evaluations. For such optimizers, consider synchronous execution or an optimizer that explicitly supports asynchronous operations.","message":"Not all optimizers support the fully asynchronous 'ask and tell' interface. Optimizers with `no_parallelization=True` will not work correctly in parallel execution environments designed for asynchronous `ask`/`tell` calls.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-15T00:00:00.000Z","next_check":"2026-07-14T00:00:00.000Z","problems":[]}