public void StartUDTOperationCalls()
        {
            Helper.RunWithMultipleSimulators((s) =>
            {
                var tracker = new StartTracker(s);
                StartOperationUDTTest.Run(s).Wait();

                Assert.Equal(1, tracker.GetNumberOfCalls("Microsoft.Quantum.Tests.StartOperation.StartOperationUDTTest"));

                var allVariantsBody        = 3;
                var allVariantsAdjoint     = 2;
                var allVariantsCtrl        = 2;
                var allVariantsAdjointCtrl = 1;
                var allVariants            = allVariantsBody + allVariantsAdjoint + allVariantsCtrl + allVariantsAdjointCtrl;
                Assert.Equal(allVariants, tracker.GetNumberOfCalls("Microsoft.Quantum.Tests.StartOperation.AllVariants"));
                Assert.Equal(allVariantsBody, tracker.GetNumberOfCalls("Microsoft.Quantum.Tests.StartOperation.AllVariants", OperationFunctor.Body));
                Assert.Equal(allVariantsAdjoint, tracker.GetNumberOfCalls("Microsoft.Quantum.Tests.StartOperation.AllVariants", OperationFunctor.Adjoint));
                Assert.Equal(allVariantsCtrl, tracker.GetNumberOfCalls("Microsoft.Quantum.Tests.StartOperation.AllVariants", OperationFunctor.Controlled));
                Assert.Equal(allVariantsAdjointCtrl, tracker.GetNumberOfCalls("Microsoft.Quantum.Tests.StartOperation.AllVariants", OperationFunctor.ControlledAdjoint));

                var basicBody        = 12;
                var basicAdjoint     = 7;
                var basicCtrl        = 9;
                var basicCtrlAdjoint = 7;
                var basic            = basicBody + basicAdjoint + basicCtrl + basicCtrlAdjoint;
                Assert.Equal(basic, tracker.GetNumberOfCalls("Microsoft.Quantum.Tests.StartOperation.Basic"));
                Assert.Equal(basicBody, tracker.GetNumberOfCalls("Microsoft.Quantum.Tests.StartOperation.Basic", OperationFunctor.Body));
                Assert.Equal(basicAdjoint, tracker.GetNumberOfCalls("Microsoft.Quantum.Tests.StartOperation.Basic", OperationFunctor.Adjoint));
                Assert.Equal(basicCtrl, tracker.GetNumberOfCalls("Microsoft.Quantum.Tests.StartOperation.Basic", OperationFunctor.Controlled));
                Assert.Equal(basicCtrlAdjoint, tracker.GetNumberOfCalls("Microsoft.Quantum.Tests.StartOperation.Basic", OperationFunctor.ControlledAdjoint));

                // Because of unwrapping, udts are not called directly, only their base operation:
                Assert.Equal(0, tracker.GetNumberOfCalls("Microsoft.Quantum.Tests.StartOperation.UDT1"));
                Assert.Equal(0, tracker.GetNumberOfCalls("Microsoft.Quantum.Tests.StartOperation.UDT1", OperationFunctor.Body));
                Assert.Equal(0, tracker.GetNumberOfCalls("Microsoft.Quantum.Tests.StartOperation.UDT1", OperationFunctor.Adjoint));
                Assert.Equal(0, tracker.GetNumberOfCalls("Microsoft.Quantum.Tests.StartOperation.UDT1", OperationFunctor.Controlled));
                Assert.Equal(0, tracker.GetNumberOfCalls("Microsoft.Quantum.Tests.StartOperation.UDT1", OperationFunctor.ControlledAdjoint));

                Assert.Equal(0, tracker.GetNumberOfCalls("Microsoft.Quantum.Tests.StartOperation.UDT2"));
                Assert.Equal(0, tracker.GetNumberOfCalls("Microsoft.Quantum.Tests.StartOperation.UDT2", OperationFunctor.Body));
                Assert.Equal(0, tracker.GetNumberOfCalls("Microsoft.Quantum.Tests.StartOperation.UDT2", OperationFunctor.Adjoint));
                Assert.Equal(0, tracker.GetNumberOfCalls("Microsoft.Quantum.Tests.StartOperation.UDT2", OperationFunctor.Controlled));
                Assert.Equal(0, tracker.GetNumberOfCalls("Microsoft.Quantum.Tests.StartOperation.UDT2", OperationFunctor.ControlledAdjoint));

                Assert.Equal(basic * 4 + 2, tracker.GetNumberOfCalls("Microsoft.Quantum.Intrinsic.X"));
                Assert.Equal(basicBody * 4 + 2, tracker.GetNumberOfCalls("Microsoft.Quantum.Intrinsic.X", OperationFunctor.Body));
                Assert.Equal(basicAdjoint * 4, tracker.GetNumberOfCalls("Microsoft.Quantum.Intrinsic.X", OperationFunctor.Adjoint));
                Assert.Equal(basicCtrl * 4, tracker.GetNumberOfCalls("Microsoft.Quantum.Intrinsic.X", OperationFunctor.Controlled));
                Assert.Equal(basicCtrlAdjoint * 4, tracker.GetNumberOfCalls("Microsoft.Quantum.Intrinsic.X", OperationFunctor.ControlledAdjoint));

                var b3Body = 8;
                Assert.Equal(0, tracker.GetNumberOfCalls("Microsoft.Quantum.Tests.StartOperation.UDT3"));
                Assert.Equal(0, tracker.GetNumberOfCalls("Microsoft.Quantum.Tests.StartOperation.UDT3", OperationFunctor.Body));
                Assert.Equal(b3Body, tracker.GetNumberOfCalls("Microsoft.Quantum.Tests.StartOperation.B3"));
                Assert.Equal(b3Body, tracker.GetNumberOfCalls("Microsoft.Quantum.Tests.StartOperation.B3", OperationFunctor.Body));;
            });
        }
