qsharp-compiler
qsharp-compiler copied to clipboard
qsharp compiler crashes with SIGILL 4 on MacOS
When executing the "hello world" code, dotnet crashes with SIGILL 4.
The debugger says: The program '[26917] ExploreInterference.dll' has exited with code 0 (0x0).
It never reaches the breakpoint (see attachment).
Steps to reproduce the behavior: Any Q# code exits with this behaviour, no matter where I set the break point.
Expected behavior
Terminal output: "Hello quantum world!"
System information
MacOS / VS Code / QDK installation as described in the official documentation: [(https://docs.microsoft.com/en-us/azure/quantum/quickstart-microsoft-qc?pivots=platform-ionq)]
CPUs | Apple M1 (8 x 24) GPU Status | 2d_canvas: enabled gpu_compositing: enabled metal: disabled_off multiple_raster_threads: enabled_on oop_rasterization: enabled opengl: enabled_on rasterization: enabled skia_renderer: disabled_off_ok video_decode: enabled webgl: enabled webgl2: enabled Load (avg) | 1, 2, 3 Memory (System) | 8.00GB (0.11GB free) Process Argv | --crash-reporter-id 603876e9-96af-49ca-b4fe-d8aa3ee2049e Screen Reader | no VM | 0%
Extension | Author (truncated) | Version |
---|---|---|
csharp | ms- | 1.24.0 |
python | ms- | 2022.0.1814523869 |
vscode-pylance | ms- | 2022.2.1 |
jupyter | ms- | 2022.1.1201831736 |
jupyter-keymap | ms- | 1.0.0 |
jupyter-renderers | ms- | 1.0.6 |
quantum-devkit-vscode | qua | 0.22.187631 |
vsliv368:30146709 vsreu685:30147344 python383cf:30185419 vspor879:30202332 vspor708:30202333 vspor363:30204092 pythonvspyl392cf:30425750 pythontb:30283811 pythonvspyt551:30345470 pythonptprofiler:30281270 vshan820:30294714 vstes263:30335439 pythondataviewer:30285071 vscod805:30301674 pythonvspyt200:30340761 binariesv615:30325510 bridge0708:30335490 bridge0723:30353136 vsaa593cf:30376535 vsc1dst:30438360 pythonvs932:30410667 wslgetstartedc:30433508 vsclayoutctrc:30437038 vsrem710:30416614 pythonvsnew555cf:30436485 vsbas813:30436447 vscscmwlcmt:30436993 helixcf:30438276 cppdebug:30437093
You may only use the Microsoft .NET Core Debugger (vsdbg) with Visual Studio Code, Visual Studio or Visual Studio for Mac software to help you develop and test your applications.
Loaded '/usr/local/share/dotnet/shared/Microsoft.NETCore.App/3.1.19/System.Private.CoreLib.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled. Loaded '/Users/user/qsharp/ExploreInterference/bin/Debug/netcoreapp3.1/ExploreInterference.dll'. Symbols loaded. Loaded '/usr/local/share/dotnet/shared/Microsoft.NETCore.App/3.1.19/System.Runtime.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled. Step into: Stepping over non-user code 'QsEntryPoint.QsEntryPoint.<Main>' Loaded '/usr/local/share/dotnet/shared/Microsoft.NETCore.App/3.1.19/System.Threading.Tasks.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled. Step into: Stepping over non-user code 'QsEntryPoint.QsEntryPoint.Main' Step into: Stepping over non-user code 'QsEntryPoint.QsEntryPoint.<Main>d__0..ctor' Loaded '/usr/local/share/dotnet/shared/Microsoft.NETCore.App/3.1.19/System.Collections.Immutable.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled. Loaded '/Users/user/qsharp/ExploreInterference/bin/Debug/netcoreapp3.1/Microsoft.Quantum.Runtime.Core.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled. Loaded '/usr/local/share/dotnet/shared/Microsoft.NETCore.App/3.1.19/netstandard.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled. Loaded '/Users/user/qsharp/ExploreInterference/bin/Debug/netcoreapp3.1/Microsoft.Quantum.EntryPointDriver.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled. Loaded '/Users/user/qsharp/ExploreInterference/bin/Debug/netcoreapp3.1/System.CommandLine.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled. Loaded '/usr/local/share/dotnet/shared/Microsoft.NETCore.App/3.1.19/System.Collections.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled. Loaded '/usr/local/share/dotnet/shared/Microsoft.NETCore.App/3.1.19/System.Linq.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled. Loaded '/usr/local/share/dotnet/shared/Microsoft.NETCore.App/3.1.19/System.Console.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled. Loaded '/usr/local/share/dotnet/shared/Microsoft.NETCore.App/3.1.19/System.Runtime.Extensions.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled. Loaded '/usr/local/share/dotnet/shared/Microsoft.NETCore.App/3.1.19/System.IO.FileSystem.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled. Loaded '/usr/local/share/dotnet/shared/Microsoft.NETCore.App/3.1.19/System.Threading.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled. Loaded '/Users/user/qsharp/ExploreInterference/bin/Debug/netcoreapp3.1/Microsoft.Azure.Quantum.Client.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled. Loaded '/usr/local/share/dotnet/shared/Microsoft.NETCore.App/3.1.19/System.Private.Uri.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled. Loaded '/usr/local/share/dotnet/shared/Microsoft.NETCore.App/3.1.19/System.ComponentModel.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled. Loaded '/usr/local/share/dotnet/shared/Microsoft.NETCore.App/3.1.19/System.Memory.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled. Loaded '/usr/local/share/dotnet/shared/Microsoft.NETCore.App/3.1.19/System.Buffers.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled. Loaded '/usr/local/share/dotnet/shared/Microsoft.NETCore.App/3.1.19/System.Diagnostics.Process.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled. Loaded '/usr/local/share/dotnet/shared/Microsoft.NETCore.App/3.1.19/System.ComponentModel.Primitives.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled. Loaded '/usr/local/share/dotnet/shared/Microsoft.NETCore.App/3.1.19/System.Diagnostics.Debug.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled. Loaded '/usr/local/share/dotnet/shared/Microsoft.NETCore.App/3.1.19/System.Collections.Concurrent.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled. Loaded '/Users/user/qsharp/ExploreInterference/bin/Debug/netcoreapp3.1/Microsoft.Quantum.Simulators.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled. Loaded '/Users/user/qsharp/ExploreInterference/bin/Debug/netcoreapp3.1/Microsoft.Quantum.Simulation.Common.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled. Loaded '/Users/user/qsharp/ExploreInterference/bin/Debug/netcoreapp3.1/Microsoft.Quantum.Targets.Interfaces.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled. Loaded '/usr/local/share/dotnet/shared/Microsoft.NETCore.App/3.1.19/System.Runtime.InteropServices.RuntimeInformation.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled. Loaded '/Users/user/qsharp/ExploreInterference/bin/Debug/netcoreapp3.1/Microsoft.Quantum.QSharp.Foundation.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled. Loaded '/usr/local/share/dotnet/shared/Microsoft.NETCore.App/3.1.19/System.Runtime.InteropServices.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled. The program '[24747] ExploreInterference.dll' has exited with code 0 (0x0).
@qudarr Could you please confirm if you are hitting this issue also without using the debugger? I.e. what is the failure if for the dotnet run
command?
Yes, I still encounter this issue. I get the SIGILL 4 error and no output in the terminal.
@qudarr Which versions of the .NET SDK do you have installed? For reference, the list of supported .NET versions for arm-based Macs can be found here: https://docs.microsoft.com/en-us/dotnet/core/install/macos#arm-based-macs.
For now, we do not officially support Apple Silicon systems. However, it would be good to understand what versions and setup is causing it to fail this way. You mentioned that you followed the instructions in the setup page from https://docs.microsoft.com/en-us/azure/quantum/quickstart-microsoft-qc?pivots=platform-ionq. Did you use the manual .NET installation and use the dotnet cli, or did you use a conda/anaconda standalone setup environment?
Hi swernli,
I use .NET version 3.1.413 and QDK version 0.22.187631 from within VS code.
Executing code has worked until ~2 weeks ago fine on my arm Mac. I tried reverting to an older QDK version, but to no avail.
The .net installation came automatically with selecting QDK in vs code.
Since then I also installed anaconda, but this didn't fix the issue.
Thanks for the extra info! Since we don't support Apple Silicon, we don't have additional steps for you to take. We'll improve our documentation to make this support statement more explicit, and I'll put a link here and close the issue once that doc update is available.
I can confirm that I can see the same on my M1 Mac. I saw this immediately after the net6.0 release but didn't have time to look closer at the time, and reverted to .NET Core 3.1 variant (0.21.2112180703) for the time being.
Previously QDK was broken with arm64 dotnet SDK (see https://github.com/microsoft/qsharp-compiler/issues/1273) but there was a workaround described in that issue where you could use the Rosetta emulate x64 dotnet SDK instead.
Since the move of QDK to .net6.0 it has been broken even under the emulated x64. What I see is the following error (which is effectively the same as the issue author's):
/Users/filipw/dev/demos/1 (main*) dotnet exec bin/Debug/net6.0/1.dll
[1] 74120 illegal hardware instruction
This only affects the default full state simulator. Running the same program using e.g. SparseSimulator, ResourcesEstimator or ToffoliSimulator is fine.
When the full state simulator is used, something very wrong happens, because it even fails for the most simple program that does not use any quantum state , for example for this:
namespace Demos {
open Microsoft.Quantum.Intrinsic;
@EntryPoint()
operation Main() : Unit {
Message("hello");
}
}
Given the popularity of arm64 Macs, and the fact you pretty much cannot buy x64 Macs anymore, it would be great to address this.
edit: I tried with Microsoft.Quantum.Experimental.OpenSystemsSimulator
and that also works, so it's really specific to the default full state simulator.
One more thing that I would like to add. Given that illegal hardware instructions are extremely rare for the dotnet runtime, my best guess is that this is not dotnet 6.0 related at all, but simply a native change to the default simulator (such as https://github.com/microsoft/qsharp-runtime/pull/895 or https://github.com/microsoft/qsharp-runtime/pull/897) that is the real root cause, coincided with the move to dotnet 6.0.
Rosetta 2 translation is documented to not support AVX instructions so it could be that.
I can confirm that copying Microsoft.Quantum.Experimental.Simulators.Runtime.dll
and libMicrosoft.Quantum.Simulator.Runtime.dylib
from microsoft.quantum.simulators.0.21.2112180703
over the ones included in microsoft.quantum.simulators.0.24.201332
(while keeping the rest of the packages at 0.24.201332 and the runtime at .net 6.0 level) solves the issue and allows the simulator to continue to work under x64 Rosetta translation.
Obviously this is a horrible workaround, but better than nothing!
Since the move of QDK to .net6.0 it has been broken even under the emulated x64.
Confirm, I tried using the x64 for emulation, but I get no output on dotnet run
.
Unfortunately the workaround I described above is the best I found - copy the simulators runtime from microsoft.quantum.simulators.0.21.2112180703
over the ones from the latest QDK, and you can now use the latest QDK with x64 emulation.
Very fragile and not sustainable though, plus you are stuck on an old simulator so something else will stop working sooner or later.
@filipw Does your workaround still work? I do not see /usr/local/share/dotnet/x64
in my installation:
PlatiniumM1Pro in /usr/local/share/dotnetπ
β― tree -f | grep x64
βΒ Β βββ ./sdk/6.0.302/Microsoft.VisualStudio.TestTools.CppUnitTestFramework.Executor.x64.dll
βΒ Β βββ ./sdk/6.0.302/Microsoft.VisualStudio.TestTools.CppUnitTestFramework.Executor.x64.dll.manifest
βΒ Β βββ ./sdk/6.0.302/Microsoft.VisualStudio.TestTools.CppUnitTestFramework.x64.dll
βΒ Β βΒ Β βββ ./sdk/6.0.302/TestHost/x64
βΒ Β βΒ Β βΒ Β βββ ./sdk/6.0.302/TestHost/x64/msdia140.dll
βΒ Β βΒ Β βΒ Β βββ ./sdk/6.0.302/TestHost/x64/msdia140.dll.manifest
βΒ Β βββ ./sdk/6.0.302/x64
βΒ Β βΒ Β βββ ./sdk/6.0.302/x64/dbghelp.dll
PlatiniumM1Pro in /usr/local/share/dotnetπ
β―
[...]
PlatiniumM1Pro in ~/Projects/runSayHello via .NET v6.0.302 π― net6.0
β― dotnet --info
.NET SDK (reflecting any global.json):
Version: 6.0.302
Commit: c857713418
Runtime Environment:
OS Name: Mac OS X
OS Version: 12.4
OS Platform: Darwin
RID: osx.12-arm64
Base Path: /usr/local/share/dotnet/sdk/6.0.302/
global.json file:
Not found
Host:
Version: 6.0.7
Architecture: arm64
Commit: 0ec02c8c96
.NET SDKs installed:
6.0.302 [/usr/local/share/dotnet/sdk]
.NET runtimes installed:
Microsoft.AspNetCore.App 6.0.7 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.NETCore.App 6.0.7 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
Download .NET:
https://aka.ms/dotnet-download
Learn about .NET Runtimes and SDKs:
https://aka.ms/dotnet/runtimes-sdk-info
yes it still works for me, but you need to explicitly install x64 dotnet as well, it will then create the /usr/local/share/dotnet/x64
folder (the default /usr/local/share/dotnet
path is reserved for the arm64 variant)
@filipw thanks, I didn't realize it required a separate installation. Here are the steps for anyone else trying:
- Install macOS x64 dotnet from https://dotnet.microsoft.com/en-us/download/dotnet/6.0 (direct link for v6.0.400) and set the path
export PATH=/usr/local/share/dotnet/x64:$PATH
- Obtain the right version of the simulator from https://www.nuget.org/api/v2/package/Microsoft.Quantum.Simulators/0.21.2112180703
- (In my case, I actually had the previous version already in the nuget cache.) Copy over the said libraries from 0.21.2112180703 to the most recent version of simulator inside the nuget cache:
β― ls ~/.nuget/packages/microsoft.quantum.simulators/0.21.2112180703/runtimes/osx-x64/native/
Microsoft.Quantum.Experimental.Simulators.Runtime.dll libMicrosoft.Quantum.Simulator.Runtime.dylib
PlatiniumM1Pro in ~/.nuget/packages/microsoft.quantum.simulators
β― cp 0.21.2112180703/runtimes/osx-x64/native/* 0.25.222597/runtimes/osx-x64/native
- Profit:
PlatiniumM1Pro in ~/Projects
β― dotnet new console -lang Q# -o runSayHello
The template "Console Application" was created successfully.
PlatiniumM1Pro in ~/Projects took 1s
β― cd runSayHello
PlatiniumM1Pro in ~/Projects/runSayHello via .NET v6.0.400 π― net6.0
β― dotnet run
Hello quantum world!
Does this solution still work? I tried this on QDK 0.27.244707 and received the following error.
Test Run Aborted with error System.Exception: One or more errors occurred. ---> System.Exception: Unable to read beyond the end of the stream. at System.IO.BinaryReader.Read7BitEncodedInt() at System.IO.BinaryReader.ReadString() at Microsoft.VisualStudio.TestPlatform.CommunicationUtilities.LengthPrefixCommunicationChannel.NotifyDataAvailable() at Microsoft.VisualStudio.TestPlatform.CommunicationUtilities.TcpClientExtensions.MessageLoopAsync(TcpClient client, ICommunicationChannel channel, Action
1 errorHandler, CancellationToken cancellationToken)
--- End of inner exception stack trace ---.
` Any help would be appreciated.
Does this solution still work? I tried this on QDK 0.27.244707 and received the following error.
Test Run Aborted with error System.Exception: One or more errors occurred. ---> System.Exception: Unable to read beyond the end of the stream. at System.IO.BinaryReader.Read7BitEncodedInt() at System.IO.BinaryReader.ReadString() at Microsoft.VisualStudio.TestPlatform.CommunicationUtilities.LengthPrefixCommunicationChannel.NotifyDataAvailable() at Microsoft.VisualStudio.TestPlatform.CommunicationUtilities.TcpClientExtensions.MessageLoopAsync(TcpClient client, ICommunicationChannel channel, Action
1 errorHandler, CancellationToken cancellationToken) --- End of inner exception stack trace ---. ` Any help would be appreciated.
@TheRyanVaughan Make sure you have .NET 6 installed (both the osx64 and arm64 versions), you might have to uninstall .NET 7 fully before installing them. That fixed it for me! hope this helps!