示例#1
0
        static void Main(string[] args)
        {
            int nLayers = 3;

            using QuantumSimulator qsim = new QuantumSimulator();
            bool[] result = GroversSearch_Main.Run(qsim, nLayers).Result.ToArray();

            // Convert the result into a tree decoration instruction
            for (int i = 0; i < nLayers; ++i)
            {
                for (int j = 0; j < nLayers - i; ++j)
                {
                    Console.Write(" ");
                }
                for (int j = i * i; j < (i + 1) * (i + 1); j++)
                {
                    Console.Write(result[j] ? "0" : "X");
                }
                Console.WriteLine();
            }
            for (int j = 0; j < nLayers; ++j)
            {
                Console.Write(" ");
            }
            Console.WriteLine("|");

            Console.WriteLine("Press any key to continue...");
            Console.ReadKey();
        }
示例#2
0
        static void Main(string[] args)
        {
            int  nLayers = 4;
            bool emulate = true;

            Stopwatch stopWatch = new Stopwatch();

            stopWatch.Start();
            using QuantumSimulator qsim = new QuantumSimulator();

            // define EmulatedOracle (operation declared in Q# code without a body implementation) as an emulation described by DecorationsCheck
            EmulatedOracleFactory.Register <EmulatedOracle>(qsim, (n, x, y) => DecorationsCheck(n, x) ^ y);

            bool[] result = GroversSearch_Main.Run(qsim, nLayers, emulate).Result.ToArray();

            stopWatch.Stop();
            // Get the elapsed time as a TimeSpan value.
            TimeSpan ts = stopWatch.Elapsed;

            // Format and display the TimeSpan value.
            string elapsedTime = String.Format("{0:00}:{1:00}:{2:00}.{3:00}",
                                               ts.Hours, ts.Minutes, ts.Seconds,
                                               ts.Milliseconds / 10);

            Console.WriteLine("RunTime " + elapsedTime);

            // Convert the result into a tree decoration instruction
            for (int i = 0; i < nLayers; ++i)
            {
                for (int j = 0; j < nLayers - i; ++j)
                {
                    Console.Write(" ");
                }
                for (int j = i * i; j < (i + 1) * (i + 1); j++)
                {
                    Console.Write(result[j] ? "0" : "X");
                }
                Console.WriteLine();
            }
            for (int j = 0; j < nLayers; ++j)
            {
                Console.Write(" ");
            }
            Console.WriteLine("|");

            Console.WriteLine("Press any key to continue...");
            Console.ReadKey();
        }