我正在Windows 10计算机上尝试新的Q#语言。
我有三台Windows 10机器,它们都有WSL(Ubuntu)。
在三个中,有两个能够安装最新的.NET Core SDK并运行Q#
代码
因为它在Windows上本地执行。
但是,第三台机器无法运行(但编译完美)。
不知何故,SDK的安装正在被破坏,我在C#
代码调用来自Microsoft.Quantum.*
的方法时获得了运行时异常。
我尝试重新安装Ubuntu WSL(干净),但问题仍然存在。
它与这个机器上的事实有关,因为在这台机器上,WSL在预览之后和运送到Win Store之前就存在了。
为了实验我下载了Debian(来自商店),只安装了.NET SDK,Q#
代码运行正常。
现在问题是我如何 PURGE 传统的Ubunut WSL并在该特定计算机上进行全新安装?
这是WSL在dotnet run
命令
Unhandled Exception: System.DllNotFoundException: Unable to load DLL
'Microsoft.Quantum.Simulator.Runtime.dll': The specified module or one of its dependencies could not be found.
(Exception from HRESULT: 0x8007007E)
at Microsoft.Quantum.Simulation.Simulators.QuantumSimulator.Init()
at Microsoft.Quantum.Simulation.Simulators.QuantumSimulator..ctor(Boolean
throwOnReleasingQubitsNotInZeroState, Nullable`1 randomNumberGeneratorSeed,
Boolean disableBorrowing)
at Bell.Driver.Test_Simple() in
/mnt/c/Users/.../Programming/Temp/QS/Bell/Driver.cs:line 26
at Bell.Driver.Main(String[] args) in
/mnt/c/Users/.../Programming/Temp/QS/Bell/Driver.cs:line 12
这是我调用Q#
相关代码
private static void Test_Simple()
{
WriteLine($"\r\n{nameof(Test_Simple)}");
var header = $"{"Initial", -10}|{Result.Zero, -10}|{Result.One, -10}|";
WriteLine(new string('-', header.Length));
WriteLine(header);
WriteLine(new string('-', header.Length));
// --> Exception is thrown here <--
using (var simulator = new QuantumSimulator())
{
var nRuns = 10_000;
var initials = new [] { Result.Zero, Result.One };
foreach (var init in initials)
{
var (nZero, nOne) =
Quantum.BellTestSimple.Run(simulator, nRuns, init).Result;
WriteLine($"{init, -10}|{nZero, -10}|{nOne, -10}");
}
}
}
这个完全相同的项目在本机和Debian子系统上的相同机器上运行良好,但在Ubuntu子系统上失败。
答案 0 :(得分:1)
可能是您缺少struct OSCArgument
{
char Type;
Variant Data;
}
struct OSCBundleElement
{
virtual ~OSCBundleElement() {}
};
struct OSCMessage : OSCBundleElement
{
String AddressPattern;
DynamicArray<OSCArgument> Arguments;
};
struct OSCBundle : OSCBundleElement
{
TDateTime TimeTag;
DynamicArray<OSCBundleElement*> Elements;
~OSCBundle()
{
int len = Elements.Length;
for (int i = 0; i < len; ++i)
delete Elements[i];
}
};
int32_t readInt32(const TIdBytes &Bytes, int &offset)
{
uint32_t ret = GStack->NetworkToHost(BytesToUInt32(Bytes, offset));
offet += 4;
return reinterpret_cast<int32_t&>(ret);
}
TDateTime readOSCTimeTag(const TIdBytes &Bytes, int &offset)
{
int32_t secondsSinceEpoch = readInt32(Bytes, offset); // since January 1 1900 00:00:00
int32_t fractionalSeconds = readInt32(Bytes, offset); // precision of about 200 picoseconds
// TODO: convert seconds to TDateTime...
TDateTime ret = ...;
return ret;
}
float readFloat32(const TIdBytes &Bytes, int &offset)
{
uint32_t ret = BytesToUInt32(Bytes, offset);
offet += 4;
return reinterpret_cast<float&>(ret);
}
String readOSCString(const TIdBytes &Bytes, int &offset)
{
int found = ByteIndex(0x00, Bytes, offset);
if (found == -1) throw ...; // error!
int len = found - offset;
String ret = BytesToString(Bytes, offset, len, IndyTextEncoding_ASCII());
len = ((len + 3) & ~3)); // round up to even multiple of 32 bits
offset += len;
return ret;
}
TIdBytes readOSCBlob(const TIdBytes &Bytes, int &offset)
{
int32_t size = readInt32(Bytes, offset);
TIdBytes ret;
ret.Length = size;
CopyTIdBytes(Bytes, offset, ret, 0, size);
size = ((size + 3) & ~3)); // round up to even multiple of 32 bits
offset += size;
return ret;
}
OSCMessage* readOSCMessage(const TIdBytes &Bytes, int &offset);
OSCBundle* readOSCBundle(const TIdBytes &Bytes, int &offset);
OSCBundleElement* readOSCBundleElement(const TIdBytes &Bytes, int &offset)
{
TIdBytes data = readOSCBlob(Bytes, offset);
int dataOffset = 0;
switch (data[0])
{
case '/': return readOSCMessage(data, dataOffset);
case '#': return readOSCBundle(data, dataOffset);
}
throw ...; // unknown data!
}
Variant readOSCArgumentData(char ArgType, const TIdBytes &Bytes, int &offset)
{
switch (ArgType)
{
case 'i': return readInt32(Bytes, offset);
case 'f': return readFloat32(Bytes, offset);
case 's': return readOSCString(Bytes, offset);
case 'b': return readOSCBlob(Bytes, offset);
// other types as needed ...
}
throw ...; // unknown data!
}
OSCMessage* readOSCMessage(const TIdBytes &Bytes, int &offset)
{
OSCMessage* ret = new OSCMessage;
try
{
ret->AddressPattern = readOSCString(Bytes, offset);
String ArgumentTypes = readOSCString(Bytes, offset);
if (ArgumentTypes[1] != ',') throw ...; // error!
for (int i = 2; i <= ret->ArgumentTypes.Length(); ++i)
{
OSCArgument arg;
arg.Type = ArgumentTypes[i];
arg.Data = readOSCArgumentData(arg.Type, Bytes, offset);
ret.Arguments.Length = ret.Arguments.Length + 1;
ret.Arguments[ret.Arguments.High] = arg;
}
}
catch (...)
{
delete ret;
throw;
}
return ret;
}
OSCBundle* readOSCBundle(const TIdBytes &Bytes, int &offset)
{
if (readOSCString(Bytes, offset) != "#bundle")
throw ...; // error!
OSCBundle *ret = new OSCBundle;
try
{
ret->TimeTag = readOSCTimeTag(Bytes, offset);
int len = Bytes.Length;
while (offset < len)
{
OSCBundleElement *element = readOSCBundleElement(Bytes, offset);
try
{
ret->Elements.Length = ret->Elements.Length + 1;
ret->Elements[ret->Elements.High] = element;
}
catch (...)
{
delete element;
throw;
}
}
}
catch (...)
{
delete ret;
throw;
}
return ret;
}
void __fastcall TMain::UDPServerUDPRead(TIdUDPListenerThread *AThread, const TIdBytes AData,
TIdSocketHandle *ABinding)
{
int offset = 0;
if (AData[0] == '/')
{
OSCMessage *msg = readOSCMessage(AData, offset);
// process msg as needed...
delete msg;
}
else if (AData[0] == '#')
{
OSCBundle *bundle = readOSCBundle(AData, offset);
// process bundle as needed...
delete bundle;
}
else
{
// unknown data!
}
}
库所依赖的本机库。例如,其他用户here他们缺少libgomp1。要检查是否具有所需的所有依赖项,可以使用Microsoft.Quantum.Simulator.Runtime.dll
来获取有关如何解析每个本机运行时依赖项的报告。例如:
ldd
此代码段向我们显示$ ldd ~/.nuget/packages/microsoft.quantum.development.kit/0.2.1802.2202-preview/runtimes/linux-x64/native/Microsoft.Quantum.Simulator.Runtime.dll
linux-vdso.so.1 => (0x00007fffc4fab000)
libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007f1d692d0000)
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f1d68fc0000)
libgomp.so.1 => /usr/lib/x86_64-linux-gnu/libgomp.so.1 (0x00007f1d68d80000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f1d689b0000)
/lib64/ld-linux-x86-64.so.2 (0x00007f1d69a00000)
libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007f1d68790000)
libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f1d68570000)
libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f1d68350000)
已成功解析为libgomp.so.1
,而如果该库遗失,则您会获得不同的商家信息:
/usr/lib/x86_64-linux-gnu/libgomp.so.1