Ejemplo n.º 1
0
        public void RecursionFail1Test()
        {
            ToffoliSimulator sim = new ToffoliSimulator();

            {
                StackTraceCollector sc = new StackTraceCollector(sim);
                ICallable           op = sim.Get <ICallable, RecursionFail1>();
                try
                {
                    QVoid res = op.Apply <QVoid>(QVoid.Instance);
                }
                catch (ExecutionFailException)
                {
                    StackFrame[] stackFrames = sc.CallStack;

                    Assert.Equal(4, stackFrames.Length);

                    Assert.Equal(namespacePrefix + "RecursionFail", stackFrames[0].Callable.FullName);
                    Assert.Equal(namespacePrefix + "RecursionFail", stackFrames[1].Callable.FullName);
                    Assert.Equal(namespacePrefix + "RecursionFail", stackFrames[2].Callable.FullName);
                    Assert.Equal(namespacePrefix + "RecursionFail1", stackFrames[3].Callable.FullName);

                    Assert.Equal(OperationFunctor.Body, stackFrames[0].Callable.Variant);
                    Assert.Equal(OperationFunctor.Body, stackFrames[1].Callable.Variant);
                    Assert.Equal(OperationFunctor.Body, stackFrames[2].Callable.Variant);
                    Assert.Equal(OperationFunctor.Body, stackFrames[3].Callable.Variant);

                    Assert.Equal(70, stackFrames[0].FailedLineNumber);
                    Assert.Equal(66, stackFrames[1].FailedLineNumber);
                    Assert.Equal(66, stackFrames[2].FailedLineNumber);
                    Assert.Equal(75, stackFrames[3].FailedLineNumber);
                }
            }
        }
        /// <summary>
        /// A shell for simple Apply tests.
        /// </summary>
        internal static void applyTestShell <I, O>(SimulatorBase sim, ICallable <I, O> operation, Action <Qubit> test)
        {
            var allocate = sim.Get <Intrinsic.Allocate>();
            var release  = sim.Get <Intrinsic.Release>();

            var qbits = allocate.Apply(1);

            var q = qbits[0];

            operation.Apply(q);    // this is ok.

            test(q);

            operation.Apply(q);    // still ok.
            release.Apply(qbits);
        }
Ejemplo n.º 3
0
        private static void RunClause(ICallable op, OperationFunctor type, IQArray <Qubit>?ctrls)
        {
            switch (type)
            {
            case OperationFunctor.Body: op.Apply(QVoid.Instance); break;

            case OperationFunctor.Adjoint: ((IAdjointable)(op)).Adjoint.Apply(QVoid.Instance); break;

            case OperationFunctor.Controlled: ((IControllable)(op)).Controlled.Apply((ctrls, QVoid.Instance)); break;

            case OperationFunctor.ControlledAdjoint: ((IUnitary)(op)).Controlled.Adjoint.Apply((ctrls, QVoid.Instance)); break;
            }
        }