qsharp-compiler icon indicating copy to clipboard operation
qsharp-compiler copied to clipboard

QDK is broken when ARM64 .NET 6 SDK is installed

Open filipw opened this issue 4 years ago • 11 comments

Describe the bug

Since .NET 6 introduced the split into how the ARM64 and x64 SDKs are installed, the experience with Q# is broken on ARM (where things used to work OK through emulation). I can only speak about MacOS here, but it could be that other platforms experience the same.

If you have .NET 6 ARM SDK installed, and x64 versions of SDK 5.x.x and 3.1.x, the "dotnet" command from the CLI points to the ARM SDK.

  • ARM SDK is now located at /usr/local/share/dotnet
  • x64 SDK is now located at /usr/local/share/dotnet/x64

This leads to a lot of things breaking in Q# such as, trying to run/compile the program does not work:

dotnet run /Users/filipw/.nuget/packages/microsoft.quantum.sdk/0.19.2109165653/Sdk/Sdk.targets(62,5): error MSB3073: The command "dotnet "/Users/filipw/.nuget/packages/microsoft.quantum.sdk/0.19.2109165653/DefaultItems/../tools/utils/Microsoft.Quantum.Sdk.BuildConfiguration.dll" -v Normal --output "obj/qsharp/config/qsc.config" --QscReferences "(/Users/filipw/.nuget/packages/microsoft.quantum.csharpgeneration/0.19.2109165653/build//../lib/netstandard2.1/Microsoft.Quantum.CSharpGeneration.dll, -1)"" exited with code 134. [/Users/filipw/dev/qsharp-code/qpe/qpe.csproj]

The actual problem is ARM incompatibility:

Unhandled exception. System.BadImageFormatException: Could not load file or assembly '/Users/filipw/.nuget/packages/microsoft.quantum.sdk/0.19.2109165653/tools/utils/Microsoft.Quantum.Sdk.BuildConfiguration.dll'. An attempt was made to load a program with an incorrect format.

The current workaround, although not ideal is to export the x64 path as dotnet, which bypasses the native ARM SDK

export PATH=/usr/local/share/dotnet/x64:$PATH

though doing this globally is of course not really feasible so it's needed per terminal session which is not great.

To Reproduce

Setup NET 6 SDK according to the instructions in https://github.com/dotnet/sdk/issues/22380

Expected behavior

Either everything works out of the box, or I have an option to provide custom path to the "dotnet" executabale, rather than QDK taking it from the path. In the latter case, I could just point it at /usr/local/share/dotnet/x64

System information

  • MacOS Monterey 12.0.1, M1 2020
  • QDK 0.19.2109165653

dotnet info:

(base) /Users/filipw » dotnet --info                                                                                                                                                                                                                                              ~  
.NET SDK (reflecting any global.json):
 Version:   6.0.100
 Commit:    9e8b04bbff

Runtime Environment:
 OS Name:     Mac OS X
 OS Version:  12.0
 OS Platform: Darwin
 RID:         osx-arm64
 Base Path:   /usr/local/share/dotnet/sdk/6.0.100/

Host (useful for support):
  Version: 6.0.0
  Commit:  4822e3c3aa

.NET SDKs installed:
  6.0.100 [/usr/local/share/dotnet/sdk]

.NET runtimes installed:
  Microsoft.AspNetCore.App 6.0.0 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 6.0.0 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]

To install additional .NET runtimes or SDKs:
  https://aka.ms/dotnet-download

dotnet x64 info

(base) /Users/filipw » dotnet64 --info                                                                                                                                                                                                                                         ~ 1 ↵ 
.NET SDK (reflecting any global.json):
 Version:   5.0.403
 Commit:    bf9d168ac2

Runtime Environment:
 OS Name:     Mac OS X
 OS Version:  11.0
 OS Platform: Darwin
 RID:         osx-x64
 Base Path:   /usr/local/share/dotnet/x64/sdk/5.0.403/

