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
101 changes: 101 additions & 0 deletions docs/ext/pymoo.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
{
"cells": [
{
"cell_type": "markdown",
"id": "0",
"metadata": {},
"source": [
"# Pymoo External Connector\n",
"ParetoBench's benchmark problems can be used in [pymoo](https://pymoo.org/) through the wrapper class `PymooProblemWrapper`. On this page, we demonstrate running one of pymoo's optimization algorithms against a ParetoBench problem."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "1",
"metadata": {},
"outputs": [],
"source": [
"from pymoo.algorithms.moo.nsga2 import NSGA2\n",
"from pymoo.optimize import minimize\n",
"\n",
"import paretobench as pb\n",
"from paretobench.ext.pymoo import PymooProblemWrapper"
]
},
{
"cell_type": "markdown",
"id": "2",
"metadata": {},
"source": [
"### Using ParetoBench Problems in Pymoo\n",
"`PymooProblemWrapper` subclasses pymoo's `Problem` class and evaluates the ParetoBench problem using vectorization. Data such as number of objectives, variables and their bounds, etc are passed through from the ParetoBench problem."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "3",
"metadata": {},
"outputs": [],
"source": [
"# Wrap one of ParetoBench's problems for use in pymoo\n",
"prob = PymooProblemWrapper.from_line_fmt(\"ZDT3\")\n",
"prob"
]
},
{
"cell_type": "markdown",
"id": "4",
"metadata": {},
"source": [
"The wrapper may be passed directly to pymoo's algorithms. We will run a short optimization with pymoo's NSGA-II implementation."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "5",
"metadata": {},
"outputs": [],
"source": [
"# Run a short optimization\n",
"res = minimize(prob, NSGA2(pop_size=32), (\"n_gen\", 64), seed=1, verbose=False)\n",
"print(f\"Number of nondominated solutions: {len(res.X)}\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "6",
"metadata": {},
"outputs": [],
"source": [
"# Load the result into a ParetoBench Population and plot it against the true Pareto front\n",
"pop = pb.Population(x=res.X, f=res.F)\n",
"pop.plot_obj_scatter(problem=\"ZDT3\")"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "paretobench",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.12.13"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
1 change: 1 addition & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,4 @@ nav:
- IGD Analysis: analysis/inverted_generational_distance_analysis.ipynb
- External Connectors:
- Xopt: ext/xopt.ipynb
- Pymoo: ext/pymoo.ipynb
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ docs = [
"mkdocs",
"mkdocs-jupyter",
"mkdocs-material",
"pymoo",
"xopt"
]

Expand Down
Loading