Skip to content

Data and Variables in Tao

ChristopherMayes edited this page Sep 6, 2017 · 9 revisions

Data

In order to optimize, you must tell Tao what quantities that you want to calculate that will contribute to the merit function. The basic structure has several: d2_data, which contains d1_data, which contains individual datums. You input these in the tao.init file as:

&tao_d2_data
    d2_data%name = 'twiss'
    n_d1_data = 2
/
&tao_d1_data
    ix_d1_data = 1
    d1_data%name = 'end'
    datum( 1) =  'beta.a'     '' '' 'END'   'target'  12.5   1e1  
    datum( 2) =  'alpha.a'    '' '' 'END'   'target'  -1     1e2
/ 
&tao_d1_data
    ix_d1_data = 2
    d1_data%name = 'max'
    datum( 1) =  'beta.a'    '' 'Q1' 'END'   'max'  100   1e1
    datum( 2) =  'eta.x'     '' 'Q1' 'END'   'abs_max'  1     1e2
/ 

The first datum means that beta.a at element END should be 12.5 m with a weight of 10. If the model beta function is, say, 20 m at element END, then this datum would contribute 10*(20 - 12.5)^2 to the merit function.

The columns of an individual datum(i) are a shorthand input of the datum structure (type 'getf tao_datum_input' on the command line to see a full list). The columns are:

data_type       ! Type of data: 'orbit.x', etc.
ele_ref_name    ! Name of reference lattice element
ele_start_name  ! Name of starting lattice element when there is a range
ele_name        ! Name of the lattice element where datum is evaluated.
merit_type      ! Type of constraint: 'target', 'max', 'min', etc.
meas            ! Measured datum value.
weight          ! Weight for the merit function term

In Tao, these can be shown with:

Tao> show dat

  Name                                 Using for Optimization
  twiss.end[1:6]                                 Using: 1:6
  twiss.max[1:2]                                 Using: 1:2

Variables

Variables must be defined in order to optimize. The simplest possible variable definition is:

&tao_var
  v1_var%name = 'quad'
  default_step = 1e-4
  default_attribute = 'k1'
  search_for_lat_eles = 'Quad::*'
  ! or: 
  ! var(1:)%ele_name = 'Q1', 'Q2', 'Q3', 'Q4', 'Q5', 'Q6'
/

This will search the lattice of all quadrupole key elements, and control their 'k1' attribute with a step of 1e-4.

In tao you will then see (if the elements exist) the variables in a short notation:

Tao> sho var
       Name                                      Using for Optimization
    quad[1:6]

or a more detailed list:

Tao> sho var quad
Variable name:  quad

 Index  Controlled Attributes(s)    Meas         Model        Design  Useit_opt
     1  Q1[K1]                  8.6924-311    0.0000E+00    0.0000E+00       F
     2  Q2[K1]                  8.6924-311    0.0000E+00    0.0000E+00       F
     3  Q3[K1]                  8.6924-311    0.0000E+00    0.0000E+00       F
     4  Q4[K1]                  8.6924-311    0.0000E+00    0.0000E+00       F
     5  Q5[K1]                  8.6924-311    0.0000E+00    0.0000E+00       F
     6  Q6[K1]                  8.6924-311    0.0000E+00    0.0000E+00       F
 Index  Controlled Attributes(s)    Meas         Model        Design  Useit_opt

A tao_var is an array of variables, each of which can have individually set attributes. Type:

Tao> sho var quad[2]
%ele_name         = Q2
%attrib_name      = K1
...

to see a complete list. Prepending: 'default_' in front of any of these in the variable definition will flag all variables to have the same property, like 'k1'.

Variables can also have mixed properties, as in:

var(1:4)%ele_name = 'FF.Qua01',  'FF.Qua02',  'FF.Qua02',  'O_quad_length'
var(1:4)%attribute = 'b1_gradient', 'b1_gradient', 'x_offset', 'f'
var(1:4)%key_delta = 0.1, 0.1, 0.0001, .01
var(1:4)%low_lim = -50, -50, -.1, .2
var(1:4)%high_lim = 50,  50,  .1, .8

Variable properties can also be changed within Tao. For example,

Tao> set var quad[1:4]|low_lim = -1

will set the lower limit for the first four quads.


Key bound variables

An alternative use for variables is to bind them to keys on the keyboard for use in Tao's 'Single Mode'. The two properties to set are %key_bound and %key_delta. In the input file, adding these properties as:

&tao_var
  v1_var%name = 'quad'
  ...
  default_key_bound = T
  default_key_delta = 1e-2
/

Will then bind these variables to the keyboard keys 1-9, Q-O in single mode. For example,

Tao> single
Entering Single Mode...
11>>111>>11qq>>>11

Enters single mode, and 1 raises the variable quad[1] by 1e-2, and q (the key under 1 on the keyboard) lowers it. The > and < signs change the default step by a factor of 2 or 1/2, which is useful when you would like the keys to make larger or smaller steps. The '11>>111>>11qq>>>11' is a history of what was pressed.

To quit single mode, type upper case Z:

Z
Entering line mode...

Tao>