Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SLEDO v0.1.1 #12

Merged
merged 40 commits into from
Oct 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
30c6ee1
📝 Update README
lukethehuman Sep 22, 2023
94bb4f5
📦️ Add pyproject.toml
lukethehuman Sep 22, 2023
568985b
👷 Add Build & Test CI to github actions
lukethehuman Sep 22, 2023
2ac8bb7
🐳 Add Dockerfile
lukethehuman Sep 22, 2023
2d0563a
📦️ Add install scripts
lukethehuman Sep 22, 2023
3dab473
📝 Add placeholder tutorial.
lukethehuman Sep 22, 2023
77c1a26
✅ Add tests
lukethehuman Sep 22, 2023
f05451c
🙈 Update .gitignore
lukethehuman Sep 22, 2023
46cb8e5
🔧 Add config.yaml
lukethehuman Sep 22, 2023
be4426c
⬆️ Upgrade dependencies
lukethehuman Sep 22, 2023
c7bb492
✨ Add sledo source code
lukethehuman Sep 22, 2023
234edc4
📝 Add monoblock examples
lukethehuman Sep 22, 2023
9c50448
➕ Add ipykernel dependency
lukethehuman Oct 19, 2023
cf99cef
📌 Use explicit python3 and pip3 commands
lukethehuman Oct 19, 2023
138287e
📝 Add config.yaml step to README
lukethehuman Oct 19, 2023
1d08a38
🔧 Set MOOSE_PATH default value to None
lukethehuman Oct 19, 2023
97a80f4
🙈 Update .gitignore
lukethehuman Oct 19, 2023
f312f13
✏️ Fix path to git repo in Dockerfile
lukethehuman Oct 20, 2023
1360636
🐳 Update Dockerfile to checkout incoming branch
lukethehuman Oct 20, 2023
1a2768f
🐳 Add python3-venv install to Dockerfile
lukethehuman Oct 20, 2023
d69ac7c
🐳 Add `sudo apt update` to Dockerfile
lukethehuman Oct 20, 2023
8fcad1f
🔥 Remove venv step from install scripts.
lukethehuman Oct 20, 2023
0e7d020
🔥 Remove venv steps from Dockerfile.
lukethehuman Oct 20, 2023
efb0086
👷 Remove venv from test action in CI
lukethehuman Oct 20, 2023
e467959
✅ Fix bug in tests where `.i` ext added twice
lukethehuman Oct 20, 2023
01775ae
👷 Fix pytest line in CI
lukethehuman Oct 20, 2023
5c62284
✅ Have each test clear the tmpdir before running
lukethehuman Oct 20, 2023
5d4ac53
🐳 Add python3.8-venv install to Dockerfile
lukethehuman Oct 20, 2023
a936ba1
🐳 Add `sudo apt update` to Dockerfile
lukethehuman Oct 20, 2023
4b11f40
🐳 Upgrade pip in Dockerfile
lukethehuman Oct 20, 2023
de40359
🐳 `pip` --> `python 3 -m pip` in Dockerfile
lukethehuman Oct 20, 2023
65dfbdb
⬇️ Downgrade ax-platform to v0.3.3
lukethehuman Oct 20, 2023
bd196f3
⬆️ Upgrade dependencies
lukethehuman Oct 20, 2023
0f677f2
⬆️ Require python 3.9
lukethehuman Oct 20, 2023
2755df1
🐳 Add python3.9-venv install to Dockerfile
lukethehuman Oct 20, 2023
f4d13bc
🐳 Add -y flags to Dockerfile
lukethehuman Oct 20, 2023
70b7dd1
⬇️ Downgrade botorch and ax-platform versions
lukethehuman Oct 20, 2023
345db7d
⬇️ Downgrade numpy to version 1.24.4
lukethehuman Oct 20, 2023
15b4fef
Revert "⬇️ Downgrade numpy to version 1.24.4"
lukethehuman Oct 23, 2023
4813725
Revert "⬇️ Downgrade botorch and ax-platform versions"
lukethehuman Oct 23, 2023
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
60 changes: 60 additions & 0 deletions .github/workflows/build-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
name: CI

# This section controls when the workflow will run
on:
# Run the workflow on push to "main" branch
push:
branches: [ "main" ]
# Run the workflow on pull request to "main" branch
pull_request:
branches: [ "main"]
# Run the workflow manually
workflow_dispatch:

# This section controls which jobs the workflow will run
jobs:
run-linter:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3

