public void QuantumTestSuiteSelfTests(TestOperation op)
        {
            var sim = new TrivialSimulator(); //these tests do not do anything quantum

            sim.OnLog += (msg) => { output.WriteLine(msg); };
            op.TestOperationRunner(sim);
        }
 public void QrackSimTestTarget(TestOperation op)
 {
     using (var sim = new QrackSimulator(throwOnReleasingQubitsNotInZeroState: true))
     {
         op.TestOperationRunner(sim);
     }
 }
Exemple #3
0
        public void QuantumSimulatorOldCanonTarget(TestOperation opData)
        {
            // It is convenient to store seed for test that can fail with small probability
            uint?seed = RetriveStoredSeed(opData);

            using (var sim = new QuantumSimulator(randomNumberGeneratorSeed: seed))
            {
#if DEBUG
                // Frequently tests include measurement and randomness.
                // To reproduce the failed test it is useful to record seed that has been used
                // for the random number generator inside the simulator.
                LogSimulatorSeed(opData, sim);

                // This ensures that when the test is run in Debug mode, all message logged in
                // Q# by calling Microsoft.Quantum.Primitives.Message show-up
                // in Debug output
                sim.OnLog += (string message) => { Debug.WriteLine(message); };

                // this ensures that all message logged in Q# by calling
                // Microsoft.Quantum.Primitives.Message show-up
                // in test output
                sim.OnLog += (string message) => { output.WriteLine(message); };

                // executes operation
                opData.TestOperationRunner(sim);
#else
                throw new System.Exception("Tests should be removed from Microsoft.Quantum.Canon.dll.");
#endif
            }
        }
Exemple #4
0
        public void QuantumSimulatorTargetShouldFail(TestOperation opData)
        {
            // It is convenient to store seed for test that can fail with small probability
            uint?seed = RetriveStoredSeed(opData);

            using (var sim = new QuantumSimulator(randomNumberGeneratorSeed: seed))
            {
                // Frequently tests include measurement and randomness.
                // To reproduce the failed test it is useful to record seed that has been used
                // for the random number generator inside the simulator.
                LogSimulatorSeed(opData, sim);

                // This ensures that when the test is run in Debug mode, all message logged in
                // Q# by calling Microsoft.Quantum.Primitives.Message show-up
                // in Debug output
                sim.OnLog += (string message) => { Debug.WriteLine(message); };

                // this ensures that all message logged in Q# by calling
                // Microsoft.Quantum.Primitives.Message show-up
                // in test output
                sim.OnLog += (string message) => { output.WriteLine(message); };

                // executes operation and expects and exception from Q#
                Assert.ThrowsAny <ExecutionFailException>(() => opData.TestOperationRunner(sim));
            }
        }
        public void QSimTestTarget(TestOperation op)
        {
            using (var sim = new QuantumSimulator())
            {
                OverrideOperation <
                    ICallable <(Qubit, Qubit), QVoid>,
                    Simulators.QCTraceSimulators.Implementation.Interface_CX,
                    Intrinsic.CNOT>(sim);

                OverrideOperation <
                    ICallable <(Pauli, Int64, Int64, Qubit), QVoid>,
                    Simulators.QCTraceSimulators.Implementation.Interface_RFrac,
                    Intrinsic.RFrac>(sim);

                OverrideOperation <
                    ICallable <(Pauli, Double, Qubit), QVoid>,
                    Simulators.QCTraceSimulators.Implementation.Interface_R,
                    Intrinsic.R>(sim);

                OverrideOperation <
                    ICallable <(Int64, Pauli, Qubit), QVoid>,
                    Simulators.QCTraceSimulators.Implementation.Interface_Clifford,
                    Interface_Clifford>(sim);

                sim.OnLog += (msg) => { output.WriteLine(msg); };
                sim.OnLog += (msg) => { Debug.WriteLine(msg); };

                op.TestOperationRunner(sim);
            }
        }
        public void QuantumSimulatorTarget(TestOperation operationDescription)
        {
            try
            {
                using (var sim = new QuantumSimulator())
                {
                    // Frequently tests include measurement and randomness.
                    // To reproduce the failed test it is useful to record seed that has been used
                    // for the random number generator inside the simulator.
                    output.WriteLine($"The seed used for this test is {sim.Seed}");
                    Debug.WriteLine($"The seed used for this test is {sim.Seed}");

                    // This ensures that when the test is run in Debug mode, all message logged in
                    // Q# by calling Microsoft.Quantum.Primitives.Message show-up
                    // in Debug output
                    sim.OnLog += (string message) => { Debug.WriteLine(message); };

                    // this ensures that all message logged in Q# by calling
                    // Microsoft.Quantum.Primitives.Message show-up
                    // in test output
                    sim.OnLog += (string message) => { output.WriteLine(message); };

                    // Executes operation described by operationDescription on a QuantumSimulator
                    operationDescription.TestOperationRunner(sim);
                }
            }
            catch (System.BadImageFormatException e)
            {
                throw new System.BadImageFormatException($"Could not load Quantum Simulator. If you are running tests using Visual Studio 2017, " +
                                                         $"this problem can be fixed by using menu Test > Test Settings > Default Processor Architecture " +
                                                         $"and switching to X64 instead of X86. Alternatively, press Ctrl+Q and type `Default Processor Architecture`. If you are running from command line using " +
                                                         $"vstest.console.exe use command line option /Platform:x64.", e);
            }
        }
 //[OperationDriver(TestCasePrefix = "QSim:", TestNamespace = "Microsoft.Quantum.Simulation.TestSuite.VeryLong")]
 private void QSimTestTargetVeryLong(TestOperation op)
 {
     using (var sim = new QuantumSimulator(throwOnReleasingQubitsNotInZeroState: true))
     {
         sim.OnLog += (msg) => { output.WriteLine(msg); };
         op.TestOperationRunner(sim);
     }
 }
