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 .github/CODEOWNERS
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Automatically tag in libraries maintainers on Q# API changes.
*.qs @microsoft/quantumlibraries
19 changes: 19 additions & 0 deletions Simulation.sln
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Library1", "src\Simulation\
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Library2", "src\Simulation\Simulators.Tests\TestProjects\Library2\Library2.csproj", "{A85277B3-4E07-4E15-8F0C-07CC855A3BCB}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Library with Spaces", "src\Simulation\Simulators.Tests\TestProjects\Library with Spaces\Library with Spaces.csproj", "{418E79F7-9FCF-4128-AA35-1334A685377D}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "UnitTests", "src\Simulation\Simulators.Tests\TestProjects\UnitTests\UnitTests.csproj", "{46278108-D247-4EFC-AC34-23D4A676F62F}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Azure", "Azure", "{37CDC768-16D4-4574-8553-07D99D0A72F7}"
Expand Down Expand Up @@ -355,6 +357,22 @@ Global
{46278108-D247-4EFC-AC34-23D4A676F62F}.RelWithDebInfo|Any CPU.Build.0 = Release|Any CPU
{46278108-D247-4EFC-AC34-23D4A676F62F}.RelWithDebInfo|x64.ActiveCfg = Release|Any CPU
{46278108-D247-4EFC-AC34-23D4A676F62F}.RelWithDebInfo|x64.Build.0 = Release|Any CPU
{418E79F7-9FCF-4128-AA35-1334A685377D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{418E79F7-9FCF-4128-AA35-1334A685377D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{418E79F7-9FCF-4128-AA35-1334A685377D}.Debug|x64.ActiveCfg = Debug|Any CPU
{418E79F7-9FCF-4128-AA35-1334A685377D}.Debug|x64.Build.0 = Debug|Any CPU
{418E79F7-9FCF-4128-AA35-1334A685377D}.MinSizeRel|Any CPU.ActiveCfg = Debug|Any CPU
{418E79F7-9FCF-4128-AA35-1334A685377D}.MinSizeRel|Any CPU.Build.0 = Debug|Any CPU
{418E79F7-9FCF-4128-AA35-1334A685377D}.MinSizeRel|x64.ActiveCfg = Debug|Any CPU
{418E79F7-9FCF-4128-AA35-1334A685377D}.MinSizeRel|x64.Build.0 = Debug|Any CPU
{418E79F7-9FCF-4128-AA35-1334A685377D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{418E79F7-9FCF-4128-AA35-1334A685377D}.Release|Any CPU.Build.0 = Release|Any CPU
{418E79F7-9FCF-4128-AA35-1334A685377D}.Release|x64.ActiveCfg = Release|Any CPU
{418E79F7-9FCF-4128-AA35-1334A685377D}.Release|x64.Build.0 = Release|Any CPU
{418E79F7-9FCF-4128-AA35-1334A685377D}.RelWithDebInfo|Any CPU.ActiveCfg = Debug|Any CPU
{418E79F7-9FCF-4128-AA35-1334A685377D}.RelWithDebInfo|Any CPU.Build.0 = Debug|Any CPU
{418E79F7-9FCF-4128-AA35-1334A685377D}.RelWithDebInfo|x64.ActiveCfg = Debug|Any CPU
{418E79F7-9FCF-4128-AA35-1334A685377D}.RelWithDebInfo|x64.Build.0 = Debug|Any CPU
{7F05FD87-A2FB-4915-A988-4EF92AB82179}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{7F05FD87-A2FB-4915-A988-4EF92AB82179}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7F05FD87-A2FB-4915-A988-4EF92AB82179}.Debug|x64.ActiveCfg = Debug|Any CPU
Expand Down Expand Up @@ -411,6 +429,7 @@ Global
{7256B986-6705-42FC-9F57-485D72D9DE51} = {09C842CB-930C-4C7D-AD5F-E30DE4A55820}
{A85277B3-4E07-4E15-8F0C-07CC855A3BCB} = {09C842CB-930C-4C7D-AD5F-E30DE4A55820}
{46278108-D247-4EFC-AC34-23D4A676F62F} = {09C842CB-930C-4C7D-AD5F-E30DE4A55820}
{418E79F7-9FCF-4128-AA35-1334A685377D} = {09C842CB-930C-4C7D-AD5F-E30DE4A55820}
{7F05FD87-A2FB-4915-A988-4EF92AB82179} = {37CDC768-16D4-4574-8553-07D99D0A72F7}
{4858E5E3-23FA-4928-B99A-54065875A2B9} = {37CDC768-16D4-4574-8553-07D99D0A72F7}
EndGlobalSection
Expand Down
2 changes: 1 addition & 1 deletion src/Azure/Azure.Quantum.Client/Storage/StorageHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public async Task UploadBlobAsync(
try
{
// Ensure container is created
await containerClient.CreateIfNotExistsAsync(PublicAccessType.Blob, cancellationToken: cancellationToken);
await containerClient.CreateIfNotExistsAsync(PublicAccessType.None, cancellationToken: cancellationToken);

// Upload blob
BlobClient blob = containerClient.GetBlobClient(blobName);
Expand Down
2 changes: 1 addition & 1 deletion src/Simulation/Common/IQuantumProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,7 @@ public interface IQuantumProcessor
void Assert(IQArray<Pauli> bases, IQArray<Qubit> qubits, Result result, string msg);

/// <summary>
/// Called when <a href="https://docs.microsoft.com/qsharp/api/qsharp/microsoft.quantum.intrinsic.assertprob">Microsoft.Quantum.Intrinsic.Assert</a> is called in Q#.
/// Called when <a href="https://docs.microsoft.com/qsharp/api/qsharp/microsoft.quantum.intrinsic.assertprob">Microsoft.Quantum.Intrinsic.AssertProb</a> is called in Q#.
/// </summary>
/// <remarks>
/// The names and the order of the parameters is similar to the corresponding Q# operation./
Expand Down
19 changes: 19 additions & 0 deletions src/Simulation/Common/SimulatorBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,14 @@ public abstract class SimulatorBase : AbstractFactory<AbstractCallable>, IOperat
public event Action<string>? OnLog = null;
public event Action<Exception, IEnumerable<StackFrame>>? OnException = null;


/// <summary>
/// An event fired whenever a simulator has additional diagnostic data
/// available for display (e.g. state information, assertion details,
/// execution traces).
/// </summary>
public event Action<object>? OnDisplayableDiagnostic = null;

public IQubitManager? QubitManager { get; }

public abstract string Name { get; }
Expand Down Expand Up @@ -182,6 +190,17 @@ public void EnableExceptionPrinting()
OnException += WriteStackTraceToLog;
}

/// <summary>
/// Sends diagnostic data to any listening display handlers.
/// Display handlers may discard any unrecognized data, such that
/// no guarantee is made as to any particular action taken as a result
/// of calling this method.
/// </summary>
protected void MaybeDisplayDiagnostic(object data)
{
OnDisplayableDiagnostic?.Invoke(data);
}


/// <summary>
/// Disables default handling of stack traces, such that stack
Expand Down
27 changes: 16 additions & 11 deletions src/Simulation/CsharpGeneration.Tests/SimulationCodeTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ open System
open System.Collections.Immutable
open System.IO
open System.Globalization
open System.Web

open Microsoft.CodeAnalysis
open Microsoft.CodeAnalysis.CSharp
Expand Down Expand Up @@ -218,9 +219,13 @@ namespace N1


let testOneFile fileName (expected:string) =
let expected = expected.Replace("%%%", (Uri(Path.GetFullPath fileName)).AbsolutePath)
let expected = expected.Replace("%%", (Path.GetFullPath fileName).Replace("\\", "\\\\"))
let tree = parse [(Path.Combine("Circuits","Intrinsic.qs")); fileName]
let fullPath = Path.GetFullPath fileName
let escapeCSharpString (s : string) = SymbolDisplay.FormatLiteral (s, false)
let expected =
expected
|> (fun s -> s.Replace("%%%", fullPath |> HttpUtility.JavaScriptStringEncode |> escapeCSharpString))
|> (fun s -> s.Replace("%%", fullPath |> escapeCSharpString))
let tree = parse [Path.Combine ("Circuits", "Intrinsic.qs"); fileName]
let actual =
CodegenContext.Create (tree, ImmutableDictionary.Empty)
|> generate (Path.GetFullPath fileName |> NonNullable<string>.New)
Expand Down Expand Up @@ -2307,7 +2312,7 @@ namespace N1
false |> testOne randomOperation

let testOneClass (_,op : QsCallable) executionTarget (expected : string) =
let expected = expected.Replace("%%%", op.SourceFile.Value)
let expected = expected.Replace("%%%", HttpUtility.JavaScriptStringEncode op.SourceFile.Value)
let assemblyConstants =
new System.Collections.Generic.KeyValuePair<_,_> (AssemblyConstants.ExecutionTarget, executionTarget)
|> Seq.singleton
Expand Down Expand Up @@ -3397,7 +3402,7 @@ using Microsoft.Quantum.Simulation.Core;
#line hidden
namespace Microsoft.Quantum.Tests.Inline
{
[SourceLocation("%%%", OperationFunctor.Body, 7, -1)]
[SourceLocation("%%", OperationFunctor.Body, 7, -1)]
public partial class HelloWorld : Operation<Int64, Int64>, ICallable
{
public HelloWorld(IOperationFactory m) : base(m)
Expand Down Expand Up @@ -3454,7 +3459,7 @@ using Microsoft.Quantum.Simulation.Core;
#line hidden
namespace Microsoft.Quantum.Tests.LineNumbers
{
[SourceLocation("%%%", OperationFunctor.Body, 9, -1)]
[SourceLocation("%%", OperationFunctor.Body, 9, -1)]
public partial class TestLineInBlocks : Operation<Int64, Result>, ICallable
{
public TestLineInBlocks(IOperationFactory m) : base(m)
Expand Down Expand Up @@ -3628,7 +3633,7 @@ namespace Microsoft.Quantum.Diagnostics
#line hidden
namespace Microsoft.Quantum.Tests.UnitTests
{
[SourceLocation("%%%", OperationFunctor.Body, 22, 26)]
[SourceLocation("%%", OperationFunctor.Body, 22, 26)]
public partial class UnitTest1 : Operation<QVoid, QVoid>, ICallable
{
public UnitTest1(IOperationFactory m) : base(m)
Expand All @@ -3651,7 +3656,7 @@ namespace Microsoft.Quantum.Tests.UnitTests
[Xunit.Trait("Target", "QuantumSimulator")]
[Xunit.Trait("Name", "UnitTest1")]
public void UnitTest1()
#line 22 "%%%"
#line 22 "%%"
{
var sim = new Microsoft.Quantum.Simulation.Simulators.QuantumSimulator();
if (sim is Microsoft.Quantum.Simulation.Common.SimulatorBase baseSim && this.Output != null)
Expand Down Expand Up @@ -3683,7 +3688,7 @@ namespace Microsoft.Quantum.Tests.UnitTests
[Xunit.Trait("Target", "ToffoliSimulator")]
[Xunit.Trait("Name", "UnitTest1")]
public void UnitTest1()
#line 22 "%%%"
#line 22 "%%"
{
var sim = new Microsoft.Quantum.Simulation.Simulators.ToffoliSimulator();
if (sim is Microsoft.Quantum.Simulation.Common.SimulatorBase baseSim && this.Output != null)
Expand Down Expand Up @@ -3721,7 +3726,7 @@ namespace Microsoft.Quantum.Tests.UnitTests
}
}

[SourceLocation("%%%", OperationFunctor.Body, 26, -1)]
[SourceLocation("%%", OperationFunctor.Body, 26, -1)]
public partial class UnitTest2 : Operation<QVoid, QVoid>, ICallable
{
public UnitTest2(IOperationFactory m) : base(m)
Expand All @@ -3744,7 +3749,7 @@ namespace Microsoft.Quantum.Tests.UnitTests
[Xunit.Trait("Target", "CustomSimulator")]
[Xunit.Trait("Name", "UnitTest2")]
public void UnitTest2()
#line 26 "%%%"
#line 26 "%%"
{
var sim = new SomeNamespace.CustomSimulator();
if (sim is Microsoft.Quantum.Simulation.Common.SimulatorBase baseSim && this.Output != null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

<ItemGroup>
<PackageReference Update="FSharp.Core" Version="4.7.0" />
<PackageReference Include="Microsoft.Quantum.Compiler" Version="0.11.2006.2118-beta" />
<PackageReference Include="Microsoft.Quantum.Compiler" Version="0.11.2006.2309-alpha" />
</ItemGroup>

<ItemGroup>
Expand Down
9 changes: 3 additions & 6 deletions src/Simulation/CsharpGeneration/SimulationCode.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1573,13 +1573,10 @@ module SimulationCode =
generator.Apply elements

// Returns only those namespaces and their elements that are defined for the given file.
let findLocalElements selector fileName syntaxTree =
let path =
match CompilationBuilder.CompilationUnitManager.TryGetUri fileName with
| true, uri -> uri.AbsolutePath |> NonNullable<string>.New
| false, _ -> NonNullable<string>.New ""
let findLocalElements selector (fileName : NonNullable<string>) syntaxTree =
syntaxTree
|> Seq.map (fun ns -> (ns.Name, (FilterBySourceFile.Apply (ns, path)).Elements |> Seq.choose selector |> Seq.toList))
|> Seq.map (fun ns ->
(ns.Name, (FilterBySourceFile.Apply (ns, fileName)).Elements |> Seq.choose selector |> Seq.toList))
|> Seq.sortBy fst
|> Seq.filter (fun (_,elements) -> not elements.IsEmpty)
|> Seq.toList
Expand Down
18 changes: 9 additions & 9 deletions src/Simulation/EntryPointDriver.Tests/Tests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -474,15 +474,15 @@ let ``Shadows --shots`` () =

// The expected output from the resources estimator.
let private resourceSummary =
"Metric Sum
CNOT 0
QubitClifford 1
R 0
Measure 1
T 0
Depth 0
Width 1
BorrowedWidth 0"
"Metric Sum Max
CNOT 0 0
QubitClifford 1 1
R 0 0
Measure 1 1
T 0 0
Depth 0 0
Width 1 1
BorrowedWidth 0 0"

[<Fact>]
let ``Supports QuantumSimulator`` () =
Expand Down
25 changes: 25 additions & 0 deletions src/Simulation/QCTraceSimulator.Tests/Circuits/RandomTests.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.Simulation.QCTraceSimulatorRuntime.Tests {
open Microsoft.Quantum.Intrinsic;
open Microsoft.Quantum.Diagnostics;

internal function Fact(condition : Bool, message : String) : Unit {
if (not condition) {
fail message;
}
}

@Test("ResourcesEstimator")
/// # Summary
/// Checks for regression against microsoft/qsharp-runtime#256.
operation CheckRandomInCorrectRange() : Unit {
for (idxTrial in 0..99) {
let sample = Random([1.0, 2.0, 2.0]);

Fact(0 <= sample and sample <= 2, $"sample was {sample}, not in range [0, 2]");
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.Quantum.Sdk/0.11.2006.2118-beta">
<Project Sdk="Microsoft.Quantum.Sdk/0.11.2006.2309-alpha">

<Import Project="..\Common\AssemblyCommon.props" />
<Import Project="..\Common\Simulators.Dev.props" />
Expand Down
33 changes: 33 additions & 0 deletions src/Simulation/QsharpCore/Arrays/Enumeration.qs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

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

/// # Summary
/// Given an array, returns a range over the indices of that array, suitable
/// for use in a for loop.
///
/// # Type Parameters
/// ## 'TElement
/// The type of elements of the array.
///
/// # Input
/// ## array
/// An array for which a range of indices should be returned.
///
/// # Output
/// A range over all indices of the array.
///
/// # Example
/// The following `for` loops are equivalent:
/// ```Q#
/// for (idx in IndexRange(array)) { ... }
/// for (idx in IndexRange(array)) { ... }
/// ```
function IndexRange<'TElement>(array : 'TElement[]) : Range {
return 0..(Length(array) - 1);
}

}
45 changes: 45 additions & 0 deletions src/Simulation/QsharpCore/Canon/NoOp.qs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

namespace Microsoft.Quantum.Canon {

/// # Summary
/// Performs the identity operation (no-op) on an argument.
///
/// # Description
/// This operation takes a value of any type and does nothing to it.
/// This can be useful whenever an input of an operation type is expected,
/// but no action should be taken.
/// For instance, if a particular error correction syndrome indicates that
/// no error has occurred, `NoOp<Qubit[]>` may be the correct recovery
/// procedure.
/// Similarly, if an operation expects a state preparation procedure as
/// input, `NoOp<Qubit[]>` can be used to prepare the state
/// $\ket{0 \cdots 0}$.
///
/// # Input
/// ## input
/// A value to be ignored.
///
/// # Remarks
/// In almost all cases, the type parameter for `NoOp` needs to be specified
/// explicitly. For instance, `NoOp<Qubit>` is identical to
/// <xref:microsoft.quantum.intrinsic.i>.
///
/// # See Also
/// - Microsoft.Quantum.Intrinsic.I
operation NoOp<'T>(input : 'T) : Unit is Adj + Ctl {
}


/// # Summary
/// Ignores the output of an operation or function.
///
/// # Input
/// ## value
/// A value to be ignored.
function Ignore<'T> (value : 'T) : Unit {
return ();
}

}
Loading