Skip to content

Commit

Permalink
Updated the schema, notebook and examples.
Browse files Browse the repository at this point in the history
  • Loading branch information
lauri-codes committed Nov 1, 2024
1 parent ea27364 commit 2cc625a
Show file tree
Hide file tree
Showing 14 changed files with 9,047 additions and 4,385 deletions.
13 changes: 2 additions & 11 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -114,14 +114,5 @@ where = ["src"]
"nomad_bayesian_optimization.apps:bayesian_optimization_tasks" = "nomad_bayesian_optimization.apps:bayesian_optimization_tasks"
"nomad_bayesian_optimization.schema_packages:experiments" = "nomad_bayesian_optimization.schema_packages:experiments"
"nomad_bayesian_optimization.schema_packages:bayesian_optimization" = "nomad_bayesian_optimization.schema_packages:bayesian_optimization"
#"nomad_bayesian_optimization.schema_packages:jobs" = "nomad_bayesian_optimization.schema_packages:jobs"
#"nomad_bayesian_optimization.example_uploads:getting_started" = "nomad_bayesian_optimization.example_uploads:getting_started"
#"nomad_bayesian_optimization.example_uploads:optimization_tasks" = "nomad_bayesian_optimization.example_uploads:optimization_tasks"
"nomad_bayesian_optimization.example_uploads:file" = "nomad_bayesian_optimization.example_uploads:file"
"nomad_bayesian_optimization.example_uploads:file_target" = "nomad_bayesian_optimization.example_uploads:file_target"
"nomad_bayesian_optimization.example_uploads:folder" = "nomad_bayesian_optimization.example_uploads:folder"
"nomad_bayesian_optimization.example_uploads:folder_contents" = "nomad_bayesian_optimization.example_uploads:folder_contents"
"nomad_bayesian_optimization.example_uploads:zip_unpack" = "nomad_bayesian_optimization.example_uploads:zip_unpack"
"nomad_bayesian_optimization.example_uploads:multiple_files" = "nomad_bayesian_optimization.example_uploads:multiple_files"
"nomad_bayesian_optimization.example_uploads:zip_online_unpack" = "nomad_bayesian_optimization.example_uploads:zip_online_unpack"
"nomad_bayesian_optimization.example_uploads:multiple_online_files" = "nomad_bayesian_optimization.example_uploads:multiple_online_files"
"nomad_bayesian_optimization.example_uploads:getting_started" = "nomad_bayesian_optimization.example_uploads:getting_started"
"nomad_bayesian_optimization.example_uploads:optimization_tasks" = "nomad_bayesian_optimization.example_uploads:optimization_tasks"
104 changes: 8 additions & 96 deletions src/nomad_bayesian_optimization/example_uploads/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from nomad.config.models.plugins import ExampleUploadEntryPoint, UploadResource
from nomad.config.models.plugins import ExampleUploadEntryPoint
from nomad.utils import strip

