Skip to content

Improve Test System #407

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Sep 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions tests/tests/test-ng-maps/cleanup.mad
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
local filesys in MAD
local clean_plots = false
local clean_results = true
local clean_configs = true
MAD.warn(
"Cleaning up" ..
(clean_plots and " plots," or "") ..
(clean_results and " results," or "") ..
(clean_configs and " configs," or "") ..
" and all txt files in output/"
)

for filename in filesys.dir ("output/") do
if clean_results and filename:find("_res.tfs") then
os.remove("output/"..filename)
elseif clean_configs and filename:find("_cfg.tfs") then
os.remove("output/"..filename)
elseif filename:find(".txt") then
os.remove("output/"..filename)
end
end

if clean_plots then
for filename in filesys.dir ("output/plots/") do
os.remove("output/plots/"..filename)
end
end
os.remove("TMP_MAD_PLOT")
os.remove("setup1.out")
os.remove("output/setup1.mad")
os.remove("setup2.out")
os.remove("output/setup2.mad")
6 changes: 4 additions & 2 deletions tests/tests/test-ng-maps/test-all-maps.mad
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,7 @@ Usage of directions:

-- list of test suites (see src/madl_main.mad)
local modules = {
"curved", "electric", "fringe", "misalignment", "misc", "multipole", "patch",
"subelm"
"curv", "elec", "fringe", "mis", "misc", "patch", "straight", "subelm"
}

-- allow global access
Expand Down Expand Up @@ -97,6 +96,9 @@ MAD.strict()
local parse_cmd_args, run_tests in require("testvsng")
if parse_cmd_args() then return run_tests() end

ref_cfg.do_utest = true -- Unittest setup
ref_cfg.doplot = true -- Unittest setup

-- run test suites
local status = MAD.utest.LuaUnit.run()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,6 @@ local run_test in require("trackvsng")
-- The tests ------------------------------------------------------------------o
TestCurved = {}

function TestCurved:setUp()
-- Turn off all unnecessary components for unit testing
ref_cfg.dodbg = false
ref_cfg.doprnt = 0
ref_cfg.dosave = false

-- Turn on the components for unit testing
ref_cfg.dorun = true
ref_cfg.do_utest = true
ref_cfg.doplot = true
end

