microsoft/qsharp-runtime

Consider sanitizing the native part of the QuantumSimulator

kuzminrobin opened this issue · 1 comments

2022.05.02
Actually we do sanitize the native part of the QuantumSimulator. Here, here, and here. That is built and executed in the Debug config only by the microsoft.qsharp-runtime.sanitized pipeline (see here, here). But only the QIR tests are run against the sanitized native part of the QuantumSimulator.

We need to run all the tests against the sanitized native part of the QuantumSimulator. For that we need to add this line and this line (and their dependencies) to this file.

As a temporary bug bash measure we can run an ordinary pipeline with BUILD_CONFIGURATION=Debug to see if there are any issues detectable by the sanitizers. This requires installing something extra:
Mac:

The active test run was aborted. Reason: Test host process crashed : ==21693==ERROR: Interceptors are not working. This may be because AddressSanitizer is loaded too late (e.g. via dlopen). Please launch the executable with:
DYLD_INSERT_LIBRARIES=/Applications/Xcode_13.2.1.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/13.0.0/lib/darwin/libclang_rt.asan_osx_dynamic.dylib
"interceptors not installed" && 0

Linux:
(likely the same)

System.DllNotFoundException : Unable to load shared library 'Microsoft.Quantum.Simulator.Runtime' or one of its dependencies. In order to help diagnose loading problems, consider setting the LD_DEBUG environment variable: libMicrosoft.Quantum.Simulator.Runtime: cannot open shared object file: No such file or directory

2022.03.23
Looks like we never ended up sanitizing the native part of the QuantumSimulator.
Of and on that part crashes during the CI tests. Details and examples are in "Build Setup and Repos" Teams channel, conversation with topic "Crashes on native simulator" started on 2022.03.23 9:30am PT by Andres.

Crash extract
Starting test execution, please wait...
A total of 1 test files matched the specified pattern.
The active test run was aborted. Reason: Test host process crashed : Fatal error. System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
Repeat 2 times:
--------------------------------
   at Microsoft.Quantum.Simulation.Simulators.QuantumSimulator.SetSeedNative(UInt32, UInt32)
--------------------------------
   at Microsoft.Quantum.Simulation.Simulators.Tests.QuantumSimulatorTests.QSimVerifyX()
   at Microsoft.Quantum.Simulation.Simulators.Tests.QuantumSimulatorTests.<QSimMultithreading>b__4_0()
   at System.Threading.Tasks.Task.InnerInvoke()
   at System.Threading.Tasks.Task+<>c.<.cctor>b__272_0(System.Object)
   at System.Threading.ExecutionContext.RunFromThreadPoolDispatchLoop(System.Threading.Thread, System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object)
   at System.Threading.Tasks.Task.ExecuteWithThreadLocal(System.Threading.Tasks.Task ByRef, System.Threading.Thread)
   at System.Threading.Tasks.Task.ExecuteEntryUnsafe(System.Threading.Thread)
   at System.Threading.ThreadPoolWorkQueue.Dispatch()
   at System.Threading.PortableThreadPool+WorkerThread.WorkerThreadStart()
   at System.Threading.Thread.StartCallback()

We need to sanitize the native part.

  • Add warnings and sanitizers in the Debug config (example).
  • Add the sanitized pipeline (example yml, pipeline) that
    • Builds the Debug version
    • Runs the QuantumSimulator tests against Debug version

After fixing all the found bugs we probably need to disable that pipeline until some other issues need to be sanitized.