getting_started = ExampleUploadEntryPoint(
Expand All @@ -7,104 +7,16 @@
Example upload that contains a Jupyter notebook demonstrating the basics of
Bayesian optimization.
"""),
resources='example_uploads/getting_started/*',
path='example_uploads/getting_started',
category='Bayesian optimization',
)

# optimization_tasks = ExampleUploadEntryPoint(
# title='Example optimization tasks',
# description=strip("""
# Contains a series of optimization runs for exploring what bayesian optimization data
# looks like.
# """),
# path='example_uploads/optimization_tasks',
# category='Bayesian optimization',
# )

file = ExampleUploadEntryPoint(
title='file',
description=strip("""
Example upload that contains a Jupyter notebook demonstrating the basics of
Bayesian optimization.
"""),
resources='example_uploads/getting_started/README.md',
category='Lab automation',
)

file_target = ExampleUploadEntryPoint(
title='file_target',
description=strip("""
Example upload that contains a Jupyter notebook demonstrating the basics of
Bayesian optimization.
"""),
resources=UploadResource(
path='example_uploads/getting_started/README.md', target='folder_1/folder2/'
),
category='Lab automation',
)

folder = ExampleUploadEntryPoint(
title='folder',
description=strip("""
Example upload that contains a Jupyter notebook demonstrating the basics of
Bayesian optimization.
"""),
resources='example_uploads/getting_started',
category='Lab automation',
)

folder_contents = ExampleUploadEntryPoint(
title='folder_contents',
description=strip("""
Example upload that contains a Jupyter notebook demonstrating the basics of
Bayesian optimization.
"""),
resources='example_uploads/getting_started/*',
category='Lab automation',
)

zip_unpack = ExampleUploadEntryPoint(
title='zip_unpack',
description=strip("""
Example upload that contains a Jupyter notebook demonstrating the basics of
Bayesian optimization.
"""),
resources='example_uploads/getting_started/nomad-oasis.zip',
category='Lab automation',
)

multiple_files = ExampleUploadEntryPoint(
title='multiple_files',
optimization_tasks = ExampleUploadEntryPoint(
title='Example optimization tasks',
description=strip("""
Example upload that contains a Jupyter notebook demonstrating the basics of
Bayesian optimization.
Contains a series of optimization runs for exploring what bayesian optimization data
looks like.
"""),
resources=[
'example_uploads/getting_started/notebook.ipynb',
'example_uploads/getting_started/nomad-oasis.zip',
],
category='Lab automation',
)

zip_online_unpack = ExampleUploadEntryPoint(
title='zip_online_unpack',
description=strip("""
Example upload that contains a Jupyter notebook demonstrating the basics of
Bayesian optimization.
"""),
resources='https://nomad-lab.eu/prod/v1/docs/assets/nomad-oasis.zip',
category='Lab automation',
)

multiple_online_files = ExampleUploadEntryPoint(
title='multiple_online_files',
description=strip("""
Example upload that contains a Jupyter notebook demonstrating the basics of
Bayesian optimization.
"""),
resources=[
'https://nomad-lab.eu/prod/v1/docs/assets/nomad-oasis.zip',
'https://nomad-lab.eu/prod/v1/docs/howto/oasis/install.html',
],
category='Lab automation',
path='example_uploads/optimization_tasks',
category='Bayesian optimization',
)
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
Expand Down Expand Up @@ -174,7 +174,6 @@
" if cvd_experiment.substrate != ideal_substrate:\n",
" refractive_index *= 0.9\n",
" cvd_experiment.refractive_index = refractive_index\n",
" time.sleep(2)\n",
" return cvd_experiment\n"
]
},
Expand All @@ -187,88 +186,11 @@
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": null,
"metadata": {
"id": "4PSMvrp-sdDL"
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"New recommendation:\n",
" substrate gas_flow_rate temperature\n",
"2 Silicon carbide 3.227608 303.536005\n",
"Testing recommendation...\n",
"Testing finished!\n",
"New recommendation:\n",
" substrate gas_flow_rate temperature\n",
"index \n",
"0 Gallium nitride 1.003181 568.323795\n",
"Testing recommendation...\n",
"Testing finished!\n",
"New recommendation:\n",
" substrate gas_flow_rate temperature\n",
"index \n",
"2 Silicon carbide 4.391106 338.416694\n",
"Testing recommendation...\n",
"Testing finished!\n",
"New recommendation:\n",
" substrate gas_flow_rate temperature\n",
"index \n",
"2 Silicon carbide 2.091479 300.0\n",
"Testing recommendation...\n",
"Testing finished!\n",
"New recommendation:\n",
" substrate gas_flow_rate temperature\n",
"index \n",
"2 Silicon carbide 0.834176 300.0\n",
"Testing recommendation...\n",
"Testing finished!\n",
"New recommendation:\n",
" substrate gas_flow_rate temperature\n",
"index \n",
"1 Silicon 1.254739 347.692091\n",
"Testing recommendation...\n",
"Testing finished!\n",
"New recommendation:\n",
" substrate gas_flow_rate temperature\n",
"index \n",
"1 Silicon 2.323314 317.086362\n",
"Testing recommendation...\n",
"Testing finished!\n",
"New recommendation:\n",
" substrate gas_flow_rate temperature\n",
"index \n",
"1 Silicon 0.674845 364.194368\n",
"Testing recommendation...\n",
"Testing finished!\n",
"New recommendation:\n",
" substrate gas_flow_rate temperature\n",
"index \n",
"0 Gallium nitride 3.448516 595.562806\n",
"Testing recommendation...\n",
"Testing finished!\n",
"New recommendation:\n",
" substrate gas_flow_rate temperature\n",
"index \n",
"0 Gallium nitride 5.0 520.86546\n",
"Testing recommendation...\n",
"Testing finished!\n",
"New recommendation:\n",
" substrate gas_flow_rate temperature\n",
"index \n",
"0 Gallium nitride 2.273746 310.058048\n",
"Testing recommendation...\n",
"Testing finished!\n",
"New recommendation:\n",
" substrate gas_flow_rate temperature\n",
"index \n",
"2 Silicon carbide 2.03576 358.808878\n",
"Testing recommendation...\n"
]
}
],
"outputs": [],
"source": [
"import json\n",
"from baybe import Campaign\n",
Expand All @@ -283,45 +205,36 @@
"campaign = Campaign(searchspace, objective, recommender)\n",
"i = 0\n",
"result = 0\n",
"threshold = 0.2\n",
"threshold = 0.05\n",
"while abs(refractive_index_target - result) > threshold:\n",
" df = campaign.recommend(batch_size=1)\n",
" print('New recommendation:')\n",
" print(df)\n",
" print('Testing recommendation...')\n",
" if i > 10:\n",
" break\n",
" print('Start testing recommendation...')\n",
" archive = get_samples(df)\n",
" print('Testing finished!')\n",
" result = archive.refractive_index\n",
" print(f'Testing finished, refractive_index: {result}')\n",
" df['refractive_index'] = [result]\n",
" campaign.add_measurements(df)\n",
" i += 1\n",
"print('Optimization finished!')\n",
"\n",
"# At the end of the run, lets store the whole optimization run into an entry\n",
"archive = EntryArchive()\n",
"bopt = BayesianOptimization.from_baybe_campaign(campaign)\n",
"archive.data = bopt\n",
"bopt.optimization = Optimization(n_steps=1, status='Finished')\n",
"bopt.normalize(archive, None)\n",
"with open('archive.json', 'w') as fout:\n",
" json.dump(archive.m_to_dict(), fout, indent=2)\n"
"with open('example.archive.json', 'w') as fout:\n",
" json.dump(archive.m_to_dict(), fout, indent=2)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"colab": {
"provenance": []
},
"kernelspec": {
"display_name": "Python 3",
"display_name": "nomad",
"language": "python",
"name": "python3"
},
"language_info": {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
# Getting started with Bayesian optimization
# Example optimization tasks

This notebook will teach you how to run a basic Bayesian Optimization task
within NOMAD using remote tools.

- Click on the **FILES** tab and open `notebook.ipynb`.
- Launch notebook in *jupyter*. If jupyter is already running, please press stop and start a new one.
- Follow the notebook for the rest of the tutorial.
This upload contains a set of example Bayesian optimization task entries that
can be explored. These examples have been generated using Jupyter notebook
included in the "Getting started" example upload.
Loading

0 comments on commit 2cc625a

Please sign in to comment.