Ошибки компилятора Q # в Quantum Development Kit на macOS - PullRequest
0 голосов
/ 30 октября 2018

У меня есть ошибка компиляции этого простого примера Q # недавно Microsoft Quantum Development Kit:

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.

Более простой рабочий пример: здесь .

Ответы [ 2 ]

0 голосов
/ 08 февраля 2019

Я столкнулся с той же проблемой, см. Ниже:

Изменить строку 6 Driver.cs

namespace Quantum.Bell

https://gist.github.com/He-ya/4cc50073e75d5dfb2aeeb535b5dec87f

или вы можете добавить using Quantum.Bell; вместо добавления namespace Quantum.Bell

0 голосов
/ 31 октября 2018

Существует несоответствие пространств имен: пространство имен, используемое в коде Q #, равно Quantum.Bell, тогда как пространство имен, используемое в коде C #, просто Bell - вам нужно либо исправить файлы, чтобы использовать то же пространство имен, либо добавить using Quantum.Bell; к коду C #.

...