예제 #1
0
        public void TestResolveMagic()
        {
            var resolver = Startup.Create <MagicSymbolResolver>("Workspace.Broken");

            var symbol = resolver.Resolve("%workspace");

            Assert.IsNotNull(symbol);
            Assert.AreEqual("%workspace", symbol.Name);

            symbol = resolver.Resolve("%package") as MagicSymbol;
            Assert.IsNotNull(symbol);
            Assert.AreEqual("%package", symbol.Name);

            Assert.IsNotNull(resolver.Resolve("%who"));
            Assert.IsNotNull(resolver.Resolve("%estimate"));
            Assert.IsNotNull(resolver.Resolve("%simulate"));

            symbol = resolver.Resolve("%foo");
            Assert.IsNull(symbol);

            // AzureClient-provided commands
            Assert.IsNotNull(resolver.Resolve("%azure.connect"));
            Assert.IsNotNull(resolver.Resolve("%azure.target"));
            Assert.IsNotNull(resolver.Resolve("%azure.submit"));
            Assert.IsNotNull(resolver.Resolve("%azure.execute"));
            Assert.IsNotNull(resolver.Resolve("%azure.status"));
            Assert.IsNotNull(resolver.Resolve("%azure.output"));
            Assert.IsNotNull(resolver.Resolve("%azure.jobs"));
        }
예제 #2
0
        public void TestResolveMagic()
        {
            var resolver = Startup.Create <MagicSymbolResolver>("Workspace.Broken");

            // We use the null-forgiving operator on symbol below, as the C# 8
            // nullable reference feature does not incorporate the result of
            // Assert.IsNotNull.

            var symbol = resolver.Resolve("%workspace");

            Assert.IsNotNull(symbol);
            Assert.AreEqual("%workspace", symbol !.Name);

            symbol = resolver.Resolve("%package") as MagicSymbol;
            Assert.IsNotNull(symbol);
            Assert.AreEqual("%package", symbol !.Name);

            Assert.IsNotNull(resolver.Resolve("%who"));
            Assert.IsNotNull(resolver.Resolve("%estimate"));
            Assert.IsNotNull(resolver.Resolve("%simulate"));

            symbol = resolver.Resolve("%foo");
            Assert.IsNull(symbol);

            // AzureClient-provided commands
            Assert.IsNotNull(resolver.Resolve("%azure.connect"));
            Assert.IsNotNull(resolver.Resolve("%azure.target"));
            Assert.IsNotNull(resolver.Resolve("%azure.submit"));
            Assert.IsNotNull(resolver.Resolve("%azure.execute"));
            Assert.IsNotNull(resolver.Resolve("%azure.status"));
            Assert.IsNotNull(resolver.Resolve("%azure.output"));
            Assert.IsNotNull(resolver.Resolve("%azure.jobs"));
        }
예제 #3
0
        public async Task ReloadWorkspace()
        {
            var ws = Startup.Create <Workspace>("Workspace");
            await ws.Initialization;
            var originalAssembly = ws.AssemblyInfo;
            var op = ws.AssemblyInfo.Operations.FirstOrDefault(o => o.FullName == "Tests.qss.NoOp");

            Assert.IsFalse(ws.HasErrors);
            Assert.IsNotNull(op);

            // Calling Reload with no changes, should regenerate the dll:
            ws.Reload();
            op = ws.AssemblyInfo?.Operations.FirstOrDefault(o => o.FullName == "Tests.qss.NoOp");
            Assert.IsFalse(ws.HasErrors);
            Assert.IsNotNull(op);
            Assert.AreNotSame(originalAssembly, ws.AssemblyInfo);

            var fileName = Path.Combine(Path.GetFullPath("Workspace"), "BasicOps.qs");

            File.SetLastWriteTimeUtc(fileName, DateTime.UtcNow);
            ws.Reload();
            op = ws.AssemblyInfo.Operations.FirstOrDefault(o => o.FullName == "Tests.qss.NoOp");
            Assert.IsFalse(ws.HasErrors);
            Assert.AreNotSame(originalAssembly, ws.AssemblyInfo);
            Assert.IsNotNull(op);
        }
예제 #4
0
        public void BrokenWorkspace()
        {
            var ws = Startup.Create <Workspace>("Workspace.Broken");

            ws.Reload();
            Assert.IsTrue(ws.HasErrors);
        }