Exemple #8
0
 /// <summary>
 /// Executes a quantum test operation.
 /// </summary>
 /// <param name="Operation">The operation to run</param>
 private void RunTest(TestOperation Operation)
 {
     using (QuantumSimulator simulator = new QuantumSimulator())
     {
         simulator.OnLog += HandleTestLogMessage;
         Operation.TestOperationRunner(simulator);
     }
 }
 public void QrackSimTestTarget(TestOperation op)
 {
     using (var sim = new QrackSimulator(throwOnReleasingQubitsNotInZeroState: true))
     {
         sim.OnLog += (msg) => { output.WriteLine(msg); };
         op.TestOperationRunner(sim);
     }
 }
        public void QSimTests(TestOperation op)
        {
            var sim = new QuantumSimulator();

            // OnLog defines action(s) performed when Q# test calls function Message
            sim.OnLog += (msg) => { output.WriteLine(msg); };
            sim.OnLog += (msg) => { Debug.WriteLine(msg); };
            op.TestOperationRunner(sim);
        }
        public void TestTarget(TestOperation op)
        {
            var sim = new ToffoliSimulator();

            // OnLog defines action(s) performed when Q# test calls function Message
            sim.OnLog += (msg) => { this.output.WriteLine(msg); };
            sim.OnLog += (msg) => { Debug.WriteLine(msg); };
            op.TestOperationRunner(sim);
        }
 public void TestTarget(TestOperation op)
 {
     using (var sim = new CounterSimulator())
     {
         // OnLog defines action(s) performed when Q# test calls function Message
         sim.OnLog += (msg) => { output.WriteLine(msg); };
         sim.OnLog += (msg) => { Debug.WriteLine(msg); };
         op.TestOperationRunner(sim);
     }
 }
