Dies ist mein erstes Q # -Programm und ich folge diesem ersten Link. https://docs.microsoft.com/en-us/quantum/quantum-writeaquantumprogram?view=qsharp-previewQuantum Program Der Name 'BellTest' existiert nicht im aktuellen Kontext
Fehler ist
Der Name ‚BellTest‘ existiert nicht im aktuellen Kontext aber seine Definition in den Bell.cs
Ich folgte den Schritten und wenn sein mit Fehlern Aufbau . Ich bin mir nicht sicher, wie die Operationen von .qs file
in den Treiber c# file
importiert werden, da dieser Fehler so aussieht, als könnte er diese Operation nicht finden.
Jede Hilfe wirklich
Hier geschätzt wird, ist der Code
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);
}
}
}
erhielt ich, dass Fehler ein paar Mal, als ich hatte ein Kompilierfehler im q # -Code. – speckledcarp