Skip to content
This repository was archived by the owner on Jan 12, 2024. It is now read-only.
Closed
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ bld/
[Ll]og/
[Dd]rops/
**/qir-gen.ll
**/qir-targeted.ll

# Visual Studio 2015/2017 cache/options directory
.vs/
Expand Down
10 changes: 10 additions & 0 deletions src/QirRuntime/build-qir-runtime.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,16 @@ if ($Env:ENABLE_QIRRUNTIME -eq "true") {
Copy-Item -Path (Join-Path $qirStaticPath qir *.ll) -Destination (Split-Path $qirStaticPath -Parent)
# Also copy to drops so it ends up in build artifacts, for easier post-build debugging.
Copy-Item -Path (Join-Path $qirStaticPath qir *.ll) -Destination $Env:DROPS_DIR

$qirTargetedPath = Join-Path $PSScriptRoot test QIR-static qsharp-targeted
dotnet build $qirTargetedPath -c $Env:BUILD_CONFIGURATION -v $Env:BUILD_VERBOSITY
if ($LastExitCode -ne 0) {
Write-Host "##vso[task.logissue type=error;]Failed to compile Q# project at '$qirTargetedPath' into QIR."
return
}
Copy-Item -Path (Join-Path $qirTargetedPath qir *.ll) -Destination (Split-Path $qirTargetedPath -Parent)
# Also copy to drops so it ends up in build artifacts, for easier post-build debugging.
Copy-Item -Path (Join-Path $qirTargetedPath qir *.ll) -Destination $Env:DROPS_DIR

Write-Host "##[info]Build QIR Runtime"
$oldCC = $env:CC
Expand Down
1 change: 1 addition & 0 deletions src/QirRuntime/test/QIR-static/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
set(TEST_FILES
qir-test-noqsharp
qir-gen
qir-targeted
)

foreach(file ${TEST_FILES})
Expand Down
4 changes: 2 additions & 2 deletions src/QirRuntime/test/QIR-static/qir-test-conditionals.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ TEST_CASE("QIR: ApplyConditionally", "[qir][qir.conditionals]")
CHECK_NOTHROW(Microsoft__Quantum__Testing__QIR__TestApplyConditionally__body());

INFO(qapi->GetHistory());
CHECK(qapi->xCallbacks.size() == 4);
CHECK(qapi->cxCallbacks.size() == 2);
CHECK(qapi->xCallbacks.size() == 2);
CHECK(qapi->cxCallbacks.size() == 0);
CHECK(qapi->otherCallbacks.size() == 0);
}
10 changes: 10 additions & 0 deletions src/QirRuntime/test/QIR-static/qsharp-targeted/entrypoint.qs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace Microsoft.Quantum.Testing.QIR {

@EntryPoint()
operation Tests() : Unit {
TestApplyIf();
TestApplyIfWithFunctors();
TestApplyConditionally();
}

}
13 changes: 13 additions & 0 deletions src/QirRuntime/test/QIR-static/qsharp-targeted/main.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

