Julia 1.7.3 returns incorrect result in compiled mode, not in interpreted mode

I’ve written up a numeric function that computes the log-likelihood of a discrete-time hidden Markov model, which involves Gauss quadrature and an optimization step. The function using Julia 1.6.2 gives the same exact results as does another implementation written in MATLAB.

I noticed the function outputted different values once I upgraded from version 1.6.2 to version 1.7.3; the log-likelihood was different by around 100. When I went into the VS Code debugger everything worked correctly, except when I called the function from the debugging terminal it once again gave the wrong results.

Before I spend time deducing a MWE, does anyone have an idea what may be causing the problem? Is this the kind of issue that should be posted on the Github?

For anyone who may stumble upon this post in the future, the change in behavior from 1.6.2 to 1.7.3 was due to a rounding error. The rounding error caused a covariance matrix, cov_mat, to become asymmetric: cov_mat[1,2] - cov_mat[2,1] = 1e-16. This triggered an isposdef(cov_mat) if-else statement, which revealed a bug in my code.

For whatever reason, the rounding error only occurred during compiled mode and not in interpreted mode. This made the issue especially hard to debug. But ultimately it was an issue in my code which caused the instability.

Because of @fastmath and similar optimizations, floating point results are not required to be bitwise exact between various optimization modes.

3 Likes