Host (useful for support):
  Version: 5.0.12
  Commit:  7211aa01b3

.NET SDKs installed:
  3.1.415 [/usr/local/share/dotnet/x64/sdk]
  5.0.403 [/usr/local/share/dotnet/x64/sdk]

.NET runtimes installed:
  Microsoft.AspNetCore.App 3.1.21 [/usr/local/share/dotnet/x64/shared/Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 5.0.12 [/usr/local/share/dotnet/x64/shared/Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 3.1.21 [/usr/local/share/dotnet/x64/shared/Microsoft.NETCore.App]
  Microsoft.NETCore.App 5.0.12 [/usr/local/share/dotnet/x64/shared/Microsoft.NETCore.App]

To install additional .NET runtimes or SDKs:
  https://aka.ms/dotnet-download

filipw avatar Nov 29 '21 19:11 filipw

Thanks for the report, @filipw! We're currently working on adding support for .NET6 in the QDK, and we'll consider this issue as part of the work we're doing.

ricardo-espinoza avatar Dec 01 '21 22:12 ricardo-espinoza

I believe .net6 support was added a few weeks ago, but I am still getting this same issue:

PlatiniumM1Pro in ~/Projects/runSayHello via .NET v6.0.104 🎯 net6.0 ❯ dotnet run /Users/kartik/.nuget/packages/microsoft.quantum.sdk/0.24.208024/Sdk/Sdk.targets(62,5): error MSB3073: The command "dotnet "/Users/kartik/.nuget/packages/microsoft.quantum.sdk/0.24.208024/DefaultItems/../tools/utils/Microsoft.Quantum.Sdk.BuildConfiguration.dll" -v Normal --output "obj/qsharp/config/qsc.config" --QscReferences "(/Users/kartik/.nuget/packages/microsoft.quantum.csharpgeneration/0.24.208024/build//../lib/netstandard2.1/Microsoft.Quantum.CSharpGeneration.dll, -1)"" exited with code 134. [/Users/kartik/Projects/runSayHello/runSayHello.csproj]

The build failed. Fix the build errors and run again.

k4rtik avatar May 18 '22 19:05 k4rtik

same here, on a M1 Mac mini, with latest Microsoft.Quantum.ProjectTemplates so definitely still not fixed

rodrmoya avatar Jul 17 '22 14:07 rodrmoya

@ricardo-espinoza is there any possibility to fix this issue? It seems the x64-simulation workaround that @filipw had described in the OP does not work anymore.

EDIT: it still works, but requires extra hoops to jump.

k4rtik avatar Jul 20 '22 15:07 k4rtik

Currently trying the workaround suggested by @k4rtik but this does still seem to be an issue on my M1 Max MacBook. Additionally, running in a container (such as mcr.microsoft.com/quantum/samples) doesn't work either, presumably because the container is only trying it's best to pretend it's x86 without actually emulating it properly.

SpyreFallen avatar Aug 07 '22 13:08 SpyreFallen

I thought I'd give it a try with the latest version of dotnet and quantum SDK, but it's still broken with .NET 7 and QDK version 0.27.238334.

devloperrobin avatar Nov 20 '22 16:11 devloperrobin

Unfortunately yes, it is still broken (yesterday was the 1st birthday of the bug report 🎂😀) - but the workaround with using the old simulator, and the x64 Rosetta emulation still works (although it's far from ideal)

filipw avatar Nov 30 '22 15:11 filipw

Still not working on Mac M1 2020 :/

lmarangio avatar May 26 '23 14:05 lmarangio

A good alternative at this point is to compile to QIR and use a QIR runner instead

filipw avatar Jun 05 '23 07:06 filipw

still not working on Mac M1 with Venture 13.1.

pascal1609 avatar Dec 08 '23 10:12 pascal1609

I believe they released a new QDK that works universally: https://github.com/microsoft/qsharp

k4rtik avatar Dec 08 '23 12:12 k4rtik