You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: tests/tests/test-ptc-maps/readme.md
+42-13Lines changed: 42 additions & 13 deletions
Original file line number
Diff line number
Diff line change
@@ -1,35 +1,61 @@
1
1
Building a test for an element
2
2
------------------------------
3
3
4
-
To create a test for a single element, there are two main components that need to be created; the sequence and the configuration specific to the element.
4
+
To create a test for a single element, there is a single component that is required; an object containing the configuration of the test. This object must hold the following information:
5
+
6
+
* A string, named `elm`, containing the MAD-X element definition, with the parameters to be tested as part of the string, ready to be formatted with the configuration table, see below.
7
+
* An array part, named `alist` for attribute list, within the object, containing the names of the parameters to be tested.
8
+
* The hash part of the object, containing an *iterable* for each parameter, see below.
9
+
10
+
Since the array part and the hash part also need to contain the reference parameters, the configuration object specific to your test must inherit from ref_cfg, which is a table that contains the reference parameters. To take from reference `alist`, you must use the `tbl_cat` function, see below.
5
11
6
12
The sequence is a string that contains the MAD-X script to create the element that you desire to test, with all the necessary parameters, the parameters can be assigned through formatting with the configuration table. For example, a quadrupole with the parameters `k1`, `k1s``fringe` and `tilt` can be created with the following string:
7
13
```
8
-
local elm_str = "QUADRUPOLE, at=0.75, l=1.5, k1=${k1}, k1s=${k1s}, tilt=${tilt}*pi/8, fringe=${fringe}"
The configuration table is a table that contains the names of the parameters and therefore keys in the array part of the table, and the values attached to the parameter name in the hash part of the table, see the example below;
12
-
17
+
Below is an example of a configuration object for a quadrupole, with the parameters `k1`, `k1s``fringe` and `tilt`:
13
18
```
14
-
quad_cfg = {
15
-
"tilt", "fringe", "k1", "k1s",
19
+
local cfg = ref_cfg "quadrupole" {
20
+
elm = " QUADRUPOLE, at=0.75, l=1.5, k1=${k1}, k1s=${k1s}, tilt=${tilt}*pi/8, fringe=${fringe}",
Then this can be combined with the reference table using ``tbl_cat(ref_cfg, quad_cfg)`` to create a table that contains all the parameters for the element. The reference table contains the parameters that are common to all elements, such as the energy, the number of slices, the initial conditions, etc. To change the reference table, you must copy the table using ``tblcopy`` and then change the values in the copy, as the reference table is used by all the tests.
32
+
Above shows the required parts of the object, the element string, tolerance, an extended attribute list and the parameters with their ranges. The tolerance is the number that the difference between the maps is compared to, it is multiplied by your machine epsilon (`eps`) to get the number to compare to. The tolerance is optional as the default is 1000. If the tolerance is set to a string then the test will try to read the tolerance from a file with the same name as the tolerance string
33
+
34
+
Finally, the test is run by calling ``run_test(cfg)``.
35
+
36
+
How the tests work
37
+
------------------
38
+
39
+
The entry function to running the tests is inventively called `run_test`. This function takes a configuration object as the only argument. Within this function the following steps are taken:
40
+
41
+
1. Checks if cfg.dorun is not nil or false, if it is, then the function prints the previous results from the previous run and returns.
42
+
2. An mtable with 2 columns is created, the first column will store the configuration snapshots, while the second column will store the results of each configuration snapshot.
43
+
3. The configuration snapshots are created using a recursive function that takes the configuration object and creates the snapshots and runs the function `run_cfg` on each snapshot.
44
+
The function `run_cfg` takes a configuration snapshot and does the following:
45
+
1. Calls `do_trck`, which runs track and ptc to get the difference between MAD and PTC, then stores the results in a table and returns it.
46
+
2. Stores the configuration snapshot and the results into the mtable.
47
+
3. If cfg.doprnt then the results are printed to the console in a single line per config.
48
+
4. If cfg.dodbg then the results are compared to the tolerance, if the results are outside the tolerance then the test stops and the results are printed to the console.
49
+
4. Now the mtable has been filled with the results of each configuration snapshot, we create the generator columns for the mtable, which link the tables of each configuration snapshot and the results to a column in the mtable.
50
+
5. If cfg.dosave or the file does not exist then the mtable is saved to a file with the name of the element appended with `_cfg` or `_res` for the configuration snapshots and the results respectively.
51
+
6. If cfg.doprnt then a summary of the results is printed to the console. (See below for an example of the summary)
52
+
7. If the test has not been stopped by cfg.dodbg then several excess files are removed.
24
53
25
-
Finally, the test is run by calling ``run_test(element, elm_str, cfg, tol_)``, where `element` is the element object that would like to be tested, `elm_str` is the string that contains the MAD-X script to create the element, `cfg` is the total configuration table, and `tol_` is the (optional) tolerance for the test. This test will first create the config mtable then loop through the config, creating a file called ``element.seq`` that is called by MAD-X and MAD-NG. The final map is then gathered from the mflow in MAD-NG and from the debug output of MAD-X-PTC to be compared and stored into a max dif mtable, which is then saved to a file called ``element_name_max_err.tfs`` at the end of the test.
26
54
27
55
Running the tests
28
56
-----------------
29
57
30
-
To run the test, just call the element function with a optionally a tolerance as the only argument. The tolerance should be an integer, as the number that the difference between the maps is compared to is this tolerance multiplied by your machine epsilon (`eps`).
31
-
32
-
For example, ``testQUAD(1000)`` will run the test `testQUAD` (the quadrupole) with a tolerance of `1000*eps`.
58
+
To run the test, just call the element function For example, ``testQUAD()`` will run the test `testQUAD` (the quadrupole).
33
59
34
60
There are four flags that can be used to control how your tests run and the reported results:
35
61
@@ -44,11 +70,14 @@ There are four flags that can be used to control how your tests run and the repo
44
70
>require "madl_dbgmap".cmpmdump("element_name")
45
71
>```
46
72
47
-
With the `doprnt=true`, you will also receive a final output. This output is the sum of all the failures for each order, for each column of your config. The idea of this sum is to give you an idea of what is causing the failure. For example, see the output below for a quadrupole (truncated at order 0), run on linux with ``testQUAD(1000)`` as the input command.
73
+
With the `doprnt=true`, you will also receive a final output. This output is the sum of all the failures for each order, for each column of your config. The idea of this sum is to give you an idea of what is causing the failure. For example, see the output below for a quadrupole (truncated at order 0), run on linux with ``testQUAD()`` as the input command.
0 commit comments