Skip to content

Commit 60e2567

Browse files
committed
Moved the majority of documentation into the copier-template sphinx build
1 parent f722f7e commit 60e2567

File tree

8 files changed

+259
-358
lines changed

8 files changed

+259
-358
lines changed

INSTALL.rst

Lines changed: 0 additions & 37 deletions
This file was deleted.

README.md

Lines changed: 4 additions & 187 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,9 @@
44
[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://www.apache.org/licenses/LICENSE-2.0)
55

66

7+
# ATIP - Accelerator Toolbox Interface for Pytac
78

8-
==============================================
9-
ATIP - Accelerator Toolbox Interface for Pytac
10-
==============================================
11-
12-
ATIP is an addition to `Pytac <https://github.com/DiamondLightSource/pytac>`_,
9+
ATIP is an addition to [Pytac](<https://github.com/DiamondLightSource/pytac>),
1310
a framework for controlling particle accelerators. ATIP adds a simulator to
1411
Pytac, which can be used and addressed in the same way as a real accelerator.
1512

@@ -26,195 +23,15 @@ controls applications, by either of two methods:
2623
to configure this EPICS port.
2724

2825
The python implementation of
29-
`Accelerator Toolbox <https://github.com/atcollab/at>`_ (pyAT) is used for the
26+
[Accelerator Toolbox](<https://github.com/atcollab/at>) (pyAT) is used for the
3027
simulation.
3128

3229
Source | <https://github.com/DiamondLightSource/atip>
3330
:---: | :---:
3431
PyPI | `pip install atip`
3532
Docker | `docker run ghcr.io/diamondlightsource/atip:latest`
3633
Documentation | <https://diamondlightsource.github.io/atip>
34+
Installation | <https://diamondlightsource.github.io/atip/tutorials/installation>
3735
Releases | <https://github.com/DiamondLightSource/atip/releases>
3836

39-
Installation:
40-
-------------
41-
42-
See the ``INSTALL.rst`` document.
43-
44-
General Use:
45-
------------
46-
47-
ATIP produces an "integrated lattice", which is a Pytac lattice object with a
48-
simulation data source added. The simulated data sources are added using the
49-
``load()`` function found in ``load_sim.py``.
50-
51-
This adds ``pytac.SIM`` data sources on to the lattice and each of the
52-
elements.
53-
54-
The integrated lattice acts like a normal Pytac lattice; the simulator can be
55-
referenced like the live machine but with the data source specified as
56-
``pytac.SIM`` instead of ``pytac.LIVE``.
57-
58-
For example, a get request to a BPM would be
59-
``<bpm-element>.get_value('x', data_source=pytac.SIM)``.
60-
61-
The simulated data sources behave exactly like the live machine, except for a
62-
few cases. For example, the simulator has a number of lattice fields that the
63-
live accelerator doesn't have; and the live machine has a few element fields
64-
that the simulator doesn't.
65-
66-
Example
67-
^^^^^^^
68-
69-
Note that you need an AT lattice that is compatible with Pytac. Some are provided
70-
in ``atip/rings/``, otherwise try running the Matlab function
71-
``atip/rings/create_lattice_matfile.m`` with an AT lattice loaded.
72-
73-
.. code-block:: python
74-
75-
>>> import pytac
76-
>>> import atip
77-
>>> # Load the DIAD lattice from Pytac.
78-
>>> lat = pytac.load_csv.load('DIAD')
79-
>>> # Load the AT sim into the Pytac lattice.
80-
>>> atip.load_sim.load_from_filepath(lat, 'atip/rings/DIAD.mat')
81-
>>> # Use the sim by default.
82-
>>> lat.set_default_data_source(pytac.SIM)
83-
>>> # The initial beam position is zero.
84-
>>> lat.get_value('x')
85-
array([0., 0., 0., ..., 0., 0., 0.])
86-
>>> # Get the first horizontal corrector magnet and set its current to 1A.
87-
>>> hcor1 = lat.get_elements('HSTR')[0]
88-
>>> hcor1.set_value('x_kick', 1, units=pytac.ENG)
89-
>>> # Now the x beam position has changed.
90-
>>> lat.get_value('x')
91-
array([0.00240101, 0.00240101, 0.00239875, ..., 0.00240393, 0.00240327,
92-
0.00240327])
93-
>>>
94-
95-
Virtual Accelerator:
96-
--------------------
97-
98-
Instructions for using ATIP as a virtual accelerator can be found in
99-
``virtac/README.rst``.
100-
101-
Implementation:
102-
---------------
103-
104-
All the accelerator data for the simulator is held in an ``ATSimulator``
105-
object, which is referenced by the data sources of the lattice and each
106-
element.Each Pytac element has an equivalent pyAT element, held in a
107-
``ATElementDataSource``; when a get request is made, the appropriate data from
108-
that AT element is returned.
109-
110-
The ``ATSimulator`` object has a queue of pending changes. When a set request
111-
is received by an element, the element puts the changes onto the queue of the
112-
``ATSimulator``. Inside the ``ATSimulator`` a
113-
`Cothread <https://github.com/DiamondLightSource/cothread>`_ thread checks the
114-
length of the queue. When it sees changes on the queue, the thread
115-
recalculates the physics data of the lattice to ensure that it is up to date.
116-
This means that the emittance and linear optics data held by ``ATSimulator``
117-
is updated after every batch of changes, and that without excessive calculation
118-
a very recent version of the lattice's physics data is always available.
119-
120-
API:
121-
----
122-
123-
load_sim:
124-
* ``load_from_filepath(pytac_lattice, at_lattice_filepath, callback=None)``
125-
- loads the AT lattice from the given filepath to the .mat file and then
126-
calls ``load``.
127-
* ``load(pytac_lattice, at_lattice, callback=None)`` - loads the simulator
128-
onto the passed Pytac lattice, callback is a callable that is passed to
129-
ATSimulator during creation to be called on completion of each round of
130-
physics calculations.
131-
132-
ATElementDataSource:
133-
* ``get_fields()`` - return the fields on the element.
134-
* ``add_field(field)`` - add the given field to this element's data source.
135-
* ``get_value(field)`` - get the value for a given field on the element.
136-
* ``set_value(field, value)`` - set the value for a given field on the
137-
element, appends the change to the queue.
138-
139-
ATLatticeDataSource:
140-
* ``get_fields()`` - return the fields on the lattice.
141-
* ``get_value(field)`` - get the value for a given field on the lattice.
142-
* ``set_value(field, set_value)`` - set the value for a given field on the
143-
lattice, currently not supported so raises HandleException.
144-
145-
ATSimulator:
146-
* ``toggle_calculations()`` - pause or unpause the recalculation thread.
147-
* ``wait_for_calculations(timeout=10)`` - wait up to 'timeout' seconds for
148-
the current calculations to conclude, if they do it returns True, if not
149-
False is returned; if 'timeout' is not passed it will wait 10 seconds.
150-
* ``get_at_element(index)`` - return a shallow copy of the specified AT
151-
element from the central AT ring, N.B. An 'index' of 1 returns ring[0].
152-
* ``get_at_lattice()`` - return a shallow copy of the entire centralised AT
153-
lattice object.
154-
* ``get_s()`` - return the 's position' of every element in the lattice.
155-
* ``get_total_bend_angle()`` - return the total bending angle of all the
156-
dipoles in the lattice.
157-
* ``get_total_absolute_bend_angle()`` - return the total absolute bending
158-
angle of all the dipoles in the lattice.
159-
* ``get_energy()`` - return the energy of the lattice.
160-
* ``get_tune(field)`` - return the specified plane of the lattice's
161-
'tune'; 'x' or 'y'.
162-
* ``get_chromaticity(field)`` - return the specified plane of the lattice's
163-
'chromaticity'; 'x' or 'y'.
164-
* ``get_orbit(field)`` - return the specified plane of the lattice's
165-
'closed orbit'; 'x', 'phase_x', 'y', or 'phase_y'.
166-
* ``get_dispersion()`` - return the 'dispersion' vector for every element
167-
in the lattice.
168-
* ``get_alpha()`` - return the 'alpha' vector at every element in the
169-
lattice.
170-
* ``get_beta()`` - return the 'beta' vector at every element in the
171-
lattice.
172-
* ``get_mu()`` - return 'mu' at every element in the lattice.
173-
* ``get_m44()`` - return the 4x4 transfer matrix for every element in the
174-
lattice.
175-
* ``get_emittance(field)`` - return the specified plane of the lattice's
176-
'emittance'; 'x' or 'y'.
177-
* ``get_radiation_integrals()`` - return the 5 Synchrotron Integrals for
178-
the lattice.
179-
* ``get_momentum_compaction()`` - return the momentum compaction factor
180-
for the lattice.
181-
* ``get_energy_spread()`` - return the energy spread for the lattice.
182-
* ``get_energy_loss()`` - return the energy loss per turn of the lattice.
183-
* ``get_damping_partition_numbers()`` - return the damping partition
184-
numbers for the lattice's three normal modes.
185-
* ``get_damping_times()`` - return the damping times for the lattice's
186-
three normal modes.
187-
* ``get_linear_dispersion_action()`` - return the Linear Dispersion Action
188-
("curly H") for the lattice.
189-
* ``get_horizontal_emittance()`` - return the horizontal ('x') emittance
190-
for the lattice calculated from the radiation integrals.
191-
192-
193-
Specific Notes:
194-
---------------
195-
196-
In order for ATIP to function correctly, the AT and Pytac lattices used must be
197-
directly equivalent, i.e. they must have the same length and elements in the
198-
same positions.
199-
200-
If local (not pip) installations are used, ATIP, AT, and Pytac must all be
201-
located in the same source directory in order for ATIP to function correctly.
202-
203-
The methods on ATIP's data sources that take ``handle`` and ``throw`` arguments
204-
do so only to conform with the Pytac ``DataSource`` base class from which they
205-
inherit. Inside ATIP they are not used and can be ignored.
206-
207-
To interpret which data is to be returned or set, both ``ATElementDataSource``
208-
and ``ATLatticeDataSource`` use a dictionary of functions corresponding to
209-
fields. In the case where a cell needs to be passed to the data handling
210-
functions, for further specification, functools' ``partial()`` is used.
211-
212-
The physics data is received from AT all together; to make it easier to manage,
213-
it is split by ATIP and accessed by a number of methods of the ``ATSimulator``
214-
object. This aims to be more convenient for the user but does result in the
215-
ATSimulator object having a large number of methods.
216-
217-
A number of functions that perform tasks that are frequent or long-winded are
218-
included in ``utils.py`` to make life easier for the user.
219-
22037
<!-- README only content. Anything below this line won't be included in index.md -->

src/virtac/FEEDBACK_SYSTEMS.rst renamed to docs/explanations/feedback_systems

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
================
2-
Feedback Systems
3-
================
1+
# Feedback Systems
2+
43

54
Currently supported "slow" feedback systems at Diamond are:
65

@@ -12,8 +11,7 @@ Currently supported "slow" feedback systems at Diamond are:
1211
In order to support these various feedback systems, the virtual accelerator
1312
makes several adjustments and additions to core ATIP functionality.
1413

15-
Mirrored Records:
16-
-----------------
14+
## Mirrored Records:
1715

1816
The ability to create mirror records is provided. A mirror record can take
1917
value(s) from one or more records as inputs and set its output dependent on
@@ -36,8 +34,7 @@ For more information on mirror records see docstrings of the classes in
3634
``mirror_objects.py``, the relevant methods on ``ATIPServer``, and
3735
``generate_mirrored_pvs`` in ``create_csv.py``.
3836

39-
Masks:
40-
------
37+
## Masks:
4138

4239
Masks are wrappers for existing functions to enable them to be addressed using
4340
a different syntax than normal. The types of masks are:
@@ -54,8 +51,7 @@ a different syntax than normal. The types of masks are:
5451
record object, ``.set(value)`` simply calls ``caput(stored_pv, value)``.
5552

5653

57-
Tune feedback
58-
-------------
54+
## Tune feedback
5955

6056
As mentioned above, the ``callback_offset`` class allows the tune feedback
6157
system to function exactly as it does on the live machine.
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# Implementation:
2+
3+
All the accelerator data for the simulator is held in an ATSimulator object, which is referenced by the data sources of the lattice and each element.Each Pytac element has an equivalent pyAT element, held in a ATElementDataSource; when a get request is made, the appropriate data from that AT element is returned.
4+
5+
The ATSimulator object has a queue of pending changes. When a set request is received by an element, the element puts the changes onto the queue of the ATSimulator. Inside the ATSimulator a Cothread thread checks the length of the queue. When it sees changes on the queue, the thread recalculates the physics data of the lattice to ensure that it is up to date. This means that the emittance and linear optics data held by ATSimulator is updated after every batch of changes, and that without excessive calculation a very recent version of the lattice's physics data is always available.
6+
7+
# API:
8+
9+
load_sim:
10+
11+
load_from_filepath(pytac_lattice, at_lattice_filepath, callback=None) - loads the AT lattice from the given filepath to the .mat file and then calls load.
12+
load(pytac_lattice, at_lattice, callback=None) - loads the simulator onto the passed Pytac lattice, callback is a callable that is passed to ATSimulator during creation to be called on completion of each round of physics calculations.
13+
14+
ATElementDataSource:
15+
16+
get_fields() - return the fields on the element.
17+
add_field(field) - add the given field to this element's data source.
18+
get_value(field) - get the value for a given field on the element.
19+
set_value(field, value) - set the value for a given field on the element, appends the change to the queue.
20+
21+
ATLatticeDataSource:
22+
23+
get_fields() - return the fields on the lattice.
24+
get_value(field) - get the value for a given field on the lattice.
25+
set_value(field, set_value) - set the value for a given field on the lattice, currently not supported so raises HandleException.
26+
27+
ATSimulator:
28+
29+
toggle_calculations() - pause or unpause the recalculation thread.
30+
wait_for_calculations(timeout=10) - wait up to 'timeout' seconds for the current calculations to conclude, if they do it returns True, if not False is returned; if 'timeout' is not passed it will wait 10 seconds.
31+
get_at_element(index) - return a shallow copy of the specified AT element from the central AT ring, N.B. An 'index' of 1 returns ring[0].
32+
get_at_lattice() - return a shallow copy of the entire centralised AT lattice object.
33+
get_s() - return the 's position' of every element in the lattice.
34+
get_total_bend_angle() - return the total bending angle of all the dipoles in the lattice.
35+
get_total_absolute_bend_angle() - return the total absolute bending angle of all the dipoles in the lattice.
36+
get_energy() - return the energy of the lattice.
37+
get_tune(field) - return the specified plane of the lattice's 'tune'; 'x' or 'y'.
38+
get_chromaticity(field) - return the specified plane of the lattice's 'chromaticity'; 'x' or 'y'.
39+
get_orbit(field) - return the specified plane of the lattice's 'closed orbit'; 'x', 'phase_x', 'y', or 'phase_y'.
40+
get_dispersion() - return the 'dispersion' vector for every element in the lattice.
41+
get_alpha() - return the 'alpha' vector at every element in the lattice.
42+
get_beta() - return the 'beta' vector at every element in the lattice.
43+
get_mu() - return 'mu' at every element in the lattice.
44+
get_m44() - return the 4x4 transfer matrix for every element in the lattice.
45+
get_emittance(field) - return the specified plane of the lattice's 'emittance'; 'x' or 'y'.
46+
get_radiation_integrals() - return the 5 Synchrotron Integrals for the lattice.
47+
get_momentum_compaction() - return the momentum compaction factor for the lattice.
48+
get_energy_spread() - return the energy spread for the lattice.
49+
get_energy_loss() - return the energy loss per turn of the lattice.
50+
get_damping_partition_numbers() - return the damping partition numbers for the lattice's three normal modes.
51+
get_damping_times() - return the damping times for the lattice's three normal modes.
52+
get_linear_dispersion_action() - return the Linear Dispersion Action ("curly H") for the lattice.
53+
get_horizontal_emittance() - return the horizontal ('x') emittance for the lattice calculated from the radiation integrals.

docs/tutorials/ATIP_example.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# ATIP example
2+
3+
## Simmulating accelerator physics using ATIP as a data source for Pytac
4+
5+
Note that you need an AT lattice that is compatible with Pytac. Some are provided
6+
in ``atip/rings/``, otherwise try running the Matlab function
7+
``atip/rings/create_lattice_matfile.m`` with an AT lattice loaded.
8+
9+
.. code-block:: python
10+
11+
>>> import pytac
12+
>>> import atip
13+
>>> # Load the DIAD lattice from Pytac.
14+
>>> lat = pytac.load_csv.load('DIAD')
15+
>>> # Load the AT sim into the Pytac lattice.
16+
>>> atip.load_sim.load_from_filepath(lat, 'atip/rings/DIAD.mat')
17+
>>> # Use the sim by default.
18+
>>> lat.set_default_data_source(pytac.SIM)
19+
>>> # The initial beam position is zero.
20+
>>> lat.get_value('x')
21+
array([0., 0., 0., ..., 0., 0., 0.])
22+
>>> # Get the first horizontal corrector magnet and set its current to 1A.
23+
>>> hcor1 = lat.get_elements('HSTR')[0]
24+
>>> hcor1.set_value('x_kick', 1, units=pytac.ENG)
25+
>>> # Now the x beam position has changed.
26+
>>> lat.get_value('x')
27+
array([0.00240101, 0.00240101, 0.00239875, ..., 0.00240393, 0.00240327,
28+
0.00240327])
29+
>>>

0 commit comments

Comments
 (0)