- name: Create venv and install requirements
run: |
python3 -m venv venv
. venv/bin/activate
pip3 install build --upgrade
python3 -m build
pip3 install ./dist/*.whl

- name: Run linter
run: |
. venv/bin/activate
pip3 install flake8
flake8 . --exclude=venv* --count --max-complexity=10 --max-line-length=79 --statistics

build-and-test:
runs-on: ubuntu-latest

env:
PRCOMMITSHA : ${{ github.event.pull_request.head.sha }}

steps:
- uses: actions/checkout@v3

- name: Print github context
run: echo $PRCOMMITSHA

- name: Docker build (pull request)
if: ${{ github.event.pull_request.head.sha != '' }}
run: docker build -t ci-sledo-ubuntu --build-arg build_git_sha=$PRCOMMITSHA docker/sledo-ubuntu/

- name: Docker build (push)
if: ${{ github.event.pull_request.head.sha == '' }}
run: docker build -t ci-sledo-ubuntu --build-arg build_git_sha=$GITHUB_SHA docker/sledo-ubuntu/

- name: Run tests
run: |
pip3 install pytest
pytest tests

9 changes: 9 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -158,3 +158,12 @@ cython_debug/
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/

# Ignore vscode files
.vscode

# Ignore any results folders
results

# Ignore config file
config.yaml
81 changes: 80 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,81 @@
# sledo
Sequential learning engineering design optimiser.

SLEDO (Sequential Learning Engineering Design Optimiser) is a tool for optimising parametric component designs, developed for fusion engineering.

Sledo uses Bayesian Optimisation to intelligently select candidate designs from a parametric search space and MOOSE to evaluate the design performance via scalable multiphysics simulation.

# Installation

## Linux

We recommend creating a virtual environment before running `sledo`.
Skip this step if you intend to install `sledo` into an existing python environment.
```
python3 -m venv venv
source venv/bin/activate
```

### Standard install
To install `sledo`, run the following:
```
# Ensure `build` package is installed.
pip3 install build --upgrade

# Build the distribution package.
python3 -m build

# Install the built distribution.
pip3 install ./dist/*.whl
```

If you intend to use the jupyter notebook tutorials, also run the following line:
```
# Enable virtual environment in the tutorial notebooks.
python3 -m ipykernel install --user --name=venv
```

Sledo can now be imported into python as:
```
import sledo
```

To test the installation, run `python3 -c "import sledo"`. If the installation was unsuccessful, an error will be raised.

In order to run simulations, make sure to add the path to your MOOSE app of choice to `config.yaml`.

### Editable install (developer mode)
Developers may wish to create an editable installation. This allows changes to the source code to immediately take effect without the need to re-package and re-install sledo. This can be useful when running tests and other scripts.

To install `sledo` this way, run the following:
```
# Install as an editable installation.
pip3 install --editable .
```

# Getting started

To start using sledo, please refer to the `tutorials` and `examples` folders for example usage.

# Contributors

Luke Humphrey, UK Atomic Energy Authority

Aleksander Dubas, UK Atomic Energy Authority

Andrew Davis, UK Atomic Energy Authority

Lloyd Fletcher, UK Atomic Energy Authority

# Citing Sledo

If using Sledo in your research, please cite the following:

> Citation TBC

Please also cite Sledo's dependencies as indicated on their individual websites:

- MOOSE (https://mooseframework.inl.gov/citing.html)
- BoTorch (https://botorch.org/docs/papers)
- NumPy (https://numpy.org/citing-numpy/)
- SciPy (https://scipy.org/citing-scipy/)
- Matplotlib (https://matplotlib.org/stable/users/project/citing.html)
2 changes: 2 additions & 0 deletions config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Path to default moose app for running simulations.
MOOSE_PATH: None
23 changes: 23 additions & 0 deletions docker/sledo-ubuntu/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Get base image
FROM idaholab/moose:latest

ARG WORKDIR="opt"

# By default, checkout the main branch
ARG build_git_sha="main"

# Build Sledo
RUN cd /$WORKDIR && \
git clone https://github.com/aurora-multiphysics/sledo.git && \
cd sledo && \
git checkout "$build_git_sha" && \
sudo apt update -y && \
sudo apt install python3 -y && \
sudo apt install python3.9-venv -y && \
python3 -m pip install --upgrade pip && \
chmod +x install.sh && \
./install.sh

# Add MOOSE python packages to python path
RUN export PYTHONPATH=${PYTHONPATH}:/${WORKDIR}/moose/python/pyhit && \
export PYTHONPATH=${PYTHONPATH}:/${WORKDIR}/moose/python/moosetree
37 changes: 37 additions & 0 deletions examples/example_1_simple_monoblock.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
from sledo.optimiser import Optimiser
from sledo.simulation import ThermoMechSimulation

DATA_DIR = "./results/example_1"

search_space = (
{
"name": "Armour height",
"type": "range",
"hit_name": "monoBArmHeight",
"hit_block": "",
"bounds": [1e-3, 20e-3],
},
{
"name": "Block width",
"type": "range",
"hit_name": "monoBWidth",
"hit_block": "",
"bounds": [17e-3, 34e-3],
},
)

opt = Optimiser(
name="simple_monoblock",
search_space=search_space,
simulation_class=ThermoMechSimulation,
data_dir=DATA_DIR,
)

opt.load_input_file("./input_files/simple_monoblock.i")
opt.run_optimisation_loop(
objective_name="stress",
max_iter=20,
minimise=True,
)

opt.pickle()
51 changes: 51 additions & 0 deletions examples/example_2_monoblock.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
from sledo.optimiser import Optimiser
from sledo.simulation import ThermoMechSimulation

DATA_DIR = "./results/example_2"

search_space = (
{
"name": "Pipe thickness",
"type": "range",
"hit_name": "pipeThick",
"hit_block": "",
"bounds": [1e-3, 6e-3],
},
{
"name": "Interlayer thickness",
"type": "range",
"hit_name": "intLayerThick",
"hit_block": "",
"bounds": [1e-3, 6e-3],
},
{
"name": "Block thickness",
"type": "range",
"hit_name": "monoBThick",
"hit_block": "",
"bounds": [1e-3, 6e-3],
},
{
"name": "Armour height",
"type": "range",
"hit_name": "monoBArmHeight",
"hit_block": "",
"bounds": [1e-3, 16e-3],
},
)

opt = Optimiser(
name="monoblock",
search_space=search_space,
simulation_class=ThermoMechSimulation,
data_dir=DATA_DIR,
)

opt.load_input_file("./input_files/monoblock.i")
opt.run_optimisation_loop(
objective_name="stress",
max_iter=20,
minimise=True,
)

opt.pickle()
Loading
Loading