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

Add simulated hardware #69

Merged
merged 9 commits into from
Jul 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 2 additions & 2 deletions .github/workflows/testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ on:
push:
pull_request:
workflow_dispatch:
# schedule:
# - cron: '00 4 * * *' # daily at 4AM
schedule:
- cron: '00 6 * * *' # daily at 6AM UTC

jobs:
run_tests:
Expand Down
1 change: 1 addition & 0 deletions docs/source/tutorials.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ Tutorials
tutorials/hyperparameters.ipynb
tutorials/pareto-fronts.ipynb
tutorials/passive-dofs.ipynb
tutorials/kb-mirrors.ipynb
2 changes: 1 addition & 1 deletion docs/source/tutorials/hyperparameters.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.0"
"version": "3.11.9"
},
"vscode": {
"interpreter": {
Expand Down
142 changes: 142 additions & 0 deletions docs/source/tutorials/kb-mirrors.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
{
"cells": [
{
"cell_type": "markdown",
"id": "c1ac0e4b-d065-41af-97ec-b73bbc7dad7d",
"metadata": {},
"source": [
"# Hyperparameters\n",
"\n",
"This example simulates the alignment of a KB mirror endstation (with four degrees of freedom)."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "2a1798fa-b251-409e-9d2d-097240372b03",
"metadata": {},
"outputs": [],
"source": [
"from blop.utils import prepare_re_env\n",
"\n",
"%run -i $prepare_re_env.__file__ --db-type=temp\n",
"bec.disable_plots()"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "0ca926ab-5859-49f3-a96a-73c401cc18e6",
"metadata": {},
"outputs": [],
"source": [
"from blop.sim import Beamline\n",
"\n",
"beamline = Beamline(name=\"bl\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "28ee6cfc-428a-4472-b503-bb072f939866",
"metadata": {},
"outputs": [],
"source": [
"from blop import DOF, Objective, Agent\n",
"from blop.digestion import beam_stats_digestion\n",
"\n",
"dofs = [\n",
" DOF(description=\"KBV downstream\", device=beamline.kbv_dsv, search_domain=(-5.0, 5.0)),\n",
" DOF(description=\"KBV upstream\", device=beamline.kbv_usv, search_domain=(-5.0, 5.0)),\n",
" DOF(description=\"KBH downstream\", device=beamline.kbh_dsh, search_domain=(-5.0, 5.0)),\n",
" DOF(description=\"KBH upstream\", device=beamline.kbh_ush, search_domain=(-5.0, 5.0)),\n",
"]\n",
"\n",
"objectives = [\n",
" Objective(name=\"bl_det_sum\", target=\"max\", transform=\"log\", trust_domain=(200, np.inf)),\n",
" Objective(name=\"bl_det_wid_x\", target=\"min\", transform=\"log\", latent_groups=[(\"bl_kbh_dsh\", \"bl_kbh_ush\")]),\n",
" Objective(name=\"bl_det_wid_y\", target=\"min\", transform=\"log\", latent_groups=[(\"bl_kbv_dsv\", \"bl_kbv_usv\")]),\n",
"]\n",
"\n",
"agent = Agent(\n",
" dofs=dofs,\n",
" objectives=objectives,\n",
" detectors=[beamline.det],\n",
" digestion=beam_stats_digestion,\n",
" digestion_kwargs={\"image_key\": \"bl_det_image\"},\n",
" verbose=True,\n",
" db=db,\n",
" tolerate_acquisition_errors=False,\n",
" enforce_all_objectives_valid=True,\n",
" train_every=3,\n",
")\n",
"\n",
"(uid,) = RE(agent.learn(\"qr\", n=32))"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "491636be-1e04-45a2-a622-dc21e192d208",
"metadata": {},
"outputs": [],
"source": [
"RE(agent.learn(\"qei\", n=4, iterations=4))"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "d6434fc9-682a-45fa-b100-465dfda3aff1",
"metadata": {},
"outputs": [],
"source": [
"plt.imshow(agent.best.bl_det_image)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "ef89c0cd-65be-4d1f-ab6d-c8a4ce251d7b",
"metadata": {},
"outputs": [],
"source": [
"agent.plot_objectives(axes=(2, 3))"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "fb56db05-0fe5-46a5-8435-383f1e34f55d",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3.12.2 64-bit",
"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.12.2"
},
"vscode": {
"interpreter": {
"hash": "b0fa6594d8f4cbf19f97940f81e996739fb7646882a419484c72d19e05852a7e"
}
}
},
"nbformat": 4,
"nbformat_minor": 5
}
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,14 @@ maintainers = [
requires-python = ">=3.9"

dependencies = [
"area-detector-handlers",
"bluesky",
"botorch",
"databroker",
"gpytorch",
"h5py",
"matplotlib",
"numpy",
"numpy<2",
"ophyd",
"ortools",
"scipy",
Expand Down
Loading
Loading