Skip to content
This repository was archived by the owner on Jan 12, 2024. It is now read-only.

Commit 59e55c0

Browse files
swernliidavis
andauthored
Basic Runtime Driver (#859)
* Basic Runtime Driver implementation * Remove leftover comment * fix copyright comment * Include memory header * Adding static lib generation * Removing static lib changes Co-authored-by: Ian Davis <[email protected]>
1 parent 9239c42 commit 59e55c0

File tree

4 files changed

+97
-1
lines changed

4 files changed

+97
-1
lines changed
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
// Copyright (c) Microsoft Corporation.
2+
// Licensed under the MIT License.
3+
4+
#include <cstdint>
5+
#include <memory>
6+
7+
#include "QirRuntimeApi_I.hpp"
8+
#include "QubitManager.hpp"
9+
#include "BasicRuntimeDriverFactory.h"
10+
11+
namespace Microsoft
12+
{
13+
namespace Quantum
14+
{
15+
class CBasicRuntimeDriver : public IRuntimeDriver
16+
{
17+
std::unique_ptr<CQubitManager> qubitManager;
18+
19+
public:
20+
CBasicRuntimeDriver()
21+
{
22+
qubitManager = std::make_unique<CQubitManager>();
23+
}
24+
25+
~CBasicRuntimeDriver() override
26+
{
27+
}
28+
29+
std::string QubitToString(QubitIdType q) override
30+
{
31+
return std::to_string(q);
32+
}
33+
34+
QubitIdType AllocateQubit() override
35+
{
36+
return qubitManager->Allocate();
37+
}
38+
39+
void ReleaseQubit(QubitIdType q) override
40+
{
41+
qubitManager->Release(q);
42+
}
43+
44+
void ReleaseResult(Result /* result */) override
45+
{
46+
}
47+
48+
bool AreEqualResults(Result r1, Result r2) override
49+
{
50+
return r1 == r2;
51+
}
52+
53+
ResultValue GetResultValue(Result r) override
54+
{
55+
return (r == UseZero()) ? Result_Zero : Result_One;
56+
}
57+
58+
Result UseZero() override
59+
{
60+
return reinterpret_cast<Result>(0);
61+
}
62+
63+
Result UseOne() override
64+
{
65+
return reinterpret_cast<Result>(1);
66+
}
67+
};
68+
69+
extern "C" void* CreateBasicRuntimeDriver()
70+
{
71+
return (IRuntimeDriver*)new CBasicRuntimeDriver();
72+
}
73+
74+
} // namespace Quantum
75+
} // namespace Microsoft

src/Qir/Runtime/lib/QIR/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ set(rt_sup_source_files
1919
strings.cpp
2020
utils.cpp
2121
QubitManager.cpp
22+
BasicRuntimeDriver.cpp
2223
)
2324

2425
# Produce object lib we'll use to create a shared lib (so/dll) later on

src/Qir/Runtime/lib/QSharpFoundation/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,3 @@ install(TARGETS Microsoft.Quantum.Qir.QSharp.Foundation
4747
LIBRARY DESTINATION "${CMAKE_BINARY_DIR}/bin"
4848
ARCHIVE DESTINATION "${CMAKE_BINARY_DIR}/bin"
4949
)
50-
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Copyright (c) Microsoft Corporation.
2+
// Licensed under the MIT License.
3+
4+
#ifndef BASICRUNTIMEDRIVERFACTORY_H
5+
#define BASICRUNTIMEDRIVERFACTORY_H
6+
7+
#include <stdint.h>
8+
#include "CoreDefines.h"
9+
10+
#ifdef __cplusplus
11+
extern "C"
12+
{
13+
#endif
14+
15+
QIR_SHARED_API void* CreateBasicRuntimeDriver();
16+
17+
#ifdef __cplusplus
18+
} // extern "C"
19+
#endif
20+
21+
#endif // #ifndef BASICRUNTIMEDRIVERFACTORY_H

0 commit comments

Comments
 (0)