public void ToffoliMeasure() { var sim = new ToffoliSimulator(); var measure = sim.Get <Intrinsic.M>(); var allocate = sim.Get <Intrinsic.Allocate>(); var release = sim.Get <Intrinsic.Release>(); var qubits = allocate.Apply(1); Assert.Single(qubits); var q = qubits[0]; var result = measure.Apply(q); Assert.Equal(Result.Zero, result); sim.State[q.Id] = true; result = measure.Apply(q); Assert.Equal(Result.One, result); sim.State[q.Id] = false; // Make it safe to release release.Apply(qubits); sim.CheckNoQubitLeak(); }
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); } } }
public void ToffoliX() { var sim = new ToffoliSimulator(); var x = sim.Get <Intrinsic.X>(); OperationsTestHelper.applyTestShell(sim, x, (q) => { var measure = sim.Get <Intrinsic.M>(); var set = sim.Get <SetQubit>(); set.Apply((Result.Zero, q)); x.Apply(q); var result = measure.Apply(q); Assert.Equal(Result.One, result); x.Apply(q); result = measure.Apply(q); Assert.Equal(Result.Zero, result); x.Apply(q); // The test helper is going to apply another X before releasing });