Skip to content
This repository has been archived by the owner on Jan 12, 2024. It is now read-only.

IQ# - Fullstate Simulator V1 Output Format #713

Closed
wants to merge 21 commits into from
Closed
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
3bf085b
Pass Assembly Constants in to GenerateBitcode
ScottCarda-MS Jul 12, 2022
1225d74
Get the processor architecture from the execution target.
ScottCarda-MS Jul 12, 2022
0fab004
versions
ScottCarda-MS Aug 25, 2022
d5649c6
merge in from main
ScottCarda-MS Aug 25, 2022
2b82bdc
Removed special handling for Microsoft simulator for cloud jobs.
ScottCarda-MS Aug 26, 2022
bfb6bbf
Added test for IQ# change
ScottCarda-MS Aug 29, 2022
a26e9bd
Differentiate logic based on job.OutputDataFormat
ScottCarda-MS Aug 30, 2022
df9cca3
Add output format to cloud job mocks.
ScottCarda-MS Aug 31, 2022
394091c
Got a test working
ScottCarda-MS Aug 31, 2022
0e03b64
Merge branch 'main' into sccarda/V1OutputRecording
ricardo-espinoza Sep 6, 2022
20ca1ef
small changes
ScottCarda-MS Sep 10, 2022
e71c622
Merge branch 'sccarda/V1OutputRecording' of https://github.com/micros…
ScottCarda-MS Sep 10, 2022
0e4218f
combine uses of assemblyConstants
ScottCarda-MS Sep 10, 2022
084941e
merge in from main
ScottCarda-MS Sep 12, 2022
0b3d489
use beta packages
ScottCarda-MS Sep 13, 2022
06997d5
removed unused using
ScottCarda-MS Sep 16, 2022
d7f405b
Merge branch 'main' into sccarda/V1OutputRecording
ScottCarda-MS Sep 16, 2022
cb8cc16
Merge branch 'main' into sccarda/V1OutputRecording
ScottCarda-MS Sep 16, 2022
95ddbb6
Merge branch 'main' into sccarda/V1OutputRecording
ScottCarda-MS Sep 19, 2022
67bdc28
Merge branch 'sccarda/V1OutputRecording' of https://github.com/micros…
ScottCarda-MS Sep 19, 2022
6cfaf7f
Merge branch 'main' into sccarda/V1OutputRecording
ScottCarda-MS Sep 19, 2022
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
2 changes: 1 addition & 1 deletion global.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
"rollForward": "latestMinor"
},
"msbuild-sdks": {
"Microsoft.Quantum.Sdk": "0.25.222597"
"Microsoft.Quantum.Sdk": "0.25.227074-beta"
}
}
2 changes: 1 addition & 1 deletion images/iqsharp-base/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ ENV PATH=$PATH:${HOME}/dotnet:${HOME}/.dotnet/tools \
# Install IQ# and the project templates, using the NuGet packages from the
# build context.
ARG IQSHARP_VERSION
RUN dotnet new -i "Microsoft.Quantum.ProjectTemplates::0.25.222597" && \
RUN dotnet new -i "Microsoft.Quantum.ProjectTemplates::0.25.227074-beta" && \
dotnet tool install \
--global \
Microsoft.Quantum.IQSharp \
Expand Down
27 changes: 23 additions & 4 deletions src/AzureClient/AzureClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using System.IO;
using System.Net;
using System.Net.Http;
using System.Runtime.InteropServices.ComTypes;
ScottCarda-MS marked this conversation as resolved.
Show resolved Hide resolved
using System.Threading;

using Azure.Core;
Expand All @@ -23,6 +24,18 @@

