量子程序当前环境中不存在名称"BellTest" [英] Quantum Program The name 'BellTest' does not exist in the current context

查看:162
本文介绍了量子程序当前环境中不存在名称"BellTest"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的第一个Q#程序,我正在关注此入门链接.

This is my first Q# program and i'm following this getting started link.https://docs.microsoft.com/en-us/quantum/quantum-writeaquantumprogram?view=qsharp-preview

错误是

名称"BellTest"在当前上下文中不存在 但它在Bell.cs中定义

The name 'BellTest' does not exist in the current context but its defined in the Bell.cs

我按照步骤进行操作,并且在构建时出现错误.我不确定如何将操作从.qs file导入驱动程序c# file,因为此错误似乎找不到该操作.

I followed the steps and when building its having errors. I'm not sure how to import the operations from .qs file to driver c# file as this error looks like it can't find that operation.

我们非常感谢您的帮助

这是代码

Driver.cs

Driver.cs

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

namespace Quantum.Bell
{
    class Driver
    {
        static void Main(string[] args)
        {
            using (var sim = new QuantumSimulator())
            {
                // Try initial values
                Result[] initials = new Result[] { Result.Zero, Result.One };
                foreach (Result initial in initials)
                {
                    var res = BellTest.Run(sim, 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();

        }
    }
}

Bell.qs

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

    operation Set (desired:Result,q1:Qubit) : ()
    {
        body
        {

             let current = M(q1);

            if (desired != current)
            {
                X(q1);
            }

        }
    }

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

                    let res = M (qubits[0]);

                    // Count the number of ones we saw:
                    if (res == One)
                    {
                        set numOnes = numOnes + 1;
                    }
                }
                Set(Zero, qubits[0]);
            }
            // Return number of times we saw a |0> and number of times we saw a |1>
            return (count-numOnes, numOnes);
        }    
    }
}

推荐答案

我也遇到了同样的错误,但是我可以通过按F5键来做到这一点.

I also got the same error, but I was able to do it by pressing the F5 key.

也许Visual Studio编辑器尚未完全支持.qs文件. 在.cs文件和.qs文件之间,命名空间共享似乎无法正常工作.

Perhaps the Visual Studio editor is not yet fully support to the .qs file. Namespace sharing does not seem to be working properly between .cs file and .qs file.

我能够在开发环境中使用您的代码来执行.

I was able to execute using your code in my development environment.

-

IDE:Visual Studio Community 2017(版本15.5.2)
开发套件:Microsoft Quantum开发套件(0和1)

IDE: Visual Studio Community 2017 (Version 15.5.2)
Dev Kit: Microsoft Quantum Development Kit (0 and 1)

这篇关于量子程序当前环境中不存在名称"BellTest"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