While working on building our dataset (in our case, for seasonal adjustment), we observed that X-13ARIMA-SEATS routines can crash when the current directory is different from the path of the Matlab script where we call the X13 routines. This behavior seems to be eratic: it occurs while we loop over a loop of variables and it does not always crash on the same variable.
In the attached example, I replicate this crash with random data on which I want to do seasonal adjustment. I loop over an arbitrary number of variables (N=30). To trigger the crash, one needs to change the current directory of Matlab to any subfolder.
%% Create a subfodlermkdir SomeFolderaddpath('./SomeFolder')%% To trigger the bug set bug = truebug = true ;if bug cd('./SomeFolder') else cd(cwd)end
In this case, the loop will eventually stop. Sometimes, it can stop for the first variable, sometimes it can iterate until a higher number of variable, for a reason we cannot explain.
@PierreAldama I am not able to reproduce this issue on my machine (I tried to increase NVar up to 300, but it works flawlessly). I suspect that this problem is specific to your environment. For some reason, when you decide to work in another directory (but I am not sure if that is really the cause of the error), the run method (that is the call to x13) fails or does not return what it should in o. We should return a message when something goes wrong with the run method. Here, your code fails later, but it's hard to understand why.
Thanks for looking into it! Indeed, I experienced it again today and it wasn't due to the change of directory (i.e. my example could not reproduce it either). It only diseappeared after restarting my computer (also tried to restart Matlab before that, but it didn't do anything).
I have just pushed a patch in Dynare to throw an error if the call to X13 fails. Can you test the same example tomorrow with the latest snapshot, and tell me if you see this new error message. Otherwise, it probably means that it's a formatting issue in one of the many files generated by the X13 binary.
Hi Stéphane,
I have experienced the bug once again this morning:
Seasonal adjustment of variable f0_s11s12n_3: DONESeasonal adjustment of variable f0_s11n_3: DONESeasonal adjustment of variable f0_s12n_3: DONESeasonal adjustment of variable f0_s13n_3: DONESeasonal adjustment of variable f0_s14n_3: DONESeasonal adjustment of variable f0_s15n_3: DONESeasonal adjustment of variable f0_s1n_3: DONESeasonal adjustment of variable f3_s11r_3: DONESeasonal adjustment of variable f3_s11e_3: DONESeasonal adjustment of variable f2_s14e_3: DONESeasonal adjustment of variable f3_s14e_3: DONESeasonal adjustment of variable f4_s14r_3: DONESeasonal adjustment of variable f4_s14e_3: DONESeasonal adjustment of variable f5_s14e_3: DONE X-13ARIMA-SEATS Seasonal Adjustment Program Version Number 1.1 Build 59 Execution began Jan 11, 2023 09.46.34 Reading input spec file from KSdO0MOKOb.spc Storing any program output into KSdO0MOKOb.out Storing any program error messages into KSdO0MOKOb.errProgram received signal SIGSEGV: Segmentation fault - invalid memory reference.Backtrace for this error:#0 0xffffffff#1 0xffffffff#2 0xffffffff#3 0xffffffff#4 0xffffffff#5 0xffffffff#6 0xffffffff#7 0xffffffff#8 0xffffffff#9 0xffffffff#10 0xffffffff#11 0xffffffff#12 0xffffffff#13 0xffffffff#14 0xffffffff#15 0xffffffff#16 0xffffffff#17 0xffffffff#18 0xffffffff#19 0xffffffff#20 0xffffffffError using x13/run (line 40)X13 failed on KSdO0MOKOb.spcError in x13/subsref (line 72) feval(S(1).subs, o);Error in MainBaseSource (line 1526) Temp.run();Error in run (line 91)evalin('caller', strcat(script, ';'));Error in MainBase (line 24) run ('MainBaseSource.m')
I am using: dynare-6-unstable-2023-01-06-1542-f7694208
Je remonte ce sujet : j'ai à présent le bonheur de déclencher le même message d'erreur depuis deux semaines.
Je ne sais pas à quoi c'est lié étant donné que je ne la rencontrais jamais sous dynare-6-unstable-2023-05-12-1808-3c35f34a, que j'ai commencé à la recontrer sous dynare-6-unstable-2023-05-19-1925-03db691a (mais le retour à la version précédente n'a pas résolu le problème), et que dynare-6-unstable-2023-06-04-0811-b1933d58 ne résout pas le soucis.
Pour le moment ma seule solution consiste à redémarer le PC, ne lancer -que- dynare et faire tourner nos codes. Si le processus marche une fois dans une instance de matlab, alors il ne semble pas tomber en panne plus tard (ouvrir une nouvelle instance de matlab peut déclancher le problème dans cette seule instance, sans affecter l'autre).
It looks like the bug is in x13as, which is a third-party program developed by the US Census Bureau. As a consequence, it is unclear whether we can fix the problem ourselves.
In order to try to reproduce the bug, and have a better understanding of it, could you send us the .spc file that triggers the crash?
I can reproduce the problem with cSuLqLWmwF.spc
The problem is the o.transform('function','log')-step. The error disappears if I switch to o.transform('function','auto');
Strangely, the issue is not about the spc-file per se. I tried calling x13as directly from the Matlab command line using the string of the x13.run()-command. This yields the expected
>> !C:\dynare\6-unstable-2023-05-19-1925-03db691a\matlab\modules\dseries\src\..\externals\x13\windows\64\x13as.exe eQlsNHSTaf X-13ARIMA-SEATS Seasonal Adjustment Program Version Number 1.1 Build 59 Execution began Jun 13, 2023 16.11.40 Reading input spec file from eQlsNHSTaf.spc Storing any program output into eQlsNHSTaf.out Storing any program error messages into eQlsNHSTaf.err Program received signal SIGSEGV: Segmentation fault - invalid memory reference.Backtrace for this error:#0 0xffffffff#1 0xffffffff#2 0xffffffff#3 0xffffffff#4 0xffffffff#5 0xffffffff#6 0xffffffff#7 0xffffffff#8 0xffffffff#9 0xffffffff#10 0xffffffff#11 0xffffffff#12 0xffffffff#13 0xffffffff#14 0xffffffff#15 0xffffffff#16 0xffffffff#17 0xffffffff#18 0xffffffff#19 0xffffffff#20 0xffffffff
However, using the direct path without the .. works:
K>> !C:\dynare\6-unstable-2023-05-19-1925-03db691a\matlab\modules\dseries\externals\x13\windows\64\x13as.exe eQlsNHSTaf X-13ARIMA-SEATS Seasonal Adjustment Program Version Number 1.1 Build 59 Execution began Jun 13, 2023 16.11.58 Reading input spec file from eQlsNHSTaf.spc Storing any program output into eQlsNHSTaf.out Storing any program error messages into eQlsNHSTaf.err Execution complete for eQlsNHSTaf.spc at Jun 13, 2023 16.11.58
Thanks to you both for investigating, I did not provide my file as the codes suddenly did not trigger the bug anymore (without any changes on my side, and I could not find a way to reliably trigger it before either). I'll be sure to get the next unstable and will let you know if I ever get this issue again.
The problem comes from an invalid memory read in x13as. It essentially means that the program tries to read in a random memory location. Sometimes it reads in an authorized location, and it gets a bogus value (but does not crash); sometimes it reads in a forbidden location, and it crashes (with a segmentation fault). Hence the apparently random nature of the bug. Some small change in the environment can make the crash happen or not (and for this reason, I don’t think that dseries!45 (closed) solves the problem; the path location is most likely just one of the many factors that affect the randomness).
By investigating with a memory analyzer (valgrind) I found a possible location for the bug. But on the other hand GCC Address Sanitizer (ASAN) does not find any problem. So I’m unsure about the way forward. In any case, as said above, the bug is in a program that is not maintained by the Dynare Team, so fixing it may not be possible for us, or it may require many resources.
@JohannesPfeifer@Ugo As you know, the x13as binary in the Dynare package is compiled by ourselves. In order to rule out a bug/problem in our compilation process, could you try the binary provided by the US Census Bureau and see whether the bug still occurs (keeping in mind that you must test various scenarios, due to the randomness)? It is available there: https://www2.census.gov/software/x-13arima-seats/x13as/windows/program-archives/x13as_ascii-v1-1-b59.zip
(do not forget to rename x13as_ascii.exe into x13as.exe and put it in the right location)
There is a problem with our binary. The Census one works like a charm:
!C:\dynare\6-unstable-2023-05-19-1925-03db691a\matlab\modules\dseries\src\..\externals\x13\windows\64\x13as_ascii.exe I87exIa4x7 X-13ARIMA-SEATS Seasonal Adjustment Program Version Number 1.1 Build 59 Execution began Jun 14, 2023 08.31.43 Reading input spec file from I87exIa4x7.spc Storing any program output into I87exIa4x7.out Storing any program error messages into I87exIa4x7.err
That's encouraging. But did you test it in enough different scenarios to make sure that the absence of crash is not just because of a favourable state of nature in the non-deterministic behaviour?
I have one real-world time series that I need to deseasonalize. And our Dynare binary always crashes with that particular series if the .. is present in the call to the binary name. I haven't encountered other cases yet, but I am investigating.
I just switched to the latest unstable (its publishing time appears to match your comment), I'll be sure to report any misbehavior from X13 here if it acts up again.