예제 #5
0
        public void ManuallyAddProjects()
        {
            var ws = Startup.Create <Workspace>("Workspace");

            ws.Reload();
            Assert.IsFalse(ws.HasErrors, string.Join(Environment.NewLine, ws.ErrorMessages));

            ws.AddProject("../Workspace.ProjectReferences.ProjectA/ProjectA.csproj");
            ws.Reload();
            Assert.IsFalse(ws.HasErrors, string.Join(Environment.NewLine, ws.ErrorMessages));

            var operations = ws.Projects.SelectMany(p => p.AssemblyInfo?.Operations);

            Assert.IsFalse(operations.Where(o => o.FullName == "Tests.ProjectReferences.MeasureSingleQubit").Any());
            Assert.IsTrue(operations.Where(o => o.FullName == "Tests.ProjectReferences.ProjectA.RotateAndMeasure").Any());

            ws.AddProject("../Workspace.ProjectReferences/Workspace.ProjectReferences.csproj");
            ws.Reload();
            Assert.IsFalse(ws.HasErrors, string.Join(Environment.NewLine, ws.ErrorMessages));

            operations = ws.Projects.SelectMany(p => p.AssemblyInfo?.Operations);
            Assert.IsTrue(operations.Where(o => o.FullName == "Tests.ProjectReferences.MeasureSingleQubit").Any());
            Assert.IsTrue(operations.Where(o => o.FullName == "Tests.ProjectReferences.ProjectA.RotateAndMeasure").Any());

            // Try to add a project that doesn't exist
            Assert.ThrowsException <FileNotFoundException>(() =>
                                                           ws.AddProject("../InvalidProject/InvalidProject.csproj")
                                                           );

            // Try to add a project that should have already been loaded
            Assert.ThrowsException <InvalidOperationException>(() =>
                                                               ws.AddProject("../Workspace.ProjectReferences.ProjectB/ProjectB.csproj")
                                                               );
        }
예제 #6
0
        public IQSharpEngine Init(string workspace = "Workspace")
        {
            var engine = Startup.Create <IQSharpEngine>(workspace);

            engine.Workspace.Initialization.Wait();
            return(engine);
        }
예제 #7
0
        public void InitWorkspace()
        {
            var ws = Startup.Create <Workspace>("Workspace");

            var dll = Path.Combine(ws.CacheFolder, "__ws__.dll");

            if (File.Exists(dll))
            {
                File.Delete(dll);
            }

            // First time
            ws = Startup.Create <Workspace>("Workspace");
            Assert.IsFalse(ws.HasErrors);

            var op = ws.AssemblyInfo.Operations.FirstOrDefault(o => o.FullName == "Tests.qss.NoOp");

            Assert.IsNotNull(op);

            // On next reload:
            ws = Startup.Create <Workspace>("Workspace");
            Assert.IsFalse(ws.HasErrors);

            op = ws.AssemblyInfo.Operations.FirstOrDefault(o => o.FullName == "Tests.qss.NoOp");
            Assert.IsNotNull(op);
        }
예제 #8
0
        public async Task InitWorkspace()
        {
            var ws = Startup.Create <Workspace>("Workspace");
            await ws.Initialization;

            var dll = ws.Projects.Single().CacheDllPath;

            if (File.Exists(dll))
            {
                File.Delete(dll);
            }

            // First time
            ws = Startup.Create <Workspace>("Workspace");
            await ws.Initialization;

            Assert.IsFalse(ws.HasErrors);

            var op = ws.AssemblyInfo.Operations.FirstOrDefault(o => o.FullName == "Tests.qss.NoOp");

            Assert.IsNotNull(op);

            // On next reload:
            ws = Startup.Create <Workspace>("Workspace");
            await ws.Initialization;

            Assert.IsFalse(ws.HasErrors);

            op = ws.AssemblyInfo.Operations.FirstOrDefault(o => o.FullName == "Tests.qss.NoOp");
            Assert.IsNotNull(op);
        }
예제 #9
0
        public Workspace InitWorkspace()
        {
            var ws = Startup.Create <Workspace>("Workspace.ExecutionPathTracer");

            ws.GlobalReferences.AddPackage("mock.standard").Wait();
            ws.Reload();
            Assert.IsFalse(ws.HasErrors);
            return(ws);
        }
