Skip to main content

A pymoo plugin for the ropt robust optimization library

Project description

A pymoo optimizer plugin for ropt

This package installs a plugin for the ropt robust optimization package, providing access to algorithms from the pymoo optimization package.

ropt-pymoo is developed by the Netherlands Organisation for Applied Scientific Research (TNO). All files in this repository are released under the GNU General Public License v3.0 (a copy is provided in the LICENSE file).

Dependencies

This code has been tested with Python versions 3.8-3.12.

The plugin requires the pymoo optimizer.

Installation

From PyPI:

pip install ropt-pymoo

Usage

An optimization by ropt using the plugin works mostly as any other optimization run (see also the ropt documentation). However, there are a few things to consider:

  1. Gradients are not used, as pymoo does not seem to support passing user-defined gradients. Hence, any specifications relating to gradient calulcations in ropt are ignored.
  2. Some standard optimization parameters that can be specified in the optimization section are ignored, specifically:
    • max_iterations
    • tolerance
  3. The initial values of the variables are ignored, since pymoo generally does not use them. In ropt you still need to specify them, since the size of the vector determines the number of variables. Setting it to a vector of zero values is fine.
  4. Linear and non-linear constraints are both supported. Linear constraints are not supported directly, but are internally converted to non-linear constraints.
  5. The algorithm and its options are specified using a syntax closely following the pymoo manual. For instance, rather than just giving an algorithm name, you have to specify the full qualified name of the corresponding object as found in the pymoo.algorithms module. For instance to specify the GA algorithm, use: soo.nonconvex.ga.GA.
  6. The algorithms itself are entirely configured via the options field in the optimization section of the ropt configuration object. Also in this case, the syntax follows the pymoo manual. See the section below for more information.

Configuring an algorithm.

Configuration of any of the pymoo algorithms is done via the options field in the ropt configuration object. For instance, consider this example for starting a GA optimization from the pymoo manual, with a penalty constraint added:

from pymoo.algorithms.soo.nonconvex.ga import GA
from pymoo.operators.crossover.sbx import SBX
from pymoo.operators.mutation.pm import PM
from pymoo.operators.repair.rounding import RoundingRepair
from pymoo.operators.sampling.rnd import IntegerRandomSampling
from pymoo.optimize import minimize
from pymoo.constraints.as_penalty import ConstraintsAsPenalty

method = GA(
    pop_size=20,
    sampling=IntegerRandomSampling(),
    crossover=SBX(prob=1.0, eta=3.0, vtype=float, repair=RoundingRepair()),
    mutation=PM(prob=1.0, eta=3.0, vtype=float, repair=RoundingRepair()),
    eliminate_duplicates=True,
)

res = minimize(ConstraintsAsPenalty(
    problem, penalty=100.0),
    method,
    termination=('n_gen', 40),
    seed=1234,
)

To run the equivalent optimization, we need to specify the method and the termination in the options field. We also need to specify the constraints object, and a seed. To do this the different objects are specified with their parameters in a nested dictionary that will be parsed into equivalent code. For this example we need to pass a nested dict, for clarity displayed as yml here:

parameters:  # The parameters of the GA object:
    pop_size: 20
    sampling:  # The sampling parameter is an object, specify its full path in pymoo:
    object: operators.sampling.rnd.IntegerRandomSampling
    crossover:  # Also an object:
    object: operators.crossover.sbx.SBX
    parameters:  # Specify the parameters passed to the crossover ojbect:
        prob: 1.0
        eta: 3.0
        vtype: float
        repair:  # A repair object, passed to the crossover object:
        object: operators.repair.rounding.RoundingRepair
    mutation:  # An object:
    object: operators.mutation.pm.PM
    parameters:  # And its parameters:
        prob: 1.0
        eta: 3.0
        vtype: float
        repair:  # A repair object, passed to the mutation object:
        object: operators.repair.rounding.RoundingRepair
    eliminate_duplicates: True
termination:  # Specification of the termination object:
    name: max_gen.MaximumGenerationTermination
    parameters:
        n_max_gen: 10
# Alternative specification for the termination, following pymoo practice:
# "termination": ("n_iter", 30)
constraints:  # Specification of the constraint object:
    name: as_penalty.ConstraintsAsPenalty
    parameters:
        penalty: 100.0
seed: 1234  # The seed that is passed to the minimize function:

Development

The ropt-pymoo source distribution can be found on GitHub. It uses a standard pyproject.toml file, which contains build information and configuration settings for various tools. A development environment can be set up with compatible tools of your choice.

The ropt-pymoo package uses ruff (for formatting and linting), mypy (for static typing), and pytest (for running the test suite).

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

ropt_pymoo-0.9.0.tar.gz (28.4 kB view details)

Uploaded Source

Built Distribution

ropt_pymoo-0.9.0-py3-none-any.whl (22.3 kB view details)

Uploaded Python 3

File details

Details for the file ropt_pymoo-0.9.0.tar.gz.

File metadata

  • Download URL: ropt_pymoo-0.9.0.tar.gz
  • Upload date:
  • Size: 28.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for ropt_pymoo-0.9.0.tar.gz
Algorithm Hash digest
SHA256 977120cc0e5cc560fe08dfa937f1aea7e4b2e9995473a89da8c190b16c9599ab
MD5 89b3545531cbe34cdf41786575152588
BLAKE2b-256 edb334ad6ef6af91bca0216870a686d87cffd93028b172ddbb9dfdc3b5202a30

See more details on using hashes here.

Provenance

The following attestation bundles were made for ropt_pymoo-0.9.0.tar.gz:

Publisher: release.yml on TNO-ropt/ropt-pymoo

Attestations:

File details

Details for the file ropt_pymoo-0.9.0-py3-none-any.whl.

File metadata

  • Download URL: ropt_pymoo-0.9.0-py3-none-any.whl
  • Upload date:
  • Size: 22.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for ropt_pymoo-0.9.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c1421b18ec971a9f135588b7ece8d858b89e703942a5efce1adce6e155eb1765
MD5 de50a6170cec2ef4634689b7c939315e
BLAKE2b-256 d5d55d163bbd84f7c9ed74ddf47837bef924c93289dcfc8beccb58560b414534

See more details on using hashes here.

Provenance

The following attestation bundles were made for ropt_pymoo-0.9.0-py3-none-any.whl:

Publisher: release.yml on TNO-ropt/ropt-pymoo

Attestations:

Supported by

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