{ "cells": [ { "cell_type": "markdown", "id": "0", "metadata": {}, "source": [ "# KB Mirrors\n", "\n", "This example simulates the alignment of a KB mirror endstation (with four degrees of freedom)." ] }, { "cell_type": "code", "execution_count": null, "id": "1", "metadata": {}, "outputs": [], "source": [ "from blop.utils import prepare_re_env # noqa\n", "\n", "%run -i $prepare_re_env.__file__ --db-type=temp\n", "bec.disable_plots()" ] }, { "cell_type": "code", "execution_count": null, "id": "2", "metadata": {}, "outputs": [], "source": [ "from blop.sim import Beamline\n", "\n", "beamline = Beamline(name=\"bl\")" ] }, { "cell_type": "code", "execution_count": null, "id": "3", "metadata": {}, "outputs": [], "source": [ "from blop import DOF, Agent, Objective\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": "4", "metadata": {}, "outputs": [], "source": [ "RE(agent.learn(\"qei\", n=4, iterations=4))" ] }, { "cell_type": "code", "execution_count": null, "id": "5", "metadata": {}, "outputs": [], "source": [ "plt.imshow(agent.best.bl_det_image)" ] }, { "cell_type": "code", "execution_count": null, "id": "6", "metadata": {}, "outputs": [], "source": [ "agent.plot_objectives(axes=(2, 3))" ] } ], "metadata": { "kernelspec": { "display_name": "blop-dev", "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.8" } }, "nbformat": 4, "nbformat_minor": 5 }