namespace Microsoft.Quantum.IQSharp.AzureClient
{
/// <summary>
/// Supported output data formats for QIR.
/// </summary>
internal static class OutputFormat
{
public const string QirResultsV1 = "microsoft.qir-results.v1";

public const string QuantumResultsV1 = "microsoft.quantum-results.v1";

public const string ResourceEstimatesV1 = "microsoft.resource-estimates.v1";
}

/// <inheritdoc/>
public class AzureClient : IAzureClient
{
Expand Down Expand Up @@ -635,7 +648,7 @@ public async Task<ExecutionResult> GetJobResultAsync(IChannel? channel, string?
}
}

private async Task<ExecutionResult> CreateOutput(CloudJob job, IChannel? channel, CancellationToken cancellationToken)
internal async Task<ExecutionResult> CreateOutput(CloudJob job, IChannel? channel, CancellationToken cancellationToken)
{
async Task<Stream> ReadHttp()
{
Expand All @@ -649,16 +662,22 @@ async Task<Stream> ReadHttp()
using var stream = job.OutputDataUri.IsFile
? File.OpenRead(job.OutputDataUri.LocalPath)
: await ReadHttp();
if (this.ActiveTarget?.TargetId?.StartsWith(MicrosoftSimulator) ?? false)

if (job.OutputDataFormat == OutputFormat.QirResultsV1)
{
var (messages, result) = ParseSimulatorOutput(stream);
channel?.Stdout(messages);
return result.ToExecutionResult();
}
else
else if (job.OutputDataFormat == OutputFormat.QuantumResultsV1)
{
return stream.ToHistogram(channel, Logger).ToExecutionResult();
}
else
{
channel?.Stderr($"Job ID {job.Id} has unsupported output format: {job.OutputDataFormat}");
return AzureClientError.JobOutputDownloadFailed.ToExecutionResult();
}
}

private static (string Messages, string Result) ParseSimulatorOutput(Stream stream)
Expand All @@ -669,7 +688,7 @@ private static (string Messages, string Result) ParseSimulatorOutput(Stream stre
var line = String.Empty;
while ((line = reader.ReadLine()) != null)
{
outputLines.Add(line.Trim());
outputLines.Add(line.Trim());
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/AzureClient/AzureClient.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

<ItemGroup>
<PackageReference Include="Azure.Quantum.Jobs" Version="1.0.0-beta.3" />
<PackageReference Include="Microsoft.Azure.Quantum.Client" Version="0.25.222597" />
<PackageReference Include="Microsoft.Azure.Quantum.Client" Version="0.25.227074-beta" />
<PackageReference Include="Microsoft.Rest.ClientRuntime" Version="2.3.23" />
<PackageReference Include="Microsoft.Rest.ClientRuntime.Azure" Version="3.3.19" />
<PackageReference Include="System.Reactive" Version="4.3.2" />
Expand Down
19 changes: 15 additions & 4 deletions src/AzureClient/Mocks/MockCloudJob.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,13 @@ public float? EstimatedTotal
/// </summary>
internal class MockJobDetails : JobDetails
{
public MockJobDetails(string containerUri, string inputDataFormat, string providerId, string target)
public MockJobDetails(string containerUri, string inputDataFormat, string providerId, string target, string outputDataFormat)
: base(containerUri: containerUri,
inputDataFormat: inputDataFormat,
providerId: providerId,
target: target)
{
OutputDataFormat = outputDataFormat;
}

private MockCostEstimate? costEstimate;
Expand Down Expand Up @@ -110,14 +111,15 @@ internal class MockCloudJob : CloudJob
private string _id;
private string? _outputFile;

public MockCloudJob(string? id = null)
public MockCloudJob(string? id = null, string outputFormat = OutputFormat.QuantumResultsV1)
: base(
new MockAzureWorkspace("mockSubscriptionId", "mockResourceGroupName", "mockWorkspaceName", "mockLocation"),
new MockJobDetails(
containerUri: string.Empty,
inputDataFormat: string.Empty,
providerId: string.Empty,
target: string.Empty
target: string.Empty,
outputDataFormat: outputFormat
))
{
_id = id ?? Guid.NewGuid().ToString();
Expand All @@ -135,7 +137,16 @@ public override Uri OutputDataUri
{
var path = Path.GetTempFileName();
using var outputFile = new StreamWriter(path);
outputFile.WriteLine(@"{'Histogram':['0',0.5,'1',0.5]}");
if (OutputDataFormat == OutputFormat.QirResultsV1)
{
outputFile.WriteLine("\"This is a message.\"");
outputFile.WriteLine("\"The is a two-line");
outputFile.WriteLine("string result.\"");
}
else
{
outputFile.WriteLine(@"{'Histogram':['0',0.5,'1',0.5]}");
}

_outputFile = path;
}
Expand Down
14 changes: 13 additions & 1 deletion src/Core/Compiler/CompilerService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,18 @@ string WrapInNamespace(Snippet s) =>
var (qsCompilation, assemblyConstants) = this.UpdateCompilation(sources, metadata.QsMetadatas, logger, compileAsExecutable, executionTarget, capability, parent: perfTask);
logger.WarningCodesToIgnore.Remove(QsCompiler.Diagnostics.WarningCode.EntryPointInLibrary);

string processorArchitecture = "Any";
ScottCarda-MS marked this conversation as resolved.
Show resolved Hide resolved
if (!(executionTarget is null) && executionTarget.ToLower() == "microsoft.simulator.fullstate")
ScottCarda-MS marked this conversation as resolved.
Show resolved Hide resolved
{
processorArchitecture = AssemblyConstants.MicrosoftSimulator;
}

var assebmlyConstants = new Dictionary<string, string?>
{
[AssemblyConstants.TargetCapability] = capability?.Name,
[AssemblyConstants.ProcessorArchitecture] = processorArchitecture
};

if (logger.HasErrors || qsCompilation == null) return null;

try
Expand Down Expand Up @@ -454,7 +466,7 @@ string WrapInNamespace(Snippet s) =>
var tempPath = Path.GetTempFileName();
var bcFile = CompilationLoader.GeneratedFile(tempPath, Path.GetDirectoryName(tempPath), ".bc", "");
var diagnostics = new List<IRewriteStep.Diagnostic>();
CompilationSteps.GenerateBitcode(qsCompilation, capability, bcFile, diagnostics: diagnostics);
CompilationSteps.GenerateBitcode(qsCompilation, assebmlyConstants, bcFile, diagnostics: diagnostics);
ScottCarda-MS marked this conversation as resolved.
Show resolved Hide resolved
foreach (var diagnostic in diagnostics)
{
Logger?.Log(
Expand Down
10 changes: 5 additions & 5 deletions src/Core/Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@
<PackageReference Include="Microsoft.CSharp" Version="4.5.0" />
<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.25.222597" />
<PackageReference Include="Microsoft.Quantum.QirGeneration" Version="0.25.222597" />
<PackageReference Include="Microsoft.Quantum.CSharpGeneration" Version="0.25.222597" />
<PackageReference Include="Microsoft.Quantum.Simulators" Version="0.25.222597" />
<PackageReference Include="Microsoft.Quantum.QSharp.Core" Version="0.25.222597" />
<PackageReference Include="Microsoft.Quantum.Compiler" Version="0.25.227074-beta" />
<PackageReference Include="Microsoft.Quantum.QirGeneration" Version="0.25.227074-beta" />
<PackageReference Include="Microsoft.Quantum.CSharpGeneration" Version="0.25.227074-beta" />
<PackageReference Include="Microsoft.Quantum.Simulators" Version="0.25.227074-beta" />
<PackageReference Include="Microsoft.Quantum.QSharp.Core" Version="0.25.227074-beta" />
<PackageReference Include="Microsoft.Windows.Compatibility" Version="5.0.2" />
<PackageReference Include="NuGet.Resolver" Version="5.1.0" />
<PackageReference Include="System.DirectoryServices.Protocols" Version="5.0.1" />
Expand Down
2 changes: 1 addition & 1 deletion src/ExecutionPathTracer/ExecutionPathTracer.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Quantum.Simulators" Version="0.25.222597" />
<PackageReference Include="Microsoft.Quantum.Simulators" Version="0.25.227074-beta" />
</ItemGroup>

</Project>
2 changes: 1 addition & 1 deletion src/Kernel/Kernel.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

<ItemGroup>
<PackageReference Include="System.Reactive" Version="4.3.2" />
<PackageReference Include="Microsoft.Quantum.QirGeneration" Version="0.25.222597" />
<PackageReference Include="Microsoft.Quantum.QirGeneration" Version="0.25.227074-beta" />
</ItemGroup>

<!-- TypeScript compilation -->
Expand Down
4 changes: 2 additions & 2 deletions src/MockLibraries/Mock.Chemistry/Mock.Chemistry.csproj
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<Project Sdk="Microsoft.Quantum.Sdk/0.25.222597">
<Project Sdk="Microsoft.Quantum.Sdk/0.25.227074-beta">

<PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework>
<IncludeQsharpCorePackages>false</IncludeQsharpCorePackages> <!-- otherwise the standard library is included by the Sdk -->
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Quantum.Simulators" Version="0.25.222597" />
<PackageReference Include="Microsoft.Quantum.Simulators" Version="0.25.227074-beta" />
</ItemGroup>
</Project>
4 changes: 2 additions & 2 deletions src/MockLibraries/Mock.Standard/Mock.Standard.csproj
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<Project Sdk="Microsoft.Quantum.Sdk/0.25.222597">
<Project Sdk="Microsoft.Quantum.Sdk/0.25.227074-beta">

<PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework>
<IncludeQsharpCorePackages>false</IncludeQsharpCorePackages> <!-- otherwise the standard library is included by the Sdk -->
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Quantum.Simulators" Version="0.25.222597" />
<PackageReference Include="Microsoft.Quantum.Simulators" Version="0.25.227074-beta" />
</ItemGroup>
</Project>
29 changes: 29 additions & 0 deletions src/Tests/AzureClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,35 @@ public void TestJobExecution()
Assert.IsNotNull(histogram);
}

[TestMethod]
public void TestJobOutputFormats()
{
var services = Startup.CreateServiceProvider("Workspace");
var azureClient = (AzureClient)services.GetRequiredService<IAzureClient>();

// connect
var targets = ExpectSuccess<IEnumerable<TargetStatusInfo>>(ConnectToWorkspaceAsync(azureClient));
Assert.IsFalse(targets.Any());

// add a target
var azureWorkspace = azureClient.ActiveWorkspace as MockAzureWorkspace;
Assert.IsNotNull(azureWorkspace);
azureWorkspace?.AddProviders("microsoft");

// set the active target
var target = ExpectSuccess<TargetStatusInfo>(azureClient.SetActiveTargetAsync(new MockChannel(), "microsoft.simulator"));
Assert.AreEqual("microsoft.simulator", target.TargetId);

var qirResultsJob = new MockCloudJob(null, OutputFormat.QirResultsV1);
var quantumResultsJob = new MockCloudJob(null, OutputFormat.QuantumResultsV1);

var histogram = ExpectSuccess<Histogram>(azureClient.CreateOutput(quantumResultsJob, new MockChannel(), CancellationToken.None));
Assert.IsNotNull(histogram);

var stringOutput = ExpectSuccess<string>(azureClient.CreateOutput(qirResultsJob, new MockChannel(), CancellationToken.None));
Assert.IsNotNull(stringOutput);
}

[TestMethod]
public void TestJobExecutionWithArrayInput()
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.Quantum.Sdk/0.25.222597">
<Project Sdk="Microsoft.Quantum.Sdk/0.25.227074-beta">

<PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.Quantum.Sdk/0.25.222597">
<Project Sdk="Microsoft.Quantum.Sdk/0.25.227074-beta">

<PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.Quantum.Sdk/0.25.222597">
<Project Sdk="Microsoft.Quantum.Sdk/0.25.227074-beta">

<PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework>
Expand All @@ -7,7 +7,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Quantum.Xunit" Version="0.25.222597" />
<PackageReference Include="Microsoft.Quantum.Xunit" Version="0.25.227074-beta" />
</ItemGroup>

<ItemGroup>
Expand Down
36 changes: 18 additions & 18 deletions src/Tool/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,23 @@
},
"AllowedHosts": "*",
"DefaultPackageVersions": [
"Microsoft.Quantum.Compiler::0.25.222597",
"Microsoft.Quantum.CSharpGeneration::0.25.222597",
"Microsoft.Quantum.QirGeneration::0.25.222597",
"Microsoft.Quantum.Development.Kit::0.25.222597",
"Microsoft.Quantum.Simulators::0.25.222597",
"Microsoft.Quantum.Xunit::0.25.222597",
"Microsoft.Quantum.Standard::0.25.222597",
"Microsoft.Quantum.Standard.Visualization::0.25.222597",
"Microsoft.Quantum.Chemistry::0.25.222597",
"Microsoft.Quantum.Chemistry.Jupyter::0.25.222597",
"Microsoft.Quantum.MachineLearning::0.25.222597",
"Microsoft.Quantum.Numerics::0.25.222597",
"Microsoft.Quantum.Katas::0.25.222597",
"Microsoft.Quantum.Research::0.25.222597",
"Microsoft.Quantum.Providers.IonQ::0.25.222597",
"Microsoft.Quantum.Providers.Honeywell::0.25.222597",
"Microsoft.Quantum.Providers.QCI::0.25.222597",
"Microsoft.Quantum.Providers.Rigetti::0.25.222597"
"Microsoft.Quantum.Compiler::0.25.227074-beta",
"Microsoft.Quantum.CSharpGeneration::0.25.227074-beta",
"Microsoft.Quantum.QirGeneration::0.25.227074-beta",
"Microsoft.Quantum.Development.Kit::0.25.227074-beta",
"Microsoft.Quantum.Simulators::0.25.227074-beta",
"Microsoft.Quantum.Xunit::0.25.227074-beta",
"Microsoft.Quantum.Standard::0.25.227074-beta",
"Microsoft.Quantum.Standard.Visualization::0.25.227074-beta",
"Microsoft.Quantum.Chemistry::0.25.227074-beta",
"Microsoft.Quantum.Chemistry.Jupyter::0.25.227074-beta",
"Microsoft.Quantum.MachineLearning::0.25.227074-beta",
"Microsoft.Quantum.Numerics::0.25.227074-beta",
"Microsoft.Quantum.Katas::0.25.227074-beta",
"Microsoft.Quantum.Research::0.25.227074-beta",
"Microsoft.Quantum.Providers.IonQ::0.25.227074-beta",
"Microsoft.Quantum.Providers.Honeywell::0.25.227074-beta",
"Microsoft.Quantum.Providers.QCI::0.25.227074-beta",
"Microsoft.Quantum.Providers.Rigetti::0.25.227074-beta"
]
}