Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions .github/workflows/check_python_package.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: Check

on:
push:
pull_request:
branches: ["main"]

jobs:
test:
strategy:
fail-fast: false
matrix:
runs-on: [ubuntu-latest, macos-latest, windows-latest]
python-version: ["3.10", "3.11", "3.12", "3.13"]
runs-on: ${{matrix.runs-on}}
steps:
- uses: actions/checkout@v6
with:
fetch-depth: 0

- name: Install uv
uses: astral-sh/setup-uv@v7
with:
python-version: ${{ matrix.python-version }}

- name: Install the project
run: uv sync --all-extras --dev

- name: Lint with ruff
run: uv run ruff check --output-format=github .

- name: Run tests
run: uv run pytest --cov=opltools --cov-report=term-missing
62 changes: 62 additions & 0 deletions examples/cobi.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
from opltools import Implementation, Generator, Reference, Library, Variable, Constraint
from pydantic_yaml import to_yaml_str

things = {}

things["cobi_impl"] = Implementation(
name="COBI Implementation",
description="Python library for COBI (COnstrained BI-objective optimization) problem generator",
language="python",
links=[
{
"type": "repository",
"url": "https://github.com/numbbo/cobi-problem-generator/",
},
{
"type": "v0.5.0",
"url": "https://github.com/numbbo/cobi-problem-generator/releases/tag/v0.5.0",
},
],
requirements="https://github.com/numbbo/cobi-problem-generator/blob/main/requirements.txt",
)

things["cobi_problem"] = Generator(
name="COBI Problem",
description="Generator of COnstrained BI-objective optimization problems",
tags={
"constrained",
"bi-objective",
"continuous",
"black-box",
"location",
"multi-peak",
"convex-quadratic",
},
references=[
Reference(
title="Pareto Set Characterization in Constrained Multiobjective Optimization and the COBI Problem Generator",
authors=["Anne Auger", "Dimo Brockhoff", "Luka Opravš", "Tea Tušar"],
link={"type": "arxiv", "url": "https://arxiv.org/abs/2604.09131"},
)
],
objectives={2},
variables=[Variable(type="continuous", dim={"min": 1})],
implementations={"cobi_impl"},
can_evaluate_objectives_independently="no",
constraints=[
# FIXME: Check
Constraint(type="box", hard="yes", number={"min": 1}),
Constraint(type="linear", hard="yes", number={"min": 1}),
Constraint(type="function", hard="yes", number={"min": 1}),
],
noise_type={"none"},
dynamic_type=None,
allows_partial_evaluation="no",
modality={"multi-modal per objective"},
fidelity_levels={1},
source={"artificial"},
code_examples={"./code_153.py"},
)
library = Library(things)

print(to_yaml_str(library))
35 changes: 35 additions & 0 deletions examples/demo.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
from opltools import Suite, Problem, Library, Link, Variable, ValueRange
from pydantic_yaml import to_yaml_str
from opltools.schema import Implementation

things = {}

things["impl_py_cocoex"] = Implementation(
name="coco-experiment Python module",
description="Python bindings for the experiment part of the COCO framework",
language="python",
links=[
Link(type="repository", url="https://github.com/numbbo/coco-experiment"),
Link(type="package", url="https://pypi.org/project/coco-experiment/"),
],
evaluation_time="sub second",
)

for fnr in range(1, 25):
id = f"fn_bbob_f{fnr}"
things[f"fn_bbob_f{fnr}"] = Problem(
name=f"BBOB F_{fnr}",
objectives={1},
variables={Variable(type="continuous", dim=ValueRange(min=1, max=80))},
implementations=["impl_py_cocoex"],
)

things["suite_bbob"] = Suite(
name="BBOB",
problems={f"fn_bbob_f{fnr}" for fnr in range(1, 25)},
implementations=["impl_py_cocoex"],
)

library = Library(things)

print(to_yaml_str(library))
82 changes: 82 additions & 0 deletions examples/emdo.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
from opltools import Library, Problem, Implementation
from pydantic_yaml import to_yaml_str

#! - name: Electric Motor Design Optimization
#! suite/generator/single: Single Problem
#! variable type: Continuous, Integer
#! dimensionality: '13'
#! objectives: '1'
#! constraints: 'yes'
#! dynamic: 'no'
#! noise: 'yes'
#! multimodal: 'yes'
#! multi-fidelity: 'no'
#! source (real-world/artificial): Real-World Application
#! implementation: Implementation not freely available
#! textual description: The goal is to find a design of a synchronous electric motor
#! for power steering systems that minimizes costs and satisfies all constraints.
#! reference: https://dis.ijs.si/tea/Publications/Tusar23Multistep.pdf (paper in Slovene)
#! other info:
#! partial evaluations: 'no'
#! full name: Electric Motor Design Optimization
#! constraint properties: Hard Constraints, Soft Constraints, Box Constraints
#! number of constraints: '12'
#! description of multimodality: Constraints are multimodal
#! key challenges / characteristics: Time-consuming solution evaluation, highly-constrained
#! problem
#! scientific motivation: Challenging to find good solutions in a limited time
#! limitations: 'Unavailability, even if available, it wouldn''t be helpful to use
#! for benchmarking due taking a long time to evaluate a single solution '
#! implementation languages: Python
#! approximate evaluation time: 8 minutes
#! general: This is not an available problem, but could be interesting to show to
#! researchers which difficulties appear in real-world problems

library = Library({
"impl_emdo": Implementation(
name="Electric Motor Design Optimization",
description="Not publicly available",
language="python",
evaluation_time="8 minutes"
),
"fn_emdo": Problem(
name="Electric Motor Design Optimization",
description="""# Goal
Find a design of a synchronous electric motor for power steering systems that minimizes costs and satisfies all constraints.

# Motivation
Challenging to find good solutions in a limited time

# Key Challenges
* Time-consuming solution evaluation,
* highly-constrained problem
* Constraints are multimodal

This is not an available problem, but could be interesting to show to researchers which difficulties appear in real-world problems""",
objectives=[1],
variables=[
{"type": "continuous", "dim": {"min": None, "max": 13}},
{"type": "integer", "dim": {"min": None, "max": 13}},
],
modality=["multimodal"],
allows_partial_evaluation="no",
constraints=[
{"type": "box", "hard": "some", "number": 12}
],
dynamic_type=["no"],
noise_type=["yes"],
fidelity_levels=[1],
source=["real-world"],
references=[
{
"title": "A Multi-Step Evaluation Process in Electric Motor Design",
"lang": "sj",
"authors": ["Tea Tušar", "Peter Korošec", "Bogdan Filipič"],
"link": {"url": "https://dis.ijs.si/tea/Publications/Tusar23Multistep.pdf"}
}
],
implementations=["impl_emdo"]
)
})

print(to_yaml_str(library))
Loading
Loading