Skip to content

Slightly relax tolerance in a test case of Apply1InteriorArbitrary#671

Merged
pavoljuhas merged 1 commit into
quantumlib:masterfrom
mhucka:adjust-mps-test-tolerance
Sep 5, 2024
Merged

Slightly relax tolerance in a test case of Apply1InteriorArbitrary#671
pavoljuhas merged 1 commit into
quantumlib:masterfrom
mhucka:adjust-mps-test-tolerance

Conversation

@mhucka
Copy link
Copy Markdown
Collaborator

@mhucka mhucka commented Sep 4, 2024

The test case in third_party/qsim/tests/mps_simulator_test.cc on line 262 fails if the Eigen linear algebra library is updated to a recent version available from https://gitlab.com/libeigen/eigen. Specifically, commit 59498c96 in the Eigen repo (which can be seen at https://gitlab.com/libeigen/eigen/-/merge_requests/1663) changed the code in Eigen/src/Core/arch/Complex.h for pmul() to use a fused multiply-add-subtract (FMA) instruction (fmaddsub) instead of the previous separate multiply and add-subtract instructions. The new code improved accuracy for many of the tests in mps_simulator_test.cc, slightly worsened accuracy for some of the tests, and in the case of the one on line 262, made it cross the absolute tolerance value of 1e-5 by a very small amount. After considering various alternatives, the least-worst option seems to be to increase the tolerance for this one case.

Note: the qsim repository on GitHub has its own vendored copy of Eigen, so this change is not strictly necessary; however, if we ever update qsim's internal copy of Eigen, then this change will become relevant.

The original debugging & solution are the work of @pavoljuhas.

The test case in third_party/qsim/tests/mps_simulator_test.cc on
line 262 fails if the Eigen linear algebra library is updated to a
recent version available from https://gitlab.com/libeigen/eigen.
Specifically, commit 59498c96 in the Eigen repo (which can be seen at
https://gitlab.com/libeigen/eigen/-/merge_requests/1663) changed the
code in Eigen/src/Core/arch/Complex.h for pmul() to use a fused
multiply-add-subtract (FMA) instruction (fmaddsub) instead of the
previous separate multiply and add-subtract instructions. The new code
improved accuracy for many of the tests in mps_simulator_test.cc,
slightly worsened accuracy for some of the tests, and in the case of
the one on line 262, made it cross the absolute tolerance value of
1e-5 by a very small amount. After considering various alternatives,
the least-worst option seems to be to increase the tolerance for this
one case.

The qsim repository on GitHub has its own vendored copy of Eigen, so
this change is not strictly necessary; however, if we ever update
qsim's internal copy of Eigen, then this change will become relevant.

Note: the original debugging & solution are the work of @pavoljuhas.
@pavoljuhas
Copy link
Copy Markdown
Collaborator

The CI errors show on the master branch too and are unrelated to this change. Perhaps this can be merged as is for the sake of consistency with downstream fix?

@mhucka
Copy link
Copy Markdown
Collaborator Author

mhucka commented Sep 5, 2024

That sounds reasonable to me.

It currently needs reviewer approval from @sergeisakov. (Sergei, this is the same tiny change as was made in the internal code base recently for the same problem, so hopefully will take next to no time to review.)

@pavoljuhas pavoljuhas self-requested a review September 5, 2024 17:45
@pavoljuhas pavoljuhas merged commit 80e3026 into quantumlib:master Sep 5, 2024
@mhucka mhucka deleted the adjust-mps-test-tolerance branch January 1, 2026 18:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants