我正在创建一个程序Q#。
问题
你有两个处于状态 |00? 的量子比特。您的任务是为它们创建以下状态:1/3–?(|00?+|01?+|10?) 您必须实现一个操作,该操作将 2 个量子位的数组作为输入并且没有输出。您的解决方案的“输出”是它离开输入量子位的状态。
代码
namespace Solution {
open Microsoft.Quantum.Primitive;
open Microsoft.Quantum.Canon;
open Microsoft.Quantum.Math;
open Microsoft.Quantum.Convert;
operation Solve (qs : Qubit[]) : Unit
{
body
{
Ry(ArcCos(Sqrt(2.0/3.0))*2.0,qs[0]);
(ControlledOnInt(0,H))([qs[0]],qs[1]);
}
}
}
Run Code Online (Sandbox Code Playgroud)
但是当我运行它时会显示以下错误。
错误
CSC : error CS5001: Program does not contain a static 'Main' method suitable for an entry point
[C:\Users\Pawar\Desktop\HK\codeforces\Q#\Solution\Solution.csproj]
Run Code Online (Sandbox Code Playgroud)
所以我试着把EntryPoint()方法声明放在前面。这向我显示了不同的错误
错误 QS6231:无效的入口点。Qubit 类型的值不能用作参数或返回值到入口点。[C:\Users\Pawar\Desktop\HK\codeforces\Q#\Solution\Solution.csproj]
请帮我如何正确运行它?谢谢 ??
为了将 Q# 程序作为可执行文件运行,您需要@EntryPoint()定义一个操作。您可以在这篇优秀的博文中阅读更多内容:https : //qsharp.community/blog/qsharp-entrypoint/。
具体来说,在您的情况下,错误消息表明这Qubit[]不是程序主入口点的有效参数。这是有道理的,因为从命令行执行程序时传递量子位数组是没有意义的。而且,您的操作不会打印任何内容或返回任何结果,因此您将无法看到它在做什么。
您可能应该创建一个@EntryPoint()包装器操作,使用适当的参数调用现有操作,可能会打印一些诊断信息,然后返回一些结果。在您的情况下,您也许可以执行以下操作(请注意您需要打开的其他命名空间):
open Microsoft.Quantum.Diagnostics;
open Microsoft.Quantum.Measurement;
@EntryPoint()
operation SolveForTwoQubits() : Result[]
{
using (qubits = Qubit[2])
{
Solve(qubits); // invoke your existing Solve operation
DumpMachine(); // outputs the state of your qubits
let results = MultiM(qubits); // measure the qubits
ResetAll(qubits); // reset the qubits to the initial state
return results; // return the measured results
}
}
Run Code Online (Sandbox Code Playgroud)
这将给出一些如下所示的输出:
# wave function for qubits with ids (least to most significant): 0;1
?0?: 0.577350 + 0.000000 i == ******* [ 0.333333 ] --- [ 0.00000 rad ]
?1?: 0.577350 + 0.000000 i == ******* [ 0.333333 ] --- [ 0.00000 rad ]
?2?: 0.577350 + 0.000000 i == ******* [ 0.333333 ] --- [ 0.00000 rad ]
?3?: 0.000000 + 0.000000 i == [ 0.000000 ]
[Zero,One]
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
174 次 |
| 最近记录: |