Skip to content

Commit 26344c5

Browse files
committed
docs: update Docs
1 parent 236d4fa commit 26344c5

File tree

4 files changed

+71
-28
lines changed

4 files changed

+71
-28
lines changed

README.md

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,11 @@ of OpenFOAM cases.
1111
- Parameter values are fetched through a YAML/JSON configuration file. Absolutely no code should be needed, add parameters
1212
to the YAML file and they should be picked up automatically
1313
- The no-code thing is taken to the extreme, through a YAML config file, you can (need-to):
14-
- Specify the template case
15-
- Specify how the case is ran
16-
- Specify how/where parameters are substituted
17-
- Specify how your metrics are computed
14+
- Specify the template case. This must be a "complete" (no placeholder), and runnable (as-is) OpenFOAM case.
15+
- Specify how the case is ran. Locally, or on SLURM, and specifying the commands to run.
16+
- Specify how/where parameters are substituted. `PyFoam` is used for this purpose for now.
17+
- Specify how your metrics are computed. These are just shell commands that output a single scalar
18+
value to `STDOUT`.
1819

1920
## How do I try this out?
2021

@@ -27,14 +28,17 @@ OpenFOAM-like dictionary (See [single-objective opt. example](examples/local/sin
2728
for inspiration.
2829

2930
```bash
30-
# Clone the repository
31+
# Install the package
32+
pip install foambo
33+
# Clone the repo to get the examples
3134
git clone https://github.com/FoamScience/OpenFOAM-Multi-Objective-Optimization foamBO
32-
cd foamBO
33-
# Install dependencies
34-
pip3 install -r requirements.txt
35+
cd foamBO/examples
3536
```
3637
### Apptainer containers
3738

39+
If you'd like to try this out in Apptainer containers instead, It's recommended to
40+
(Must have `ansible` installed for this to work):
41+
3842
```bash
3943
git clone https://github.com/FoamScience/openfoam-apptainer-packaging /tmp/of_tainers
4044
git clone https://github.com/FoamScience/OpenFOAM-Multi-Objective-Optimization foamBO
@@ -43,6 +47,12 @@ ansible-playbook /tmp/of_tainers/build.yaml --extra-vars="original_dir=$PWD" --e
4347
# Get an apptainer container at containers/projects/foambo-<version>.sif
4448
```
4549

50+
Each example has some description in its README:
51+
- [Single-Objective BO of a single-parameter function, ran locally](examples/local/single-objective/README.md)
52+
- [Multi-Objective BO of a `pitzDaily` case, ran locally and on a SLURM Cluster](examples/local/multi-objective/README.md)
53+
- [Multi-Objective BO of a `pitzDaily` case, ran on a SLURM cluster](examples/slurm/README.md)
54+
and providing "dependent parameters setup" variants.
55+
4656
## Contribution is welcome!
4757

4858
By either filing issues or opening pull requests, you can contribute to the development

examples/local/multi-objective/README.md

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
## Prerequisites
44

5-
- You need the Python dependencies: `pip install -r requirements.txt`
5+
- You need the `foamBO` package: `pip install foamBO`
66
- You need an OpenFOAM version. Set `FOAMBO_OPENFOAM` to its installation folder.
77
`${FOAMBO_OPENFOAM}/etc/bashrc` will be sourced in cases' `Allrun`.
88

@@ -28,26 +28,27 @@ I describe the workflow in two cases:
2828
> If you're going with option 1, you can skip setting up the cluster. If you intend to adopt option 2, I
2929
> recommend you still go through option 1
3030
>
31-
> This toolkit relies on [ax-platform](https://ax.dev) to do the optimization, so we support what they support.
31+
> This toolkit relies on [ax-platform](https://ax.dev) to do the optimization, so we support what they support + a few custom things.
3232
>
3333
> Here are few nice words about [Bayesian Optimization](https://ax.dev/docs/bayesopt.html). If you want to extend
3434
> these tools, you might want to take a look at the [Service and Developer APIs](https://ax.dev/docs/api.html)
3535
36-
> Also, Python scripts are [Hydra Applications](https://hydra.cc/docs/intro/), so you can load different configurations
36+
> Also, `foamBO`, `foamDash` and `validateBO` scripts are [Hydra Applications](https://hydra.cc/docs/intro/),
37+
> so you can load different configurations
3738
> and/or override config values from the command line.
3839
3940
## Features we're exploring
4041

4142
- Zero-code configuration for running parameter variations.
4243
- As long as you're able to do stuff through Bash.
4344
- Unattended algorithm selection for the trial generation strategy and Bayesian optimization.
44-
- Easy to expand; especially for metric evaluation; it's just a --new Python function--.
45+
- Ease of use; especially for metric evaluation; it's just a --new Python function--.
4546

4647
## The example problem
4748

4849
To illustrate the somewhat complex workflow of running optimization studies with this toolkit, I picked
4950
the `pitzDaily` case from the standard tutorials (the one that works with `simpleFOAM`/`RAS`). The case
50-
can be ran both in serial and in parallel with 2 processors.
51+
can run both in serial and in parallel with 2 processors.
5152

5253
![](pitzDaily/pitzDaily.png)
5354

@@ -59,7 +60,7 @@ Our objectives are:
5960
- Execution Time, extracted straight from the solver log files
6061
- Continuity Errors, also extracted from log files
6162

62-
> Note that we are not particularly interested in the results of the study;
63+
> Note that we are **not** particularly interested in the results of the study;
6364
> All we care about is demonstrating how to optimize this problem with Bayesian algorithms.
6465
6566

@@ -106,17 +107,14 @@ All subsequent operations are supposed to run on the head node.
106107
> If you don't want to use the cluster, please adapt the paths to your local machine.
107108
> Don't forget to clone https://github.com/FoamScience/OpenFOAM-Multi-Objective-Optimization
108109
109-
I've only tested the scripts with Python 3.8, so I recommend you use that version too. Just to avoid any
110-
surprises.
111-
112110
The best option is to get [Miniconda](https://docs.conda.io/en/latest/miniconda.html) and:
113111
```bash
114112
# Remember /axc on the head node, would be slurm-cluster/var/axc on your machine
115113
cd /axc/multiOptOF
116-
conda create -n of-opt python=3.8 pip
114+
conda create -n of-opt python=3.12 pip
117115
conda activate of-opt
118116
# This will install a load of packages
119-
pip install -r requirements.txt
117+
pip install foambo
120118
```
121119

122120
## Local runs
@@ -131,10 +129,11 @@ for reference.
131129

132130
### Design parameters
133131

134-
The configuration file has at least three important sections:
132+
The configuration file has at least four important sections:
135133
- `problem`: where you describe your problem inputs
136134
- `meta`: where you describe control settings for the optimization procedure
137-
- `visualize`: which an optional section for when you run `foamDash.py`
135+
- `validate`: where you optionally configure how the cross-validation of fitted models should be performed by `validateBO`
136+
- `visualize`: where you optionally configure how trials are visualized when you run `foamDash`
138137

139138
The first thing is `problem.template_case` which points to the case you want to use as a base template.
140139
This case is then cloned each time with the help of PyFOAM. `meta.case_subdirs_to_clone` specifies

examples/local/single-objective/README.md

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ paper, with parameters `k=1, m=0, lambda=0.01`.
88

99
## Prerequisites
1010

11-
- You only need the Python dependencies: `pip install -r requirements.txt`
11+
- You only need the `foamBO` package: `pip install foamBO`
1212
- No OpenFOAM installation is needed.
1313

1414
## Basic Ax usage
@@ -68,8 +68,9 @@ a single dictionary).
6868

6969
### Configuration and "OpenFOAM" case
7070

71-
The configuration file usually contains three sections `problem`, `meta` and `visualize`.
72-
In this example, we can ignore `visualize` as it's necessary only if you run `foamDash.py`.
71+
The configuration file usually contains four sections `problem`, `meta`, `validate` and `visualize`.
72+
In this example, we can ignore `visualize` as it configures how `foamDash` utility visualizes
73+
the optimization trials and metric evolution.
7374

7475
The first section, `problem`, defines the optimization problem you're treating.
7576
It points to the base OpenFOAM case (`problem.template_case`) and distinguishes between
@@ -171,19 +172,44 @@ the content:
171172
x 0;
172173
```
173174

175+
After the optimization has gone through all of its trials, you can run the `validateBO` command
176+
to run some validation routines on the surrogate model. The `validate` section configures
177+
how to perform the validation:
178+
179+
> It's important not to change the `config.yaml` between running `foamBO` and `validateBO`
180+
181+
```yaml
182+
validate:
183+
cross_validate: True # Run Ax's cross validation (doesn't run new trials)
184+
# if no "trials" and no "pareto_frontier" is present, on the cross-validate from Ax
185+
# will run
186+
trials: # The utility w
187+
- x: 0.2
188+
- x: 1.0
189+
- x: -100
190+
# IF it's a multi-objective optimization, you can generate 10 pareto frontier points
191+
# and run them to check how the close the prediction is to the actual metric values
192+
#pareto_frontier: 10
193+
#primary_objective: "metric_1"
194+
#secondary_objective: "metric_2"
195+
```
196+
197+
The `validateBO` will run the trials using the same configuration used to run the experiment's trials,
198+
and will result in a CSV file `Validate_<cfg.problem.name>_validate_report.csv` which has the required
199+
data to perform validation analysis.
200+
174201
### Generating predictions from models trained with foamBO
175202

176203
`foamBO` will periodically save your experiment to a JSON file, and once the optimization is
177204
stopped, it will write its current state to another JSON. You can load those again into an Ax client:
178205
```python
179-
# You need to load stuff from core.py to be able to de-serialize them
206+
# You need to load stuff from core.py to be able to de-serialize the custom runners, metrics, ... etc
180207
from foambo.core import *
181208
from ax.service.ax_client import AxClient
182209
from ax.storage.json_store.load import load_experiment
183210
cl = AxClient().load_from_json_file('SingleObjF1_client_state.json')
184211
exp = load_experiment(f"SingleObjF1_experiment.json")
185212
cl._experiment = exp
186-
exp = load_experiment(f"SingleObjF1_experiment.json")
187213
cl.get_model_predictions_for_parameterizations([{'x': 100}, {'x': -50}])
188214
```
189-
This then results in very similar results to what `tutorial.py` reports.
215+
This then should result in very similar results to what `tutorial.py` reports.

examples/slurm/README.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,30 @@ challenge. Head to the
55
[OFMLHackathon folder](https://github.com/FoamScience/OFMLHackathon/tree/main/2023-07/bayesian-optimization)
66
for a more detailed overview.
77

8+
> The study was performed on a SLURM cluster powered by AWS.
9+
810
## Prerequisites
911

10-
- You need the Python dependencies: `pip install -r requirements.txt`
12+
- You need the `foamBO`: `pip install foamBO`
1113
- You need an OpenFOAM version. Set `FOAMBO_OPENFOAM` to its installation folder.
1214
`${FOAMBO_OPENFOAM}/etc/bashrc` will be sourced in cases' `Allrun`.
1315
- A SLURM cluster (See [multi-objective opt. tutorial](../local/multi-objective/README)
1416
for an example cluster)
1517
- Mesh parametrization is done through a `OpenSCAD -> cfMesh -> ParaView` workflow.
1618

19+
> While `OpenSCAD` is fine for most purposes, I found out later that `madcad` is
20+
> a better fit for this type of needs because it can export 2D surfaces.
21+
1722
## PitzDaily with varying lowerWall geometry
1823

1924
The [config.yaml](shape-optimization/config.yaml) file shows how to setup the
2025
[pitzDaily](shape-optimization/pitzDaily) for shape optimization using SAASBO. This simply
2126
parameterizes the lower wall of the geometry as a cubic Bezier curve with 8 control
2227
points, whose coordinates are used as optimization parameters.
2328

29+
> Using SAASBO specifically was done merely for demonstration purposes. In production
30+
> runs, SAASBO shouldn't be used unless the problem features a huge search space.
31+
2432
## Dependent parameters
2533

2634
The [config-dependent.yaml](./shape-optimization/config-dependent.yaml) and the corresponding

0 commit comments

Comments
 (0)