Exemple #13
0
 public void TestTarget(TestOperation op)
 {
     Console.WriteLine(op.className);
     if (op.className.Contains("ToffoliSim"))
     {
         var sim = new ToffoliSimulator();
         sim.OnLog += (msg) => { output.WriteLine(msg); };
         sim.OnLog += (msg) => { Debug.WriteLine(msg); };
         op.TestOperationRunner(sim);
     }
     else
     {
         using (var sim = new QuantumSimulator()) {
             sim.OnLog += (msg) => { output.WriteLine(msg); };
             sim.OnLog += (msg) => { Debug.WriteLine(msg); };
             op.TestOperationRunner(sim);
         }
     }
 }
 public void TestGaussianElimination(TestOperation op)
 {
     using (var sim = new QuantumSimulator())
     {
         // OnLog defines action(s) performed when Q# test calls function Message
         sim.OnLog += (msg) => { output.WriteLine(msg); };
         sim.OnLog += (msg) => { Debug.WriteLine(msg); };
         op.TestOperationRunner(sim);
     }
 }
        public void TestTarget(TestOperation op)
        {
            // It is convenient to use a seed for test that can fail with small probability
            uint?seed = RetrieveGeneratedSeed(op);

            using (var sim = new QuantumSimulator(randomNumberGeneratorSeed: seed))
            {
                // OnLog defines action(s) performed when Q# test calls function Message
                sim.OnLog += (msg) => { output.WriteLine(msg); };
                sim.OnLog += (msg) => { Debug.WriteLine(msg); };
                op.TestOperationRunner(sim);
            }
        }
        public void TestTarget(TestOperation op)
        {
            using (var sim = new CounterSimulator())
            {
                // OnLog defines action(s) performed when Q# test calls function Message
                sim.OnLog += (msg) => { output.WriteLine(msg); };
                sim.OnLog += (msg) => { Debug.WriteLine(msg); };

                var watch = System.Diagnostics.Stopwatch.StartNew();
                op.TestOperationRunner(sim);
                watch.Stop();
                long ticks = watch.ElapsedTicks;
                Console.WriteLine("Name: " + op.className + " RunTime: " + ticks);
            }
        }
Exemple #17
0
        public void TestTarget(TestOperation op)
        {
            var watch = new System.Diagnostics.Stopwatch();

            System.Console.WriteLine($"Testing for Oracle: {op.fullClassName}");
            watch.Start();
            using (var sim = new OracleCounterSimulator())
            {
                // OnLog defines action(s) performed when Q# test calls function Message
                sim.OnLog += msg => { output.WriteLine(msg); };
                sim.OnLog += msg => { Debug.WriteLine(msg); };
                op.TestOperationRunner(sim);
            }
            watch.Stop();
            System.Console.WriteLine($"Execution Time: {watch.ElapsedMilliseconds} ms");
        }
 public void QSimTestTargetFailures(TestOperation op)
 {
     using (var sim = new QuantumSimulator(throwOnReleasingQubitsNotInZeroState: true))
     {
         sim.OnLog += (msg) => { output.WriteLine(msg); };
         Action action    = () => op.TestOperationRunner(sim);
         bool   hasThrown = false;
         try
         {
             action.IgnoreDebugAssert();
         }
         catch (ExecutionFailException)
         {
             hasThrown = true;
         }
         Assert.True(hasThrown, "The operation was known to throw. It does not throw anymore. Congratulations ! You fixed the bug.");
     }
 }
        public void QuantumSimulatorTarget(TestOperation operationDescription)
        {
            try
            {
                // Generate seed based on name of testclass, so testruns are more deterministic
                // but we don't always use the same seed throughout the solution.
                byte[] bytes = Encoding.Unicode.GetBytes(operationDescription.fullClassName);
                byte[] hash  = hashMethod.ComputeHash(bytes);
                uint   seed  = BitConverter.ToUInt32(hash, 0);

                using (var sim = new QuantumSimulator(randomNumberGeneratorSeed: seed))
                {
                    // Frequently tests include measurement and randomness.
                    // To reproduce the failed test it is useful to record seed that has been used
                    // for the random number generator inside the simulator.
                    output.WriteLine($"The seed used for this test is {sim.Seed}");
                    Debug.WriteLine($"The seed used for this test is {sim.Seed}");

                    // This ensures that when the test is run in Debug mode, all message logged in
                    // Q# by calling Microsoft.Quantum.Primitives.Message show-up
                    // in Debug output
                    sim.OnLog += (string message) => { Debug.WriteLine(message); };

                    // this ensures that all message logged in Q# by calling
                    // Microsoft.Quantum.Primitives.Message show-up
                    // in test output
                    sim.OnLog += (string message) => { output.WriteLine(message); };

                    // Executes operation described by operationDescription on a QuantumSimulator
                    operationDescription.TestOperationRunner(sim);
                }
            }
            catch (System.BadImageFormatException e)
            {
                throw new System.BadImageFormatException($"Could not load Quantum Simulator. If you are running tests using Visual Studio 2017, " +
                                                         $"this problem can be fixed by using menu Test > Test Settings > Default Processor Architecture " +
                                                         $"and switching to X64 instead of X86. Alternatively, press Ctrl+Q and type `Default Processor Architecture`. If you are running from command line using " +
                                                         $"vstest.console.exe use command line option /Platform:x64.", e);
            }
        }