Commit ef7bd2a2aa337bf289103748be005ec785bd5ab6
1 parent
0573b3fb
Try reducing ctools unit test duration (#2310)
Showing
5 changed files
with
37 additions
and
47 deletions
test/data/workflow.xml
| ... | ... | @@ -10,7 +10,7 @@ |
| 10 | 10 | <parameter name="ra" value="83.63" /> |
| 11 | 11 | <parameter name="dec" value="22.51" /> |
| 12 | 12 | <parameter name="target" value="Crab" /> |
| 13 | - <parameter name="emin" value="0.1" /> | |
| 13 | + <parameter name="emin" value="1.0" /> | |
| 14 | 14 | <parameter name="emax" value="100.0" /> |
| 15 | 15 | <parameter name="tmin" value="0.0" /> |
| 16 | 16 | <parameter name="tmax" value="300.0" /> | ... | ... |
test/test_cstsdist.py
| ... | ... | @@ -33,7 +33,7 @@ class Test(test): |
| 33 | 33 | This test class makes unit tests for the cstsdist script by using it |
| 34 | 34 | from the command line and from Python. |
| 35 | 35 | """ |
| 36 | - | |
| 36 | + | |
| 37 | 37 | # Constructor |
| 38 | 38 | def __init__(self): |
| 39 | 39 | """ |
| ... | ... | @@ -97,7 +97,7 @@ class Test(test): |
| 97 | 97 | cmd = cstsdist+' inobs="event_file_that_does_not_exist.xml"'+ \ |
| 98 | 98 | ' inmodel="'+self._model+'" srcname="Crab"'+ \ |
| 99 | 99 | ' caldb="'+self._caldb+'" irf="'+self._irf+'"'+ \ |
| 100 | - ' ntrials=1 '+ \ | |
| 100 | + ' ntrials=2 '+ \ | |
| 101 | 101 | ' outfile="cstsdist_cmd2.dat"'+ \ |
| 102 | 102 | ' logfile="cstsdist_cmd2.log" chatter=2' |
| 103 | 103 | |
| ... | ... | @@ -136,27 +136,6 @@ class Test(test): |
| 136 | 136 | # Check TS distribution file |
| 137 | 137 | self._check_result_file('cstsdist_py1.dat') |
| 138 | 138 | |
| 139 | - # Set-up cstsdist without multiprocessing | |
| 140 | - tsdist = cscripts.cstsdist() | |
| 141 | - tsdist['inobs'] = self._events | |
| 142 | - tsdist['inmodel'] = self._model | |
| 143 | - tsdist['srcname'] = 'Crab' | |
| 144 | - tsdist['caldb'] = self._caldb | |
| 145 | - tsdist['irf'] = self._irf | |
| 146 | - tsdist['ntrials'] = 2 | |
| 147 | - tsdist['outfile'] = 'cstsdist_py2.dat' | |
| 148 | - tsdist['logfile'] = 'cstsdist_py2.log' | |
| 149 | - tsdist['chatter'] = 3 | |
| 150 | - tsdist['nthreads'] = 1 | |
| 151 | - | |
| 152 | - # Run cstsdist script | |
| 153 | - tsdist.logFileOpen() # Make sure we get a log file | |
| 154 | - tsdist.run() | |
| 155 | - tsdist.save() | |
| 156 | - | |
| 157 | - # Check TS distribution file | |
| 158 | - self._check_result_file('cstsdist_py2.dat') | |
| 159 | - | |
| 160 | 139 | # Return |
| 161 | 140 | return |
| 162 | 141 | |
| ... | ... | @@ -223,15 +202,16 @@ class Test(test): |
| 223 | 202 | |
| 224 | 203 | # Set-up cstsdist for event list |
| 225 | 204 | tsdist = cscripts.cstsdist() |
| 226 | - tsdist['inobs'] = self._events | |
| 227 | - tsdist['inmodel'] = self._model | |
| 228 | - tsdist['srcname'] = 'Crab' | |
| 229 | - tsdist['caldb'] = self._caldb | |
| 230 | - tsdist['irf'] = self._irf | |
| 231 | - tsdist['ntrials'] = 2 | |
| 232 | - tsdist['outfile'] = 'cstsdist_py1_pickle.dat' | |
| 233 | - tsdist['logfile'] = 'cstsdist_py1_pickle.log' | |
| 234 | - tsdist['chatter'] = 3 | |
| 205 | + tsdist['inobs'] = self._events | |
| 206 | + tsdist['inmodel'] = self._model | |
| 207 | + tsdist['srcname'] = 'Crab' | |
| 208 | + tsdist['caldb'] = self._caldb | |
| 209 | + tsdist['irf'] = self._irf | |
| 210 | + tsdist['ntrials'] = 2 | |
| 211 | + tsdist['nthreads'] = 1 # This tests at the same time no multiprocessing | |
| 212 | + tsdist['outfile'] = 'cstsdist_py1_pickle.dat' | |
| 213 | + tsdist['logfile'] = 'cstsdist_py1_pickle.log' | |
| 214 | + tsdist['chatter'] = 3 | |
| 235 | 215 | |
| 236 | 216 | # Perform pickeling tests of filled class |
| 237 | 217 | obj = self._pickeling(tsdist) | ... | ... |
test/test_csworkflow.py
| ... | ... | @@ -138,18 +138,24 @@ class Test(test): |
| 138 | 138 | # Load fit results |
| 139 | 139 | models = gammalib.GModels(filename) |
| 140 | 140 | |
| 141 | + # Set reference values | |
| 142 | + prefactor = 3.65452317299086e-16 | |
| 143 | + index = 2.39356360627502 | |
| 144 | + pre_background = 1.01409721455405 | |
| 145 | + index_background = 0.0436264224942131 | |
| 146 | + | |
| 141 | 147 | # Check fit result values |
| 142 | 148 | self.test_value(models['Crab'][2].value(), |
| 143 | - 5.65974581468379e-16, 1.0e-4 * 5.65974581468379e-16, | |
| 149 | + prefactor, 1.0e-4 * prefactor, | |
| 144 | 150 | 'Check Crab prefactor') |
| 145 | 151 | self.test_value(models['Crab'][3].value(), |
| 146 | - -2.45911900829089, 1.0e-4 * 2.45911900829089, | |
| 152 | + -index, 1.0e-4 * index, | |
| 147 | 153 | 'Check Crab index') |
| 148 | 154 | self.test_value(models['Background'][0].value(), |
| 149 | - 1.04744971751241, 1.0e-4 * 1.04744971751241, | |
| 155 | + pre_background, 1.0e-4 * pre_background, | |
| 150 | 156 | 'Check background model prefactor') |
| 151 | 157 | self.test_value(models['Background'][1].value(), |
| 152 | - 0.0117967073949693, 1.0e-4 * 0.0117967073949693, | |
| 158 | + index_background, 1.0e-4 * index_background, | |
| 153 | 159 | 'Check background model index') |
| 154 | 160 | |
| 155 | 161 | # Return | ... | ... |
test/test_cterror.py
| ... | ... | @@ -68,7 +68,7 @@ class Test(test): |
| 68 | 68 | cmd = cterror+' inobs="'+self._events+'"'+ \ |
| 69 | 69 | ' inmodel="'+self._model+'" srcname="Crab"'+ \ |
| 70 | 70 | ' caldb="'+self._caldb+'" irf="'+self._irf+'"'+ \ |
| 71 | - ' outmodel="cterror_cmd1.xml"'+ \ | |
| 71 | + ' tol=0.1 outmodel="cterror_cmd1.xml"'+ \ | |
| 72 | 72 | ' logfile="cterror_cmd1.log" chatter=1' |
| 73 | 73 | |
| 74 | 74 | # Check if execution was successful |
| ... | ... | @@ -82,7 +82,7 @@ class Test(test): |
| 82 | 82 | cmd = cterror+' inobs="event_file_that_does_not_exist.fits"'+ \ |
| 83 | 83 | ' inmodel="'+self._model+'" srcname="Crab"'+ \ |
| 84 | 84 | ' caldb="'+self._caldb+'" irf="'+self._irf+'"'+ \ |
| 85 | - ' outmodel="cterror_cmd2.xml"'+ \ | |
| 85 | + ' tol=0.1 outmodel="cterror_cmd2.xml"'+ \ | |
| 86 | 86 | ' logfile="cterror_cmd2.log" debug=yes chatter=1' |
| 87 | 87 | |
| 88 | 88 | # Check if execution failed |
| ... | ... | @@ -124,6 +124,7 @@ class Test(test): |
| 124 | 124 | error['srcname'] = 'Crab' |
| 125 | 125 | error['caldb'] = self._caldb |
| 126 | 126 | error['irf'] = self._irf |
| 127 | + error['tol'] = 0.1 | |
| 127 | 128 | error['outmodel'] = 'cterror_py1.xml' |
| 128 | 129 | error['logfile'] = 'cterror_py1.log' |
| 129 | 130 | error['chatter'] = 2 |
| ... | ... | @@ -170,6 +171,7 @@ class Test(test): |
| 170 | 171 | error['srcname'] = 'Crab' |
| 171 | 172 | error['caldb'] = self._caldb |
| 172 | 173 | error['irf'] = self._irf |
| 174 | + error['tol'] = 0.1 | |
| 173 | 175 | error['outmodel'] = 'cterror_py3.xml' |
| 174 | 176 | error['logfile'] = 'cterror_py3.log' |
| 175 | 177 | error['chatter'] = 4 |
| ... | ... | @@ -259,9 +261,9 @@ class Test(test): |
| 259 | 261 | |
| 260 | 262 | # Set reference values |
| 261 | 263 | prefactor = 3.65452317573063e-16 |
| 262 | - prefactor_error = 1.12697923756417e-16 | |
| 264 | + prefactor_error = 1.12920470341148e-16 | |
| 263 | 265 | index = 2.39356360626209 |
| 264 | - index_error = 0.131093571504494 | |
| 266 | + index_error = 0.128468611886618 | |
| 265 | 267 | pre_background = 1.01409721534593 |
| 266 | 268 | pre_background_error = 0.122650321517162 |
| 267 | 269 | index_background = 0.0436264224948547 | ... | ... |
test/test_ctulimit.py
| ... | ... | @@ -67,7 +67,7 @@ class Test(test): |
| 67 | 67 | cmd = ctulimit+' inobs="'+self._events+'"'+ \ |
| 68 | 68 | ' inmodel="'+self._model+'" srcname="Crab"'+ \ |
| 69 | 69 | ' caldb="'+self._caldb+'" irf="'+self._irf+'"'+ \ |
| 70 | - ' logfile="ctulimit_cmd1.log" chatter=1' | |
| 70 | + ' tol=0.1 logfile="ctulimit_cmd1.log" chatter=1' | |
| 71 | 71 | |
| 72 | 72 | # Check if execution was successful |
| 73 | 73 | self.test_assert(self._execute(cmd) == 0, |
| ... | ... | @@ -77,7 +77,7 @@ class Test(test): |
| 77 | 77 | cmd = ctulimit+' inobs="event_file_that_does_not_exist.fits"'+ \ |
| 78 | 78 | ' inmodel="'+self._model+'" srcname="Crab"'+ \ |
| 79 | 79 | ' caldb="'+self._caldb+'" irf="'+self._irf+'"'+ \ |
| 80 | - ' logfile="ctulimit_cmd2.log" debug=yes chatter=2' | |
| 80 | + ' tol=0.1 logfile="ctulimit_cmd2.log" debug=yes chatter=2' | |
| 81 | 81 | |
| 82 | 82 | # Check if execution failed |
| 83 | 83 | self.test_assert(self._execute(cmd, success=False) != 0, |
| ... | ... | @@ -87,7 +87,7 @@ class Test(test): |
| 87 | 87 | cmd = ctulimit+' inobs="'+self._events+'"'+ \ |
| 88 | 88 | ' inmodel="'+self._model+'" srcname="Vela"'+ \ |
| 89 | 89 | ' caldb="'+self._caldb+'" irf="'+self._irf+'"'+ \ |
| 90 | - ' logfile="ctulimit_cmd2.log" debug=yes chatter=2' | |
| 90 | + ' tol=0.1 logfile="ctulimit_cmd2.log" debug=yes chatter=2' | |
| 91 | 91 | |
| 92 | 92 | # Check if execution failed |
| 93 | 93 | self.test_assert(self._execute(cmd, success=False) != 0, |
| ... | ... | @@ -129,6 +129,7 @@ class Test(test): |
| 129 | 129 | ulimit['srcname'] = 'Crab' |
| 130 | 130 | ulimit['caldb'] = self._caldb |
| 131 | 131 | ulimit['irf'] = self._irf |
| 132 | + ulimit['tol'] = 0.1 | |
| 132 | 133 | ulimit['logfile'] = 'ctulimit_py1.log' |
| 133 | 134 | ulimit['chatter'] = 2 |
| 134 | 135 | |
| ... | ... | @@ -138,9 +139,9 @@ class Test(test): |
| 138 | 139 | ulimit.save() |
| 139 | 140 | |
| 140 | 141 | # Set reference value |
| 141 | - ref_diff = 2.7504120441004e-17 | |
| 142 | - ref_flux = 1.66909538876204e-11 | |
| 143 | - ref_eflux = 6.46471558856293e-11 | |
| 142 | + ref_diff = 2.75359655874408e-17 | |
| 143 | + ref_flux = 1.66942609234064e-11 | |
| 144 | + ref_eflux = 6.4588860064421e-11 | |
| 144 | 145 | |
| 145 | 146 | # Check results |
| 146 | 147 | self.test_value(ulimit.diff_ulimit(), ref_diff, 1.0e-21, |
| ... | ... | @@ -200,6 +201,7 @@ class Test(test): |
| 200 | 201 | # maximum likelihood |
| 201 | 202 | ulimit = ctools.ctulimit(like.obs()) |
| 202 | 203 | ulimit['srcname'] = 'Crab' |
| 204 | + ulimit['tol'] = 0.1 | |
| 203 | 205 | ulimit['logfile'] = 'ctulimit_py2.log' |
| 204 | 206 | ulimit['chatter'] = 3 |
| 205 | 207 | ... | ... |