예제 #10
0
        public void ReloadWorkspace()
        {
            var ws = Startup.Create <Workspace>("Workspace");

            ws.Reload();
            Assert.IsFalse(ws.HasErrors);

            var op = ws.AssemblyInfo.Operations.FirstOrDefault(o => o.FullName == "Tests.qss.NoOp");

            Assert.IsNotNull(op);
        }
예제 #11
0
        public async static Task <IQSharpEngine> Init(string workspace = "Workspace")
        {
            var engine = Startup.Create <IQSharpEngine>(workspace);

            engine.Start();
            await engine.Initialized;

            Assert.IsNotNull(engine.Workspace);
            await engine.Workspace !.Initialization;

            return(engine);
        }
예제 #12
0
        public void ProjectReferencesWorkspace()
        {
            // Loading this workspace should succeed and automatically pull in the referenced projects
            // Workspace.ProjectReferences.ProjectA and Workspace.ProjectReferences.ProjectB.
            var ws = Startup.Create <Workspace>("Workspace.ProjectReferences");

            ws.Reload();
            Assert.IsFalse(ws.HasErrors, string.Join(Environment.NewLine, ws.ErrorMessages));

            var operations = ws.Projects.SelectMany(p => p.AssemblyInfo?.Operations);

            Assert.IsTrue(operations.Where(o => o.FullName == "Tests.ProjectReferences.MeasureSingleQubit").Any());
            Assert.IsTrue(operations.Where(o => o.FullName == "Tests.ProjectReferences.ProjectA.RotateAndMeasure").Any());
            Assert.IsTrue(operations.Where(o => o.FullName == "Tests.ProjectReferences.ProjectB.RotateAndMeasure").Any());
        }
예제 #13
0
        public void ChemistryWorkspace()
        {
            var ws = Startup.Create <Workspace>("Workspace.Chemistry");

            ws.Reload();
            Assert.IsTrue(ws.HasErrors);

            ws.GlobalReferences.AddPackage("Microsoft.Quantum.Research").Wait();
            ws.Reload();
            Assert.IsFalse(ws.HasErrors);

            var op = ws.AssemblyInfo.Operations.FirstOrDefault(o => o.FullName == "Microsoft.Quantum.Chemistry.Samples.OptimizedTrotterEstimateEnergy");

            Assert.IsNotNull(op);
        }
예제 #14
0
        public void ChemistryWorkspace()
        {
            var ws = Startup.Create <Workspace>("Workspace.Chemistry");

            ws.Reload();
            Assert.IsTrue(ws.HasErrors);

            ws.GlobalReferences.AddPackage($"mock.chemistry").Wait();
            ws.Reload();
            Assert.IsFalse(ws.HasErrors);

            var op = ws.AssemblyInfo.Operations.FirstOrDefault(o => o.FullName == "Tests.IQSharp.Chemistry.Samples.UseJordanWignerEncodingData");

            Assert.IsNotNull(op);
        }
예제 #15
0
        public void TestResolver()
        {
            var snippets = Startup.Create <Snippets>("Workspace");

            snippets.Compile(SNIPPETS.HelloQ);

            var resolver = new SymbolResolver(snippets);

            // Intrinsics:
            var symbol = resolver.Resolve("X");

            Assert.IsNotNull(symbol);
            Assert.AreEqual("Microsoft.Quantum.Intrinsic.X", symbol.Name);

            // FQN Intrinsics:
            symbol = resolver.Resolve("Microsoft.Quantum.Intrinsic.X");
            Assert.IsNotNull(symbol);
            Assert.AreEqual("Microsoft.Quantum.Intrinsic.X", symbol.Name);

            // From namespace:
            symbol = resolver.Resolve("Tests.qss.CCNOTDriver");
            Assert.IsNotNull(symbol);
            Assert.AreEqual("Tests.qss.CCNOTDriver", symbol.Name);

            symbol = resolver.Resolve("CCNOTDriver");
            Assert.IsNotNull(symbol);
            Assert.AreEqual("Tests.qss.CCNOTDriver", symbol.Name);

            /// From Canon:
            symbol = resolver.Resolve("ApplyToEach");
            Assert.IsNotNull(symbol);
            Assert.AreEqual("Microsoft.Quantum.Canon.ApplyToEach", symbol.Name);

            // Snippets:
            symbol = resolver.Resolve("HelloQ");
            Assert.IsNotNull(symbol);
            Assert.AreEqual("HelloQ", symbol.Name);

            // resolver is case sensitive:
            symbol = resolver.Resolve("helloq");
            Assert.IsNull(symbol);

            // Invalid name
            symbol = resolver.Resolve("foo");
            Assert.IsNull(symbol);
        }