function TestCurved:testSBEND() -- Test the body (~2 min)
local cfg = ref_cfg "sbend" {
elm = [[sbend 'sbend' {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,6 @@ local run_test in require("trackvsng")
-- The tests ------------------------------------------------------------------o
TestElectric = {}

function TestElectric:setUp()
-- Turn off all unnecessary components for unit testing

ref_cfg.dodbg = false
ref_cfg.doprnt = 0
ref_cfg.dosave = false

-- Turn on the components for unit testing
ref_cfg.dorun = true
ref_cfg.do_utest = true
ref_cfg.doplot = true
end

function TestElectric:testRFMULTIPOLE()
local cfg = ref_cfg "rfmultipole" {
elm = [[${element} 'rfm' {
Expand Down
12 changes: 0 additions & 12 deletions tests/tests/test-ng-maps/test-fringe-maps.mad
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,6 @@ local run_test in require("trackvsng")
-- The tests ------------------------------------------------------------------o
TestFringes = {}

function TestFringes:setUp()
-- Turn off all unnecessary components for unit testing
ref_cfg.dodbg = false
ref_cfg.doprnt = 0
ref_cfg.dosave = false

-- Turn on the components for unit testing
ref_cfg.dorun = true
ref_cfg.do_utest = true
ref_cfg.doplot = true
end

function TestFringes:testQUADfQSAD ()
local qsad in fringe
fringe.qsad = 4
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,6 @@ local run_test in require("trackvsng")
-- The tests ------------------------------------------------------------------o
TestMis = {} --backtrack has high error (1e-12) for straight elements

function TestMis:setUp()
-- Turn off all unnecessary components for unit testing
ref_cfg.dodbg = false
ref_cfg.doprnt = 0
ref_cfg.dosave = false

-- Turn on the components for unit testing
ref_cfg.dorun = true
ref_cfg.do_utest = true
ref_cfg.doplot = true
end

function TestMis:testSBENDtrans() -- Test the body (~2 min)
local cfg = ref_cfg "sbend_trans" {
elm = [[sbend 'sbend' {
Expand Down
12 changes: 0 additions & 12 deletions tests/tests/test-ng-maps/test-misc-maps.mad
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,6 @@ local run_test in require("trackvsng")
-- The tests ------------------------------------------------------------------o
TestMisc = {}

function TestMisc:setUp()
-- Turn off all unnecessary components for unit testing
ref_cfg.dodbg = false
ref_cfg.doprnt = 0
ref_cfg.dosave = false

-- Turn on the components for unit testing
ref_cfg.dorun = true
ref_cfg.do_utest = true
ref_cfg.doplot = true
end

function TestMisc:testKICKER()
local cfg = ref_cfg "kicker" {
elm = "kicker 'kicker' {at=0.75, l=1.5, hkick=${bdir}*${hkick}, vkick=${bdir}*${vkick}}",
Expand Down
12 changes: 0 additions & 12 deletions tests/tests/test-ng-maps/test-patch-maps.mad
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,6 @@ local run_test in require("trackvsng")
-- The tests ------------------------------------------------------------------o
TestPatch = {}

function TestPatch:setUp()
-- Turn off all unnecessary components for unit testing
ref_cfg.dodbg = false
ref_cfg.doprnt = 0
ref_cfg.dosave = false

-- Turn on the components for unit testing
ref_cfg.dorun = true
ref_cfg.do_utest = true
ref_cfg.doplot = true
end

function TestPatch:testROTATION()
local cfg = ref_cfg "rot" {
elm = "${dir}rotation 'rot' {at=${at}, angle=${tdir}*math.pi/${_angle}}",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,9 @@ local tblcat in MAD.utility
local run_test in require("trackvsng")

-- The tests ------------------------------------------------------------------o
TestMult = {}

function TestMult:setUp()
-- Turn off all unnecessary components for unit testing
ref_cfg.dodbg = false
ref_cfg.doprnt = 0
ref_cfg.dosave = false

-- Turn on the components for unit testing
ref_cfg.dorun = true
ref_cfg.do_utest = true
ref_cfg.doplot = true
end
TestStraight = {}

function TestMult:testQUAD() -- Test the body (~2 min)
function TestStraight:testQUAD() -- Test the body (~2 min)
local cfg = ref_cfg "quad" {
elm = "quadrupole 'quad' {at=0.75, l=1.5, k1=${bdir}*${k1}, k1s=${bdir}*${k1s},tilt=${tdir}*${tilt}, fringe=0}",
model = {1, 2},
Expand Down Expand Up @@ -53,7 +41,7 @@ function TestMult:testQUAD() -- Test the body (~2 min)
run_test(cfg, equiv)
end

function TestMult:testSEXT()
function TestStraight:testSEXT()
local cfg = ref_cfg "sext" {
elm = "sextupole 'sext' {at=0.75, l=1.5, k2=${bdir}*${k2}, k2s=${bdir}*${k2s},tilt=${tilt}}",
model = {1, 2},
Expand Down Expand Up @@ -90,7 +78,7 @@ function TestMult:testSEXT()
run_test(cfg, equiv)
end

function TestMult:testOCT()
function TestStraight:testOCT()
local cfg = ref_cfg "oct" {
elm = "octupole 'oct' {at=0.75, l=1.5, k3=${bdir}*${k3}, k3s=${bdir}*${k3s},tilt=${tilt}, fringe=0}",
model = {1, 2},
Expand Down Expand Up @@ -125,7 +113,7 @@ function TestMult:testOCT()
run_test(cfg, equiv)
end

function TestMult:testMULTIPOLE()
function TestStraight:testMULTIPOLE()
local cfg = ref_cfg "mult" {
elm = [[
multipole 'mult' {
Expand Down
1 change: 1 addition & 0 deletions tests/tests/test-ng-maps/test-subelm-maps.mad
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ local object, vector in MAD
local tblcat in MAD.utility
local run_test in require("trackvsng")

MAD.warn("TestSubElm: This test is not complete, missing fringe/tilt/misalignment tests")
--[[
MISSING TEST -> SUB ELEMENTS + FRINGE/TILT/MISALIGNMENT
]]
Expand Down
2 changes: 1 addition & 1 deletion tests/tests/test-ng-maps/testvsng.mad
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ Additional/Augmented options for unit tests, provided for tests against PTC:
-c, --cmapall: Only run the cmap comparison, charge, edir and backtracking tests
-l --luaall: Only run the lua charge, edir and backtracking tests
-t, --test: Do not run unittests, instead run as a test where PTC is
run for every configuration.
run for every configuration. See -t -h for more details.

If any of the following options are selected, by default all other tests are deselected
--chg: Select to run the charge tests
Expand Down
48 changes: 35 additions & 13 deletions tests/tests/test-ng-maps/trackvsng.mad
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ local is_number, is_damap in MAD.typeid
local assertTrue in MAD.utest

package.path = package.path .. ";../tools/?.mad"
local get_diff, store_results, prnt_results, gen_cfg, in_dir, X0s, chk_tol, get_cfgs_to_run,
out_dir, add_trk_gen_cols, show_res, get_prev_res, tbl2da, save_res in require "track-tool"
local get_diff, store_results, prnt_results, gen_cfg, in_dir, X0s, chk_tol,
get_cfgs_to_run, out_dir, add_trk_gen_cols, show_res, get_prev_res,
tbl2da, save_res in require "track-tool"

local plt_dir, plot_trk_res, do_norun in require "plot-tool"
local args_to_cfg in require "test-tool"
Expand Down Expand Up @@ -126,6 +127,10 @@ local function dif_save_prnt_dbg(cfg, exp, res, result_mtbl, script) -- exp and
end

local function backtrack(cfg, results)
if not cfg.chk_cfg then -- If cfg is not in the list of cfgs to run, increment cfgid and return
cfg.cur_cfg.cfgid = cfg.cur_cfg.cfgid + cfg.npar
return
end
if not cfg.dobck then return end
-- Setup backward tracking
local bck_cfg = tblcpy(cfg.cur_cfg)
Expand Down Expand Up @@ -153,11 +158,19 @@ local function reverse_attr(cfg, results, attr)
end

local function reverse_chg(cfg, results)
if not cfg.chk_cfg then -- If cfg is not in the list of cfgs to run, increment cfgid and return
cfg.cur_cfg.cfgid = cfg.cur_cfg.cfgid + cfg.npar
return
end
if not cfg.dochg then return end
reverse_attr(cfg, results, "chg")
end

local function reverse_edir(cfg, results)
if not cfg.chk_cfg then -- If cfg is not in the list of cfgs to run, increment cfgid and return
cfg.cur_cfg.cfgid = cfg.cur_cfg.cfgid + cfg.npar
return
end
if not cfg.doedir then return end
reverse_attr(cfg, results, "edir")
end
Expand All @@ -166,7 +179,9 @@ local function cmaps(cfg, results)
cfg.cmap = not cfg.cmap
local cmap_script = create_run(cfg, cfg.cur_cfg)
local _, cmap_res = loadstring(cmap_script)()
if cfg.docmap then
if not cfg.chk_cfg then -- If cfg is not in the list of cfgs to run, increment cfgid and continue
cfg.cur_cfg.cfgid = cfg.cur_cfg.cfgid + cfg.npar
elseif cfg.docmap then
cfg.cur_cfg.test_type = "cmap" -- Set test type
dif_save_prnt_dbg(cfg, cfg.ref_map, cmap_res, results, cmap_script)
end
Expand All @@ -182,10 +197,6 @@ end

local function run_cfg(cfg, equiv, results)
-- Get the mflow for the main config
if not cfg.chk_cfg then -- If cfg is not in the list of cfgs to run, increment cfgid and return
cfg.cur_cfg.cfgid = cfg.cur_cfg.cfgid + cfg.npar
return
end
cfg.ref_script = create_run(cfg, cfg.cur_cfg)
local _, ref = assert(loadstring(cfg.ref_script))()
cfg.ref_map = ref
Expand All @@ -201,7 +212,10 @@ local function run_cfg(cfg, equiv, results)
end

-- Copy main config to make comparable config and then compare

if not cfg.chk_cfg then -- If cfg is not in the list of cfgs to run, increment cfgid and return
cfg.cur_cfg.cfgid = cfg.cur_cfg.cfgid + cfg.npar
return
end
-- Generate similar configs
if not cfg.docstm then return end
for i, change_type in ipairs(equiv.alist or {}) do -- Go through list of equivalences
Expand Down Expand Up @@ -254,15 +268,15 @@ end
-- Run test -------------------------------------------------------------------o
local function run_test(cfg, equiv)
-- list of core values that are changed manually throughout the tests
args_to_cfg(cfg) -- Do this first to avoid side effects (cmap)

cfg.edir = 1 -- 1/-1 (element direction)
cfg.sdir = 1 -- 1/-1 (tracking direction)
cfg.chg = 1 -- 1/-1 (charge)
cfg.tdir = \s-> s.edir * s.sdir -- tracking time direction
cfg.bdir = \s-> s.edir * s.sdir * s.chg -- tracking beam direction
cfg.cmap = true -- Change the default for the release 0.9.8

args_to_cfg(cfg)
cfg.chk_cfg = get_cfgs_to_run(cfg.cid)
cfg.cmap = false -- default is lua since the test was built for lua first
cfg.chk_cfg = get_cfgs_to_run(cfg.cid) -- if cid not nil, get the cfgs to run otherwise true

-- If the user does not want to run the test, just show results from previous run
if not cfg.dorun then return do_norun (cfg) end
Expand All @@ -278,7 +292,15 @@ local function run_test(cfg, equiv)
novector = true,
}

io.write("Running ", cfg.name, " (tol = ", tostring(cfg.tol), ")\n")
io.write("Running ", cfg.name, " (tol = ", tostring(cfg.tol), " eps)\n")
io.write(
"setup =", cfg.dosave and " sv" or "", cfg.doplot and " plt" or "",
cfg.doprnt > 0 and " prnt" or "", cfg.dodbg and " dbg" or "",
cfg.dobck and " bck" or "", cfg.doedir and " edir" or "",
cfg.dochg and " chg" or "", cfg.docmap and " cmap" or "",
cfg.docstm and " cstm" or "", not cfg.doluaall and " nolua" or "",
not cfg.docppall and " nocpp" or "", " o", cfg.order, " npar", cfg.npar, "\n"
)
if cfg.doprnt > 1 then
-- Print the header
io.write("cfgid\t")
Expand Down
41 changes: 41 additions & 0 deletions tests/tests/test-ptc-maps/cleanup.mad
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
local filesys in MAD
local clean_plots = false
local clean_results = true
local clean_configs = true
MAD.warn(
"Cleaning up" ..
(clean_plots and " plots," or "") ..
(clean_results and " results," or "") ..
(clean_configs and " configs," or "") ..
" and all txt files in output/"
)

local input_files = { -- List of files that should not be removed
["ref.mad" ] = true,
["ref.madx"] = true,
["." ] = true,
[".." ] = true,
}

for filename in filesys.dir ("input/") do
if not input_files[filename] then
os.remove("input/"..filename)
end
end

for filename in filesys.dir ("output/") do
if clean_results and filename:find("_res.tfs") then
os.remove("output/"..filename)
elseif clean_configs and filename:find("_cfg.tfs") then
os.remove("output/"..filename)
elseif filename:find(".txt") then
os.remove("output/"..filename)
end
end

if clean_plots then
for filename in filesys.dir ("output/plots/") do
os.remove("output/plots/"..filename)
end
end
os.remove("TMP_MAD_PLOT")
Loading