Namespace qir¶
-
namespace qir¶
Enums
-
enum class Execution¶
Whether the JIT’d program runs to produce measurement samples or to leave the final quantum state in qir::Runtime for external extraction.
In
StateExtractionmode the session strips QIR measurement and result-management calls from the IR before JIT-compiling, so the runtime’s quantum state remains intact aftermainreturns. Intended for QIR Base Profile programs only.Values:
-
enumerator Sampling¶
-
enumerator StateExtraction¶
-
enumerator Sampling¶
Functions
-
std::size_t stripMeasurementRelatedCalls(llvm::Module &m)¶
Strips QIR measurement-related calls from
min place.Erases calls to the QIR measurement intrinsics, to the result-recording intrinsic, and to the result reference-count update intrinsic (whose Result operands would otherwise reference the null pointers left by the stripped measurements). Intended for QIR Base Profile programs only: in Adaptive Profile programs, measurement results feed classical control flow, so removing them silently changes observable behavior.
The typical use is to prepare a Base Profile module for state-vector extraction: after this transform the JIT’d
maincan be run once and the resulting state remains in the qir::Runtime DD instead of being collapsed by measurement.- Parameters:
m – Module to rewrite in place.
- Returns:
Number of instructions erased.
Variables
-
constexpr std::array<llvm::StringRef, 5> STRIP_TARGETS = {"__quantum__qis__mz__body", "__quantum__qis__m__body", "__quantum__qis__measure__body", "__quantum__rt__result_record_output", "__quantum__rt__result_update_reference_count",}¶
The set of call targets that stripMeasurementRelatedCalls erases.
-
template<typename T>
static constexpr bool IS_STD_ARRAY_V = false¶
-
template<typename T, typename ...Args>
static constexpr size_t SIZE_OF_PACK_OF_TYPE_V = SizeOfPackOfType<T, Args...>::VALUE¶
-
template<template<typename, typename...> class V, typename T, typename ...Args>
static constexpr size_t SKIP_UNTIL_TYPE_V = SkipUntilType<V, T, Args...>::VALUE¶
-
class JitSession¶
- #include <Session.hpp>
In-process JIT executor for QIR programs.
The session does the following, in order:
Loads an LLVM module from either an IR file (text or bitcode) or an in-memory buffer,
JIT-compiles it via LLVM’s OrcJIT with lazy compilation.
wires up the QIR runtime symbols, and
runs the module’s
mainfunction. A session owns a single LLJIT instance and is not meant to be reused across modules; create a new JitSession for each program.
Public Types
-
using MainFn = int(int, char**)¶
Signature of the
mainfunction produced by QIR-compiled modules.
Public Functions
-
explicit JitSession(llvm::StringRef inputFile, Execution mode = Execution::Sampling)¶
Build a session by loading IR from a file on disk.
- Parameters:
inputFile – Path to a textual IR or bitcode file.
mode – Execution mode; see Execution.
- Throws:
std::runtime_error – if the file cannot be parsed or the JIT fails to initialize.
-
JitSession(llvm::StringRef irBytes, llvm::StringRef bufferName, Execution mode = Execution::Sampling)¶
Build a session by loading IR from a memory buffer.
Accepts either textual IR or bitcode. The buffer does not have to be null-terminated.
- Parameters:
irBytes – Byte view of the IR.
bufferName – Identifier used in diagnostics.
mode – Execution mode; see Execution.
- Throws:
std::runtime_error – if the IR cannot be parsed or the JIT fails to initialize.
-
~JitSession()¶
Tears down the LLJIT and any JIT’d resources owned by the session.
-
int run(llvm::ArrayRef<std::string> args = {}, llvm::StringRef progName = "") const¶
Executes the JIT’d
mainfunction.- Parameters:
args – Argument strings passed as
argv(excludingargv[0]).progName – Value used as
argv[0].
- Returns:
The integer returned by the JIT’d
main.
-
class Runtime¶
- #include <Runtime.hpp>
Note
This class is implemented following the design pattern Singleton in order to access an instance of this class from the C function without having a handle to it.
Public Functions
-
auto recordOutput(Result *result) -> void¶
Append the value referenced by
resultto the recorded outputs bit string in record order.
-
auto getRecordedOutputs() const -> const std::string&¶
- Returns:
the outputs declared by the program as a bit string in record order.
-
auto takeState() -> QState¶
Move the quantum state out of the runtime. Then reset the runtime to a clean state ready for the next job. Intended for use after a
JitSessionconstructed withExecution::StateExtractionhas finished running.- Returns:
the moved
QStatefrom the runtime.
-
struct QState¶
- #include <Runtime.hpp>
The quantum state held by the runtime:
a DD package,
the root edge into that package, and
the number of qubits the state spans.
Public Functions
-
inline auto reset() -> void¶
Reset to a fresh empty state. If
ddis currently populated, the existing package’sdecRefplusgarbageCollectpath is used so the package (and its internal caches) is kept warm. Ifddwas moved out (e.g. by Runtime::takeState), a new package is allocated.
-
auto recordOutput(Result *result) -> void¶
-
template<typename T, typename ...Args>
struct SizeOfPackOfType¶
-
template<template<typename, typename...> class V, typename T, typename ...Args>
struct SkipUntilType¶
-
template<template<typename, typename...> class V, typename T, typename ...Args>
struct SkipUntilType<V, T, T, Args...>¶
-
template<template<typename, typename...> class V, typename T, typename U, typename ...Args>
struct SkipUntilType<V, T, U, Args...>¶
-
class Utils¶
-
enum class Execution¶