MCPcopy
hub / github.com/facebookresearch/nevergrad

github.com/facebookresearch/nevergrad @1.03 sqlite

repository ↗ · DeepWiki ↗ · release 1.03 ↗
2,651 symbols 8,328 edges 203 files 768 documented · 29%
README

Support Ukraine CircleCI

Nevergrad - A gradient-free optimization platform

Nevergrad

nevergrad is a Python 3.8+ library. It can be installed with:

pip install nevergrad

More installation options, including windows installation, and complete instructions are available in the "Getting started" section of the documentation.

You can join Nevergrad users Facebook group here.

Minimizing a function using an optimizer (here NGOpt) is straightforward:

import nevergrad as ng

def square(x):
    return sum((x - .5)**2)

optimizer = ng.optimizers.NGOpt(parametrization=2, budget=100)
recommendation = optimizer.minimize(square)
print(recommendation.value)  # recommended value
>>> [0.49971112 0.5002944]

nevergrad can also support bounded continuous variables as well as discrete variables, and mixture of those. To do this, one can specify the input space:

import nevergrad as ng

def fake_training(learning_rate: float, batch_size: int, architecture: str) -> float:
    # optimal for learning_rate=0.2, batch_size=4, architecture="conv"
    return (learning_rate - 0.2)**2 + (batch_size - 4)**2 + (0 if architecture == "conv" else 10)

# Instrumentation class is used for functions with multiple inputs
# (positional and/or keywords)
parametrization = ng.p.Instrumentation(
    # a log-distributed scalar between 0.001 and 1.0
    learning_rate=ng.p.Log(lower=0.001, upper=1.0),
    # an integer from 1 to 12
    batch_size=ng.p.Scalar(lower=1, upper=12).set_integer_casting(),
    # either "conv" or "fc"
    architecture=ng.p.Choice(["conv", "fc"])
)

optimizer = ng.optimizers.NGOpt(parametrization=parametrization, budget=100)
recommendation = optimizer.minimize(fake_training)

# show the recommended keyword arguments of the function
print(recommendation.kwargs)
>>> {'learning_rate': 0.1998, 'batch_size': 4, 'architecture': 'conv'}

Learn more on parametrization in the documentation!

Example of optimization

Convergence of a population of points to the minima with two-points DE.

Documentation

Check out our documentation! It's still a work in progress, so don't hesitate to submit issues and/or pull requests (PRs) to update it and make it clearer! The last version of our data and the last version of our PDF report.

Citing

@misc{nevergrad,
    author = {J. Rapin and O. Teytaud},
    title = {{Nevergrad - A gradient-free optimization platform}},
    year = {2018},
    publisher = {GitHub},
    journal = {GitHub repository},
    howpublished = {\url{https://GitHub.com/FacebookResearch/Nevergrad}},
}

License

nevergrad is released under the MIT license. See LICENSE for additional details about it. See also our Terms of Use and Privacy Policy.

Core symbols most depended-on inside this repo

set_name
called by 395
nevergrad/optimization/base.py
append
called by 164
nevergrad/optimization/multiobjective/hypervolume.py
spawn_child
called by 115
nevergrad/parametrization/core.py
set_standardized_data
called by 102
nevergrad/parametrization/core.py
create_seed_generator
called by 83
nevergrad/benchmark/xpbase.py
minimize
called by 81
nevergrad/optimization/base.py
get_standardized_data
called by 81
nevergrad/parametrization/core.py
tell
called by 75
nevergrad/optimization/utils.py

Shape

Method 1,255
Function 962
Class 425
Route 9

Languages

Python100%

Modules by API surface

nevergrad/optimization/optimizerlib.py336 symbols
nevergrad/benchmark/experiments.py153 symbols
nevergrad/common/sphere.py110 symbols
nevergrad/optimization/test_optimizerlib.py70 symbols
nevergrad/optimization/utils.py51 symbols
nevergrad/functions/corefuncs.py51 symbols
nevergrad/parametrization/_datalayers.py48 symbols
nevergrad/functions/lsgo/_funcs.py46 symbols
nevergrad/parametrization/core.py45 symbols
nevergrad/optimization/base.py45 symbols
nevergrad/parametrization/mutation.py44 symbols
nevergrad/parametrization/transforms.py43 symbols

Used by 1 indexed graphs manifest dependencies, hub-wide

For agents

$ claude mcp add nevergrad \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact