2121
2222
2323def test_compilation ():
24+ xb ._skip_xsuite_version_check = True
2425 source_files = xb .generate_executable_source ()
2526 assert Path (Path .cwd () / "main.c" ).exists ()
2627 assert Path (Path .cwd () / "sim_config.h" ).exists ()
@@ -31,29 +32,35 @@ def test_compilation():
3132 assert len (exec_file ) == 1
3233 assert exec_file [0 ].exists ()
3334 assert os .access (exec_file [0 ], os .X_OK )
35+ xb ._skip_xsuite_version_check = False
3436
3537
36- def test_generate_input ():
37- # Simulation input
38+ def _make_input ():
3839 line = xt .Line .from_json (line_file )
3940 line .build_tracker ()
4041 x_norm = np .linspace (- .5 , .5 , 50 )
4142 delta = np .linspace (- 1.e-5 , 1.e-5 , 50 )
4243 part = line .build_particles (x_norm = x_norm , delta = delta , nemitt_x = 3.5e-6 , nemitt_y = 3.5e-6 )
44+ return line , part
45+
4346
44- # Assemble data structure
47+ def test_generate_input ():
48+ xb ._skip_xsuite_version_check = True
49+ line , part = _make_input ()
4550 xb .SimConfig .build (line = line , particles = part , num_turns = num_turns , checkpoint_every = 10 ,
4651 filename = 'xboinc_input.bin' )
47-
4852 input_file = Path .cwd () / "xboinc_input.bin"
4953 assert input_file .exists ()
54+ xb ._skip_xsuite_version_check = False
5055
5156
5257def test_track ():
58+ xb ._skip_xsuite_version_check = True
5359 # If no executable is present, make one
5460 exec_file = list (Path .cwd ().glob (f'xboinc_{ xb .app_version } -*' ))
5561 if len (exec_file )== 0 or not exec_file [0 ].exists ():
56- xb .generate_executable ()
62+ test_compilation ()
63+ exec_file = list (Path .cwd ().glob (f'xboinc_{ xb .app_version } -*' ))
5764 exec_file = exec_file [0 ]
5865
5966 # If no input file is present, make one
@@ -79,15 +86,24 @@ def test_track():
7986 assert np .all (part_xboinc .at_turn == num_turns ), "Unexpected survivals (particles)"
8087 assert sim_state .i_turn == num_turns , "Unexpecteds survival (sim_state)"
8188
89+ # Check that the tracking made sense, i.e. that not all values are the same
90+ assert not np .allclose (part_xboinc .x , part_xboinc .x [0 ], rtol = 1e-4 , atol = 0 )
91+ assert not np .allclose (part_xboinc .px , part_xboinc .px [0 ], rtol = 1e-4 , atol = 0 )
92+ assert not np .allclose (part_xboinc .y , part_xboinc .y [0 ], rtol = 1e-4 , atol = 0 )
93+ assert not np .allclose (part_xboinc .py , part_xboinc .py [0 ], rtol = 1e-4 , atol = 0 )
94+
8295 # Rename file for comparison in next test
8396 output_file .rename (output_file .parent / f'{ output_file .name } _2' )
97+ xb ._skip_xsuite_version_check = False
8498
8599
86100def test_checkpoint ():
101+ xb ._skip_xsuite_version_check = True
87102 # If no executable is present, make one
88103 exec_file = list (Path .cwd ().glob (f'xboinc_{ xb .app_version } -*' ))
89104 if len (exec_file )== 0 or not exec_file [0 ].exists ():
90- xb .generate_executable ()
105+ test_compilation ()
106+ exec_file = list (Path .cwd ().glob (f'xboinc_{ xb .app_version } -*' ))
91107 exec_file = exec_file [0 ]
92108
93109 # If no input file is present, make one
@@ -123,22 +139,20 @@ def test_checkpoint():
123139 output_file = Path .cwd () / 'sim_state_out.bin'
124140 assert output_file .exists ()
125141 assert filecmp .cmp (output_file , output_file .parent / f'{ output_file .name } _2' , shallow = False )
142+ xb ._skip_xsuite_version_check = False
126143
127144
128145def test_vs_xtrack ():
146+ xb ._skip_xsuite_version_check = True
129147 # If no output is present, make one
130- output_file = Path .cwd () / 'sim_state_out.bin '
148+ output_file = Path .cwd () / 'sim_state_out.bin_2 '
131149 if not output_file .exists ():
132150 test_track ()
133151 sim_state = xb .SimState .from_binary (output_file )
134152 part_xboinc = sim_state .particles
135153
136154 # Testing results with xtrack
137- line = xt .Line .from_json (line_file )
138- line .build_tracker ()
139- x_norm = np .linspace (- .5 , .5 , 50 )
140- delta = np .linspace (- 1.e-5 , 1.e-5 , 50 )
141- part = line .build_particles (x_norm = x_norm , delta = delta , nemitt_x = 3.5e-6 , nemitt_y = 3.5e-6 )
155+ line , part = _make_input ()
142156 line .track (part , num_turns = num_turns )
143157
144158 assert np .array_equal (part .at_turn , part_xboinc .at_turn ), "Fail to match xtrack: survivals are not equal"
@@ -148,3 +162,4 @@ def test_vs_xtrack():
148162 assert np .array_equal (part .px , part_xboinc .px ), "Fail to match xtrack: px are not equal"
149163 assert np .array_equal (part .py , part_xboinc .py ), "Fail to match xtrack: py are not equal"
150164 assert np .array_equal (part .delta , part_xboinc .delta ), "Fail to match xtrack: delta are not equal"
165+ xb ._skip_xsuite_version_check = False
0 commit comments