Beispiel #1
0
        public void SimulatorBuiltInOperations()
        {
            // The SimulatorBase class only implements operations for Qubit management,
            // i.e. Allocate/Release:
            var subject = new TrivialSimulator();

            Assert.Equal(typeof(TrivialSimulator).Name, subject.Name);

            var allocate = subject.Get <Intrinsic.Allocate>();
            var release  = subject.Get <Intrinsic.Release>();

            // Try the operations
            var qubits = allocate.Apply(3);

            Assert.Equal(3, qubits.Length);

            release.Apply(qubits);

            subject.CheckNoQubitLeak();
        }
        public void SimulatorBuiltInOperations()
        {
            // The SimulatorBase class only implements operations for Qubit management,
            // i.e. Allocate/Release:
            var subject = new TrivialSimulator();

            Assert.Equal(typeof(TrivialSimulator).Name, subject.Name);

            // Check whether our events for allocation and deallocation
            // are actually called.
            var calledOnAllocate = false;
            var calledOnRelease  = false;

            subject.BeforeAllocateQubits += count =>
            {
                output.WriteLine($"Allocate count = {count}");
                calledOnAllocate = true;
            };
            subject.BeforeReleaseQubits += register =>
            {
                output.WriteLine($"Release qubits = {register}");
                calledOnRelease = true;
            };

            var allocate = subject.Get <Intrinsic.Allocate>();
            var release  = subject.Get <Intrinsic.Release>();

            // Try the operations
            var qubits = allocate.Apply(3);

            Assert.True(calledOnAllocate);
            Assert.Equal(3, qubits.Length);

            release.Apply(qubits);
            Assert.True(calledOnRelease);

            subject.CheckNoQubitLeak();
        }