Skip to main content

User-friendly Bayesian Optimisation for computationally expensive problems

Project description

veropt - the versatile optimiser

veropt is a Python package that aims to make Bayesian Optimisation easy to approach, inspect and adjust. It was developed for the Versatile Ocean Simulator (VEROS) with the aim of providing a user-friendly optimisation tool to tune ocean simulations to real world data.

veropt can be used with any optimisation problem but has been developed for expensive optimisation problems with a small amount of evaluations (~100) and will probably be most relevant in such a context.

Installation

veropt is available on the Python Package Index (PyPI) and can be installed with pip.

pip install veropt

Please note that veropt relies on complex packages such as pytorch and will probably benefit from living in a conda (or other) environment. Furthermore, it may be recommendable to install pytorch separately first. See their website for their current recommendations.

Usage

Below is a simple example of setting up an optimisation problem with veropt.

from veropt.optimiser.practice_objectives import VehicleSafety
from veropt import bayesian_optimiser

objective = VehicleSafety()

optimiser = bayesian_optimiser(
    n_initial_points=16,
    n_bayesian_points=32,
    n_evaluations_per_step=4,
    objective=objective
)

Here we use a simple practice objective called 'VehicleSafety'. When setting up your own, real optimisation problem, we recommend looking in our 'interfaces' subpackage which will help run your expensive objective function, even when using slurm on a cluster. See more about this below.

With a simple practice objective like this, everything is already set up, and we can simply step forward the optimisation with,

optimiser.run_optimisation_step()

and we'll receive a message like,

Optimisation running in initial mode at step 1 out of 12 
Best objective value(s): [1691.06, 10.02, 0.11] at variable values [2.77, 2.51, 2.11, 2.31, 2.46] 
Newest objective value(s): [1683.49, 8.93, 0.10] at variable values [2.23, 2.68, 1.55, 1.50, 2.92] 

Please note that in order to follow common Bayesian Optimisation convention, veropt always maximises. If you need to minimise, simply put a negative sign on your objective.

The Visualisation Tools

Once our optimisation has run for a few steps, we can visualise the surrogate model or other aspects of the optimisation to make sure everything is set up correctly.

For example, we can call,

plot_prediction_grid_from_optimiser(
    optimiser=optimiser
)

and we'll get a figure like the one below.

for_readme

For every objective function and variable combination, we see a cross section of the domain, where we can inspect the surrogate model (black line with grey area for uncertainty), acquisition function (grey lines), suggested points (red points with uncertainty bars) and evaluated points (colourful points).

These graphics are made with the library 'plotly', which offers modern, interactive plots. These can be saved and shared as html's, retaining the interactive features.

If you want to try out the library with a practice objective before setting up your own optimisation problem, we recommend looking through our examples.

Interfaces

For optimization of computationally heavy, complex models, veropt interfaces provide a framework to automatically submit, track and evaluate user-defined simulations. Below is an example of an experiment where a parameter of the ocean model veros is optimised to simulate realistic current strength in an idealised setup.

from veropt.interfaces.experiment import Experiment
from veropt.interfaces.local_simulation import LocalVerosRunner, LocalVerosConfig
from veropt.interfaces.result_processing import TestVerosResultProcessor

simulation_config = LocalVerosConfig.load("veropt/interfaces/configs/local_veros_config.json")
simulation_runner = LocalVerosRunner(config=simulation_config)

optimiser_config = "veropt/interfaces/configs/optimiser_config.json"
experiment_config = "veropt/interfaces/configs/veros_experiment_config.json"

result_processor = TestVerosResultProcessor(objective_names=["amoc"])

experiment = Experiment(
    simulation_runner=simulation_runner,
    result_processor=result_processor,
    experiment_config=experiment_config,
    optimiser_config=optimiser_config
)

experiment.run_experiment()

veropt interfaces support the implementation of two types of experiments: local (for simulations running locally) and local slurm (for simulations running on a cluster).

For examples on how to use these features, see examples/interfaces.

License

This project uses the GPLv3 license.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

veropt-1.0.2.tar.gz (68.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

veropt-1.0.2-py3-none-any.whl (81.5 kB view details)

Uploaded Python 3

File details

Details for the file veropt-1.0.2.tar.gz.

File metadata

  • Download URL: veropt-1.0.2.tar.gz
  • Upload date:
  • Size: 68.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for veropt-1.0.2.tar.gz
Algorithm Hash digest
SHA256 03d570f943e090bdd288c6f8db114b45b000aa66423a33961acd0900d1de97ab
MD5 76f873fd97f7ec05ac30cdea9734ab55
BLAKE2b-256 abce03c127f8b3432a74bf1da7750d586f8e313e22bb57a5f5fc52305ebbced8

See more details on using hashes here.

Provenance

The following attestation bundles were made for veropt-1.0.2.tar.gz:

Publisher: python-publish.yml on aster-stoustrup/veropt

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file veropt-1.0.2-py3-none-any.whl.

File metadata

  • Download URL: veropt-1.0.2-py3-none-any.whl
  • Upload date:
  • Size: 81.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for veropt-1.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 40436d60af50ca08f79ce265131bc5db58873692504314cb4510d0502929928a
MD5 b3b76393516e4e39e6349e2c739a0a22
BLAKE2b-256 7db824864b7aac92b254a665c59ad24981ad15add4f4adb834fc144f179278d3

See more details on using hashes here.

Provenance

The following attestation bundles were made for veropt-1.0.2-py3-none-any.whl:

Publisher: python-publish.yml on aster-stoustrup/veropt

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page