static void Main(string[] args) { // We begin by defining a quantum simulator to be our target machine using (var qsim = new QuantumSimulator()) { #region Simple oracles // Create an oracle from a C# lambda. // The result is an operation with signature // (Qubit[], Qubit[]) => Unit // that can be passed to Q#. var oracle = EmulatedOracleFactory.Create(qsim, (x, y) => 42 ^ y); // Provide the definition of an oracle that has been declared in // Q#, replacing the stub body defined in Operations.qs. This // way, the `HalfAnswer` oracle is accessible via the // `OracleEmulation` namespace and does not have to be passed to // operations depending on it (unlike the oracle created above). EmulatedOracleFactory.Register <HalfAnswer>(qsim, (x, y) => 21 ^ y); // Execute the simple oracles and print the results. RunConstantOracles.Run(qsim, oracle).Wait(); Pause(); #endregion #region Emulated arithmetic // Run the demo for emulated arithmetic. RunAddOracle.Run(qsim).Wait(); Pause(); #endregion } }
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(); }