gpt4 book ai didi

.net - macOS 上的 Quantum 开发套件中的 Q# 编译器错误

转载 作者:行者123 更新时间:2023-12-01 23:22:18 25 4
gpt4 key购买 nike

我在新的 Microsoft Quantum 开发套件的这个简单 Q# 示例中遇到编译错误:

namespace Quantum.Bell
{
open Microsoft.Quantum.Primitive;
open Microsoft.Quantum.Canon;

operation Set (desired: Result, q1: Qubit) : Unit
{
let current = M(q1);
if (desired != current)
{
X(q1);
}
}

operation BellTest (count : Int, initial: Result) : (Int, Int)
{
mutable numOnes = 0;
using (qubit = Qubit())
{
for (test in 1..count)
{
Set (initial, qubit);

let res = M (qubit);

// Count the number of ones we saw:
if (res == One)
{
set numOnes = numOnes + 1;
}
}
Set(Zero, qubit);
}

// Return number of times we saw a |0> and number of times we saw a |1>
return (count-numOnes, numOnes);
}
}

C# 量子模拟器代码如下

using System;

using Microsoft.Quantum.Simulation.Core;
using Microsoft.Quantum.Simulation.Simulators;

namespace Bell
{
class Driver
{
static void Main(string[] args)
{
using (var qsim = new QuantumSimulator())
{
// Try initial values
Result[] initials = new Result[] { Result.Zero, Result.One };
foreach (Result initial in initials)
{
var res = BellTest.Run(qsim, 1000, initial).Result;
var (numZeros, numOnes) = res;
System.Console.WriteLine(
$"Init:{initial,-4} 0s={numZeros,-4} 1s={numOnes,-4}");
}
}

System.Console.WriteLine("Press any key to continue...");
System.Console.ReadKey();
}
}
}

使用 dotnet run 编译时,我得到

ip-192-168-1-103:Bell loretoparisi$ dotnet run
Driver.cs(18,31): error CS0103: The name 'BellTest' does not exist in the current context [/Users/loretoparisi/Documents/Projects/AI/quantum/Bell/Bell.csproj]
Driver.cs(19,26): error CS8130: Cannot infer the type of implicitly-typed deconstruction variable 'numZeros'. [/Users/loretoparisi/Documents/Projects/AI/quantum/Bell/Bell.csproj]
Driver.cs(19,36): error CS8130: Cannot infer the type of implicitly-typed deconstruction variable 'numOnes'. [/Users/loretoparisi/Documents/Projects/AI/quantum/Bell/Bell.csproj]

The build failed. Please fix the build errors and run again.

一个更简单的工作示例是 here .

最佳答案

命名空间不匹配:Q# 代码中使用的命名空间是 Quantum.Bell,而 C# 代码中使用的命名空间只是 Bell - 您需要修复文件以使用相同的命名空间或将 using Quantum.Bell; 添加到 C# 代码。

关于.net - macOS 上的 Quantum 开发套件中的 Q# 编译器错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53072732/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com