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: 2 additions & 0 deletions build/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ variables:

jobs:
- job: "iqsharp"
pool:
vmImage: 'ubuntu-latest'
steps:
- template: steps.yml
- task: ms.vss-governance-buildtask.governance-build-task-component-detection.ComponentGovernanceComponentDetection@0
Expand Down
4 changes: 3 additions & 1 deletion images/iqsharp-base/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,9 @@ RUN mkdir -p ${HOME}/.nuget/NuGet && \
cat ${HOME}/.nuget/NuGet/NuGet.Config
# Add Python and NuGet packages from the build context
ADD nugets/*.nupkg ${LOCAL_PACKAGES}/nugets/
ADD wheels/*.whl ${LOCAL_PACKAGES}/wheels/
# When adding wheels, use *-any.whl to make sure that platform-specific wheels
# are not incorrectly added to the Docker image.
ADD wheels/*-any.whl ${LOCAL_PACKAGES}/wheels/
# Give the notebook user ownership over the packages and config copied from
# the context.
RUN chown ${USER} -R ${LOCAL_PACKAGES}/ && \
Expand Down
8 changes: 4 additions & 4 deletions src/Core/Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@
<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.16.2105140472" />
<PackageReference Include="Microsoft.Quantum.CSharpGeneration" Version="0.16.2105140472" />
<PackageReference Include="Microsoft.Quantum.Simulators" Version="0.16.2105140472" />
<PackageReference Include="Microsoft.Quantum.QSharp.Core" Version="0.16.2105140472" />
<PackageReference Include="Microsoft.Quantum.Compiler" Version="0.17.210627752-alpha" />
<PackageReference Include="Microsoft.Quantum.CSharpGeneration" Version="0.17.210627752-alpha" />
<PackageReference Include="Microsoft.Quantum.Simulators" Version="0.17.210627752-alpha" />
<PackageReference Include="Microsoft.Quantum.QSharp.Core" Version="0.17.210627752-alpha" />
<PackageReference Include="NuGet.Resolver" Version="5.1.0" />
<PackageReference Include="System.Runtime.Loader" Version="4.3.0" />
</ItemGroup>
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.16.2105140472" />
<PackageReference Include="Microsoft.Quantum.Simulators" Version="0.17.210627752-alpha" />
</ItemGroup>

</Project>
21 changes: 21 additions & 0 deletions src/Jupyter/ConfigurationSource/IConfigurationSource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using Microsoft.Quantum.Experimental;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;

Expand Down Expand Up @@ -129,5 +130,25 @@ public T GetOptionOrDefault<T>(string optionName, T defaultValue) =>
/// </summary>
public TraceVisualizationStyle TraceVisualizationStyle =>
GetOptionOrDefault("trace.style", TraceVisualizationStyle.Default);

/// <summary>
/// Specifies the number of qubits that the experimental simulators
/// support for use in running Q# programs.
/// </summary>
public uint ExperimentalSimulatorCapacity =>
GetOptionOrDefault<uint>("experimental.simulators.nQubits", 3);

/// <summary>
/// Specifies the representation to use for the initial state
/// when simulating Q# programs with experimental simulators.
/// </summary>
public string ExperimentalSimulatorRepresentation =>
GetOptionOrDefault<string>("experimental.simulators.representation", "mixed");

/// <summary>
/// Specifies the format used in dumping stabilizer states.
/// <summary>
public StabilizerStateVisualizationStyle ExperimentalSimulatorStabilizerStateVisualizationStyle =>
GetOptionOrDefault<StabilizerStateVisualizationStyle>("experimental.simulators.stabilizerStateStyle", StabilizerStateVisualizationStyle.MatrixWithDestabilizers);
}
}
77 changes: 50 additions & 27 deletions src/Jupyter/Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Text.RegularExpressions;
using Microsoft.Jupyter.Core;
using Microsoft.Quantum.Simulation.Common;
using Microsoft.Quantum.Simulation.Core;
using Microsoft.Quantum.Simulation.Simulators;
using Newtonsoft.Json;
using NumSharp;

namespace Microsoft.Quantum.IQSharp.Jupyter
{
Expand Down Expand Up @@ -166,33 +168,6 @@ 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>
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, "");
}

/// <summary>
/// Retrieves and JSON-decodes the value for the given parameter name.
/// </summary>
Expand Down Expand Up @@ -275,5 +250,53 @@ public static T DecodeParameter<T>(this Dictionary<string, string> parameters, s
}
return JsonConvert.DeserializeObject(parameterValue, type) ?? defaultValue;
}

internal static string AsLaTeXMatrixOfComplex(this NDArray array) =>
// NB: Assumes 𝑛 × 𝑛 × 2 array, where the trailing index is
// [real, imag].
// TODO: Consolidate with logic at:
// https://github.com/microsoft/QuantumLibraries/blob/505fc27383c9914c3e1f60fb63d0acfe60b11956/Visualization/src/DisplayableUnitaryEncoders.cs#L43
string.Join(
"\\\\\n",
Enumerable
.Range(0, array.Shape[0])
.Select(
idxRow => string.Join(" & ",
Enumerable
.Range(0, array.Shape[1])
.Select(
idxCol => $"{array[idxRow, idxCol, 0]} + {array[idxRow, idxCol, 1]} i"
)
)
)
);

internal static IEnumerable<NDArray> IterateOverLeftmostIndex(this NDArray array)
{
foreach (var idx in Enumerable.Range(0, array.shape[0]))
{
yield return array[idx, Slice.Ellipsis];
}
}

internal static string AsTextMatrixOfComplex(this NDArray array, string rowSep = "\n") =>
// NB: Assumes 𝑛 × 𝑛 × 2 array, where the trailing index is
// [real, imag].
// TODO: Consolidate with logic at:
// https://github.com/microsoft/QuantumLibraries/blob/505fc27383c9914c3e1f60fb63d0acfe60b11956/Visualization/src/DisplayableUnitaryEncoders.cs#L43
"[" + rowSep + string.Join(
rowSep,
Enumerable
.Range(0, array.Shape[0])
.Select(
idxRow => "[" + string.Join(", ",
Enumerable
.Range(0, array.Shape[1])
.Select(
idxCol => $"{array[idxRow, idxCol, 0]} + {array[idxRow, idxCol, 1]} i"
)
) + "]"
)
) + rowSep + "]";
}
}
20 changes: 20 additions & 0 deletions src/Jupyter/NoiseModelSource/INoiseModelSource.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Copyright (c) Microsoft Corporation
// Licensed under the MIT License.

#nullable enable

using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;

namespace Microsoft.Quantum.Experimental
{

public interface INoiseModelSource
{
NoiseModel NoiseModel { get; set; }
}

}
24 changes: 24 additions & 0 deletions src/Jupyter/NoiseModelSource/NoiseModelSource.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Copyright (c) Microsoft Corporation
// Licensed under the MIT License.

#nullable enable

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;

namespace Microsoft.Quantum.Experimental
{

public class NoiseModelSource : INoiseModelSource
{
public NoiseModel NoiseModel { get; set; } =
NoiseModel.TryGetByName("ideal", out var ideal)
? ideal
: throw new Exception("Could not load ideal noise model.");
}

}
Loading