예제 #16
0
        public void TestWho()
        {
            var snippets = Startup.Create <Snippets>("Workspace");

            snippets.Compile(SNIPPETS.HelloQ);

            var whoMagic = new WhoMagic(snippets);
            var channel  = new MockChannel();

            // Check the workspace, it should be in error state:
            var response = whoMagic.Execute("", channel);
            var result   = response.Output as string[];

            PrintResult(response, channel);
            Assert.AreEqual(ExecuteStatus.Ok, response.Status);
            Assert.AreEqual(5, result.Length);
            Assert.AreEqual("HelloQ", result[0]);
            Assert.AreEqual("Tests.qss.NoOp", result[4]);
        }
예제 #17
0
        public void TestResolveMagic()
        {
            var resolver = Startup.Create <MagicSymbolResolver>("Workspace.Broken");

            var symbol = resolver.Resolve("%workspace");

            Assert.IsNotNull(symbol);
            Assert.AreEqual("%workspace", symbol.Name);

            symbol = resolver.Resolve("%package") as MagicSymbol;
            Assert.IsNotNull(symbol);
            Assert.AreEqual("%package", symbol.Name);

            Assert.IsNotNull(resolver.Resolve("%who"));
            Assert.IsNotNull(resolver.Resolve("%estimate"));
            Assert.IsNotNull(resolver.Resolve("%simulate"));

            symbol = resolver.Resolve("%foo");
            Assert.IsNull(symbol);
        }
예제 #18
0
        public void ProjectReferencesWorkspaceNoAutoLoad()
        {
            // Loading this workspace should fail because the .csproj does not specify <IQSharpLoadAutomatically>,
            // which prevents the code that depends on Workspace.ProjectReferences.ProjectB from compiling correctly.
            var ws = Startup.Create <Workspace>("Workspace.ProjectReferences.ProjectA");

            ws.Reload();
            Assert.IsTrue(ws.HasErrors);

            // Loading this workspace should succeed, and its Q# operations should be available, but the .csproj
            // reference should not be loaded because the .csproj specifies <IQSharpLoadAutomatically> as false.
            ws = Startup.Create <Workspace>("Workspace.ProjectReferences.ProjectB");
            ws.Reload();
            Assert.IsFalse(ws.HasErrors, string.Join(Environment.NewLine, ws.ErrorMessages));
            Assert.IsTrue(ws.Projects.Count() == 1);
            Assert.IsTrue(string.IsNullOrEmpty(ws.Projects.First().ProjectFile));
            var operations = ws.Projects.SelectMany(p => p.AssemblyInfo?.Operations);

            Assert.IsTrue(operations.Where(o => o.FullName == "Tests.ProjectReferences.ProjectB.RotateAndMeasure").Any());
        }
예제 #19
0
        public async Task TestWho()
        {
            var snippets = Startup.Create <Snippets>("Workspace");
            await snippets.Workspace.Initialization;

            snippets.Compile(SNIPPETS.HelloQ);

            var whoMagic = new WhoMagic(snippets, new UnitTestLogger <WhoMagic>());
            var channel  = new MockChannel();

            // Check the workspace, it should be in error state:
            var response = await whoMagic.Execute("", channel);

            var result = response.Output as string[];

            PrintResult(response, channel);
            response.AssertIsOk();
            Assert.AreEqual(6, result?.Length);
            Assert.AreEqual("HelloQ", result?[0]);
            Assert.AreEqual("Tests.qss.NoOp", result?[4]);
        }
예제 #20
0
 public SnippetsController Init(string workspace = "Workspace")
 {
     return(Startup.Create <SnippetsController>(workspace));
 }
예제 #21
0
 public PackagesController Init(string root = @"Workspace")
 {
     return(Startup.Create <PackagesController>(root));
 }
예제 #22
0
        public NugetPackages Init()
        {
            var service = Startup.Create <References>("Workspace");

            return(service.Nugets);
        }
예제 #23
0
 public NugetPackages Init()
 {
     return(Startup.Create <NugetPackages>("Workspace"));
 }
예제 #24
0
 public IQSharpEngine Init(string workspace = "Workspace")
 {
     return(Startup.Create <IQSharpEngine>(workspace));
 }