-
Notifications
You must be signed in to change notification settings - Fork 9
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 #69 from thomaswmorris/simulated-hardware
Add simulated hardware
- Loading branch information
Showing
19 changed files
with
588 additions
and
443 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
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 |
---|---|---|
@@ -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 | ||
} |
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
Oops, something went wrong.