-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #21 from aurora-multiphysics/20-refactor-sledo-to-…
…be-agnostic-to-model-instantiation-tool undefined
- Loading branch information
Showing
24 changed files
with
2,660 additions
and
595 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -166,4 +166,4 @@ cython_debug/ | |
results | ||
|
||
# Ignore config file | ||
config.yaml | ||
moose_config.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,73 @@ | ||
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() | ||
""" | ||
SLEDO Simple Monoblock Example | ||
Example input file for running Bayesian optimisation of a simplified divertor | ||
monoblock to minimise the peak von misses stress predicted by a | ||
thermomechanical MOOSE simulation. | ||
(c) Copyright UKAEA 2023-2024. | ||
""" | ||
|
||
from ray import tune | ||
|
||
from sledo import Optimiser, MooseHerderDesignEvaluator | ||
from sledo import SLEDO_ROOT | ||
|
||
# This points to the file 'moose_config.json' in sledo root folder. | ||
# If you haven't already, please make sure you've entered the required paths | ||
# for your chosen MOOSE app. | ||
# In general, you don't need to import this as it will be used by default, | ||
# however you may point to a config file in a different location if you wish | ||
# to use something else for a given optimisation run. | ||
from sledo import MOOSE_CONFIG_FILE | ||
|
||
# Set the paths required for this example. | ||
# In general, the user will set their own paths and pass them where required. | ||
EXAMPLES_DIR = SLEDO_ROOT / "examples" | ||
INPUT_FILE = EXAMPLES_DIR / "input_files" / "simple_monoblock_thermomech.i" | ||
WORKING_DIR = EXAMPLES_DIR / "results" / "example_1" | ||
PICKLE_FILEPATH = WORKING_DIR / "example_1_optimiser.pickle" | ||
|
||
if __name__ == "__main__": | ||
|
||
# Set metrics for optimisation. These must exactly match how they appear | ||
# in your MOOSE postprocessor. In this case, we are only optimising a | ||
# single objective, but the list convention is still used. | ||
metrics = ["max_stress"] | ||
|
||
# Instantiate design evaluator. | ||
design_evaluator = MooseHerderDesignEvaluator( | ||
metrics, | ||
INPUT_FILE, # The base input file to be modified per design iteration. | ||
working_dir=WORKING_DIR, # Directory to store generated files. | ||
config_path=MOOSE_CONFIG_FILE, # Contains required MOOSE paths. | ||
) | ||
|
||
# Define a search space according to the Ray Tune API. | ||
# Documentation here: | ||
# https://docs.ray.io/en/latest/tune/api/search_space.html | ||
# The variable names must exactly match how they appear in the MOOSE input | ||
# file so that they can be updated for each design iteration. | ||
search_space = { | ||
"monoBArmHeight": tune.uniform(1e-3, 20e-3), | ||
"monoBThick": tune.uniform(0.5e-3, 9e-3), | ||
} | ||
|
||
# Instantiate SLEDO optimiser. | ||
opt = Optimiser( | ||
design_evaluator, | ||
search_space, | ||
max_total_trials=20, | ||
name="simple-monoblock-optimiser", | ||
data_dir=WORKING_DIR, | ||
) | ||
|
||
# Run optimisation. | ||
results = opt.run_optimisation() | ||
print(results) | ||
|
||
# Save the optimiser class instance to file. | ||
opt.pickle(PICKLE_FILEPATH) | ||
|
||
# To load the optimiser class from file, you can then run. | ||
opt = Optimiser.unpickle(PICKLE_FILEPATH) |
Oops, something went wrong.