Skip to main content

The Versatile Optimiser (VerOpt)

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] 

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.0.tar.gz (67.0 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.0-py3-none-any.whl (79.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: veropt-1.0.0.tar.gz
  • Upload date:
  • Size: 67.0 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.0.tar.gz
Algorithm Hash digest
SHA256 bcd0b3de52609031e608539944bcd2f7914cd24b3b2f88470c7052d9ac2fe8e0
MD5 4b5ce2c25121218083e0f9faf0403b73
BLAKE2b-256 af14863045a02332defdcf19b9c8369f6c342b15a5fc46263bed9fc1d8d58708

See more details on using hashes here.

Provenance

The following attestation bundles were made for veropt-1.0.0.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.0-py3-none-any.whl.

File metadata

  • Download URL: veropt-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 79.9 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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5716a802bcc8bc28f4228f1ec9a7cb171e09fb66fc8489fccdd20de909b9b460
MD5 bf7ee1466dcfba982c375f4baa27d5d3
BLAKE2b-256 0c54b4d7f5b80545ca0f040a5355222ffe1ffb705bc375df87d9dfc8f771727b

See more details on using hashes here.

Provenance

The following attestation bundles were made for veropt-1.0.0-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