You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 10 Next »

Overview

This page summarizes the design & implementation of the inference between the live FACET-II controls system and the FACET2E Bmad model.

Code is still WIP. Design details here are subject to change.

BmadLiveModel

The BmadLiveModel python class loads the FACET2E lattice and runs a local copy of Tao. The object connects to the production controls system via EPICS Channel Access and instantiates 4 daemon threads, three of which will monitor the controls system for live magnet/RF data and set devices in Tao accordingly, and a fourth which writes new model data to python data structures.

Modes of use

The BmadLiveModel can be used in three distinct modes, depending on the input flags at construction:

Modekw argCode snippetNotes
design model onlydesign_onlyf2m = BmadLiveModel(design_only=True)totally static, contents of BmadLiveModel.live will be identical to .design
live model data with manual updatesinstanced

f2m = BmadLiveModel(instanced=True)

f2m.update_model_data()

# --> your code here

This mode is designed for making lattice tweaks in Tao relative to extant machine settings, might be an edge-case use...
live model data with real-time streaming

with BmadLiveModel() as f2m:

    # --> your code here

Use of the context manager is the "most pythonic" practice, but manual start() and stop() functions are also defined


Daemon process design

Controls system communication is asynchronous to maximize update frequency. Responsibility of each thread should be designed for load balancing, to maximize the live model response time.

At each iteration, the watcher threads will:

  1. check the PVs associated with every live device they are responsible for setting
  2. check if device setting has changed beyond some tolerance (exact tolerance band could be device dependent, picked to prevent analog/digital noise from prompting constant updates)
  3. push tao commands to a shared queue of updates (how implement?)

Separately, the model-update thread will do the following at each iteration:

  1. read in and execute the queue of tao commands
  2. write new data to the BmadLiveModel.live data structure
Nameresponsibilitynotes
rf-watcher
  • Monitor all linac subbooster & klystron amplitudes and phases (excepting TCAVs)
  • set cavity voltages and lag times in Tao accordingly
main challenge here is going from overall klystron ampl/phase to parameters for A/B/C/D structures
mag1-watcher
  • Monitor all quadrupole magnets
  • set field strengths in Tao
is converting from integrated field strength in kGm as simple as dividing by L_eff ???
mag2-watcher
  • Monitor corrector magnets and any other miscellaneous magnets
  • set field strengths in Tao
other stuff: solenoid, sextupoles, skew devices?
model-update
  • execute queued Tao commands
  • Update the BmadLiveModel.live data structure
needs exclusive write access to model data structs to avoid races, resource starvation etc...

F2 Live Model Server

The live model server runs its own BmadLiveModel, and periodically writes live model data for NTTables accessible on the controls system via EPICS PVAccess. The table PVs are as follows

PV nametable columnsnotes
BMAD:SYS0:1:FACET2E:LIVE:TWISSelement, device_name, s, z, length, p0c, alpha_x, beta_x, eta_x, etap_x, psi_x,  alpha_y, ..., psi_ynot sure if s and z are both helpful
BMAD:SYS0:1:FACET2E:LIVE:RMATelement, device_name, s, z, length, r11, r12, r13, r14, r15, r16, r21, r22, ..., r65, r66
BMAD:SYS0:1:FACET2E:DESIGN:TWISSelement, device_name, s, z, length, p0c, alpha_x, beta_x, eta_x, etap_x, psi_x,  alpha_y, ..., psi_y
BMAD:SYS0:1:FACET2E:DESIGN:RMATelement, device_name, s, z, length, r11, r12, r13, r14, r15, r16, r21, r22, ..., r65, r66
BMAD:SYS0:1:FACET2E:LEM_DATAelement, device_name, EREF, EACT, BREF, BACT, BERR, more ??single NTTable seems simpler than lcls-style per-device PVs


Implementation details


Source: F2_live_model/Details
~/structs.pyauxiliary data structures for holding beamline data
~/bmad.pyimplements the BmadLiveModel class
~/server.pylive model PVA service
~/receiver.pycontains functions for getting data from the live model PVA server (analogous to F2_ModelReceiver.m)
  • No labels