Exemple #2
0
        public void UDTsPolyMorphism()
        {
            Helper.RunWithMultipleSimulators((s) =>
            {
                var tracker = new StartTracker(s);

                TestUDTsPolyMorphism.Run(s).Wait();

                Assert.Equal(20, tracker.GetNumberOfCalls("Microsoft.Quantum.Simulation.Simulators.Tests.Circuits.Generics.Trace", OperationFunctor.Body));
            });
        }
        public void StartOperationCalls()
        {
            Helper.RunWithMultipleSimulators((s) =>
            {
                var tracker = new StartTracker(s);
                StartOperationTest.Run(s).Wait();

                var q0 = new FreeQubit(0) as Qubit;
                var q1 = new FreeQubit(1) as Qubit;
                var q2 = new FreeQubit(2) as Qubit;
                var q3 = new FreeQubit(3) as Qubit;

                Assert.Equal(1, tracker.GetNumberOfCalls("Microsoft.Quantum.Tests.StartOperation.StartOperationTest"));

                var allVariantsBody        = 3;
                var allVariantsAdjoint     = 2;
                var allVariantsCtrl        = 2;
                var allVariantsAdjointCtrl = 1;
                var allVariants            = allVariantsBody + allVariantsAdjoint + allVariantsCtrl + allVariantsAdjointCtrl;
                Assert.Equal(allVariants, tracker.GetNumberOfCalls("Microsoft.Quantum.Tests.StartOperation.AllVariants"));
                Assert.Equal(allVariantsBody, tracker.GetNumberOfCalls("Microsoft.Quantum.Tests.StartOperation.AllVariants", OperationFunctor.Body));
                Assert.Equal(allVariantsAdjoint, tracker.GetNumberOfCalls("Microsoft.Quantum.Tests.StartOperation.AllVariants", OperationFunctor.Adjoint));
                Assert.Equal(allVariantsCtrl, tracker.GetNumberOfCalls("Microsoft.Quantum.Tests.StartOperation.AllVariants", OperationFunctor.Controlled));
                Assert.Equal(allVariantsAdjointCtrl, tracker.GetNumberOfCalls("Microsoft.Quantum.Tests.StartOperation.AllVariants", OperationFunctor.ControlledAdjoint));

                var basicBody        = 9;
                var basicAdjoint     = 7;
                var basicCtrl        = 9;
                var basicCtrlAdjoint = 7;
                var basic            = basicBody + basicAdjoint + basicCtrl + basicCtrlAdjoint;
                Assert.Equal(basic, tracker.GetNumberOfCalls("Microsoft.Quantum.Tests.StartOperation.Basic"));
                Assert.Equal(basicBody, tracker.GetNumberOfCalls("Microsoft.Quantum.Tests.StartOperation.Basic", OperationFunctor.Body));
                Assert.Equal(basicAdjoint, tracker.GetNumberOfCalls("Microsoft.Quantum.Tests.StartOperation.Basic", OperationFunctor.Adjoint));
                Assert.Equal(basicCtrl, tracker.GetNumberOfCalls("Microsoft.Quantum.Tests.StartOperation.Basic", OperationFunctor.Controlled));
                Assert.Equal(basicCtrlAdjoint, tracker.GetNumberOfCalls("Microsoft.Quantum.Tests.StartOperation.Basic", OperationFunctor.ControlledAdjoint));

                var data1 = (0L, q1, (q2, q3), Result.One);
                Assert.Equal(3, tracker.GetNumberOfCalls("Microsoft.Quantum.Tests.StartOperation.Basic", OperationFunctor.Body, data1));
                Assert.Equal(3, tracker.GetNumberOfCalls("Microsoft.Quantum.Tests.StartOperation.Basic", OperationFunctor.Adjoint, data1));

                var data2 = (1L, q1, (q2, q3), Result.Zero);
                Assert.Equal(6, tracker.GetNumberOfCalls("Microsoft.Quantum.Tests.StartOperation.Basic", OperationFunctor.Body, data2));
                Assert.Equal(4, tracker.GetNumberOfCalls("Microsoft.Quantum.Tests.StartOperation.Basic", OperationFunctor.Adjoint, data2));

                Assert.Equal(basic * 4, tracker.GetNumberOfCalls("Microsoft.Quantum.Intrinsic.X"));
                Assert.Equal(basicBody * 4, tracker.GetNumberOfCalls("Microsoft.Quantum.Intrinsic.X", OperationFunctor.Body));
                Assert.Equal(basicAdjoint * 4, tracker.GetNumberOfCalls("Microsoft.Quantum.Intrinsic.X", OperationFunctor.Adjoint));
                Assert.Equal(basicCtrl * 4, tracker.GetNumberOfCalls("Microsoft.Quantum.Intrinsic.X", OperationFunctor.Controlled));
                Assert.Equal(basicCtrlAdjoint * 4, tracker.GetNumberOfCalls("Microsoft.Quantum.Intrinsic.X", OperationFunctor.ControlledAdjoint));
            });
        }
