Quantum Resource Manager and Compiler Infrastructure (QRM&CI) 0.1.0
Daemon.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2026 MQSS Maintainers
3 * All rights reserved.
4 *
5 * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 */
7
12
13#pragma once
14
16#include "qrmci/Config.h"
17#include "qrmci/Error.h"
19#include "scheduler/scheduler.hpp"
20
21#include <MQSSCIInterfaces/MQSSCompiler.h>
22#include <atomic>
23#include <csignal>
24#include <expected>
25#include <mqss/submitter/Device.h>
26#include <optional>
27#include <string_view>
28
29namespace mqss::qrmci {
30
33using TaskScheduler = mqss::scheduler::Scheduler<mqss::QuantumTask>;
34
39inline constinit std::atomic<bool> terminationRequested{false};
40static_assert(std::atomic<bool>::is_always_lock_free);
41
46 const auto handler = [](int signal) {
47 if (signal == SIGINT || signal == SIGTERM) {
48 terminationRequested.store(true, std::memory_order_relaxed);
49 }
50 };
51 std::signal(SIGINT, handler);
52 std::signal(SIGTERM, handler);
53}
54
62[[nodiscard]] std::expected<Config, Error> initializeDaemon();
63
73[[nodiscard]] std::expected<mqss::submitter::Device, Error>
75
86[[nodiscard]] std::expected<void, Error>
87registerOwnDevice(const mqss::submitter::Device &device,
88 BackendRegistry &backends,
89 std::string_view dispatchQueue = "");
90
108std::optional<mqss::Backend>
109refreshOwnDeviceStatus(const mqss::submitter::Device &device,
110 BackendRegistry &backends, PublicationThrottle &throttle,
111 std::string_view dispatchQueue = "");
112
116
129[[nodiscard]] std::expected<void, Error> selectCompileAndSchedule(
130 mqss::QuantumTask &task, const BackendRegistry &backends,
131 mqss::mqssci::MQSSCompiler &compiler, TaskScheduler &scheduler,
133
145[[nodiscard]] std::expected<void, Error>
146compileAndSchedule(mqss::QuantumTask &task, const BackendRegistry &backends,
147 mqss::mqssci::MQSSCompiler &compiler,
148 TaskScheduler &scheduler);
149
150} // namespace mqss::qrmci
The set of backends a QRM&CI process may schedule onto, and the time-to-live after which an entry nob...
BackendSelectionPolicy
Named rule deciding which backend wins when several of them could run the same task.
@ LowestName
The compatible backend whose name sorts first.
The runtime configuration model shared by every QRM&CI daemon.
std::expected< void, Error > selectCompileAndSchedule(mqss::QuantumTask &task, const BackendRegistry &backends, mqss::mqssci::MQSSCompiler &compiler, TaskScheduler &scheduler, BackendSelectionPolicy policy=BackendSelectionPolicy::LowestName)
Select a backend for task, compile it for that backend, and hand it to scheduler.
std::expected< void, Error > registerOwnDevice(const mqss::submitter::Device &device, BackendRegistry &backends, std::string_view dispatchQueue="")
Read this process's own device and register it, so the daemon has a backend to schedule onto before i...
void logRegisteredBackends(const BackendRegistry &backends)
Log every registered backend and its capabilities at info level.
std::expected< void, Error > compileAndSchedule(mqss::QuantumTask &task, const BackendRegistry &backends, mqss::mqssci::MQSSCompiler &compiler, TaskScheduler &scheduler)
Compile task for the backend it was already assigned and hand it to scheduler.
void installTerminationHandlers()
Register SIGINT and SIGTERM handlers that set terminationRequested.
Definition Daemon.h:45
std::expected< Config, Error > initializeDaemon()
Bring a daemon process up: install the SIGINT/SIGTERM handlers, assemble the configuration,...
std::expected< mqss::submitter::Device, Error > openConfiguredDevice(const SubmitterConfig &config)
Open the QDMI device config names.
mqss::scheduler::Scheduler< mqss::QuantumTask > TaskScheduler
The scheduler every daemon that submits work runs its tasks through.
Definition Daemon.h:33
constinit std::atomic< bool > terminationRequested
Set to true once SIGINT or SIGTERM has been received.
Definition Daemon.h:39
std::optional< mqss::Backend > refreshOwnDeviceStatus(const mqss::submitter::Device &device, BackendRegistry &backends, PublicationThrottle &throttle, std::string_view dispatchQueue="")
Re-read this process's own device and refresh its registry entry, if throttle has a publish slot due.
The error type every std::expected in QRM&CI's public interfaces carries.
Paces how often a device-owning process re-reads and publishes its own status, independently of how f...
Owns the backends a process knows about, keyed by backend name.
Claims at most one status-publication slot per configured interval.
Submitter-specific configuration: its own queue/logging, QDMI credentials and device selection,...
Definition Config.h:114