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
2 changes: 1 addition & 1 deletion images/iqsharp-base/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,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.12.20072301-beta" && \
RUN dotnet new -i "Microsoft.Quantum.ProjectTemplates::0.12.20073008-beta" && \
dotnet tool install \
--global \
Microsoft.Quantum.IQSharp \
Expand Down
40 changes: 27 additions & 13 deletions iqsharp.sln
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AzureClient", "src\AzureCli
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Jupyter", "src\Jupyter\Jupyter.csproj", "{19A9E2AB-8842-47E2-8E6A-6DD292B49E97}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Mock.Chemistry", "src\Mock.Chemistry\Mock.Chemistry.csproj", "{2243DB2D-EFAC-4594-A44B-A25B399CE4DE}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Mock.Chemistry", "src\MockLibraries\Mock.Chemistry\Mock.Chemistry.csproj", "{AAAEA32B-3CFA-40D4-A7A0-D332ACB40BA1}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Mock.Standard", "src\MockLibraries\Mock.Standard\Mock.Standard.csproj", "{854E40D3-64A2-4864-AB79-AB9CC61DA1DE}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down Expand Up @@ -113,18 +115,30 @@ Global
{19A9E2AB-8842-47E2-8E6A-6DD292B49E97}.Release|x64.Build.0 = Release|Any CPU
{19A9E2AB-8842-47E2-8E6A-6DD292B49E97}.Release|x86.ActiveCfg = Release|Any CPU
{19A9E2AB-8842-47E2-8E6A-6DD292B49E97}.Release|x86.Build.0 = Release|Any CPU
{2243DB2D-EFAC-4594-A44B-A25B399CE4DE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2243DB2D-EFAC-4594-A44B-A25B399CE4DE}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2243DB2D-EFAC-4594-A44B-A25B399CE4DE}.Debug|x64.ActiveCfg = Debug|Any CPU
{2243DB2D-EFAC-4594-A44B-A25B399CE4DE}.Debug|x64.Build.0 = Debug|Any CPU
{2243DB2D-EFAC-4594-A44B-A25B399CE4DE}.Debug|x86.ActiveCfg = Debug|Any CPU
{2243DB2D-EFAC-4594-A44B-A25B399CE4DE}.Debug|x86.Build.0 = Debug|Any CPU
{2243DB2D-EFAC-4594-A44B-A25B399CE4DE}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2243DB2D-EFAC-4594-A44B-A25B399CE4DE}.Release|Any CPU.Build.0 = Release|Any CPU
{2243DB2D-EFAC-4594-A44B-A25B399CE4DE}.Release|x64.ActiveCfg = Release|Any CPU
{2243DB2D-EFAC-4594-A44B-A25B399CE4DE}.Release|x64.Build.0 = Release|Any CPU
{2243DB2D-EFAC-4594-A44B-A25B399CE4DE}.Release|x86.ActiveCfg = Release|Any CPU
{2243DB2D-EFAC-4594-A44B-A25B399CE4DE}.Release|x86.Build.0 = Release|Any CPU
{AAAEA32B-3CFA-40D4-A7A0-D332ACB40BA1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{AAAEA32B-3CFA-40D4-A7A0-D332ACB40BA1}.Debug|Any CPU.Build.0 = Debug|Any CPU
{AAAEA32B-3CFA-40D4-A7A0-D332ACB40BA1}.Debug|x64.ActiveCfg = Debug|Any CPU
{AAAEA32B-3CFA-40D4-A7A0-D332ACB40BA1}.Debug|x64.Build.0 = Debug|Any CPU
{AAAEA32B-3CFA-40D4-A7A0-D332ACB40BA1}.Debug|x86.ActiveCfg = Debug|Any CPU
{AAAEA32B-3CFA-40D4-A7A0-D332ACB40BA1}.Debug|x86.Build.0 = Debug|Any CPU
{AAAEA32B-3CFA-40D4-A7A0-D332ACB40BA1}.Release|Any CPU.ActiveCfg = Release|Any CPU
{AAAEA32B-3CFA-40D4-A7A0-D332ACB40BA1}.Release|Any CPU.Build.0 = Release|Any CPU
{AAAEA32B-3CFA-40D4-A7A0-D332ACB40BA1}.Release|x64.ActiveCfg = Release|Any CPU
{AAAEA32B-3CFA-40D4-A7A0-D332ACB40BA1}.Release|x64.Build.0 = Release|Any CPU
{AAAEA32B-3CFA-40D4-A7A0-D332ACB40BA1}.Release|x86.ActiveCfg = Release|Any CPU
{AAAEA32B-3CFA-40D4-A7A0-D332ACB40BA1}.Release|x86.Build.0 = Release|Any CPU
{854E40D3-64A2-4864-AB79-AB9CC61DA1DE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{854E40D3-64A2-4864-AB79-AB9CC61DA1DE}.Debug|Any CPU.Build.0 = Debug|Any CPU
{854E40D3-64A2-4864-AB79-AB9CC61DA1DE}.Debug|x64.ActiveCfg = Debug|Any CPU
{854E40D3-64A2-4864-AB79-AB9CC61DA1DE}.Debug|x64.Build.0 = Debug|Any CPU
{854E40D3-64A2-4864-AB79-AB9CC61DA1DE}.Debug|x86.ActiveCfg = Debug|Any CPU
{854E40D3-64A2-4864-AB79-AB9CC61DA1DE}.Debug|x86.Build.0 = Debug|Any CPU
{854E40D3-64A2-4864-AB79-AB9CC61DA1DE}.Release|Any CPU.ActiveCfg = Release|Any CPU
{854E40D3-64A2-4864-AB79-AB9CC61DA1DE}.Release|Any CPU.Build.0 = Release|Any CPU
{854E40D3-64A2-4864-AB79-AB9CC61DA1DE}.Release|x64.ActiveCfg = Release|Any CPU
{854E40D3-64A2-4864-AB79-AB9CC61DA1DE}.Release|x64.Build.0 = Release|Any CPU
{854E40D3-64A2-4864-AB79-AB9CC61DA1DE}.Release|x86.ActiveCfg = Release|Any CPU
{854E40D3-64A2-4864-AB79-AB9CC61DA1DE}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
2 changes: 1 addition & 1 deletion src/AzureClient/AzureClient.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Azure.Quantum.Client" Version="0.12.20072301-beta" />
<PackageReference Include="Microsoft.Azure.Quantum.Client" Version="0.12.20073008-beta" />
<PackageReference Include="Microsoft.Rest.ClientRuntime" Version="2.3.21" />
<PackageReference Include="Microsoft.Rest.ClientRuntime.Azure" Version="3.3.19" />
<PackageReference Include="System.Reactive" Version="4.3.2" />
Expand Down
6 changes: 3 additions & 3 deletions src/Core/Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@
<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.12.20072301-beta" />
<PackageReference Include="Microsoft.Quantum.CsharpGeneration" Version="0.12.20072301-beta" />
<PackageReference Include="Microsoft.Quantum.Simulators" Version="0.12.20072301-beta" />
<PackageReference Include="Microsoft.Quantum.Compiler" Version="0.12.20073008-beta" />
<PackageReference Include="Microsoft.Quantum.CsharpGeneration" Version="0.12.20073008-beta" />
<PackageReference Include="Microsoft.Quantum.Simulators" Version="0.12.20073008-beta" />
<PackageReference Include="NuGet.Resolver" Version="5.1.0" />
<PackageReference Include="System.Runtime.Loader" Version="4.3.0" />
</ItemGroup>
Expand Down
71 changes: 62 additions & 9 deletions src/Core/ExecutionPathTracer/ExecutionPathTracer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ public class ExecutionPathTracer
{
private int currentDepth = 0;
private int renderDepth;
private ICallable? currCompositeOp = null;
private ExecutionPathTracer? compositeTracer = null;
private Operation? currentOperation = null;
private IDictionary<int, QubitRegister> qubitRegisters = new Dictionary<int, QubitRegister>();
private IDictionary<int, List<ClassicalRegister>> classicalRegisters = new Dictionary<int, List<ClassicalRegister>>();
Expand Down Expand Up @@ -55,16 +57,36 @@ public void OnOperationStartHandler(ICallable operation, IApplyData arguments)
{
this.currentDepth++;

// Parse operations at or above specified depth
if (this.currentDepth <= this.renderDepth)
// If `compositeTracer` is initialized, pass operations into it instead
if (this.compositeTracer != null)
{
var metadata = operation.GetRuntimeMetadata(arguments);
this.compositeTracer.OnOperationStartHandler(operation, arguments);
return;
}

// Only parse operations at or above (i.e. <= `renderDepth`) specified depth
if (this.currentDepth > this.renderDepth) return;

// Save parsed operation as a potential candidate for rendering.
// We only want to render the operation at the lowest depth, so we keep
// a running track of the lowest operation seen in the stack thus far.
this.currentOperation = this.MetadataToOperation(metadata);
var metadata = operation.GetRuntimeMetadata(arguments);

// If metadata is a composite operation (i.e. want to trace its components instead),
// we recursively create a tracer that traces its components instead
if (metadata != null && metadata.IsComposite)
{
this.compositeTracer = new ExecutionPathTracer(0);
// Attach our registers by reference to compositeTracer
this.compositeTracer.qubitRegisters = this.qubitRegisters;
this.compositeTracer.classicalRegisters = this.classicalRegisters;
this.currCompositeOp = operation;
// Set currentOperation to null so we don't render higher-depth operations unintentionally.
this.currentOperation = null;
return;
}

// Save parsed operation as a potential candidate for rendering.
// We only want to render the operation at the lowest depth, so we keep
// a running track of the lowest operation seen in the stack thus far.
this.currentOperation = this.MetadataToOperation(metadata);
}

/// <summary>
Expand All @@ -75,11 +97,30 @@ public void OnOperationStartHandler(ICallable operation, IApplyData arguments)
public void OnOperationEndHandler(ICallable operation, IApplyData result)
{
this.currentDepth--;
// Add parsed operation to list of operations, if not null

// If `compositeTracer` is not null, handle the incoming operation recursively.
if (this.compositeTracer != null)
{
// If the current operation is the composite operation we started with, append
// the operations traced out by the `compositeTracer` to the current list of
// operations and reset.
if (operation == this.currCompositeOp)
{
this.AddCompositeOperations();
this.currCompositeOp = null;
this.compositeTracer = null;
return;
}

// Pass operations down to it for handling
this.compositeTracer.OnOperationEndHandler(operation, result);
return;
}

// Add latest parsed operation to list of operations, if not null
if (this.currentOperation != null)
{
this.operations.Add(this.currentOperation);
// Reset current operation to null
this.currentOperation = null;
}
}
Expand Down Expand Up @@ -129,6 +170,18 @@ private ClassicalRegister GetClassicalRegister(Qubit controlQubit)
return this.classicalRegisters[qId][cId];
}

/// <summary>
/// Parse <see cref="Operations"/>s traced out by the <c>compositeTracer</c>.
/// </summary>
private void AddCompositeOperations()
{
if (this.compositeTracer == null)
throw new NullReferenceException("ERROR: compositeTracer not initialized.");

// The composite tracer has done its job and we retrieve the operations it traced
this.operations.AddRange(this.compositeTracer.operations);
}

/// <summary>
/// Parse <see cref="RuntimeMetadata"/> into its corresponding <see cref="Operation"/>.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.


//
// These are mock classes that resemble the data structures defined in the chemistry library
//
namespace Mock.Chemistry {
open Microsoft.Quantum.Intrinsic;
open Microsoft.Quantum.Canon;


/// # Summary
/// Format of data passed from C# to Q# to represent a term of the Hamiltonian.
/// The meaning of the data represented is determined by the algorithm that receives it.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<Project Sdk="Microsoft.Quantum.Sdk/0.12.20072031">
<Project Sdk="Microsoft.Quantum.Sdk/0.12.20073008-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.12.20072031" />
<PackageReference Include="Microsoft.Quantum.Simulators" Version="0.12.20073008-beta" />
</ItemGroup>
</Project>
19 changes: 19 additions & 0 deletions src/MockLibraries/Mock.Standard/Arrays.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

using Microsoft.Quantum.Simulation.Core;
using System;

namespace Mock.Standard
{
public partial class ForEach<__T__, __U__>
{
public override RuntimeMetadata GetRuntimeMetadata(IApplyData args)
{
var metadata = base.GetRuntimeMetadata(args);
if (metadata == null) throw new NullReferenceException($"Null RuntimeMetadata found for {this.ToString()}.");
metadata.IsComposite = true;
return metadata;
}
}
}
43 changes: 43 additions & 0 deletions src/MockLibraries/Mock.Standard/Arrays.qs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

//
// These are mock classes that resemble the data structures defined in the Microsoft.Quantum.Arrays library
//
namespace Mock.Standard {
open Microsoft.Quantum.Arrays;

/// # Summary
/// Given an array and an operation that is defined
/// for the elements of the array, returns a new array that consists
/// of the images of the original array under the operation.
///
/// # Remarks
/// The operation is defined for generic types, i.e., whenever we have
/// an array `'T[]` and an operation `action : 'T -> 'U` we can map the elements
/// of the array and produce a new array of type `'U[]`.
///
/// # Type Parameters
/// ## 'T
/// The type of `array` elements.
/// ## 'U
/// The result type of the `action` operation.
///
/// # Input
/// ## action
/// An operation from `'T` to `'U` that is applied to each element.
/// ## array
/// An array of elements over `'T`.
///
/// # Output
/// An array `'U[]` of elements that are mapped by the `action` operation.
operation ForEach<'T, 'U> (action : ('T => 'U), array : 'T[]) : 'U[] {
mutable resultArray = new 'U[Length(array)];

for (idxElement in IndexRange(array)) {
set resultArray w/= idxElement <- action(array[idxElement]);
}

return resultArray;
}
}
19 changes: 19 additions & 0 deletions src/MockLibraries/Mock.Standard/Canon.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

using Microsoft.Quantum.Simulation.Core;
using System;

namespace Mock.Standard
{
public partial class ApplyToEach<__T__>
{
public override RuntimeMetadata GetRuntimeMetadata(IApplyData args)
{
var metadata = base.GetRuntimeMetadata(args);
if (metadata == null) throw new NullReferenceException($"Null RuntimeMetadata found for {this.ToString()}.");
metadata.IsComposite = true;
return metadata;
}
}
}
43 changes: 43 additions & 0 deletions src/MockLibraries/Mock.Standard/Canon.qs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

//
// These are mock classes that resemble the data structures defined in the Microsoft.Quantum.Canon library
//
namespace Mock.Standard {
open Microsoft.Quantum.Arrays;

/// # Summary
/// Applies a single-qubit operation to each element in a register.
///
/// # Input
/// ## singleElementOperation
/// Operation to apply to each qubit.
/// ## register
/// Array of qubits on which to apply the given operation.
///
/// # Type Parameters
/// ## 'T
/// The target on which the operation acts.
///
/// # Remarks
/// ## Example
/// Prepare a three-qubit $\ket{+}$ state:
/// ```qsharp
/// using (register = Qubit[3]) {
/// ApplyToEach(H, register);
/// }
/// ```
///
/// # See Also
/// - Microsoft.Quantum.Canon.ApplyToEachC
/// - Microsoft.Quantum.Canon.ApplyToEachA
/// - Microsoft.Quantum.Canon.ApplyToEachCA
operation ApplyToEach<'T> (singleElementOperation : ('T => Unit), register : 'T[]) : Unit
{
for (idxQubit in IndexRange(register))
{
singleElementOperation(register[idxQubit]);
}
}
}
11 changes: 11 additions & 0 deletions src/MockLibraries/Mock.Standard/Mock.Standard.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<Project Sdk="Microsoft.Quantum.Sdk/0.12.20073008-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.12.20073008-beta" />
</ItemGroup>
</Project>
Loading