首页 > 解决方案 > 为什么我在 q# 中使用 DumpMachine 时会出现错误?

问题描述

这是我的代码:

using (q = Qubit()) {
            Message("Input:");
            Message("q = ∣0❭, index = 1");

            Message("Requaired Output:");
            Message("∣0❭:     0.707107 +  0.000000 i");
            Message("∣1❭:     0.000000 + -0.707107 i");

            Task12(q, 1);
            Message("Your Output:");
            DumpMachine();

            Reset(q);
        }

但我得到这个错误:

The type or namespace name '_2e502c3cdee5457783e1ea9b1f54eb1b_DumpMachine' does not exist in the namespace 'Microsoft.Quantum.Diagnostics' (are you missing an assembly reference?)

有谁知道为什么?

标签: q#

解决方案


你能验证你是否open Microsoft.Quantum.Diagnostics;列出了吗?

我复制了您的代码并添加了功能,它适用于我,我使用 .NET Core 3.1 和 VisualStudio 2019,这是我的代码,我还将它添加到 GitHub https://github.com/nahidf-adventures/qsharp-adventures /tree/master/src/QbitSample

namespace QbitSample {

    open Microsoft.Quantum.Canon;
    open Microsoft.Quantum.Intrinsic;
    open Microsoft.Quantum.Measurement;
    open Microsoft.Quantum.Diagnostics;


    @EntryPoint()
    operation HelloQ() : Unit {
        using (q = Qubit()) {
            Message("Input:");
            Message("q = ∣0❭, index = 1");

            Message("Requaired Output:");
            Message("∣0❭:     0.707107 +  0.000000 i");
            Message("∣1❭:     0.000000 + -0.707107 i");

            Task12(q, 1);
            Message("Your Output:");
            DumpMachine();

            Reset(q);
        }
    }

    operation Task12(q: Qubit, count : Int) : Unit {
        }
    }

推荐阅读