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

Compare with Current View Page History

« Previous Version 24 Next »

Overview

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

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

GitHub mirror: F2_live_model.git

API documentation: f2-live-model.readthedocs.io/

BmadLiveModel

The BmadLiveModel python class loads the FACET2E lattice and runs a local copy of Tao.v This object connects to the production controls system via EPICS Channel Access, and connects callback functions to each live quantity (PV) of interest. When live quantities change, these callbacks will submit tao update commands to a shared queue. Additionally, a daemon thread will periodically empty the queue and execute all the scheduled update commands and then update the BmadLiveModel.live data structure.

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_only
f2m = BmadLiveModel(design_only=True)
static data only, BmadLiveModel.live is not defined
live model data with manual updatesinstanced
f2m = BmadLiveModel(instanced=True)
f2m.refresh_all()
# --> your code here
This mode is designed for making lattice tweaks in Tao relative to extant machine settings
live model data with real-time streaming
f2m = BmadLiveModel()
f2m.start()
# --> your code here
f2m.stop

or:

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.

Upon PV value change, each callback function will

  1. convert the new value into Bmad units (i.e. from kGm → T, GeV → eV etc)
  2. generate a tao command string of the form: "set ele <element> -attr <attribute> = <value>"
  3. submit the update command to the command queue

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

  1. empty the command queue of (approximately*) all submitted commands
  2. disable lattice recalculation, run all the set ele commands, then re-enable lattice recalculation (and recalculate lattice parameters)
  3. update the live.p0c, live.e_tot, live.twiss, live.quads, live.xcors, live.ycors, live.bends, live.rf  data structures (← or update on request?)

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

Access to the live Bmad model server (for twiss/rmat data), should be provided through the python meme service

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
  • No labels