Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
33d6dff
first implementation of storing more general optimization data
electronsandstuff Jan 23, 2025
7a95d6c
add start of checks for old file format loading
electronsandstuff Jan 23, 2025
b32279e
add data
electronsandstuff Jan 23, 2025
2563fff
add ability to save new data
electronsandstuff Jan 23, 2025
a60199b
update plotting to handle general problems
electronsandstuff Jan 23, 2025
e58eb7a
fix g_canonical
electronsandstuff Jan 23, 2025
9263581
better checks for objective/constraint settings
electronsandstuff Jan 23, 2025
4f45334
add the objective and constraint settings to tests
electronsandstuff Jan 24, 2025
e10ac0d
update docstring
electronsandstuff Jan 24, 2025
d763c28
add check for feasibility
electronsandstuff Jan 24, 2025
9108959
allow users to pass lists for objective/constraint config
electronsandstuff Jan 24, 2025
49758d3
new names
electronsandstuff Jan 24, 2025
d9991e0
fix random obj/constraint settings generation
electronsandstuff Jan 24, 2025
6a54215
update __repr__
electronsandstuff Jan 24, 2025
03dec4a
change constraint direction meaning
electronsandstuff Jan 24, 2025
bad8cf3
some more organization
electronsandstuff Jan 24, 2025
1dad58c
more documentation
electronsandstuff Jan 24, 2025
23dbbb8
change to string directions for better readability
electronsandstuff Jan 26, 2025
42d2a41
update save file
electronsandstuff Jan 26, 2025
6431f50
some editing
electronsandstuff Jan 26, 2025
464ffae
add example of obj directions
electronsandstuff Jan 26, 2025
989d843
better container notebook
electronsandstuff Jan 26, 2025
2358e93
add objectives constraints readout to history
electronsandstuff Jan 26, 2025
ce0218e
update random constraints
electronsandstuff Jan 26, 2025
e036dd7
editing
electronsandstuff Jan 26, 2025
39dfcbd
minor edits
electronsandstuff Jan 26, 2025
d82f888
minor edits
electronsandstuff Jan 26, 2025
43a3ef9
version bump
electronsandstuff Jan 26, 2025
01a09ee
correct error check
electronsandstuff Jan 26, 2025
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
59 changes: 59 additions & 0 deletions dev_notebooks/save_new_legacy_file.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Prepare a New \"Legacy Test File\"\n",
"This notebook loads the data from the first legacy test file and saves it using a new version of the library in the latest save file format. This will ensure a record of the file format exists for the purpose of regression tests."
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"from paretobench import Experiment"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"exp = Experiment.load(\"../tests/legacy_file_formats/paretobench_file_format_v1.0.0.h5\")\n",
"exp.save(\"../tests/legacy_file_formats/paretobench_file_format_v1.1.0.h5\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"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.13.1"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
3 changes: 3 additions & 0 deletions environment.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
name: paretobench
dependencies:
- pytest
- pip
- pip:
- pre-commit
105 changes: 87 additions & 18 deletions example_notebooks/container_objects.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"metadata": {},
"outputs": [],
"source": [
"import numpy as np\n",
"import os\n",
"import paretobench as pb\n",
"import tempfile"
Expand All @@ -36,17 +37,22 @@
"name": "stdout",
"output_type": "stream",
"text": [
"Population(size=32, vars=10, objs=2, cons=0, fevals=0)\n",
"Population(size=32, vars=10, objs=[--], cons=[], fevals=32)\n",
"Decision variables: (32, 10)\n",
"Objectives: (32, 2)\n",
"Constraints: (32, 0)\n",
"Function evaluations: 0\n"
"Function evaluations: 32\n"
]
}
],
"source": [
"# Create an example population\n",
"pop = pb.Population.from_random(n_objectives=2, n_decision_vars=10, n_constraints=0, pop_size=32)\n",
"pop = pb.Population(\n",
" x=np.random.random((32, 10)), # 32 individuals worth of 10 decision vars\n",
" f=np.random.random((32, 2)), # 2 objectives\n",
" # Not specifying an array (constraints here) will cause it to populate empty based on other's shape\n",
" fevals=32,\n",
")\n",
"print(pop)\n",
"\n",
"# Examine some of the parameters\n",
Expand All @@ -67,12 +73,66 @@
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"Population(size=32, vars=10, objs=[--], cons=[>0.0e+00], fevals=32)"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Create a population with some names\n",
"pop = pb.Population(\n",
" x=np.random.random((32, 10)),\n",
" f=np.random.random((32, 2)),\n",
" g=np.random.random((32, 1)), # Add a single constraint this time\n",
" names_x=[f\"Decision var {idx}\" for idx in range(pop.x.shape[1])],\n",
" names_f=[\"Objective_1\", \"Objective_2\"],\n",
" names_g=[\"Important_Constraint\"],\n",
")\n",
"pop"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Populations default to representing minimization problems with constraints that are satisfied when each g >= 0. This can be modified as in the following code block. Configuring these settings is important when using container methods to find feasible individuals and in calculation of domination."
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"Population(size=32, vars=10, objs=[+-+], cons=[>3.3e-01,<6.6e-01], fevals=32)"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Set naems of the decision variables, objectives, and constraints\n",
"pop.names_x = [f\"Decision var {idx}\" for idx in range(pop.x.shape[1])]\n",
"pop.names_f = [\"Objective 1\", \"Objective 2\"]\n",
"pop.names_g = []"
"# Create a population and specify the objective / constraint directions and target\n",
"pop = pb.Population(\n",
" x=np.random.random((32, 10)),\n",
" f=np.random.random((32, 3)),\n",
" g=np.random.random((32, 2)),\n",
" obj_directions=\"+-+\", # \"+\" indicates maximization, \"-\" inidicates minimization\n",
" constraint_directions=\"><\", # \"<\" means satisifed when g<target and \">\" means satsified when g>target\n",
" constraint_targets=np.array([0.33, 0.66]), # >0.33 constraint and <0.66 constraint\n",
")\n",
"\n",
"pop"
]
},
{
Expand All @@ -85,23 +145,32 @@
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": 5,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"History(problem='WFG1 (n=10)', reports=15, vars=10, objs=2, cons=0)\n",
"Problem: WFG1 (n=10)\n",
"Number of reports: 15\n"
"History(problem='WFG1', reports=10, vars=30, objs=[--], cons=[])\n",
"Problem: WFG1\n",
"Number of reports: 10\n"
]
}
],
"source": [
"# Create an example history object\n",
"hist = pb.History.from_random(n_populations=15, n_objectives=2, n_decision_vars=10, n_constraints=0, pop_size=32)\n",
"hist.problem = \"WFG1 (n=10)\"\n",
"# Create some population objects which will go into the history. We will use the random generation helper function here.\n",
"n_reports = 10\n",
"reports = [\n",
" pb.Population.from_random(n_objectives=2, n_decision_vars=30, n_constraints=0, pop_size=50)\n",
" for _ in range(n_reports)\n",
"]\n",
"\n",
"# Construct the history object\n",
"hist = pb.History(\n",
" reports=reports,\n",
" problem=\"WFG1\", # Use ParetoBench single line format for maximum compatibility with plotting, etc\n",
")\n",
"print(hist)\n",
"\n",
"# Print some of the properties\n",
Expand All @@ -119,17 +188,17 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 6,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Experiment(name='NSGA-II (default params)', created='2024-12-10', author='The author of ParetoBench', software='ParetoBench example notebook 1.0.0', runs=32)\n",
"Experiment(name='NSGA-II (default params)', created='2025-01-26', author='The author of ParetoBench', software='ParetoBench example notebook 1.0.0', runs=32)\n",
"Number of histories: 32\n",
"Name: NSGA-II (default params)\n",
"Creation time: 2024-12-10 05:21:51.993640+00:00\n"
"Creation time: 2025-01-26 06:36:29.299300+00:00\n"
]
}
],
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "paretobench"
version = "0.3.0"
version = "0.4.0"
authors = [
{ name="Christopher M. Pierce", email="contact@chris-pierce.com" },
]
Expand Down
Loading
Loading