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

Commit

Permalink
Merge branch 'main' into xfield/remove-function-key
Browse files Browse the repository at this point in the history
  • Loading branch information
vxfield authored Sep 16, 2022
2 parents 011c577 + 20d1e6e commit c467d84
Show file tree
Hide file tree
Showing 13 changed files with 281 additions and 186 deletions.
4 changes: 3 additions & 1 deletion images/iqsharp-base/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ RUN pip install --no-cache --upgrade pip
RUN pip install \
ipython==8.4.0 \
jupyter==1.0.0 \
notebook==6.4.12
notebook==6.4.12 \
# to workaround: https://github.com/zeromq/pyzmq/issues/1764
pyzmq==23.2.1

# Install APT prerequisites.
RUN apt-get update && \
Expand Down
12 changes: 7 additions & 5 deletions src/AzureClient/AzureClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -386,12 +386,14 @@ private async Task<ExecutionResult> SubmitOrExecuteJobAsync(
// Thus, we can branch on whether we need a QIR submitter or a translator,
// but can use the same task object to represent both return values.
Func<IEntryPoint, Task<IQuantumMachineJob>>? jobTask = null;
if (this.ActiveTarget.TryGetQirSubmitter(this.ActiveWorkspace, this.StorageConnectionString, out var submitter))
if (this.ActiveTarget.TryGetQirSubmitter(this.ActiveWorkspace, this.StorageConnectionString, this.TargetCapability, out var submitter))
{
Logger?.LogDebug("Using QIR submitter for target {Target} and capability {Capability}.", this.ActiveTarget, this.TargetCapability);
jobTask = entryPoint => entryPoint.SubmitAsync(submitter, submissionContext);
}
else if (AzureFactory.CreateMachine(this.ActiveWorkspace, this.ActiveTarget.TargetId, this.StorageConnectionString) is IQuantumMachine machine)
{
Logger?.LogDebug("Using legacy submitter for target {Target} and capability {Capability}.", this.ActiveTarget, this.TargetCapability);
jobTask = entryPoint => entryPoint.SubmitAsync(machine, submissionContext);
}
else
Expand All @@ -405,7 +407,7 @@ private async Task<ExecutionResult> SubmitOrExecuteJobAsync(
try
{
entryPoint = await EntryPointGenerator.Generate(
submissionContext.OperationName, ActiveTarget.TargetId, ActiveTarget.MaximumCapability
submissionContext.OperationName, ActiveTarget.TargetId, this.TargetCapability
);
}
catch (TaskCanceledException tce)
Expand Down Expand Up @@ -569,7 +571,7 @@ public async Task<ExecutionResult> SetActiveTargetAsync(IChannel? channel, strin

// Set the active target and load the package.
ActiveTarget = executionTarget;
TargetCapability = executionTarget.MaximumCapability;
TargetCapability = executionTarget.DefaultCapability;

channel?.Stdout($"Loading package {ActiveTarget.PackageName} and dependencies...");
await References.AddPackage(ActiveTarget.PackageName);
Expand Down Expand Up @@ -815,7 +817,7 @@ public void ClearActiveTarget()
public bool TrySetTargetCapability(IChannel? channel, string? capabilityName, [NotNullWhen(true)] out TargetCapability? targetCapability)
{
var capability = capabilityName is null
? ActiveTarget?.MaximumCapability ?? TargetCapabilityModule.Top
? ActiveTarget?.DefaultCapability ?? TargetCapabilityModule.Top
: TargetCapabilityModule.FromName(capabilityName);
if (!FSharpOption<TargetCapability>.get_IsSome(capability))
{
Expand All @@ -826,7 +828,7 @@ public bool TrySetTargetCapability(IChannel? channel, string? capabilityName, [N

if (ActiveTarget != null && !ActiveTarget.SupportsCapability(capability.Value))
{
channel?.Stderr($"Target capability {capability.Value.Name} is not supported by the active target, {ActiveTarget.TargetId}. The active target supports a maximum capability level of {ActiveTarget.MaximumCapability.Name}.");
channel?.Stderr($"Target capability {capability.Value.Name} is not supported by the active target, {ActiveTarget.TargetId}. The active target supports a maximum capability level of {ActiveTarget.DefaultCapability.Name}.");
targetCapability = null;
return false;
}
Expand Down
50 changes: 46 additions & 4 deletions src/AzureClient/AzureExecutionTarget.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ internal protected AzureExecutionTarget(string? targetId)
/// Any other target capability must be subsumed by this maximum
/// in order to be supported by this target.
/// </summary>
public TargetCapability MaximumCapability => GetProvider(TargetId) switch
public TargetCapability DefaultCapability => GetProvider(TargetId) switch
{
AzureProvider.IonQ => TargetCapabilityModule.BasicQuantumFunctionality,
AzureProvider.Quantinuum => TargetCapabilityModule.BasicMeasurementFeedback,
Expand All @@ -76,21 +76,63 @@ internal protected AzureExecutionTarget(string? targetId)
/// level.
/// </summary>
public bool SupportsCapability(TargetCapability capability) =>
TargetCapabilityModule.Subsumes(this.MaximumCapability, capability);
// NB: Duplicates logic at https://github.com/microsoft/qsharp-compiler/blob/7714168fda4379fb7e6a6c616f680ec039c482f4/src/QuantumSdk/DefaultItems/DefaultItems.targets#L78,
// but at the level of providers rather than at the level of resolved processors.
(GetProvider(TargetId) switch
{
AzureProvider.Quantinuum or AzureProvider.Honeywell => new[]
{
TargetCapabilityModule.AdaptiveExecution,
TargetCapabilityModule.BasicMeasurementFeedback,
TargetCapabilityModule.BasicQuantumFunctionality,
TargetCapabilityModule.BasicExecution
},
AzureProvider.IonQ => new[]
{
TargetCapabilityModule.BasicQuantumFunctionality
},
AzureProvider.QCI => new[]
{
TargetCapabilityModule.AdaptiveExecution,
TargetCapabilityModule.BasicExecution
},
AzureProvider.Rigetti => new[]
{
TargetCapabilityModule.BasicExecution
},
AzureProvider.Microsoft => new[]
{
TargetCapabilityModule.FullComputation
},
_ => new[]
{
TargetCapabilityModule.FullComputation,
TargetCapabilityModule.AdaptiveExecution,
TargetCapabilityModule.BasicMeasurementFeedback,
TargetCapabilityModule.BasicQuantumFunctionality,
TargetCapabilityModule.BasicExecution
}
})
.Any(c => TargetCapabilityModule.Subsumes(c, capability));

/// <summary>
/// Attempts to get a <see cref="IQirSubmitter"/> instance appropriate
/// for use with this target.
/// </summary>
public virtual bool TryGetQirSubmitter(Azure.Quantum.IWorkspace workspace, string storageConnectionString, [NotNullWhen(true)] out IQirSubmitter? submitter)
public virtual bool TryGetQirSubmitter(
Azure.Quantum.IWorkspace workspace,
string storageConnectionString,
TargetCapability? targetCapability,
[NotNullWhen(true)] out IQirSubmitter? submitter
)
{
if (this.TargetId == null || this.TargetId.EndsWith(".mock"))
{
submitter = null;
return false;
}

if (SubmitterFactory.QirSubmitter(this.TargetId, workspace, storageConnectionString, this.MaximumCapability.Name) is IQirSubmitter qirSubmitter)
if (SubmitterFactory.QirSubmitter(this.TargetId, workspace, storageConnectionString, (targetCapability ?? this.DefaultCapability).Name) is IQirSubmitter qirSubmitter)
{
submitter = qirSubmitter;
return true;
Expand Down
3 changes: 2 additions & 1 deletion src/AzureClient/Mocks/MockAzureExecutionTarget.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using Microsoft.Azure.Quantum;
using Microsoft.Quantum.QsCompiler;
using Microsoft.Quantum.Runtime;
using Microsoft.Quantum.Runtime.Submitters;

Expand Down Expand Up @@ -33,7 +34,7 @@ internal record MockAzureExecutionTarget : AzureExecutionTarget
: null;


public override bool TryGetQirSubmitter(Azure.Quantum.IWorkspace workspace, string storageConnectionString, [NotNullWhen(true)] out IQirSubmitter? submitter)
public override bool TryGetQirSubmitter(Azure.Quantum.IWorkspace workspace, string storageConnectionString, TargetCapability? targetCapability, [NotNullWhen(true)] out IQirSubmitter? submitter)
{
if (this.TargetId?.EndsWith("mock-qir") ?? false)
{
Expand Down
7 changes: 4 additions & 3 deletions src/Python/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
# This file includes requirements to build and test the Python packages.
ipython==8.4.0 # to avoid high-severity issue.
jupyter==1.0.0
nbconvert==6.5.0
nbconvert==7.0.0
notebook==6.4.12
numpy==1.21.6
numpy==1.22.0
pytest==7.1.2
pygments==2.12.0 # to avoid high-severity issue.
pygments==2.12.0 # to avoid high-severity issue.
pyzmq==23.2.1 # to workaround: https://github.com/zeromq/pyzmq/issues/1764
qutip==4.7.0
selenium==4.2.0
setuptools==62.6.0
Expand Down
2 changes: 1 addition & 1 deletion src/Tests/AzureClientMagicTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ public async Task<ExecutionResult> SetActiveTargetAsync(IChannel channel, string
{
LastAction = AzureClientAction.SetActiveTarget;
ActiveTarget = MockAzureExecutionTarget.CreateMock(targetId);
TargetCapability = ActiveTarget?.MaximumCapability ?? TargetCapabilityModule.Top;
TargetCapability = ActiveTarget?.DefaultCapability ?? TargetCapabilityModule.Top;
return ExecuteStatus.Ok.ToExecutionResult();
}

Expand Down
1 change: 1 addition & 0 deletions src/Tests/AzureClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ public void TestManualTargets()
[DataRow("--clear", "FullComputation", ExecuteStatus.Ok)]
[DataRow("honeywell.mock", "FullComputation", ExecuteStatus.Error)]
[DataRow("honeywell.mock", "BasicMeasurementFeedback", ExecuteStatus.Ok)]
[DataRow("quantinuum.mock", "AdaptiveExecution", ExecuteStatus.Ok)]
public async Task TestManualCapabilities(string targetId, string capabilityName, ExecuteStatus expectedResult) =>
await Assert.That
.UsingEngine(async services =>
Expand Down
4 changes: 2 additions & 2 deletions tests.live/All.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ BeforeAll {

# These are needed for environment credentials:
$Env:AZURE_TENANT_ID | Should -Not -BeNullOrEmpty
$Env:AZURE_CLIENT_ID | Should -Not -BeNullOrEmpty
$Env:AZURE_CLIENT_SECRET | Should -Not -BeNullOrEmpty
# $Env:AZURE_CLIENT_ID | Should -Not -BeNullOrEmpty
# $Env:AZURE_CLIENT_SECRET | Should -Not -BeNullOrEmpty
}

function Test-Notebook([string]$notebook) {
Expand Down
8 changes: 8 additions & 0 deletions tests.live/Python/qsharp/ionq/IonQ.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<Project Sdk="Microsoft.Quantum.Sdk/0.25.228311">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ExecutionTarget>ionq.simulator</ExecutionTarget>
</PropertyGroup>

</Project>
25 changes: 25 additions & 0 deletions tests.live/Python/qsharp/ionq/Operations.qs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

namespace Microsoft.Quantum.Tests {
open Microsoft.Quantum.Intrinsic;
open Microsoft.Quantum.Canon;

/// # Summary
/// A quantum random number generator with a variable number of qubits.
operation SampleQrng(count : Int, name : String) : Result[] {
Message($"Hello {name} again!");

mutable r = [Zero, size = count];
use q = Qubit[count];

ApplyToEach(H, q);

for i in 1..count {
set r w/= i-1 <- M(q[i-1]);
}

return r;
}

}
Original file line number Diff line number Diff line change
@@ -1,32 +1,14 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

/// Q# code should be in one or more .qs files that live
/// in the same directory as the python classical driver.
///

namespace Microsoft.Quantum.Tests {
open Microsoft.Quantum.Intrinsic;
open Microsoft.Quantum.Canon;

/// # Summary
/// A quantum random number generator with a variable number of qubits.
operation SampleQrng(count : Int, name : String) : Result[] {
Message($"Hello {name} again!");

mutable r = [Zero, size = count];
use q = Qubit[count];

ApplyToEach(H, q);

for i in 1..count {
set r w/= i-1 <- M(q[i-1]);
}

return r;
operation RunTeleportWithPlus() : Result {
return RunTeleport(true);
}


/// # Summary
/// Direct implementation of Teleport's circuit
operation RunTeleport(doPlus: Bool) : Result {
Expand Down Expand Up @@ -68,4 +50,5 @@ namespace Microsoft.Quantum.Tests {
X(q);
H(q);
}

}
10 changes: 10 additions & 0 deletions tests.live/Python/qsharp/quantinuum/Quantinuum.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<Project Sdk="Microsoft.Quantum.Sdk/0.25.228311">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ExecutionTarget>qci.qpu</ExecutionTarget>
<TargetCapability>AdaptiveExecution</TargetCapability>
<QirGeneration>true</QirGeneration>
</PropertyGroup>

</Project>
Loading

0 comments on commit c467d84

Please sign in to comment.