Skip to content
This repository was archived by the owner on Jan 12, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 27 additions & 10 deletions iqsharp.sln
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.26124.0
# Visual Studio Version 16
VisualStudioVersion = 16.0.29920.165
MinimumVisualStudioVersion = 15.0.26124.0
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Jupyter", "src\Jupyter\Jupyter.csproj", "{B6F42099-DACD-472F-866C-BEF92DDDF754}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Jupyter", "src\Jupyter\Jupyter.csproj", "{B6F42099-DACD-472F-866C-BEF92DDDF754}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Core", "src\Core\Core.csproj", "{0ACA57A6-A8F6-497C-85D3-D547433BFACB}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Core", "src\Core\Core.csproj", "{0ACA57A6-A8F6-497C-85D3-D547433BFACB}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tests.IQsharp", "src\Tests\Tests.IQsharp.csproj", "{756BE082-2E89-47F0-A48A-D7E762B0A82E}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Tests.IQsharp", "src\Tests\Tests.IQsharp.csproj", "{756BE082-2E89-47F0-A48A-D7E762B0A82E}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tool", "src\Tool\Tool.csproj", "{7EB9C7E8-7D40-432E-9857-1DD6301B9F4A}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Tool", "src\Tool\Tool.csproj", "{7EB9C7E8-7D40-432E-9857-1DD6301B9F4A}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Web", "src\Web\Web.csproj", "{6431E92B-12AA-432C-8D53-C9A7A54BA21B}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Web", "src\Web\Web.csproj", "{6431E92B-12AA-432C-8D53-C9A7A54BA21B}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AzureClient", "src\AzureClient\AzureClient.csproj", "{E7B60C94-B666-4024-B53E-D12C142DE8DC}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand All @@ -22,9 +24,6 @@ Global
Release|x64 = Release|x64
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{B6F42099-DACD-472F-866C-BEF92DDDF754}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B6F42099-DACD-472F-866C-BEF92DDDF754}.Debug|Any CPU.Build.0 = Debug|Any CPU
Expand Down Expand Up @@ -86,5 +85,23 @@ Global
{6431E92B-12AA-432C-8D53-C9A7A54BA21B}.Release|x64.Build.0 = Release|Any CPU
{6431E92B-12AA-432C-8D53-C9A7A54BA21B}.Release|x86.ActiveCfg = Release|Any CPU
{6431E92B-12AA-432C-8D53-C9A7A54BA21B}.Release|x86.Build.0 = Release|Any CPU
{E7B60C94-B666-4024-B53E-D12C142DE8DC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E7B60C94-B666-4024-B53E-D12C142DE8DC}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E7B60C94-B666-4024-B53E-D12C142DE8DC}.Debug|x64.ActiveCfg = Debug|Any CPU
{E7B60C94-B666-4024-B53E-D12C142DE8DC}.Debug|x64.Build.0 = Debug|Any CPU
{E7B60C94-B666-4024-B53E-D12C142DE8DC}.Debug|x86.ActiveCfg = Debug|Any CPU
{E7B60C94-B666-4024-B53E-D12C142DE8DC}.Debug|x86.Build.0 = Debug|Any CPU
{E7B60C94-B666-4024-B53E-D12C142DE8DC}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E7B60C94-B666-4024-B53E-D12C142DE8DC}.Release|Any CPU.Build.0 = Release|Any CPU
{E7B60C94-B666-4024-B53E-D12C142DE8DC}.Release|x64.ActiveCfg = Release|Any CPU
{E7B60C94-B666-4024-B53E-D12C142DE8DC}.Release|x64.Build.0 = Release|Any CPU
{E7B60C94-B666-4024-B53E-D12C142DE8DC}.Release|x86.ActiveCfg = Release|Any CPU
{E7B60C94-B666-4024-B53E-D12C142DE8DC}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {9B439141-9EFD-47B2-BD10-41BD0C96316A}
EndGlobalSection
EndGlobal
27 changes: 27 additions & 0 deletions src/AzureClient/AzureClient.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

#nullable enable

using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Jupyter.Core;
using System.Threading.Tasks;

using Microsoft.Identity.Client;
using Microsoft.Identity.Client.Extensions.Msal;
using System.Linq;
using System.IO;
using Microsoft.Azure.Quantum;
using Microsoft.Azure.Quantum.Client;
using Microsoft.Azure.Quantum.Client.Models;
using Microsoft.Quantum.Runtime;

namespace Microsoft.Quantum.IQSharp.AzureClient
{
/// <inheritdoc/>
public class AzureClient : IAzureClient
{
}
}
27 changes: 27 additions & 0 deletions src/AzureClient/AzureClient.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework>
<PlatformTarget>x64</PlatformTarget>
<RootNamespace>Microsoft.Quantum.IQSharp.AzureClient</RootNamespace>
<AssemblyName>Microsoft.Quantum.IQSharp.AzureClient</AssemblyName>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
</PropertyGroup>

