Q2NS dev
ns-3 module
Loading...
Searching...
No Matches
q2ns-types.h
Go to the documentation of this file.
1/*-----------------------------------------------------------------------------
2 * Q2NS - Quantum Network Simulator
3 * Copyright (c) 2026 quantuminternet.it
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation.
8 *---------------------------------------------------------------------------*/
9/**
10 * @file q2ns-types.h
11 * @brief Common types, enums, and small helpers shared across q2ns.
12 */
13
14#pragma once
15
16#include <Eigen/Dense>
17
18#include <complex>
19#include <cstddef>
20#include <cstdint>
21#include <functional>
22#include <memory>
23#include <string_view>
24#include <vector>
25
26#include "ns3/callback.h"
27
28namespace q2ns {
29
30class QNode;
31class Qubit;
32
33/**
34 * @ingroup q2ns_core
35 * @brief Complex scalar type used by matrix-based backends.
36 */
37using Complex = std::complex<double>;
38
39/**
40 * @ingroup q2ns_core
41 * @brief Dynamic complex matrix type used for custom gates and matrix-based states.
42 */
43using Matrix = Eigen::MatrixXcd;
44
45/**
46 * @ingroup q2ns_core
47 * @brief Generic qubit index type within a backend state.
48 */
49using Index = std::size_t;
50
51/**
52 * @ingroup q2ns_core
53 * @brief Stable identifier for a registered backend state.
54 */
55using StateId = std::uint64_t;
56
57/**
58 * @ingroup q2ns_core
59 * @brief Stable identifier for a registered qubit handle.
60 */
61using QubitId = std::uint64_t;
62
63/**
64 * @ingroup q2ns_core
65 * @brief Per-transmission quantum map callable applied to a received qubit.
66 *
67 * QMapInstance objects are typically produced by QMap::Sample() during channel
68 * transmission and later executed at the receiving node after the qubit becomes
69 * local there.
70 */
71using QMapInstance = std::function<void(QNode&, std::shared_ptr<Qubit>&)>;
72
73/**
74 * @ingroup q2ns_core
75 * @brief Callback invoked when a qubit is successfully received at a node.
76 *
77 * The callback is executed after the qubit has been adopted by the receiving
78 * node and any QMapInstance associated with the transmission has been applied.
79 *
80 * @param qubit Received qubit handle.
81 */
82using RecvCallback = ns3::Callback<void, std::shared_ptr<Qubit>>;
83
84/**
85 * @ingroup q2ns_core
86 * @brief Measurement basis for single-qubit projective measurement.
87 */
88enum class Basis { Z, X, Y };
89
90/**
91 * @ingroup q2ns_core
92 * @brief Backend family used when creating new quantum states.
93 */
94enum class QStateBackend {
95 Ket, //!< State-vector backend.
96 DM, //!< Density-matrix backend.
97 Stab //!< Stabilizer backend.
98};
99
100/**
101 * @ingroup q2ns_core
102 * @brief Parse a backend name string.
103 *
104 * Unrecognized names fall back to QStateBackend::Ket.
105 *
106 * @param s Backend name string.
107 * @return Corresponding backend enum value.
108 */
109QStateBackend BackendFromString(std::string_view s);
110
111/**
112 * @ingroup q2ns_core
113 * @brief Return all supported backend enum values.
114 * @return Vector containing all supported backend types.
115 */
116inline std::vector<QStateBackend> AllQStateBackends() {
118}
119
120/**
121 * @ingroup q2ns_core
122 * @brief Kind of simulated qubit location.
123 */
124enum class LocationType {
125 Node, //!< Qubit is local to a node identified by node id.
126 Channel, //!< Qubit is in transit on a channel identified by channel id.
127 Lost, //!< Qubit was lost and is no longer accessible.
128 Unset //!< Qubit location has not yet been assigned.
129};
130
131/**
132 * @ingroup q2ns_core
133 * @struct Location
134 * @brief Current tracked location of a qubit.
135 */
136struct Location {
137 /**
138 * @brief Kind of location.
139 */
141
142 /**
143 * @brief Owning object identifier.
144 *
145 * This is a node id when type is Node, a channel id when type is Channel,
146 * and otherwise has no required meaning.
147 */
148 uint32_t ownerId = 0;
149};
150
151/**
152 * @ingroup q2ns_core
153 * @brief Construct an Unset location value.
154 * @return Location with type LocationType::Unset.
155 */
157 Location loc;
159 return loc;
160}
161
162} // namespace q2ns
Main user-facing per-node API for quantum operations and transmission.
Definition q2ns-qnode.h:63
std::vector< QStateBackend > AllQStateBackends()
Return all supported backend enum values.
Definition q2ns-types.h:116
ns3::Callback< void, std::shared_ptr< Qubit > > RecvCallback
Callback invoked when a qubit is successfully received at a node.
Definition q2ns-types.h:82
std::uint64_t QubitId
Stable identifier for a registered qubit handle.
Definition q2ns-types.h:61
std::complex< double > Complex
Complex scalar type used by matrix-based backends.
Definition q2ns-types.h:37
Eigen::MatrixXcd Matrix
Dynamic complex matrix type used for custom gates and matrix-based states.
Definition q2ns-types.h:43
std::uint64_t StateId
Stable identifier for a registered backend state.
Definition q2ns-types.h:55
Basis
Measurement basis for single-qubit projective measurement.
Definition q2ns-types.h:88
std::function< void(QNode &, std::shared_ptr< Qubit > &)> QMapInstance
Per-transmission quantum map callable applied to a received qubit.
Definition q2ns-types.h:71
LocationType
Kind of simulated qubit location.
Definition q2ns-types.h:124
Location MakeUnsetLocation()
Construct an Unset location value.
Definition q2ns-types.h:156
QStateBackend BackendFromString(std::string_view s)
Convert a backend name string to a QStateBackend enum value.
std::size_t Index
Generic qubit index type within a backend state.
Definition q2ns-types.h:49
QStateBackend
Backend family used when creating new quantum states.
Definition q2ns-types.h:94
@ Node
Qubit is local to a node identified by node id.
@ Channel
Qubit is in transit on a channel identified by channel id.
@ Lost
Qubit was lost and is no longer accessible.
@ Unset
Qubit location has not yet been assigned.
@ DM
Density-matrix backend.
@ Stab
Stabilizer backend.
@ Ket
State-vector backend.
Current tracked location of a qubit.
Definition q2ns-types.h:136
LocationType type
Kind of location.
Definition q2ns-types.h:140
uint32_t ownerId
Owning object identifier.
Definition q2ns-types.h:148