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: 1 addition & 1 deletion src/Qir/Samples/StandaloneInputReference/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ add_executable(qir-input-reference-standalone
)

# This is where the generated QIR file is specified.
target_source_from_qir(qir-input-reference-standalone qsharp/qir/qir-standalone-input-reference.ll)
target_source_from_qir(qir-input-reference-standalone qsharp/obj/qsharp/qir-standalone-input-reference.bc)

target_link_libraries(qir-input-reference-standalone PUBLIC
"-L${runtime_lib_path}"
Expand Down
2 changes: 1 addition & 1 deletion src/Qir/Tests/FullstateSimulator/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
add_executable(fullstate-simulator-tests
FullstateSimulatorTests.cpp)

target_source_from_qir(fullstate-simulator-tests qsharp/qir/qir-test-simulator.ll)
target_source_from_qir(fullstate-simulator-tests qsharp/obj/qsharp/qir-test-simulator.bc)

target_link_libraries(fullstate-simulator-tests PUBLIC
"-L${runtime_lib_path}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -353,11 +353,11 @@ TEST_CASE("Fullstate simulator: get qubit state of Bell state", "[fullstate_simu
}
}

extern "C" int Microsoft__Quantum__Testing__QIR__Test_Simulator_QIS__body(); // NOLINT
extern "C" int Microsoft__Quantum__Testing__QIR__Test_Simulator_QIS__Interop(); // NOLINT
TEST_CASE("QIR: invoke all standard Q# gates against the fullstate simulator", "[fullstate_simulator]")
{
std::unique_ptr<IRuntimeDriver> sim = CreateFullstateSimulator();
QirExecutionContext::Scoped qirctx(sim.get(), true /*trackAllocatedObjects*/);

REQUIRE(0 == Microsoft__Quantum__Testing__QIR__Test_Simulator_QIS__body());
REQUIRE(0 == Microsoft__Quantum__Testing__QIR__Test_Simulator_QIS__Interop());
}
2 changes: 1 addition & 1 deletion src/Qir/Tests/QIR-dynamic/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
set(TEST_FILES
qsharp/qir/qir-test-random.ll
qsharp/obj/qsharp/qir-test-random.bc
)

#==============================================================================
Expand Down
37 changes: 16 additions & 21 deletions src/Qir/Tests/QIR-dynamic/qir-driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,29 +8,28 @@
#define CATCH_CONFIG_MAIN // This tells Catch to provide a main() - only do this in one cpp file
#include "catch.hpp"

#include "QirTypes.hpp"
#include "SimFactory.hpp"
#include "QirContext.hpp"
#include "OutputStream.hpp"

extern "C" int64_t Microsoft__Quantum__Testing__QIR__QuantumRandomNumberGenerator__body(); // NOLINT
extern "C" int64_t Microsoft__Quantum__Testing__QIR__QuantumRandomNumberGenerator__Interop(); // NOLINT

extern "C" void Microsoft__Quantum__Testing__QIR__DumpMachineTest__body(); // NOLINT
extern "C" void Microsoft__Quantum__Testing__QIR__DumpMachineToFileTest__body(const void*); // NOLINT
extern "C" void Microsoft__Quantum__Testing__QIR__DumpRegisterTest__body(); // NOLINT
extern "C" void Microsoft__Quantum__Testing__QIR__DumpRegisterToFileTest__body(const void*); // NOLINT
extern "C" void Microsoft__Quantum__Testing__QIR__DumpMachineTest__Interop(); // NOLINT
extern "C" void Microsoft__Quantum__Testing__QIR__DumpMachineToFileTest__Interop(const char[]); // NOLINT
extern "C" void Microsoft__Quantum__Testing__QIR__DumpRegisterTest__Interop(); // NOLINT
extern "C" void Microsoft__Quantum__Testing__QIR__DumpRegisterToFileTest__Interop(const char[]); // NOLINT

extern "C" void Microsoft__Quantum__Testing__QIR__AssertMeasurementTest__body(); // NOLINT
extern "C" void Microsoft__Quantum__Testing__QIR__AssertMeasurementTest__Interop(); // NOLINT

using namespace Microsoft::Quantum;

TEST_CASE("QIR: Generate a random number with full state simulator", "[qir]")
{
QirExecutionContext::Scoped contextReleaser{CreateFullstateSimulator().release()};

const int ret1 = Microsoft__Quantum__Testing__QIR__QuantumRandomNumberGenerator__body();
const int ret2 = Microsoft__Quantum__Testing__QIR__QuantumRandomNumberGenerator__body();
const int ret3 = Microsoft__Quantum__Testing__QIR__QuantumRandomNumberGenerator__body();
const int ret1 = Microsoft__Quantum__Testing__QIR__QuantumRandomNumberGenerator__Interop();
const int ret2 = Microsoft__Quantum__Testing__QIR__QuantumRandomNumberGenerator__Interop();
const int ret3 = Microsoft__Quantum__Testing__QIR__QuantumRandomNumberGenerator__Interop();
INFO(
std::string("Three random numbers: ") + std::to_string(ret1) + ", " + std::to_string(ret2) + ", " +
std::to_string(ret3));
Expand Down Expand Up @@ -58,7 +57,7 @@ TEST_CASE("QIR: DumpMachine", "[qir][DumpMachine]")
// Redirect the output from std::cout to outStrStream:
OutputStream::ScopedRedirector qOStreamRedirector(outStrStream);

Microsoft__Quantum__Testing__QIR__DumpMachineTest__body();
Microsoft__Quantum__Testing__QIR__DumpMachineTest__Interop();
} // qOStreamRedirector goes out of scope.

REQUIRE(outStrStream.str().size() != 0);
Expand All @@ -68,12 +67,11 @@ TEST_CASE("QIR: DumpMachine", "[qir][DumpMachine]")
// Dump to empty string location (std::cout):
{
std::ostringstream outStrStream;
const QirString qstrEmpty{std::string("")};
{
// Redirect the output from std::cout to outStrStream:
OutputStream::ScopedRedirector qOStreamRedirector(outStrStream);

Microsoft__Quantum__Testing__QIR__DumpMachineToFileTest__body(&qstrEmpty);
Microsoft__Quantum__Testing__QIR__DumpMachineToFileTest__Interop("");
} // qOStreamRedirector goes out of scope.

REQUIRE(outStrStream.str().size() != 0);
Expand All @@ -92,8 +90,7 @@ TEST_CASE("QIR: DumpMachine", "[qir][DumpMachine]")
REQUIRE(!FileExists(filePath));

// Dump the machine state to that `filePath`:
const QirString qstr{std::string(filePath)};
Microsoft__Quantum__Testing__QIR__DumpMachineToFileTest__body(&qstr);
Microsoft__Quantum__Testing__QIR__DumpMachineToFileTest__Interop(filePath);

// Make sure the file has been created.
REQUIRE(FileExists(filePath));
Expand All @@ -116,7 +113,7 @@ TEST_CASE("QIR: DumpRegister", "[qir][DumpRegister]")
// Redirect the output from std::cout to outStrStream:
OutputStream::ScopedRedirector qOStreamRedirector(outStrStream);

Microsoft__Quantum__Testing__QIR__DumpRegisterTest__body();
Microsoft__Quantum__Testing__QIR__DumpRegisterTest__Interop();
} // qOStreamRedirector goes out of scope.

REQUIRE(outStrStream.str().size() != 0);
Expand All @@ -126,12 +123,11 @@ TEST_CASE("QIR: DumpRegister", "[qir][DumpRegister]")
// Dump to empty string location (std::cout):
{
std::ostringstream outStrStream;
const QirString qstrEmpty{""};
{
// Redirect the output from std::cout to outStrStream:
OutputStream::ScopedRedirector qOStreamRedirector(outStrStream);

Microsoft__Quantum__Testing__QIR__DumpRegisterToFileTest__body(&qstrEmpty);
Microsoft__Quantum__Testing__QIR__DumpRegisterToFileTest__Interop("");
} // qOStreamRedirector goes out of scope.

REQUIRE(outStrStream.str().size() != 0);
Expand All @@ -150,8 +146,7 @@ TEST_CASE("QIR: DumpRegister", "[qir][DumpRegister]")
REQUIRE(!FileExists(filePath));

// Dump to that `filePath`:
const QirString qstr{filePath};
Microsoft__Quantum__Testing__QIR__DumpRegisterToFileTest__body(&qstr);
Microsoft__Quantum__Testing__QIR__DumpRegisterToFileTest__Interop(filePath);

// Make sure the file has been created.
REQUIRE(FileExists(filePath));
Expand All @@ -167,5 +162,5 @@ TEST_CASE("QIR: AssertMeasurement", "[qir][AssertMeasurement]")
{
QirExecutionContext::Scoped contextReleaser{CreateFullstateSimulator().release()};

Microsoft__Quantum__Testing__QIR__AssertMeasurementTest__body();
Microsoft__Quantum__Testing__QIR__AssertMeasurementTest__Interop();
} // TEST_CASE("QIR: AssertMeasurement", "[qir][AssertMeasurement]")
17 changes: 7 additions & 10 deletions src/Qir/Tests/QIR-dynamic/qsharp/qir-test-random.qs
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,13 @@ namespace Microsoft.Quantum.Testing.QIR
operation QuantumRandomNumberGenerator() : Int {
mutable randomNumber = 0;

for (i in 1 .. 64)
{
using(q = Qubit())
{
H(q);
set randomNumber = randomNumber <<< 1;
if (M(q) == One) {
set randomNumber += 1;
}
}
for i in 1 .. 64 {
use q = Qubit();
H(q);
set randomNumber = randomNumber <<< 1;
if M(q) == One {
set randomNumber += 1;
}
}
return randomNumber;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Qir/Tests/QIR-static/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
set(TEST_FILES
qir-test-noqsharp.ll
qsharp/qir/qir-gen.ll
qsharp/obj/qsharp/qir-gen.bc
)

#==============================================================================
Expand Down
25 changes: 11 additions & 14 deletions src/Qir/Tests/QIR-static/qir-driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,7 @@ struct Array {
extern "C" int64_t Microsoft__Quantum__Testing__QIR__Test_Arrays__Interop( // NOLINT
Array* array,
int64_t index,
int64_t val,
bool compilerDecoy);
int64_t val);
TEST_CASE("QIR: Using 1D arrays", "[qir][qir.arr1d]")
{
QirExecutionContext::Scoped qirctx(nullptr, true /*trackAllocatedObjects*/);
Expand All @@ -60,11 +59,11 @@ TEST_CASE("QIR: Using 1D arrays", "[qir][qir.arr1d]")
int64_t values[n] = {0, 1, 2, 3, 4};
auto array = Array{5, values};

int64_t res = Microsoft__Quantum__Testing__QIR__Test_Arrays__Interop(&array, 2, 42, false);
int64_t res = Microsoft__Quantum__Testing__QIR__Test_Arrays__Interop(&array, 2, 42);
REQUIRE(res == (0 + 42) + (42 + 3 + 4));
}

extern "C" void Microsoft__Quantum__Testing__QIR__TestQubitResultManagement__body(); // NOLINT
extern "C" void Microsoft__Quantum__Testing__QIR__TestQubitResultManagement__Interop(); // NOLINT
struct QubitsResultsTestSimulator : public Microsoft::Quantum::SimulatorStub
{
// no intelligent reuse, we just want to check that QIR releases all qubits
Expand Down Expand Up @@ -151,7 +150,7 @@ TEST_CASE("QIR: allocating and releasing qubits and results", "[qir][qir.qubit][
unique_ptr<QubitsResultsTestSimulator> sim = make_unique<QubitsResultsTestSimulator>();
QirExecutionContext::Scoped qirctx(sim.get(), true /*trackAllocatedObjects*/);

REQUIRE_NOTHROW(Microsoft__Quantum__Testing__QIR__TestQubitResultManagement__body());
REQUIRE_NOTHROW(Microsoft__Quantum__Testing__QIR__TestQubitResultManagement__Interop());

// check that all qubits have been released
for (size_t id = 0; id < sim->qubits.size(); id++)
Expand Down Expand Up @@ -205,19 +204,17 @@ TEST_CASE("QIR: Report range in a failure message", "[qir][qir.range]")
REQUIRE(failed);
}

#if 0 // TODO: Q# compiler crashes generating QIR for TestPartials
// TestPartials subtracts the second argument from the first and returns the result.
extern "C" int64_t Microsoft__Quantum__Testing__QIR__TestPartials__body(int64_t, int64_t); // NOLINT
extern "C" int64_t Microsoft__Quantum__Testing__QIR__TestPartials__Interop(int64_t, int64_t); // NOLINT
TEST_CASE("QIR: Partial application of a callable", "[qir][qir.partCallable]")
{
QirExecutionContext::Scoped qirctx(nullptr, true /*trackAllocatedObjects*/);

const int64_t res = Microsoft__Quantum__Testing__QIR__TestPartials__body(42, 17);
const int64_t res = Microsoft__Quantum__Testing__QIR__TestPartials__Interop(42, 17);
REQUIRE(res == 42 - 17);
}
#endif

// The Microsoft__Quantum__Testing__QIR__TestFunctors__body tests needs proper semantics of X and M, and nothing else.
// The Microsoft__Quantum__Testing__QIR__TestFunctors__Interop tests needs proper semantics of X and M, and nothing else.
// The validation is done inside the test and it would throw in case of failure.
struct FunctorsTestSimulator : public Microsoft::Quantum::SimulatorStub
{
Expand Down Expand Up @@ -295,8 +292,8 @@ struct FunctorsTestSimulator : public Microsoft::Quantum::SimulatorStub
FunctorsTestSimulator* g_ctrqapi = nullptr;
static int g_cKCalls = 0;
static int g_cKCallsControlled = 0;
extern "C" void Microsoft__Quantum__Testing__QIR__TestFunctors__body(); // NOLINT
extern "C" void Microsoft__Quantum__Testing__QIR__TestFunctorsNoArgs__body(); // NOLINT
extern "C" void Microsoft__Quantum__Testing__QIR__TestFunctors__Interop(); // NOLINT
extern "C" void Microsoft__Quantum__Testing__QIR__TestFunctorsNoArgs__Interop(); // NOLINT
extern "C" void __quantum__qis__k__body(Qubit q) // NOLINT
{
g_cKCalls++;
Expand All @@ -313,11 +310,11 @@ TEST_CASE("QIR: application of nested controlled functor", "[qir][qir.functor]")
QirExecutionContext::Scoped qirctx(qapi.get(), true /*trackAllocatedObjects*/);
g_ctrqapi = qapi.get();

CHECK_NOTHROW(Microsoft__Quantum__Testing__QIR__TestFunctors__body());
CHECK_NOTHROW(Microsoft__Quantum__Testing__QIR__TestFunctors__Interop());

const int cKCalls = g_cKCalls;
const int cKCallsControlled = g_cKCallsControlled;
CHECK_NOTHROW(Microsoft__Quantum__Testing__QIR__TestFunctorsNoArgs__body());
CHECK_NOTHROW(Microsoft__Quantum__Testing__QIR__TestFunctorsNoArgs__Interop());
CHECK(g_cKCalls - cKCalls == 3);
CHECK(g_cKCallsControlled - cKCallsControlled == 5);

Expand Down
12 changes: 6 additions & 6 deletions src/Qir/Tests/QIR-static/qir-test-conditionals.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,44 +114,44 @@ struct ConditionalsTestSimulator : public Microsoft::Quantum::SimulatorStub
}
};

extern "C" void Microsoft__Quantum__Testing__QIR__TestApplyIf__body(); // NOLINT
extern "C" void Microsoft__Quantum__Testing__QIR__TestApplyIf__Interop(); // NOLINT
TEST_CASE("QIR: ApplyIf", "[qir][qir.conditionals]")
{
unique_ptr<ConditionalsTestSimulator> qapi =
make_unique<ConditionalsTestSimulator>(vector<ResultValue>{Result_Zero, Result_One});
QirExecutionContext::Scoped qirctx(qapi.get(), true /*trackAllocatedObjects*/);

CHECK_NOTHROW(Microsoft__Quantum__Testing__QIR__TestApplyIf__body());
CHECK_NOTHROW(Microsoft__Quantum__Testing__QIR__TestApplyIf__Interop());

INFO(qapi->GetHistory());
CHECK(qapi->xCallbacks.size() == 8);
CHECK(qapi->cxCallbacks.size() == 0);
CHECK(qapi->otherCallbacks.size() == 0);
}

extern "C" void Microsoft__Quantum__Testing__QIR__TestApplyIfWithFunctors__body(); // NOLINT
extern "C" void Microsoft__Quantum__Testing__QIR__TestApplyIfWithFunctors__Interop(); // NOLINT
TEST_CASE("QIR: ApplyIf with functors", "[qir][qir.conditionals]")
{
unique_ptr<ConditionalsTestSimulator> qapi =
make_unique<ConditionalsTestSimulator>(vector<ResultValue>{Result_Zero, Result_One});
QirExecutionContext::Scoped qirctx(qapi.get(), true /*trackAllocatedObjects*/);

CHECK_NOTHROW(Microsoft__Quantum__Testing__QIR__TestApplyIfWithFunctors__body());
CHECK_NOTHROW(Microsoft__Quantum__Testing__QIR__TestApplyIfWithFunctors__Interop());

INFO(qapi->GetHistory());
CHECK(qapi->xCallbacks.size() == 5);
CHECK(qapi->cxCallbacks.size() == 7);
CHECK(qapi->otherCallbacks.size() == 0);
}

extern "C" void Microsoft__Quantum__Testing__QIR__TestApplyConditionally__body(); // NOLINT
extern "C" void Microsoft__Quantum__Testing__QIR__TestApplyConditionally__Interop(); // NOLINT
TEST_CASE("QIR: ApplyConditionally", "[qir][qir.conditionals]")
{
unique_ptr<ConditionalsTestSimulator> qapi =
make_unique<ConditionalsTestSimulator>(vector<ResultValue>{Result_Zero, Result_One});
QirExecutionContext::Scoped qirctx(qapi.get(), true /*trackAllocatedObjects*/);

CHECK_NOTHROW(Microsoft__Quantum__Testing__QIR__TestApplyConditionally__body());
CHECK_NOTHROW(Microsoft__Quantum__Testing__QIR__TestApplyConditionally__Interop());

INFO(qapi->GetHistory());
CHECK(qapi->xCallbacks.size() == 4);
Expand Down
Loading