<ItemGroup>
<Compile Include="..\..\build\DelaySign.cs" Link="Properties\DelaySign.cs" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Azure.Quantum.Client" Version="0.11.2004.1014-beta" />
<PackageReference Include="Microsoft.Identity.Client" Version="4.10.0" />
<PackageReference Include="Microsoft.Identity.Client.Extensions.Msal" Version="2.8.0-preview" />
<PackageReference Include="Microsoft.Jupyter.Core" Version="1.3.9214-CI-20200415-173910" />
<PackageReference Include="System.Reactive" Version="4.3.2" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Core\Core.csproj" />
</ItemGroup>

</Project>
26 changes: 26 additions & 0 deletions src/AzureClient/Extensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

#nullable enable

using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Extensions.DependencyInjection;

namespace Microsoft.Quantum.IQSharp.AzureClient
{
/// <summary>
/// Extension methods to be used with various IQ# and AzureClient objects.
/// </summary>
public static class Extensions
{
/// <summary>
/// Adds services required for the AzureClient to a given service collection.
/// </summary>
public static void AddAzureClient(this IServiceCollection services)
{
services.AddSingleton<IAzureClient, AzureClient>();
}
}
}
21 changes: 21 additions & 0 deletions src/AzureClient/IAzureClient.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

#nullable enable

using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Jupyter.Core;
using System.Threading.Tasks;

namespace Microsoft.Quantum.IQSharp.AzureClient
{
/// <summary>
/// This service is capable of connecting to Azure Quantum workspaces
/// and submitting jobs.
/// </summary>
public interface IAzureClient
{
}
}
10 changes: 5 additions & 5 deletions src/Core/Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@

<ItemGroup>
<PackageReference Include="Microsoft.CSharp" Version="4.5.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="2.2.0" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="2.2.0" />
<PackageReference Include="Microsoft.Quantum.Compiler" Version="0.10.2003.1102-beta" />
<PackageReference Include="Microsoft.Quantum.CsharpGeneration" Version="0.10.2003.1102-beta" />
<PackageReference Include="Microsoft.Quantum.Simulators" Version="0.10.2003.1102-beta" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="3.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="3.0.0" />
<PackageReference Include="Microsoft.Quantum.Compiler" Version="0.11.2004.1014-beta" />
<PackageReference Include="Microsoft.Quantum.CsharpGeneration" Version="0.11.2004.1014-beta" />
<PackageReference Include="Microsoft.Quantum.Simulators" Version="0.11.2004.1014-beta" />
<PackageReference Include="NuGet.Resolver" Version="5.1.0" />
<PackageReference Include="System.Runtime.Loader" Version="4.3.0" />
</ItemGroup>
Expand Down
38 changes: 38 additions & 0 deletions src/Core/Extensions/String.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using System;
using System.Text.RegularExpressions;

namespace Microsoft.Quantum.IQSharp
{
public static partial class Extensions
{
/// <summary>
/// Removes common indents from each line in a string,
/// similarly to Python's <c>textwrap.dedent()</c> function.
/// </summary>
public static string Dedent(this string text)
{
// First, start by finding the length of common indents,
// disregarding lines that are only whitespace.
var leadingWhitespaceRegex = new Regex(@"^[ \t]*");
var minWhitespace = int.MaxValue;
foreach (var line in text.Split("\n"))
{
if (!string.IsNullOrWhiteSpace(line))
{
var match = leadingWhitespaceRegex.Match(line);
minWhitespace = match.Success
? System.Math.Min(minWhitespace, match.Value.Length)
: minWhitespace = 0;
}
}

// We can use that to build a new regex that strips
// out common indenting.
var leftTrimRegex = new Regex(@$"^[ \t]{{{minWhitespace}}}", RegexOptions.Multiline);
return leftTrimRegex.Replace(text, "");
}
}
}
27 changes: 0 additions & 27 deletions src/Jupyter/Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -170,32 +170,5 @@ public static T WithStackTraceDisplay<T>(this T simulator, IChannel channel)
};
return simulator;
}

