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
27 changes: 26 additions & 1 deletion examples/QIR/Optimization/Hello/Hello.csproj
Original file line number Diff line number Diff line change
@@ -1,9 +1,34 @@
<Project Sdk="Microsoft.Quantum.Sdk/0.18.2106148911">
<Project Sdk="Microsoft.Quantum.Sdk/0.18.2107153439">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
<QirGeneration>true</QirGeneration>
<BuildOutputPath>$(MSBuildThisFileDirectory)build</BuildOutputPath>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Quantum.Qir.Runtime" Version="0.18.2107153439-alpha" GeneratePathProperty="true" />
<PackageReference Include="Microsoft.Quantum.Simulators" Version="0.18.2107153439" GeneratePathProperty="true" />
</ItemGroup>

<Target Name="GetDependencies" AfterTargets="Build">
<PropertyGroup>
<QirRuntimeHeaders>$(PkgMicrosoft_Quantum_Qir_Runtime)/runtimes/any/native/include</QirRuntimeHeaders>
<QirRuntimeLibs Condition="$([MSBuild]::IsOsPlatform('OSX'))">$(PkgMicrosoft_Quantum_Qir_Runtime)/runtimes/osx-x64/native</QirRuntimeLibs>
<QirRuntimeLibs Condition="$([MSBuild]::IsOsPlatform('Windows'))">$(PkgMicrosoft_Quantum_Qir_Runtime)/runtimes/win-x64/native</QirRuntimeLibs>
<QirRuntimeLibs Condition="$([MSBuild]::IsOsPlatform('Linux'))">$(PkgMicrosoft_Quantum_Qir_Runtime)/runtimes/linux-x64/native</QirRuntimeLibs>
<SimulatorRuntime Condition="$([MSBuild]::IsOsPlatform('OSX'))">$(PkgMicrosoft_Quantum_Simulators)/runtimes/osx-x64/native/Microsoft.Quantum.Simulator.Runtime.dll</SimulatorRuntime>
<SimulatorRuntime Condition="$([MSBuild]::IsOsPlatform('Windows'))">$(PkgMicrosoft_Quantum_Simulators)/runtimes/win-x64/native/Microsoft.Quantum.Simulator.Runtime.dll</SimulatorRuntime>
<SimulatorRuntime Condition="$([MSBuild]::IsOsPlatform('Linux'))">$(PkgMicrosoft_Quantum_Simulators)/runtimes/linux-x64/native/Microsoft.Quantum.Simulator.Runtime.dll</SimulatorRuntime>
</PropertyGroup>
<ItemGroup>
<_QirRuntimeLibFiles Include="$(QirRuntimeLibs)/**/*.*" Exclude="$(QirRuntimeLibs)/**/*.exe" />
<_QirRuntimeHeaderFiles Include="$(QirRuntimeHeaders)/**/*.hpp" />
</ItemGroup>
<Copy SourceFiles="$(SimulatorRuntime)" DestinationFolder="$(BuildOutputPath)" SkipUnchangedFiles="true" />
<Copy SourceFiles="@(_QirRuntimeLibFiles)" DestinationFolder="$(BuildOutputPath)\%(RecursiveDir)" SkipUnchangedFiles="true" />
<Copy SourceFiles="@(_QirRuntimeHeaderFiles)" DestinationFolder="$(BuildOutputPath)\%(RecursiveDir)" SkipUnchangedFiles="true" />
</Target>

</Project>
15 changes: 15 additions & 0 deletions examples/QIR/Optimization/Hello/Main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#include "QirContext.hpp"
#include "QirRuntime.hpp"
#include "SimFactory.hpp"

using namespace Microsoft::Quantum;
using namespace std;

extern "C" void Hello__HelloQ();

int main(int argc, char* argv[]){
unique_ptr<IRuntimeDriver> sim = CreateFullstateSimulator();
QirContextScope qirctx(sim.get(), true /*trackAllocatedObjects*/);
Hello__HelloQ();
return 0;
}
276 changes: 266 additions & 10 deletions examples/QIR/Optimization/README.md

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions src/QsCompiler/CSharpGeneration/EntryPoint.fs
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,11 @@ let private qirArguments parameters parseResult =
|> qirArgumentValue param.QSharpType
|> Option.map (fun value -> ``new`` (ident argumentType) ``(`` [ literal param.Name; value ] ``)``)

// N.B. The parameters sequence is in the right order when it is used here.
// It has to be reversed here because the fold changes the order of the expression syntax.
// This is a problem because the API for QIR submission expects the list of arguments in order.
parameters
|> Seq.rev
|> Seq.fold (fun state param -> Option.map2 (fun xs x -> x :: xs) state (argument param)) (Some [])
|> Option.map (fun args -> ident listType <.> (sprintf "Create<%s>" argumentType |> ident, args))

Expand Down
1 change: 0 additions & 1 deletion src/QsCompiler/QirGeneration/Context.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ public sealed class GenerationContext : IDisposable
static GenerationContext()
{
LibContext = Library.InitializeLLVM();
LibContext.RegisterTarget(CodeGenTarget.Native);
}

#region Member variables
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -367,9 +367,12 @@ type InferenceContext(symbolTracker: SymbolTracker) =
|> rememberErrors (resolvedType :: Constraint.types typeConstraint)

member internal context.Resolve resolvedType =
let resolveWithRange type' =
let type' = context.Resolve type'
type' |> ResolvedType.withRange (type'.Range |> TypeRange.orElse resolvedType.Range)
let resolveWithRange type_ =
let resolvedType' = context.Resolve type_

// Prefer the original type range since it may be closer to the source of an error, but otherwise fall back
// to the newly resolved type range.
resolvedType' |> ResolvedType.withRange (resolvedType.Range |> TypeRange.orElse resolvedType'.Range)

match resolvedType.Resolution with
| TypeParameter param ->
Expand Down
Loading