// Currently, compiling to QIR has to suppress C# generation but then we need to provide Main function ourselves.
namespace CompilerWorkaround
{
class Program
{
static void Main(string[] args)
{
}
}
}
17 changes: 17 additions & 0 deletions src/QirRuntime/test/QIR-static/qsharp-targeted/qir-targeted.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<Project Sdk="Microsoft.Quantum.Sdk/0.15.2102129527-alpha">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
<CSharpGeneration>false</CSharpGeneration>
<QirGeneration>True</QirGeneration>
<CSharpGeneration>false</CSharpGeneration>
<IncludeQSharpCorePackages>false</IncludeQSharpCorePackages>
<ExecutionTarget>honeywell</ExecutionTarget>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\..\..\..\Simulation\QSharpCore\Microsoft.Quantum.QSharp.Core.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -1,63 +1,70 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
namespace Microsoft.Quantum.Testing.QIR {
open Microsoft.Quantum.Intrinsic;
open Microsoft.Quantum.Simulation.QuantumProcessor.Extensions;

operation TestApplyIf() : Unit {
use q1 = Qubit();
use q2 = Qubit();

let r1 = M(q1); // expected: r1 = Zero
X(q2);
let r2 = M(q2); // expected: r2 = One

ApplyIfElseR(r1, (X, q1), (Y, q1));
ApplyIfElseR(r2, (Y, q1), (X, q1));

// Other variants
ApplyIfElseRA(r1, (X, q1), (Y, q1));
ApplyIfElseRC(r1, (X, q1), (Y, q1));
ApplyIfElseRCA(r1, (X, q1), (Y, q1));
ApplyIfOne(r2, (X, q1));
ApplyIfZero(r1, (X, q1));
}

operation TestApplyIfWithFunctors() : Unit {
use q1 = Qubit();
use q2 = Qubit();

let r1 = M(q1);
X(q2);
let r2 = M(q2);

Adjoint ApplyIfElseRCA(r1, (X, q1), (Y, q1));
Controlled ApplyIfElseRCA([q2], (r1, (X, q1), (Y, q1)));
Adjoint Controlled ApplyIfElseRCA([q2], (r1, (X, q1), (Y, q1)));
Adjoint ApplyIfElseRA(r1, (X, q1), (Y, q1));
Controlled ApplyIfElseRC([q2], (r1, (X, q1), (Y, q1)));
Adjoint ApplyIfOneA(r2, (X, q1));
Controlled ApplyIfOneC([q2], (r2, (X, q1)));
Adjoint Controlled ApplyIfOneCA([q2], (r2, (X, q1)));
Adjoint ApplyIfZeroA(r1, (X, q1));
Controlled ApplyIfZeroC([q2], (r1, (X, q1)));
Adjoint Controlled ApplyIfZeroCA([q2], (r1, (X, q1)));
}

operation TestApplyConditionally() : Unit {
use q1 = Qubit();
use q2 = Qubit();

let r1 = M(q1);
X(q2);
let r2 = M(q2);

ApplyConditionally([r1], [r2], (Y, q1), (X, q1));
ApplyConditionally([r1, One], [Zero, r2], (X, q1), (Y, q1));

Adjoint ApplyConditionallyA([r1], [r2], (Y, q1), (X, q1));
Controlled ApplyConditionallyC([q2], ([r1], [r2], (Y, q1), (X, q1)));
Adjoint Controlled ApplyConditionallyCA([q2], ([r1], [r2], (Y, q1), (X, q1)));
}

// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
namespace Microsoft.Quantum.Testing.QIR {
open Microsoft.Quantum.Intrinsic;
open Microsoft.Quantum.Canon;

operation TestApplyIf() : Unit {
use q1 = Qubit();
use q2 = Qubit();

let r1 = M(q1); // expected: r1 = Zero
X(q2);
let r2 = M(q2); // expected: r2 = One

ApplyIfElseR(r1, (X, q1), (Y, q1));
ApplyIfElseR(r2, (Y, q1), (X, q1));

// Other variants
ApplyIfElseRA(r1, (X, q1), (Y, q1));
ApplyIfElseRC(r1, (X, q1), (Y, q1));
ApplyIfElseRCA(r1, (X, q1), (Y, q1));
ApplyIfOne(r2, (X, q1));
ApplyIfZero(r1, (X, q1));
}

operation TestApplyIfWithFunctors() : Unit {
use q1 = Qubit();
use q2 = Qubit();

let r1 = M(q1);
X(q2);
let r2 = M(q2);

Adjoint ApplyIfElseRCA(r1, (X, q1), (Y, q1));
Controlled ApplyIfElseRCA([q2], (r1, (X, q1), (Y, q1)));
Adjoint Controlled ApplyIfElseRCA([q2], (r1, (X, q1), (Y, q1)));
Adjoint ApplyIfElseRA(r1, (X, q1), (Y, q1));
Controlled ApplyIfElseRC([q2], (r1, (X, q1), (Y, q1)));
Adjoint ApplyIfOneA(r2, (X, q1));
Controlled ApplyIfOneC([q2], (r2, (X, q1)));
Adjoint Controlled ApplyIfOneCA([q2], (r2, (X, q1)));
Adjoint ApplyIfZeroA(r1, (X, q1));
Controlled ApplyIfZeroC([q2], (r1, (X, q1)));
Adjoint Controlled ApplyIfZeroCA([q2], (r1, (X, q1)));
}

operation TestApplyConditionally() : Unit {
use q1 = Qubit();
use q2 = Qubit();

let r1 = M(q1);
X(q2);
let r2 = M(q2);

if r1 == r2 {
Y(q1);
}
else {
X(q1);
}

if r1 == Zero and One == r2 {
X(q1);
}
else {
Y(q1);
}
}

}
5 changes: 0 additions & 5 deletions src/QirRuntime/test/QIR-static/qsharp/qir-test-arrays.qs
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,6 @@ namespace Microsoft.Quantum.Testing.QIR {
let res18 = ArcTanTest();
let res19 = ParityTest();
MessageTest("Test");

// Conditionals:
TestApplyIf();
TestApplyIfWithFunctors();
TestApplyConditionally();
}
return sum;
}
Expand Down
9 changes: 0 additions & 9 deletions src/Simulation/QSharpCore/Properties/AssemblyInfo.cs

This file was deleted.

Loading