/// <summary>
/// Removes common indents from each line in a string,
/// similarly to Python's <c>textwrap.dedent()</c> function.
/// </summary>
internal static string Dedent(this string text)
{
// First, start by finding the length of common indents,
// disregarding lines that are only whitespace.
var leadingWhitespaceRegex = new Regex(@"^[ \t]*");
var minWhitespace = int.MaxValue;
foreach (var line in text.Split("\n"))
{
if (!string.IsNullOrWhiteSpace(line))
{
var match = leadingWhitespaceRegex.Match(line);
minWhitespace = match.Success
? System.Math.Min(minWhitespace, match.Value.Length)
: minWhitespace = 0;
}
}

// We can use that to build a new regex that strips
// out common indenting.
var leftTrimRegex = new Regex(@$"^[ \t]{{{minWhitespace}}}", RegexOptions.Multiline);
return leftTrimRegex.Replace(text, "");
}
}
}
3 changes: 2 additions & 1 deletion src/Jupyter/Jupyter.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,12 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Jupyter.Core" Version="1.3.52077" />
<PackageReference Include="Microsoft.Jupyter.Core" Version="1.3.9214-CI-20200415-173910" />
<PackageReference Include="System.Reactive" Version="4.3.2" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\AzureClient\AzureClient.csproj" />
<ProjectReference Include="..\Core\Core.csproj" />
</ItemGroup>

Expand Down
16 changes: 12 additions & 4 deletions src/Jupyter/Magic/Resolution/MagicResolver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Microsoft.Jupyter.Core;
using Microsoft.Quantum.IQSharp.AzureClient;
using Microsoft.Quantum.IQSharp.Common;

using Newtonsoft.Json;
Expand All @@ -22,7 +23,7 @@ namespace Microsoft.Quantum.IQSharp.Jupyter
/// </summary>
public class MagicSymbolResolver : IMagicSymbolResolver
{
private AssemblyInfo kernelAssembly;
private AssemblyInfo[] kernelAssemblies;
private Dictionary<AssemblyInfo, MagicSymbol[]> cache;
private IServiceProvider services;
private IReferences references;
Expand All @@ -38,7 +39,11 @@ public MagicSymbolResolver(IServiceProvider services, ILogger<MagicSymbolResolve
this.cache = new Dictionary<AssemblyInfo, MagicSymbol[]>();
this.logger = logger;

this.kernelAssembly = new AssemblyInfo(typeof(MagicSymbolResolver).Assembly);
this.kernelAssemblies = new[]
{
new AssemblyInfo(typeof(MagicSymbolResolver).Assembly),
new AssemblyInfo(typeof(AzureClient.AzureClient).Assembly)
};
this.services = services;
this.references = services.GetService<IReferences>();
}
Expand All @@ -50,7 +55,10 @@ public MagicSymbolResolver(IServiceProvider services, ILogger<MagicSymbolResolve
/// </summary>
private IEnumerable<AssemblyInfo> RelevantAssemblies()
{
yield return this.kernelAssembly;
foreach (var asm in this.kernelAssemblies)
{
yield return asm;
}

foreach (var asm in references.Assemblies)
{
Expand Down Expand Up @@ -80,7 +88,7 @@ public MagicSymbol Resolve(string symbolName)

foreach (var magic in FindAllMagicSymbols())
{
if (symbolName.StartsWith(magic.Name))
if (symbolName == magic.Name)
{
this.logger.LogDebug($"Using magic {magic.Name}");
return magic;
Expand Down
22 changes: 22 additions & 0 deletions src/Tests/AzureClientTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

#nullable enable

using Microsoft.VisualStudio.TestTools.UnitTesting;
using Microsoft.Quantum.IQSharp.AzureClient;
using System.Linq;
using System.Collections.Generic;

namespace Tests.IQSharp
{
[TestClass]
public class AzureClientTests
{
[TestMethod]
public void TestNothing()
{
Assert.IsTrue(true);
}
}
}
3 changes: 1 addition & 2 deletions src/Tests/HttpServerIntegrationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Tests.IQSharp;

namespace Tests.IQsharp
namespace Tests.IQSharp
{
[TestClass]
public class HttpServerIntegrationTests
Expand Down
2 changes: 2 additions & 0 deletions src/Tool/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Quantum.IQSharp.Jupyter;
using Microsoft.Quantum.IQSharp.AzureClient;
using System;

namespace Microsoft.Quantum.IQSharp
Expand All @@ -24,6 +25,7 @@ public virtual void ConfigureServices(IServiceCollection services)
services.AddSingleton(typeof(ITelemetryService), GetTelemetryServiceType());
services.AddIQSharp();
services.AddIQSharpKernel();
services.AddAzureClient();

var assembly = typeof(PackagesController).Assembly;
services.AddControllers()
Expand Down
1 change: 1 addition & 0 deletions src/Tool/Tool.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\AzureClient\AzureClient.csproj" />
<ProjectReference Include="..\Jupyter\Jupyter.csproj" />
<ProjectReference Include="..\Core\Core.csproj" />
<ProjectReference Include="..\Web\Web.csproj" />
Expand Down
Loading