Ejemplo n.º 1
0
        public void Toffoli()
        {
            var engine  = Init();
            var channel = new MockChannel();

            // Compile it:
            AssertCompile(engine, SNIPPETS.HelloQ, "HelloQ");

            // Run with toffoli simulator:
            var toffoliMagic = new ToffoliMagic(engine.SymbolsResolver);
            var response     = toffoliMagic.Execute("HelloQ", channel);
            var result       = response.Output as Dictionary <string, double>;

            PrintResult(response, channel);
            Assert.AreEqual(ExecuteStatus.Ok, response.Status);
            Assert.AreEqual(1, channel.msgs.Count);
            Assert.AreEqual(ChannelWithNewLines.Format("Hello from quantum world!"), channel.msgs[0]);
        }
Ejemplo n.º 2
0
        public void CompileAndSimulate()
        {
            var engine   = Init();
            var simMagic = new SimulateMagic(engine.SymbolsResolver);
            var channel  = new MockChannel();

            // Try running without compiling it, fails:
            var response = simMagic.Execute("_snippet_.HelloQ", channel);

            PrintResult(response, channel);
            Assert.AreEqual(ExecuteStatus.Error, response.Status);
            Assert.AreEqual(0, channel.msgs.Count);
            Assert.AreEqual(1, channel.errors.Count);
            Assert.AreEqual(ChannelWithNewLines.Format($"Invalid operation name: _snippet_.HelloQ"), channel.errors[0]);

            // Compile it:
            AssertCompile(engine, SNIPPETS.HelloQ, "HelloQ");

            // Try running again:
            AssertSimulate(engine, "HelloQ", "Hello from quantum world!");
        }
Ejemplo n.º 3
0
        public async Task Toffoli()
        {
            var engine = await Init();

            var channel = new MockChannel();

            Assert.IsNotNull(engine.SymbolsResolver);

            // Compile it:
            await AssertCompile(engine, SNIPPETS.HelloQ, "HelloQ");

            // Run with toffoli simulator:
            var toffoliMagic = new ToffoliMagic(engine.SymbolsResolver !, new UnitTestLogger <ToffoliMagic>());
            var response     = await toffoliMagic.Execute("HelloQ", channel);

            var result = response.Output as Dictionary <string, double>;

            PrintResult(response, channel);
            response.AssertIsOk();
            Assert.AreEqual(1, channel.msgs.Count);
            Assert.AreEqual(ChannelWithNewLines.Format("Hello from quantum world!"), channel.msgs[0]);
        }
Ejemplo n.º 4
0
        public async Task CompileAndSimulate()
        {
            var engine = await Init();

            Assert.IsNotNull(engine.SymbolsResolver);
            var configSource = new ConfigurationSource(skipLoading: true);
            var simMagic     = new SimulateMagic(engine.SymbolsResolver !, configSource, new PerformanceMonitor(), new UnitTestLogger <SimulateMagic>());
            var channel      = new MockChannel();

            // Try running without compiling it, fails:
            var response = await simMagic.Execute("_snippet_.HelloQ", channel);

            PrintResult(response, channel);
            Assert.AreEqual(ExecuteStatus.Error, response.Status);
            Assert.AreEqual(0, channel.msgs.Count);
            Assert.AreEqual(1, channel.errors.Count);
            Assert.AreEqual(ChannelWithNewLines.Format($"Invalid operation name: _snippet_.HelloQ"), channel.errors[0]);

            // Compile it:
            await AssertCompile(engine, SNIPPETS.HelloQ, "HelloQ");

            // Try running again:
            await AssertSimulate(engine, "HelloQ", "Hello from quantum world!");
        }