Exemple #4
0
        public void Borrowing()
        {
            OperationsTestHelper.RunWithMultipleSimulators((s) =>
            {
                var tracker = new StartTracker(s);

                var q0 = new FreeQubit(0) as Qubit;
                var q1 = new FreeQubit(1) as Qubit;
                var q2 = new FreeQubit(2) as Qubit;
                var q3 = new FreeQubit(3) as Qubit;
                var q4 = new FreeQubit(4) as Qubit;
                var q5 = new FreeQubit(5) as Qubit;
                var q6 = new FreeQubit(6) as Qubit;
                var q7 = new FreeQubit(7) as Qubit;
                var q8 = new FreeQubit(8) as Qubit;

                BorrowingTest.Run(s).Wait();

                var tracer = OperationsTestHelper.GetTracer <(long, Qubit)>(s);

                var testOne = new Action <int, OperationFunctor, (int, Qubit)>((int callsCount, OperationFunctor variant, (int, Qubit)info) =>
                {
                    var(available, q) = info;
                    Assert.Equal(callsCount, tracer.Log.GetNumberOfCalls(variant, (available, q)));
                });

                var testOneBody    = new Action <int, (int, Qubit)>((callsCount, info) => testOne(callsCount, OperationFunctor.Body, info));
                var testOneAdjoint = new Action <int, (int, Qubit)>((callsCount, info) => testOne(callsCount, OperationFunctor.Adjoint, info));
                var testOneCtrl    = new Action <int, (int, Qubit)>((callsCount, info) => testOne(callsCount, OperationFunctor.Controlled, info));
                var testOneCtrlAdj = new Action <int, (int, Qubit)>((callsCount, info) => testOne(callsCount, OperationFunctor.ControlledAdjoint, info));

                testOneBody(6, (0, q5));
                testOneBody(6, (0, q6));
                testOneBody(1, (1, q0));
                testOneBody(1, (1, q1));
                testOneBody(1, (1, q4));
                testOneBody(1, (1, q5));
                testOneBody(2, (1, q6));
                testOneBody(2, (2, q2));
                testOneBody(2, (2, q3));
                testOneBody(1, (3, q0));
                testOneBody(1, (3, q1));
                testOneBody(1, (3, q2));
                testOneBody(3, (3, q3));
                testOneBody(2, (4, q0));
                testOneBody(1, (4, q1));
                testOneBody(3, (4, q2));
                testOneBody(5, (5, q0));
                testOneBody(5, (5, q1));

                testOneAdjoint(3, (0, q5));
                testOneAdjoint(3, (0, q6));
                testOneAdjoint(1, (1, q0));
                testOneAdjoint(1, (1, q1));
                testOneAdjoint(1, (1, q4));
                testOneAdjoint(2, (1, q5));
                testOneAdjoint(1, (1, q6));
                testOneAdjoint(2, (2, q2));
                testOneAdjoint(2, (2, q3));
                testOneAdjoint(1, (3, q2));
                testOneAdjoint(1, (3, q3));
                testOneAdjoint(1, (4, q0));
                testOneAdjoint(1, (4, q1));
                testOneAdjoint(2, (4, q2));
                testOneAdjoint(2, (5, q0));
                testOneAdjoint(2, (5, q1));

                testOneCtrl(3, (0, q7));
                testOneCtrl(3, (0, q8));
                testOneCtrl(1, (1, q0));
                testOneCtrl(1, (1, q1));
                testOneCtrl(1, (1, q4));
                testOneCtrl(1, (1, q5));
                testOneCtrl(1, (1, q6));
                testOneCtrl(0, (2, q0));
                testOneCtrl(0, (2, q1));
                testOneCtrl(2, (2, q2));
                testOneCtrl(2, (2, q3));
                testOneCtrl(1, (3, q2));
                testOneCtrl(1, (3, q3));
                testOneCtrl(1, (4, q0));
                testOneCtrl(1, (4, q1));
                testOneCtrl(2, (4, q2));
                testOneCtrl(3, (5, q0));
                testOneCtrl(3, (5, q1));

                testOneCtrlAdj(3, (0, q7));
                testOneCtrlAdj(3, (0, q8));
                testOneCtrlAdj(1, (1, q4));
                testOneCtrlAdj(1, (1, q7));
                testOneCtrlAdj(2, (2, q2));
                testOneCtrlAdj(2, (2, q3));
                testOneCtrlAdj(1, (3, q2));
                testOneCtrlAdj(1, (3, q3));
                testOneCtrlAdj(1, (4, q0));
                testOneCtrlAdj(1, (4, q1));
                testOneCtrlAdj(2, (4, q2));
                testOneCtrlAdj(2, (5, q0));
                testOneCtrlAdj(2, (5, q1));

                Assert.Equal(20, tracker.GetNumberOfCalls("Microsoft.Quantum.Intrinsic.SWAP", OperationFunctor.Body));
                Assert.Equal(11, tracker.GetNumberOfCalls("Microsoft.Quantum.Intrinsic.SWAP", OperationFunctor.Adjoint));
                Assert.Equal(16, tracker.GetNumberOfCalls("Microsoft.Quantum.Intrinsic.SWAP", OperationFunctor.Controlled));
                Assert.Equal(13, tracker.GetNumberOfCalls("Microsoft.Quantum.Intrinsic.SWAP", OperationFunctor.ControlledAdjoint));
            });