Пример #1
0
        static void Main(string[] args)
        {
            int ones  = 0;
            int zeros = 0;

            // Show statistical propability of Superposition
            using (var qsim = new QuantumSimulator())
            {
                for (int k = 0; k < 1000; k++)
                {
                    var result = Superposition.Run(qsim).Result;

                    if (result == Result.One)
                    {
                        ones++;
                    }
                    else
                    {
                        zeros++;
                    }
                }
            }

            Console.WriteLine("==============================================");
            Console.WriteLine("======== Superposition Calculations ==========");
            Console.WriteLine("==============================================");
            Console.WriteLine();
            Console.WriteLine($"Number of ONES: {ones}, Number of ZEROS: {zeros}");
            Console.WriteLine($"With a 50% propability they should have a simular distribution");
            Console.WriteLine();

            Console.ReadKey();
        }
Пример #2
0
        static void Main(string[] args)
        {
            using (var qsim = new QuantumSimulator())
            {
                //  Each Q# operation generates a C# class with the same name. 
                // This class has a Run method that asynchronously executes the operation. 
                // The execution is asynchronous because execution on actual hardware will be asynchronous.
                // However, Result blocks execution until task completes; return synchronously
                var res = HelloQ.Run(qsim).Result;
            }
            System.Console.WriteLine("Press any key to continue...");
            System.Console.WriteLine("Next up: Superposition: ");
            Console.ReadKey();
                // work with superposition
            using (var qsim = new QuantumSimulator())
            {
                // Try initial values
                Result[] initials = new Result[] { Result.Zero, Result.One };
                foreach (Result initial in initials)
                {
                    // '.Result' blocks execution until the task completes and returns the result synchronously.
                    var res = Superposition.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.WriteLine("Next up: Entanglement: ");
            Console.ReadKey();
                // work with entanglement
            using (var qsim = new QuantumSimulator())
            {
                Result[] initials = new Result[] { Result.Zero, Result.One };
                foreach (Result initial in initials)
                {
                    var res = Entanglement.Run(qsim, 1000, initial).Result;
                    var (numZeros, numOnes, agree) = res;
                    System.Console.WriteLine(
                        $"Init:{initial,-4} 0s={numZeros,-4} 1s={numOnes,-4} agree={agree,-4}");
                }
            }

            System.Console.WriteLine("Press any key to continue...");
            Console.ReadKey();
        }
Пример #3
0
 static void Run_Superposition(string[] args)
 {
     Console.WriteLine("Running: Superposition Test");
     // Initialise the quantum simulator
     using (var qsim = new QuantumSimulator())
     {
         Result[] initials = { Result.Zero, Result.One };
         foreach (var initial in initials)
         {
             // Execute the quantum function
             var res = Superposition.Run(qsim, 1000, initial).Result;
             var(numZeros, numOnes) = res;
             Console.WriteLine($"Init:{initial,-4} 0s={numZeros,-4} 1s={numOnes,-4}");
         }
     }
     Console.WriteLine();
 }