From 6562491aea825121872a997faf475d160c0164e8 Mon Sep 17 00:00:00 2001 From: Scott Carda Date: Fri, 2 Oct 2020 11:38:12 -0700 Subject: [PATCH 1/7] Generate the C# for used libraries. --- src/Simulation/CsharpGeneration/Context.fs | 78 +++++++++---------- .../CsharpGeneration/RewriteStep.fs | 14 ++-- .../CsharpGeneration/SimulationCode.fs | 45 ----------- 3 files changed, 40 insertions(+), 97 deletions(-) diff --git a/src/Simulation/CsharpGeneration/Context.fs b/src/Simulation/CsharpGeneration/Context.fs index c692c705e9a..a1aa2a9d706 100644 --- a/src/Simulation/CsharpGeneration/Context.fs +++ b/src/Simulation/CsharpGeneration/Context.fs @@ -14,48 +14,48 @@ open Microsoft.Quantum.QsCompiler.SyntaxTree open Microsoft.Quantum.QsCompiler.Transformations.Core -module internal DeclarationLocations = - - type TransformationState() = +module internal DeclarationLocations = + + type TransformationState() = member val internal CurrentSource = null with get, set member val internal DeclarationLocations = new List * Position>() - type NamespaceTransformation(parent : SyntaxTreeTransformation) = + type NamespaceTransformation(parent : SyntaxTreeTransformation) = inherit NamespaceTransformation(parent) - override this.OnSourceFile file = + override this.OnSourceFile file = this.SharedState.CurrentSource <- file.Value file - override this.OnLocation sourceLocation = - match sourceLocation with - | Value (loc : QsLocation) when this.SharedState.CurrentSource <> null -> - this.SharedState.DeclarationLocations.Add (NonNullable.New this.SharedState.CurrentSource, loc.Offset) + override this.OnLocation sourceLocation = + match sourceLocation with + | Value (loc : QsLocation) when this.SharedState.CurrentSource <> null -> + this.SharedState.DeclarationLocations.Add (NonNullable.New this.SharedState.CurrentSource, loc.Offset) | _ -> () sourceLocation - type internal SyntaxTreeTransformation private(_private_) = + type internal SyntaxTreeTransformation private(_private_) = inherit SyntaxTreeTransformation(new TransformationState(), TransformationOptions.NoRebuild) - new () as this = + new () as this = new SyntaxTreeTransformation("_private_") then this.Namespaces <- new NamespaceTransformation(this) this.Statements <- new StatementTransformation(this, TransformationOptions.Disabled) this.Expressions <- new ExpressionTransformation(this, TransformationOptions.Disabled) this.Types <- TypeTransformation(this, TransformationOptions.Disabled) - member this.DeclarationLocations = + member this.DeclarationLocations = this.SharedState.DeclarationLocations.ToLookup (fst, snd) - let Accumulate (syntaxTree : IEnumerable) = + let Accumulate (syntaxTree : IEnumerable) = let walker = new SyntaxTreeTransformation() for ns in syntaxTree do walker.Namespaces.OnNamespace ns |> ignore walker.DeclarationLocations -type CodegenContext = { +type CodegenContext = { assemblyConstants : IDictionary allQsElements : IEnumerable allUdts : ImmutableDictionary @@ -68,66 +68,58 @@ type CodegenContext = { entryPoints : IEnumerable } with - static member public Create (syntaxTree, assemblyConstants) = + static member public Create (syntaxTree, assemblyConstants) = let udts = GlobalTypeResolutions syntaxTree let callables = GlobalCallableResolutions syntaxTree let positionInfos = DeclarationLocations.Accumulate syntaxTree - let callablesByName = + let callablesByName = let result = new Dictionary,(NonNullable*QsCallable) list>() syntaxTree |> Seq.collect (fun ns -> ns.Elements |> Seq.choose (function | QsCallable c -> Some (ns, c) | _ -> None)) - |> Seq.iter (fun (ns:QsNamespace,c:QsCallable) -> - if result.ContainsKey c.FullName.Name then result.[c.FullName.Name] <- (ns.Name, c) :: (result.[c.FullName.Name]) + |> Seq.iter (fun (ns:QsNamespace,c:QsCallable) -> + if result.ContainsKey c.FullName.Name then result.[c.FullName.Name] <- (ns.Name, c) :: (result.[c.FullName.Name]) else result.[c.FullName.Name] <- [ns.Name, c]) result.ToImmutableDictionary() - - { + + { assemblyConstants = assemblyConstants; - allQsElements = syntaxTree; - byName = callablesByName; - allUdts = udts; - allCallables = callables; + allQsElements = syntaxTree; + byName = callablesByName; + allUdts = udts; + allCallables = callables; declarationPositions = positionInfos.ToImmutableDictionary((fun g -> g.Key), (fun g -> g.ToImmutableSortedSet())) - current = None; + current = None; fileName = None; signature = None; entryPoints = ImmutableArray.Empty } - static member public Create (compilation : QsCompilation, assemblyConstants) = + static member public Create (compilation : QsCompilation, assemblyConstants) = {CodegenContext.Create(compilation.Namespaces, assemblyConstants) with entryPoints = compilation.EntryPoints} - static member public Create (compilation : QsCompilation) = + static member public Create (compilation : QsCompilation) = CodegenContext.Create(compilation, ImmutableDictionary.Empty) - static member public Create (syntaxTree : ImmutableArray) = + static member public Create (syntaxTree : ImmutableArray) = CodegenContext.Create(syntaxTree, ImmutableDictionary.Empty) - member public this.ProcessorArchitecture = - match this.assemblyConstants.TryGetValue AssemblyConstants.ProcessorArchitecture with + member public this.ProcessorArchitecture = + match this.assemblyConstants.TryGetValue AssemblyConstants.ProcessorArchitecture with | true, name -> name | false, _ -> null - member public this.ExecutionTarget = - match this.assemblyConstants.TryGetValue AssemblyConstants.ExecutionTarget with + member public this.ExecutionTarget = + match this.assemblyConstants.TryGetValue AssemblyConstants.ExecutionTarget with | true, name -> name | false, _ -> null - member public this.AssemblyName = + member public this.AssemblyName = match this.assemblyConstants.TryGetValue AssemblyConstants.AssemblyName with | true, name -> name | false, _ -> null - member public this.ExposeReferencesViaTestNames = - match this.assemblyConstants.TryGetValue AssemblyConstants.ExposeReferencesViaTestNames with + member public this.ExposeReferencesViaTestNames = + match this.assemblyConstants.TryGetValue AssemblyConstants.ExposeReferencesViaTestNames with | true, propVal -> propVal = "true" | false, _ -> false - - member internal this.GenerateCodeForSource (fileName : NonNullable) = - let targetsQuantumProcessor = - match this.assemblyConstants.TryGetValue AssemblyConstants.ProcessorArchitecture with - | true, target -> target = AssemblyConstants.HoneywellProcessor || target = AssemblyConstants.IonQProcessor || target = AssemblyConstants.QCIProcessor - | _ -> false - not (fileName.Value.EndsWith ".dll") || targetsQuantumProcessor - diff --git a/src/Simulation/CsharpGeneration/RewriteStep.fs b/src/Simulation/CsharpGeneration/RewriteStep.fs index 4fc53dd609c..baf141e35a5 100644 --- a/src/Simulation/CsharpGeneration/RewriteStep.fs +++ b/src/Simulation/CsharpGeneration/RewriteStep.fs @@ -9,7 +9,6 @@ open System.IO open Microsoft.CodeAnalysis open Microsoft.Quantum.QsCompiler open Microsoft.Quantum.QsCompiler.CsharpGeneration -open Microsoft.Quantum.QsCompiler.DataTypes open Microsoft.Quantum.QsCompiler.Diagnostics open Microsoft.Quantum.QsCompiler.ReservedKeywords open Microsoft.Quantum.QsCompiler.SyntaxTree @@ -27,7 +26,7 @@ type Emitter() = member this.Priority = -1 // doesn't matter because this rewrite step is the only one in the dll member this.AssemblyConstants = upcast _AssemblyConstants member this.GeneratedDiagnostics = upcast _Diagnostics - + member this.ImplementsPreconditionVerification = true member this.ImplementsPostconditionVerification = false member this.ImplementsTransformation = true @@ -43,22 +42,19 @@ type Emitter() = true member this.PostconditionVerification _ = NotImplementedException() |> raise - - member this.Transformation (compilation, transformed) = + + member this.Transformation (compilation, transformed) = let step = this :> IRewriteStep let dir = step.AssemblyConstants.TryGetValue AssemblyConstants.OutputPath |> function | true, outputFolder when outputFolder <> null -> Path.Combine(outputFolder, "src") | _ -> step.Name let context = CodegenContext.Create (compilation, step.AssemblyConstants) - let allSources = GetSourceFiles.Apply compilation.Namespaces + let allSources = GetSourceFiles.Apply compilation.Namespaces - for source in allSources |> Seq.filter context.GenerateCodeForSource do + for source in allSources do let content = SimulationCode.generate source context CompilationLoader.GeneratedFile(source, dir, ".g.cs", content) |> ignore - for source in allSources |> Seq.filter (not << context.GenerateCodeForSource) do - let content = SimulationCode.loadedViaTestNames source context - if content <> null then CompilationLoader.GeneratedFile(source, dir, ".dll.g.cs", content) |> ignore if not compilation.EntryPoints.IsEmpty then let callable = context.allCallables.[Seq.exactlyOne compilation.EntryPoints] diff --git a/src/Simulation/CsharpGeneration/SimulationCode.fs b/src/Simulation/CsharpGeneration/SimulationCode.fs index d1dafb7b4bf..d77de8b9c22 100644 --- a/src/Simulation/CsharpGeneration/SimulationCode.fs +++ b/src/Simulation/CsharpGeneration/SimulationCode.fs @@ -1636,51 +1636,6 @@ module SimulationCode = let msg = l.LoaderExceptions |> Array.fold (fun msg e -> msg + ";" + e.Message) "" failwith msg - /// Builds the SyntaxTree for callables and types loaded via test names, - /// formats it and returns it as a string. - /// Returns null if no elements have been loaded via test name. - let loadedViaTestNames (dllName : NonNullable) (globalContext : CodegenContext) = - let isLoadedViaTestName nsElement = - if globalContext.ExposeReferencesViaTestNames then - let asOption = function | Value _ -> Some nsElement | _ -> None - match nsElement with - | QsCallable c -> SymbolResolution.TryGetTestName c.Attributes - | QsCustomType t -> SymbolResolution.TryGetTestName t.Attributes - |> asOption - else None - let context = {globalContext with fileName = Some dllName.Value} - let localElements = findLocalElements isLoadedViaTestName dllName context.allQsElements - - let getNameCollisions (_, elems : QsNamespaceElement list) = - let tryGetCollision = function - | QsCustomType t -> - match SymbolResolution.TryGetOriginalName t.Attributes with - | Value origName -> - match context.allUdts.TryGetValue origName with - | true, collision -> - if context.GenerateCodeForSource collision.SourceFile then None - else Some (origName.Namespace, QsCustomType collision) - | _ -> None - | Null -> None - | QsCallable c -> - match SymbolResolution.TryGetOriginalName c.Attributes with - | Value origName -> - match context.allCallables.TryGetValue origName with - | true, collision -> - if context.GenerateCodeForSource collision.SourceFile then None - else Some (origName.Namespace, QsCallable collision) - | _ -> None - | Null -> None - elems |> List.choose tryGetCollision - - if localElements.Any() then - let collisions = - (localElements |> Seq.collect getNameCollisions).ToLookup(fst, snd) - |> Seq.map (fun g -> g.Key, g |> Seq.toList) |> Seq.toList - buildSyntaxTree (localElements @ collisions) context - |> formatSyntaxTree - else null - /// Main entry method for a CodeGenerator. /// Builds the SyntaxTree for the given Q# syntax tree, formats it and returns it as a string. /// Omits code generation for intrinsic callables in references. From 320a29dbb738f1fb73df5c6d6794889db9d143f6 Mon Sep 17 00:00:00 2001 From: Scott Carda Date: Mon, 5 Oct 2020 11:43:47 -0700 Subject: [PATCH 2/7] Libraries don't regenerate libraries --- src/Simulation/CsharpGeneration/Context.fs | 78 ++++++++++--------- .../CsharpGeneration/RewriteStep.fs | 28 +++++-- .../CsharpGeneration/SimulationCode.fs | 45 +++++++++++ 3 files changed, 109 insertions(+), 42 deletions(-) diff --git a/src/Simulation/CsharpGeneration/Context.fs b/src/Simulation/CsharpGeneration/Context.fs index a1aa2a9d706..c692c705e9a 100644 --- a/src/Simulation/CsharpGeneration/Context.fs +++ b/src/Simulation/CsharpGeneration/Context.fs @@ -14,48 +14,48 @@ open Microsoft.Quantum.QsCompiler.SyntaxTree open Microsoft.Quantum.QsCompiler.Transformations.Core -module internal DeclarationLocations = - - type TransformationState() = +module internal DeclarationLocations = + + type TransformationState() = member val internal CurrentSource = null with get, set member val internal DeclarationLocations = new List * Position>() - type NamespaceTransformation(parent : SyntaxTreeTransformation) = + type NamespaceTransformation(parent : SyntaxTreeTransformation) = inherit NamespaceTransformation(parent) - override this.OnSourceFile file = + override this.OnSourceFile file = this.SharedState.CurrentSource <- file.Value file - override this.OnLocation sourceLocation = - match sourceLocation with - | Value (loc : QsLocation) when this.SharedState.CurrentSource <> null -> - this.SharedState.DeclarationLocations.Add (NonNullable.New this.SharedState.CurrentSource, loc.Offset) + override this.OnLocation sourceLocation = + match sourceLocation with + | Value (loc : QsLocation) when this.SharedState.CurrentSource <> null -> + this.SharedState.DeclarationLocations.Add (NonNullable.New this.SharedState.CurrentSource, loc.Offset) | _ -> () sourceLocation - type internal SyntaxTreeTransformation private(_private_) = + type internal SyntaxTreeTransformation private(_private_) = inherit SyntaxTreeTransformation(new TransformationState(), TransformationOptions.NoRebuild) - new () as this = + new () as this = new SyntaxTreeTransformation("_private_") then this.Namespaces <- new NamespaceTransformation(this) this.Statements <- new StatementTransformation(this, TransformationOptions.Disabled) this.Expressions <- new ExpressionTransformation(this, TransformationOptions.Disabled) this.Types <- TypeTransformation(this, TransformationOptions.Disabled) - member this.DeclarationLocations = + member this.DeclarationLocations = this.SharedState.DeclarationLocations.ToLookup (fst, snd) - let Accumulate (syntaxTree : IEnumerable) = + let Accumulate (syntaxTree : IEnumerable) = let walker = new SyntaxTreeTransformation() for ns in syntaxTree do walker.Namespaces.OnNamespace ns |> ignore walker.DeclarationLocations -type CodegenContext = { +type CodegenContext = { assemblyConstants : IDictionary allQsElements : IEnumerable allUdts : ImmutableDictionary @@ -68,58 +68,66 @@ type CodegenContext = { entryPoints : IEnumerable } with - static member public Create (syntaxTree, assemblyConstants) = + static member public Create (syntaxTree, assemblyConstants) = let udts = GlobalTypeResolutions syntaxTree let callables = GlobalCallableResolutions syntaxTree let positionInfos = DeclarationLocations.Accumulate syntaxTree - let callablesByName = + let callablesByName = let result = new Dictionary,(NonNullable*QsCallable) list>() syntaxTree |> Seq.collect (fun ns -> ns.Elements |> Seq.choose (function | QsCallable c -> Some (ns, c) | _ -> None)) - |> Seq.iter (fun (ns:QsNamespace,c:QsCallable) -> - if result.ContainsKey c.FullName.Name then result.[c.FullName.Name] <- (ns.Name, c) :: (result.[c.FullName.Name]) + |> Seq.iter (fun (ns:QsNamespace,c:QsCallable) -> + if result.ContainsKey c.FullName.Name then result.[c.FullName.Name] <- (ns.Name, c) :: (result.[c.FullName.Name]) else result.[c.FullName.Name] <- [ns.Name, c]) result.ToImmutableDictionary() - - { + + { assemblyConstants = assemblyConstants; - allQsElements = syntaxTree; - byName = callablesByName; - allUdts = udts; - allCallables = callables; + allQsElements = syntaxTree; + byName = callablesByName; + allUdts = udts; + allCallables = callables; declarationPositions = positionInfos.ToImmutableDictionary((fun g -> g.Key), (fun g -> g.ToImmutableSortedSet())) - current = None; + current = None; fileName = None; signature = None; entryPoints = ImmutableArray.Empty } - static member public Create (compilation : QsCompilation, assemblyConstants) = + static member public Create (compilation : QsCompilation, assemblyConstants) = {CodegenContext.Create(compilation.Namespaces, assemblyConstants) with entryPoints = compilation.EntryPoints} - static member public Create (compilation : QsCompilation) = + static member public Create (compilation : QsCompilation) = CodegenContext.Create(compilation, ImmutableDictionary.Empty) - static member public Create (syntaxTree : ImmutableArray) = + static member public Create (syntaxTree : ImmutableArray) = CodegenContext.Create(syntaxTree, ImmutableDictionary.Empty) - member public this.ProcessorArchitecture = - match this.assemblyConstants.TryGetValue AssemblyConstants.ProcessorArchitecture with + member public this.ProcessorArchitecture = + match this.assemblyConstants.TryGetValue AssemblyConstants.ProcessorArchitecture with | true, name -> name | false, _ -> null - member public this.ExecutionTarget = - match this.assemblyConstants.TryGetValue AssemblyConstants.ExecutionTarget with + member public this.ExecutionTarget = + match this.assemblyConstants.TryGetValue AssemblyConstants.ExecutionTarget with | true, name -> name | false, _ -> null - member public this.AssemblyName = + member public this.AssemblyName = match this.assemblyConstants.TryGetValue AssemblyConstants.AssemblyName with | true, name -> name | false, _ -> null - member public this.ExposeReferencesViaTestNames = - match this.assemblyConstants.TryGetValue AssemblyConstants.ExposeReferencesViaTestNames with + member public this.ExposeReferencesViaTestNames = + match this.assemblyConstants.TryGetValue AssemblyConstants.ExposeReferencesViaTestNames with | true, propVal -> propVal = "true" | false, _ -> false + + member internal this.GenerateCodeForSource (fileName : NonNullable) = + let targetsQuantumProcessor = + match this.assemblyConstants.TryGetValue AssemblyConstants.ProcessorArchitecture with + | true, target -> target = AssemblyConstants.HoneywellProcessor || target = AssemblyConstants.IonQProcessor || target = AssemblyConstants.QCIProcessor + | _ -> false + not (fileName.Value.EndsWith ".dll") || targetsQuantumProcessor + diff --git a/src/Simulation/CsharpGeneration/RewriteStep.fs b/src/Simulation/CsharpGeneration/RewriteStep.fs index baf141e35a5..43c6db50fba 100644 --- a/src/Simulation/CsharpGeneration/RewriteStep.fs +++ b/src/Simulation/CsharpGeneration/RewriteStep.fs @@ -9,6 +9,7 @@ open System.IO open Microsoft.CodeAnalysis open Microsoft.Quantum.QsCompiler open Microsoft.Quantum.QsCompiler.CsharpGeneration +open Microsoft.Quantum.QsCompiler.DataTypes open Microsoft.Quantum.QsCompiler.Diagnostics open Microsoft.Quantum.QsCompiler.ReservedKeywords open Microsoft.Quantum.QsCompiler.SyntaxTree @@ -26,7 +27,7 @@ type Emitter() = member this.Priority = -1 // doesn't matter because this rewrite step is the only one in the dll member this.AssemblyConstants = upcast _AssemblyConstants member this.GeneratedDiagnostics = upcast _Diagnostics - + member this.ImplementsPreconditionVerification = true member this.ImplementsPostconditionVerification = false member this.ImplementsTransformation = true @@ -42,19 +43,32 @@ type Emitter() = true member this.PostconditionVerification _ = NotImplementedException() |> raise - - member this.Transformation (compilation, transformed) = + + member this.Transformation (compilation, transformed) = let step = this :> IRewriteStep let dir = step.AssemblyConstants.TryGetValue AssemblyConstants.OutputPath |> function | true, outputFolder when outputFolder <> null -> Path.Combine(outputFolder, "src") | _ -> step.Name let context = CodegenContext.Create (compilation, step.AssemblyConstants) - let allSources = GetSourceFiles.Apply compilation.Namespaces + let allSources = GetSourceFiles.Apply compilation.Namespaces - for source in allSources do - let content = SimulationCode.generate source context - CompilationLoader.GeneratedFile(source, dir, ".g.cs", content) |> ignore + let isExe = + match context.assemblyConstants.TryGetValue AssemblyConstants.QsharpOutputType with + | true, outputType -> outputType = AssemblyConstants.QsharpExe + | _ -> false + + if isExe then + for source in allSources do + let content = SimulationCode.generate source context + CompilationLoader.GeneratedFile(source, dir, ".g.cs", content) |> ignore + else + for source in allSources |> Seq.filter context.GenerateCodeForSource do + let content = SimulationCode.generate source context + CompilationLoader.GeneratedFile(source, dir, ".g.cs", content) |> ignore + for source in allSources |> Seq.filter (not << context.GenerateCodeForSource) do + let content = SimulationCode.loadedViaTestNames source context + if content <> null then CompilationLoader.GeneratedFile(source, dir, ".dll.g.cs", content) |> ignore if not compilation.EntryPoints.IsEmpty then let callable = context.allCallables.[Seq.exactlyOne compilation.EntryPoints] diff --git a/src/Simulation/CsharpGeneration/SimulationCode.fs b/src/Simulation/CsharpGeneration/SimulationCode.fs index d77de8b9c22..d1dafb7b4bf 100644 --- a/src/Simulation/CsharpGeneration/SimulationCode.fs +++ b/src/Simulation/CsharpGeneration/SimulationCode.fs @@ -1636,6 +1636,51 @@ module SimulationCode = let msg = l.LoaderExceptions |> Array.fold (fun msg e -> msg + ";" + e.Message) "" failwith msg + /// Builds the SyntaxTree for callables and types loaded via test names, + /// formats it and returns it as a string. + /// Returns null if no elements have been loaded via test name. + let loadedViaTestNames (dllName : NonNullable) (globalContext : CodegenContext) = + let isLoadedViaTestName nsElement = + if globalContext.ExposeReferencesViaTestNames then + let asOption = function | Value _ -> Some nsElement | _ -> None + match nsElement with + | QsCallable c -> SymbolResolution.TryGetTestName c.Attributes + | QsCustomType t -> SymbolResolution.TryGetTestName t.Attributes + |> asOption + else None + let context = {globalContext with fileName = Some dllName.Value} + let localElements = findLocalElements isLoadedViaTestName dllName context.allQsElements + + let getNameCollisions (_, elems : QsNamespaceElement list) = + let tryGetCollision = function + | QsCustomType t -> + match SymbolResolution.TryGetOriginalName t.Attributes with + | Value origName -> + match context.allUdts.TryGetValue origName with + | true, collision -> + if context.GenerateCodeForSource collision.SourceFile then None + else Some (origName.Namespace, QsCustomType collision) + | _ -> None + | Null -> None + | QsCallable c -> + match SymbolResolution.TryGetOriginalName c.Attributes with + | Value origName -> + match context.allCallables.TryGetValue origName with + | true, collision -> + if context.GenerateCodeForSource collision.SourceFile then None + else Some (origName.Namespace, QsCallable collision) + | _ -> None + | Null -> None + elems |> List.choose tryGetCollision + + if localElements.Any() then + let collisions = + (localElements |> Seq.collect getNameCollisions).ToLookup(fst, snd) + |> Seq.map (fun g -> g.Key, g |> Seq.toList) |> Seq.toList + buildSyntaxTree (localElements @ collisions) context + |> formatSyntaxTree + else null + /// Main entry method for a CodeGenerator. /// Builds the SyntaxTree for the given Q# syntax tree, formats it and returns it as a string. /// Omits code generation for intrinsic callables in references. From 0c33c2ccc247c22b3b3aa7e7883dca9020733204 Mon Sep 17 00:00:00 2001 From: Scott Carda Date: Thu, 17 Dec 2020 10:56:50 -0800 Subject: [PATCH 3/7] updated qdk version number to 0.14.201219763-alpha --- .../CsharpGeneration/Microsoft.Quantum.CsharpGeneration.fsproj | 2 +- ....Microsoft.Quantum.Simulation.QCTraceSimulatorRuntime.csproj | 2 +- src/Simulation/QsharpCore/Microsoft.Quantum.QSharp.Core.csproj | 2 +- .../TestProjects/HoneywellExe/HoneywellExe.csproj | 2 +- .../TestProjects/IntrinsicTests/IntrinsicTests.csproj | 2 +- .../Simulators.Tests/TestProjects/IonQExe/IonQExe.csproj | 2 +- .../TestProjects/Library with Spaces/Library with Spaces.csproj | 2 +- .../Simulators.Tests/TestProjects/Library1/Library1.csproj | 2 +- .../Simulators.Tests/TestProjects/Library2/Library2.csproj | 2 +- .../Simulators.Tests/TestProjects/QCIExe/QCIExe.csproj | 2 +- .../Simulators.Tests/TestProjects/QsharpExe/QsharpExe.csproj | 2 +- .../TestProjects/TargetedExe/TargetedExe.csproj | 2 +- .../Simulators.Tests/TestProjects/UnitTests/UnitTests.csproj | 2 +- .../Simulators.Tests/Tests.Microsoft.Quantum.Simulators.csproj | 2 +- src/Simulation/Simulators/Microsoft.Quantum.Simulators.csproj | 2 +- 15 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/Simulation/CsharpGeneration/Microsoft.Quantum.CsharpGeneration.fsproj b/src/Simulation/CsharpGeneration/Microsoft.Quantum.CsharpGeneration.fsproj index be39b8edeab..3f7c6965edc 100644 --- a/src/Simulation/CsharpGeneration/Microsoft.Quantum.CsharpGeneration.fsproj +++ b/src/Simulation/CsharpGeneration/Microsoft.Quantum.CsharpGeneration.fsproj @@ -22,7 +22,7 @@ - + diff --git a/src/Simulation/QCTraceSimulator.Tests/Tests.Microsoft.Quantum.Simulation.QCTraceSimulatorRuntime.csproj b/src/Simulation/QCTraceSimulator.Tests/Tests.Microsoft.Quantum.Simulation.QCTraceSimulatorRuntime.csproj index 4be621628ae..2f78c26f81d 100644 --- a/src/Simulation/QCTraceSimulator.Tests/Tests.Microsoft.Quantum.Simulation.QCTraceSimulatorRuntime.csproj +++ b/src/Simulation/QCTraceSimulator.Tests/Tests.Microsoft.Quantum.Simulation.QCTraceSimulatorRuntime.csproj @@ -1,4 +1,4 @@ - + diff --git a/src/Simulation/QsharpCore/Microsoft.Quantum.QSharp.Core.csproj b/src/Simulation/QsharpCore/Microsoft.Quantum.QSharp.Core.csproj index aa56561c174..97da7c951df 100644 --- a/src/Simulation/QsharpCore/Microsoft.Quantum.QSharp.Core.csproj +++ b/src/Simulation/QsharpCore/Microsoft.Quantum.QSharp.Core.csproj @@ -1,4 +1,4 @@ - + diff --git a/src/Simulation/Simulators.Tests/TestProjects/HoneywellExe/HoneywellExe.csproj b/src/Simulation/Simulators.Tests/TestProjects/HoneywellExe/HoneywellExe.csproj index 12fd65d55b0..e10a5f641a0 100644 --- a/src/Simulation/Simulators.Tests/TestProjects/HoneywellExe/HoneywellExe.csproj +++ b/src/Simulation/Simulators.Tests/TestProjects/HoneywellExe/HoneywellExe.csproj @@ -1,4 +1,4 @@ - + Library diff --git a/src/Simulation/Simulators.Tests/TestProjects/IntrinsicTests/IntrinsicTests.csproj b/src/Simulation/Simulators.Tests/TestProjects/IntrinsicTests/IntrinsicTests.csproj index e0ac7e6c07c..304151d75d5 100644 --- a/src/Simulation/Simulators.Tests/TestProjects/IntrinsicTests/IntrinsicTests.csproj +++ b/src/Simulation/Simulators.Tests/TestProjects/IntrinsicTests/IntrinsicTests.csproj @@ -1,4 +1,4 @@ - + netcoreapp3.1 diff --git a/src/Simulation/Simulators.Tests/TestProjects/IonQExe/IonQExe.csproj b/src/Simulation/Simulators.Tests/TestProjects/IonQExe/IonQExe.csproj index 4a49760ae8e..3e1ffa83b60 100644 --- a/src/Simulation/Simulators.Tests/TestProjects/IonQExe/IonQExe.csproj +++ b/src/Simulation/Simulators.Tests/TestProjects/IonQExe/IonQExe.csproj @@ -1,4 +1,4 @@ - + Library diff --git a/src/Simulation/Simulators.Tests/TestProjects/Library with Spaces/Library with Spaces.csproj b/src/Simulation/Simulators.Tests/TestProjects/Library with Spaces/Library with Spaces.csproj index f98e674ef78..fc804b17c77 100644 --- a/src/Simulation/Simulators.Tests/TestProjects/Library with Spaces/Library with Spaces.csproj +++ b/src/Simulation/Simulators.Tests/TestProjects/Library with Spaces/Library with Spaces.csproj @@ -1,4 +1,4 @@ - + netstandard2.1 false diff --git a/src/Simulation/Simulators.Tests/TestProjects/Library1/Library1.csproj b/src/Simulation/Simulators.Tests/TestProjects/Library1/Library1.csproj index af6733c8685..f32041b01a6 100644 --- a/src/Simulation/Simulators.Tests/TestProjects/Library1/Library1.csproj +++ b/src/Simulation/Simulators.Tests/TestProjects/Library1/Library1.csproj @@ -1,4 +1,4 @@ - + netstandard2.1 diff --git a/src/Simulation/Simulators.Tests/TestProjects/Library2/Library2.csproj b/src/Simulation/Simulators.Tests/TestProjects/Library2/Library2.csproj index af6733c8685..f32041b01a6 100644 --- a/src/Simulation/Simulators.Tests/TestProjects/Library2/Library2.csproj +++ b/src/Simulation/Simulators.Tests/TestProjects/Library2/Library2.csproj @@ -1,4 +1,4 @@ - + netstandard2.1 diff --git a/src/Simulation/Simulators.Tests/TestProjects/QCIExe/QCIExe.csproj b/src/Simulation/Simulators.Tests/TestProjects/QCIExe/QCIExe.csproj index 57ad5f9a890..886e5e6d4b0 100644 --- a/src/Simulation/Simulators.Tests/TestProjects/QCIExe/QCIExe.csproj +++ b/src/Simulation/Simulators.Tests/TestProjects/QCIExe/QCIExe.csproj @@ -1,4 +1,4 @@ - + Library diff --git a/src/Simulation/Simulators.Tests/TestProjects/QsharpExe/QsharpExe.csproj b/src/Simulation/Simulators.Tests/TestProjects/QsharpExe/QsharpExe.csproj index c27439aab8f..9f0a438c889 100644 --- a/src/Simulation/Simulators.Tests/TestProjects/QsharpExe/QsharpExe.csproj +++ b/src/Simulation/Simulators.Tests/TestProjects/QsharpExe/QsharpExe.csproj @@ -1,4 +1,4 @@ - + Exe diff --git a/src/Simulation/Simulators.Tests/TestProjects/TargetedExe/TargetedExe.csproj b/src/Simulation/Simulators.Tests/TestProjects/TargetedExe/TargetedExe.csproj index a6397927088..30f72ddba94 100644 --- a/src/Simulation/Simulators.Tests/TestProjects/TargetedExe/TargetedExe.csproj +++ b/src/Simulation/Simulators.Tests/TestProjects/TargetedExe/TargetedExe.csproj @@ -1,4 +1,4 @@ - + Exe diff --git a/src/Simulation/Simulators.Tests/TestProjects/UnitTests/UnitTests.csproj b/src/Simulation/Simulators.Tests/TestProjects/UnitTests/UnitTests.csproj index 4445e69a21b..b1a85d2eebc 100644 --- a/src/Simulation/Simulators.Tests/TestProjects/UnitTests/UnitTests.csproj +++ b/src/Simulation/Simulators.Tests/TestProjects/UnitTests/UnitTests.csproj @@ -1,4 +1,4 @@ - + netcoreapp3.1 diff --git a/src/Simulation/Simulators.Tests/Tests.Microsoft.Quantum.Simulators.csproj b/src/Simulation/Simulators.Tests/Tests.Microsoft.Quantum.Simulators.csproj index 9b6aa3d35a9..b69f14d9079 100644 --- a/src/Simulation/Simulators.Tests/Tests.Microsoft.Quantum.Simulators.csproj +++ b/src/Simulation/Simulators.Tests/Tests.Microsoft.Quantum.Simulators.csproj @@ -1,4 +1,4 @@ - + diff --git a/src/Simulation/Simulators/Microsoft.Quantum.Simulators.csproj b/src/Simulation/Simulators/Microsoft.Quantum.Simulators.csproj index 6fcc2a76321..7562000211f 100644 --- a/src/Simulation/Simulators/Microsoft.Quantum.Simulators.csproj +++ b/src/Simulation/Simulators/Microsoft.Quantum.Simulators.csproj @@ -1,4 +1,4 @@ - + From 3b34c43d57e6fad4f9435bd485c706d7567e80ae Mon Sep 17 00:00:00 2001 From: Scott Carda Date: Thu, 17 Dec 2020 13:13:19 -0800 Subject: [PATCH 4/7] Dump Machine and Dump Register as body intrinsic --- src/Simulation/QsharpCore/Diagnostics/Dump.qs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Simulation/QsharpCore/Diagnostics/Dump.qs b/src/Simulation/QsharpCore/Diagnostics/Dump.qs index 6484a93cc35..316b3305290 100644 --- a/src/Simulation/QsharpCore/Diagnostics/Dump.qs +++ b/src/Simulation/QsharpCore/Diagnostics/Dump.qs @@ -26,6 +26,7 @@ namespace Microsoft.Quantum.Diagnostics { /// one-dimensional array of complex numbers, in which each element represents /// the amplitudes of the probability of measuring the corresponding state. function DumpMachine<'T> (location : 'T) : Unit { + body intrinsic; } /// # Summary @@ -56,6 +57,7 @@ namespace Microsoft.Quantum.Diagnostics { /// If the given qubits are entangled with some other qubit and their /// state can't be separated, it just reports that the qubits are entangled. function DumpRegister<'T> (location : 'T, qubits : Qubit[]) : Unit { + body intrinsic; } } From f307ab573dd07137809bb92c9b0b1f5b07f95be2 Mon Sep 17 00:00:00 2001 From: Scott Carda Date: Tue, 5 Jan 2021 12:55:04 -0800 Subject: [PATCH 5/7] update RegisterPrimitiveOperationsGivenAsCircuits --- .../QCTraceSimulator/QCTraceSimulatorImpl.cs | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/Simulation/Simulators/QCTraceSimulator/QCTraceSimulatorImpl.cs b/src/Simulation/Simulators/QCTraceSimulator/QCTraceSimulatorImpl.cs index f09104eb73c..c431809aab6 100644 --- a/src/Simulation/Simulators/QCTraceSimulator/QCTraceSimulatorImpl.cs +++ b/src/Simulation/Simulators/QCTraceSimulator/QCTraceSimulatorImpl.cs @@ -148,11 +148,24 @@ protected virtual void InitializeQCTracerCoreListeners(IList primitiveOperationTypes = - from op in typeof(Intrinsic.X).Assembly.GetExportedTypes() + var dllAssembly = typeof(Intrinsic.X).Assembly; + var localAssembly = typeof(Intrinsic.ExpFrac).Assembly; + + IEnumerable primitiveOperationTypes = + from op in dllAssembly.GetExportedTypes() where op.IsSubclassOf(typeof(AbstractCallable)) select op; + if (dllAssembly.FullName != localAssembly.FullName) + { + var localPrimatives = + from op in localAssembly.GetExportedTypes() + where op.IsSubclassOf(typeof(AbstractCallable)) + select op; + + primitiveOperationTypes = primitiveOperationTypes.Concat(localPrimatives); + } + IEnumerable primitiveOperationAsCircuits = from op in typeof(Circuits.X).Assembly.GetExportedTypes() where op.IsSubclassOf(typeof(AbstractCallable)) From d914b2b3909d855e3d3ab36a8fba6c3e4fccd4ad Mon Sep 17 00:00:00 2001 From: Scott Carda Date: Tue, 5 Jan 2021 14:03:14 -0800 Subject: [PATCH 6/7] Revert to original version numbers --- .../CsharpGeneration/Microsoft.Quantum.CsharpGeneration.fsproj | 2 +- ....Microsoft.Quantum.Simulation.QCTraceSimulatorRuntime.csproj | 2 +- src/Simulation/QsharpCore/Microsoft.Quantum.QSharp.Core.csproj | 2 +- .../TestProjects/HoneywellExe/HoneywellExe.csproj | 2 +- .../TestProjects/IntrinsicTests/IntrinsicTests.csproj | 2 +- .../Simulators.Tests/TestProjects/IonQExe/IonQExe.csproj | 2 +- .../TestProjects/Library with Spaces/Library with Spaces.csproj | 2 +- .../Simulators.Tests/TestProjects/Library1/Library1.csproj | 2 +- .../Simulators.Tests/TestProjects/Library2/Library2.csproj | 2 +- .../Simulators.Tests/TestProjects/QCIExe/QCIExe.csproj | 2 +- .../Simulators.Tests/TestProjects/QsharpExe/QsharpExe.csproj | 2 +- .../TestProjects/TargetedExe/TargetedExe.csproj | 2 +- .../Simulators.Tests/TestProjects/UnitTests/UnitTests.csproj | 2 +- .../Simulators.Tests/Tests.Microsoft.Quantum.Simulators.csproj | 2 +- src/Simulation/Simulators/Microsoft.Quantum.Simulators.csproj | 2 +- 15 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/Simulation/CsharpGeneration/Microsoft.Quantum.CsharpGeneration.fsproj b/src/Simulation/CsharpGeneration/Microsoft.Quantum.CsharpGeneration.fsproj index 3f7c6965edc..be39b8edeab 100644 --- a/src/Simulation/CsharpGeneration/Microsoft.Quantum.CsharpGeneration.fsproj +++ b/src/Simulation/CsharpGeneration/Microsoft.Quantum.CsharpGeneration.fsproj @@ -22,7 +22,7 @@ - + diff --git a/src/Simulation/QCTraceSimulator.Tests/Tests.Microsoft.Quantum.Simulation.QCTraceSimulatorRuntime.csproj b/src/Simulation/QCTraceSimulator.Tests/Tests.Microsoft.Quantum.Simulation.QCTraceSimulatorRuntime.csproj index 2f78c26f81d..4be621628ae 100644 --- a/src/Simulation/QCTraceSimulator.Tests/Tests.Microsoft.Quantum.Simulation.QCTraceSimulatorRuntime.csproj +++ b/src/Simulation/QCTraceSimulator.Tests/Tests.Microsoft.Quantum.Simulation.QCTraceSimulatorRuntime.csproj @@ -1,4 +1,4 @@ - + diff --git a/src/Simulation/QsharpCore/Microsoft.Quantum.QSharp.Core.csproj b/src/Simulation/QsharpCore/Microsoft.Quantum.QSharp.Core.csproj index 97da7c951df..aa56561c174 100644 --- a/src/Simulation/QsharpCore/Microsoft.Quantum.QSharp.Core.csproj +++ b/src/Simulation/QsharpCore/Microsoft.Quantum.QSharp.Core.csproj @@ -1,4 +1,4 @@ - + diff --git a/src/Simulation/Simulators.Tests/TestProjects/HoneywellExe/HoneywellExe.csproj b/src/Simulation/Simulators.Tests/TestProjects/HoneywellExe/HoneywellExe.csproj index e10a5f641a0..12fd65d55b0 100644 --- a/src/Simulation/Simulators.Tests/TestProjects/HoneywellExe/HoneywellExe.csproj +++ b/src/Simulation/Simulators.Tests/TestProjects/HoneywellExe/HoneywellExe.csproj @@ -1,4 +1,4 @@ - + Library diff --git a/src/Simulation/Simulators.Tests/TestProjects/IntrinsicTests/IntrinsicTests.csproj b/src/Simulation/Simulators.Tests/TestProjects/IntrinsicTests/IntrinsicTests.csproj index 304151d75d5..8550cbd4749 100644 --- a/src/Simulation/Simulators.Tests/TestProjects/IntrinsicTests/IntrinsicTests.csproj +++ b/src/Simulation/Simulators.Tests/TestProjects/IntrinsicTests/IntrinsicTests.csproj @@ -1,4 +1,4 @@ - + netcoreapp3.1 diff --git a/src/Simulation/Simulators.Tests/TestProjects/IonQExe/IonQExe.csproj b/src/Simulation/Simulators.Tests/TestProjects/IonQExe/IonQExe.csproj index 3e1ffa83b60..74789d73958 100644 --- a/src/Simulation/Simulators.Tests/TestProjects/IonQExe/IonQExe.csproj +++ b/src/Simulation/Simulators.Tests/TestProjects/IonQExe/IonQExe.csproj @@ -1,4 +1,4 @@ - + Library diff --git a/src/Simulation/Simulators.Tests/TestProjects/Library with Spaces/Library with Spaces.csproj b/src/Simulation/Simulators.Tests/TestProjects/Library with Spaces/Library with Spaces.csproj index fc804b17c77..d48246c07b1 100644 --- a/src/Simulation/Simulators.Tests/TestProjects/Library with Spaces/Library with Spaces.csproj +++ b/src/Simulation/Simulators.Tests/TestProjects/Library with Spaces/Library with Spaces.csproj @@ -1,4 +1,4 @@ - + netstandard2.1 false diff --git a/src/Simulation/Simulators.Tests/TestProjects/Library1/Library1.csproj b/src/Simulation/Simulators.Tests/TestProjects/Library1/Library1.csproj index f32041b01a6..af6733c8685 100644 --- a/src/Simulation/Simulators.Tests/TestProjects/Library1/Library1.csproj +++ b/src/Simulation/Simulators.Tests/TestProjects/Library1/Library1.csproj @@ -1,4 +1,4 @@ - + netstandard2.1 diff --git a/src/Simulation/Simulators.Tests/TestProjects/Library2/Library2.csproj b/src/Simulation/Simulators.Tests/TestProjects/Library2/Library2.csproj index f32041b01a6..af6733c8685 100644 --- a/src/Simulation/Simulators.Tests/TestProjects/Library2/Library2.csproj +++ b/src/Simulation/Simulators.Tests/TestProjects/Library2/Library2.csproj @@ -1,4 +1,4 @@ - + netstandard2.1 diff --git a/src/Simulation/Simulators.Tests/TestProjects/QCIExe/QCIExe.csproj b/src/Simulation/Simulators.Tests/TestProjects/QCIExe/QCIExe.csproj index 886e5e6d4b0..da7d54671c5 100644 --- a/src/Simulation/Simulators.Tests/TestProjects/QCIExe/QCIExe.csproj +++ b/src/Simulation/Simulators.Tests/TestProjects/QCIExe/QCIExe.csproj @@ -1,4 +1,4 @@ - + Library diff --git a/src/Simulation/Simulators.Tests/TestProjects/QsharpExe/QsharpExe.csproj b/src/Simulation/Simulators.Tests/TestProjects/QsharpExe/QsharpExe.csproj index 9f0a438c889..c27439aab8f 100644 --- a/src/Simulation/Simulators.Tests/TestProjects/QsharpExe/QsharpExe.csproj +++ b/src/Simulation/Simulators.Tests/TestProjects/QsharpExe/QsharpExe.csproj @@ -1,4 +1,4 @@ - + Exe diff --git a/src/Simulation/Simulators.Tests/TestProjects/TargetedExe/TargetedExe.csproj b/src/Simulation/Simulators.Tests/TestProjects/TargetedExe/TargetedExe.csproj index 30f72ddba94..1417e1242b7 100644 --- a/src/Simulation/Simulators.Tests/TestProjects/TargetedExe/TargetedExe.csproj +++ b/src/Simulation/Simulators.Tests/TestProjects/TargetedExe/TargetedExe.csproj @@ -1,4 +1,4 @@ - + Exe diff --git a/src/Simulation/Simulators.Tests/TestProjects/UnitTests/UnitTests.csproj b/src/Simulation/Simulators.Tests/TestProjects/UnitTests/UnitTests.csproj index b1a85d2eebc..4445e69a21b 100644 --- a/src/Simulation/Simulators.Tests/TestProjects/UnitTests/UnitTests.csproj +++ b/src/Simulation/Simulators.Tests/TestProjects/UnitTests/UnitTests.csproj @@ -1,4 +1,4 @@ - + netcoreapp3.1 diff --git a/src/Simulation/Simulators.Tests/Tests.Microsoft.Quantum.Simulators.csproj b/src/Simulation/Simulators.Tests/Tests.Microsoft.Quantum.Simulators.csproj index b69f14d9079..9b6aa3d35a9 100644 --- a/src/Simulation/Simulators.Tests/Tests.Microsoft.Quantum.Simulators.csproj +++ b/src/Simulation/Simulators.Tests/Tests.Microsoft.Quantum.Simulators.csproj @@ -1,4 +1,4 @@ - + diff --git a/src/Simulation/Simulators/Microsoft.Quantum.Simulators.csproj b/src/Simulation/Simulators/Microsoft.Quantum.Simulators.csproj index 7562000211f..6fcc2a76321 100644 --- a/src/Simulation/Simulators/Microsoft.Quantum.Simulators.csproj +++ b/src/Simulation/Simulators/Microsoft.Quantum.Simulators.csproj @@ -1,4 +1,4 @@ - + From cfaa97dc6383fad0effc56a0f00570c3f6e23b86 Mon Sep 17 00:00:00 2001 From: Scott Carda Date: Tue, 5 Jan 2021 14:47:24 -0800 Subject: [PATCH 7/7] Revert "update RegisterPrimitiveOperationsGivenAsCircuits" This reverts commit f307ab573dd07137809bb92c9b0b1f5b07f95be2. --- .../QCTraceSimulator/QCTraceSimulatorImpl.cs | 17 ++--------------- 1 file changed, 2 insertions(+), 15 deletions(-) diff --git a/src/Simulation/Simulators/QCTraceSimulator/QCTraceSimulatorImpl.cs b/src/Simulation/Simulators/QCTraceSimulator/QCTraceSimulatorImpl.cs index c431809aab6..f09104eb73c 100644 --- a/src/Simulation/Simulators/QCTraceSimulator/QCTraceSimulatorImpl.cs +++ b/src/Simulation/Simulators/QCTraceSimulator/QCTraceSimulatorImpl.cs @@ -148,24 +148,11 @@ protected virtual void InitializeQCTracerCoreListeners(IList primitiveOperationTypes = - from op in dllAssembly.GetExportedTypes() + IEnumerable primitiveOperationTypes = + from op in typeof(Intrinsic.X).Assembly.GetExportedTypes() where op.IsSubclassOf(typeof(AbstractCallable)) select op; - if (dllAssembly.FullName != localAssembly.FullName) - { - var localPrimatives = - from op in localAssembly.GetExportedTypes() - where op.IsSubclassOf(typeof(AbstractCallable)) - select op; - - primitiveOperationTypes = primitiveOperationTypes.Concat(localPrimatives); - } - IEnumerable primitiveOperationAsCircuits = from op in typeof(Circuits.X).Assembly.GetExportedTypes() where op.IsSubclassOf(typeof(AbstractCallable))