|
| 1 | +{ |
| 2 | + "cells": [ |
| 3 | + { |
| 4 | + "cell_type": "markdown", |
| 5 | + "id": "d3621c17", |
| 6 | + "metadata": {}, |
| 7 | + "source": [ |
| 8 | + "# Live/Design: control modes\n", |
| 9 | + "\n", |
| 10 | + "With *pyAML* it is possible to use the same commands either:\n", |
| 11 | + "1. live: on the real accelerator\n", |
| 12 | + "2. design: in simulations\n", |
| 13 | + "3. errors: in simulations with errors (and for several seeds)\n", |
| 14 | + "4. live (with a different prefix/host): in a virtual control system (same as in point 1. for those laboratories that have a simulated control system)\n", |
| 15 | + "\n", |
| 16 | + "Those are called \"control modes\" and may be used \n", |
| 17 | + "- at a global script level (for testing in simulations and then using in real accelerator measurements with a simple switch/comment) \n", |
| 18 | + "- anywhere in the script " |
| 19 | + ] |
| 20 | + }, |
| 21 | + { |
| 22 | + "cell_type": "markdown", |
| 23 | + "id": "805b0f6c", |
| 24 | + "metadata": {}, |
| 25 | + "source": [ |
| 26 | + "Using pyAML on a real accelerator" |
| 27 | + ] |
| 28 | + }, |
| 29 | + { |
| 30 | + "cell_type": "code", |
| 31 | + "execution_count": null, |
| 32 | + "id": "c4884e24", |
| 33 | + "metadata": {}, |
| 34 | + "outputs": [], |
| 35 | + "source": [ |
| 36 | + "from pyaml.pyaml import pyaml,PyAML\n", |
| 37 | + "from pyaml.instrument import Instrument\n", |
| 38 | + "from pyaml.configuration.factory import Factory\n", |
| 39 | + "import numpy as np" |
| 40 | + ] |
| 41 | + }, |
| 42 | + { |
| 43 | + "cell_type": "markdown", |
| 44 | + "id": "b8ff1736", |
| 45 | + "metadata": {}, |
| 46 | + "source": [ |
| 47 | + "instantiate a pyAML accelerator" |
| 48 | + ] |
| 49 | + }, |
| 50 | + { |
| 51 | + "cell_type": "code", |
| 52 | + "execution_count": null, |
| 53 | + "id": "fc1881d9", |
| 54 | + "metadata": {}, |
| 55 | + "outputs": [], |
| 56 | + "source": [ |
| 57 | + "ml:PyAML = pyaml('../../tests/config/EBSTune.yaml')\n", |
| 58 | + "SR:Instrument = ml.get('sr')" |
| 59 | + ] |
| 60 | + }, |
| 61 | + { |
| 62 | + "cell_type": "markdown", |
| 63 | + "id": "9a3c6e0a", |
| 64 | + "metadata": {}, |
| 65 | + "source": [ |
| 66 | + "Switch between live and design" |
| 67 | + ] |
| 68 | + }, |
| 69 | + { |
| 70 | + "cell_type": "code", |
| 71 | + "execution_count": null, |
| 72 | + "id": "21ce8527", |
| 73 | + "metadata": {}, |
| 74 | + "outputs": [], |
| 75 | + "source": [ |
| 76 | + "# sr = SR.live # use real accelerator\n", |
| 77 | + "sr = SR.design # run script in simulations" |
| 78 | + ] |
| 79 | + }, |
| 80 | + { |
| 81 | + "cell_type": "markdown", |
| 82 | + "id": "4e55d6b6", |
| 83 | + "metadata": {}, |
| 84 | + "source": [ |
| 85 | + "access some magnet families defined in the configuration" |
| 86 | + ] |
| 87 | + }, |
| 88 | + { |
| 89 | + "cell_type": "code", |
| 90 | + "execution_count": null, |
| 91 | + "id": "b1fb943f", |
| 92 | + "metadata": {}, |
| 93 | + "outputs": [], |
| 94 | + "source": [ |
| 95 | + "\n", |
| 96 | + "quadForTuneDesign = sr.get_magnets(\"QForTune\")\n", |
| 97 | + "quadForTuneLive = sr.get_magnets(\"QForTune\")\n" |
| 98 | + ] |
| 99 | + }, |
| 100 | + { |
| 101 | + "cell_type": "markdown", |
| 102 | + "id": "fdc66eea", |
| 103 | + "metadata": {}, |
| 104 | + "source": [ |
| 105 | + "Execute actions with the magnets families (here for example a tune response matrix is evaluated)" |
| 106 | + ] |
| 107 | + }, |
| 108 | + { |
| 109 | + "cell_type": "code", |
| 110 | + "execution_count": null, |
| 111 | + "id": "d6dc44d3", |
| 112 | + "metadata": {}, |
| 113 | + "outputs": [], |
| 114 | + "source": [ |
| 115 | + "# Build tune response matrix\n", |
| 116 | + "tune = sr.get_lattice().get_tune()\n", |
| 117 | + "\n", |
| 118 | + "print(tune)\n", |
| 119 | + "tunemat = np.zeros((len(quadForTuneDesign),2))\n", |
| 120 | + "\n", |
| 121 | + "for idx,m in enumerate(quadForTuneDesign):\n", |
| 122 | + " str = m.strength.get()\n", |
| 123 | + " m.strength.set(str+1e-4)\n", |
| 124 | + " dq = sr.get_lattice().get_tune() - tune\n", |
| 125 | + " tunemat[idx] = dq*1e4\n", |
| 126 | + " m.strength.set(str)" |
| 127 | + ] |
| 128 | + }, |
| 129 | + { |
| 130 | + "cell_type": "markdown", |
| 131 | + "id": "bf75c939", |
| 132 | + "metadata": {}, |
| 133 | + "source": [ |
| 134 | + "At any point in the code it is always possible to still access any of the control modes" |
| 135 | + ] |
| 136 | + }, |
| 137 | + { |
| 138 | + "cell_type": "code", |
| 139 | + "execution_count": null, |
| 140 | + "id": "b5cec1f2", |
| 141 | + "metadata": {}, |
| 142 | + "outputs": [], |
| 143 | + "source": [ |
| 144 | + "print(sr.get_tune()) # what ever the globally set mode whas\n", |
| 145 | + "\n", |
| 146 | + "SR.design.get_tune() # tune from design simulations \n", |
| 147 | + "\n", |
| 148 | + "SR.live.get_tune() # tune from real accelerator" |
| 149 | + ] |
| 150 | + } |
| 151 | + ], |
| 152 | + "metadata": { |
| 153 | + "kernelspec": { |
| 154 | + "display_name": "pyaml_venv", |
| 155 | + "language": "python", |
| 156 | + "name": "python3" |
| 157 | + }, |
| 158 | + "language_info": { |
| 159 | + "codemirror_mode": { |
| 160 | + "name": "ipython", |
| 161 | + "version": 3 |
| 162 | + }, |
| 163 | + "file_extension": ".py", |
| 164 | + "mimetype": "text/x-python", |
| 165 | + "name": "python", |
| 166 | + "nbconvert_exporter": "python", |
| 167 | + "pygments_lexer": "ipython3", |
| 168 | + "version": "3.14.0" |
| 169 | + } |
| 170 | + }, |
| 171 | + "nbformat": 4, |
| 172 | + "nbformat_minor": 5 |
| 173 | +} |
0 commit comments