11#include "ns3/nstime.h"
12#include "ns3/q2nsviz-trace-writer.h"
13#include <initializer_list>
40template <
typename... Ts>
inline std::string
StrCat(Ts&&... parts) {
41 std::ostringstream _oss;
42 (void) std::initializer_list<int>{((_oss << std::forward<Ts>(parts)), 0)...};
47 return ns3::Simulator::Now().GetNanoSeconds();
57 <<
"\"type\":\"createNode\",\"t_ns\":0,"
58 <<
"\"label\":" <<
J(label) <<
",\"x\":" << xPct <<
",\"y\":" << yPct <<
"}";
63 const std::string& kind) {
66 <<
"\"type\":\"createChannel\",\"t_ns\":0,"
67 <<
"\"from\":" <<
J(from) <<
",\"to\":" <<
J(to) <<
",\"kind\":" <<
J(kind) <<
"}";
77 <<
"\"type\":\"createQubit\",\"t_ns\":" <<
JTns() <<
",\"node\":" <<
J(node)
78 <<
",\"label\":" <<
J(bitLabel) <<
"}";
85inline void TraceCreateCbit(
const std::string& node,
const std::string& bitLabel) {
88 <<
"\"type\":\"createCbit\",\"t_ns\":" <<
JTns() <<
",\"node\":" <<
J(node)
89 <<
",\"label\":" <<
J(bitLabel) <<
"}";
96 <<
"\"type\":\"removeCbit\","
97 <<
"\"t_ns\":" << t_ns <<
",\"bit\":" <<
J(bitLabel) <<
"}";
105 std::ostringstream o;
107 <<
"\"type\":\"entangle\",\"t_ns\":" <<
JTns() <<
",\"bits\":[";
108 for (
size_t i = 0; i < bits.size(); ++i) {
119inline void TraceEntangle(
const std::vector<std::string>& bits, uint64_t duration_ns) {
120 std::ostringstream o;
122 <<
"\"type\":\"entangle\",\"t_ns\":" <<
JTns() <<
",\"duration_ns\":" << duration_ns
124 for (
size_t i = 0; i < bits.size(); ++i) {
132inline void TraceEntangle(
const std::vector<std::string>& bits, ns3::Time duration) {
138inline void TraceMeasure(
const std::string& bitLabel,
const std::string& base =
"Z") {
139 std::ostringstream o;
141 <<
"\"type\":\"measure\",\"t_ns\":" <<
JTns() <<
",\"bit\":" <<
J(bitLabel)
142 <<
",\"base\":" <<
J(base) <<
"}";
148inline void TraceMeasure(
const std::string& bitLabel, uint64_t duration_ns,
149 const std::string& base =
"Z") {
150 std::ostringstream o;
152 <<
"\"type\":\"measure\",\"t_ns\":" <<
JTns() <<
",\"duration_ns\":" << duration_ns
153 <<
",\"bit\":" <<
J(bitLabel) <<
",\"base\":" <<
J(base) <<
"}";
156inline void TraceMeasure(
const std::string& bitLabel, ns3::Time duration,
157 const std::string& base =
"Z") {
158 TraceMeasure(bitLabel, duration.GetNanoSeconds(), base);
163 const std::string& supportNode =
"") {
164 std::ostringstream o;
166 <<
"\"type\":\"graphMeasure\",\"t_ns\":" <<
JTns() <<
",\"bit\":" <<
J(bitLabel)
167 <<
",\"base\":" <<
J(base);
168 if (!supportNode.empty()) {
169 o <<
",\"supportNode\":" <<
J(supportNode);
178 const std::string& base =
"Z",
179 const std::string& supportNode =
"") {
180 std::ostringstream o;
182 <<
"\"type\":\"graphMeasure\",\"t_ns\":" <<
JTns() <<
",\"duration_ns\":" << duration_ns
183 <<
",\"bit\":" <<
J(bitLabel) <<
",\"base\":" <<
J(base);
184 if (!supportNode.empty()) {
185 o <<
",\"supportNode\":" <<
J(supportNode);
191 const std::string& base =
"Z",
192 const std::string& supportNode =
"") {
197 const std::string& reason =
"discarded",
198 uint64_t t_ns =
NowNs()) {
199 std::ostringstream o;
201 <<
"\"type\":\"removeQubit\","
202 <<
"\"t_ns\":" << t_ns <<
",\"bit\":" <<
J(bitLabel)
203 <<
",\"reason\":" <<
J(reason) <<
"}";
212 const std::string& to, uint64_t t0_ns, uint64_t t1_ns) {
213 std::ostringstream o;
215 <<
"\"type\":\"sendQubit\",\"t0_ns\":" << t0_ns <<
",\"t1_ns\":" << t1_ns
216 <<
",\"bit\":" <<
J(bitLabel) <<
",\"from\":" <<
J(from) <<
",\"to\":" <<
J(to) <<
"}";
220 const std::string& to, ns3::Time t0, ns3::Time t1) {
221 TraceSendQubit(bitLabel, from, to, t0.GetNanoSeconds(), t1.GetNanoSeconds());
224inline void TraceSendCbit(
const std::string& bitLabel,
const std::string& from,
225 const std::string& to, uint64_t t0_ns, uint64_t t1_ns) {
226 std::ostringstream o;
228 <<
"\"type\":\"sendCbit\",\"t0_ns\":" << t0_ns <<
",\"t1_ns\":" << t1_ns
229 <<
",\"bit\":" <<
J(bitLabel) <<
",\"from\":" <<
J(from) <<
",\"to\":" <<
J(to) <<
"}";
232inline void TraceSendCbit(
const std::string& bitLabel,
const std::string& from,
233 const std::string& to, ns3::Time t0, ns3::Time t1) {
234 TraceSendCbit(bitLabel, from, to, t0.GetNanoSeconds(), t1.GetNanoSeconds());
237inline void TraceSendPacket(
const std::string& from,
const std::string& to, uint64_t t0_ns,
238 uint64_t t1_ns,
const std::string& label,
239 const std::string& protocol =
"") {
240 std::ostringstream o;
242 <<
"\"type\":\"sendPacket\",\"t0_ns\":" << t0_ns <<
",\"t1_ns\":" << t1_ns
243 <<
",\"from\":" <<
J(from) <<
",\"to\":" <<
J(to) <<
",\"label\":" <<
J(label);
244 if (!protocol.empty()) { o <<
",\"protocol\":" <<
J(protocol); }
248inline void TraceSendPacket(
const std::string& from,
const std::string& to, ns3::Time t0,
249 ns3::Time t1,
const std::string& label,
250 const std::string& protocol =
"") {
251 TraceSendPacket(from, to, t0.GetNanoSeconds(), t1.GetNanoSeconds(), label, protocol);
258 std::ostringstream o;
260 <<
"\"type\":\"traceText\",\"t_ns\":" <<
JTns() <<
",\"text\":" <<
J(text) <<
"}";
264inline void Trace(
const std::string& text) {
268template <
typename... Ts>
inline void Trace(Ts&&... parts) {
273 std::ostringstream o;
275 <<
"\"type\":\"traceText\",\"t_ns\":" <<
JTns() <<
",\"node\":" <<
J(node)
276 <<
",\"text\":" <<
J(text) <<
"}";
280inline void TraceNodeText(
const std::string& node,
const std::string& text) {
284template <
typename... Ts>
inline void TraceNodeText(
const std::string& node, Ts&&... parts) {
static TraceWriter & Instance()
void Write(const std::string &line)
std::string J(const std::string &s)
void TraceRemoveQubit(const std::string &bitLabel, const std::string &reason="discarded", uint64_t t_ns=NowNs())
std::string StrCat(Ts &&... parts)
void TraceSendCbit(const std::string &bitLabel, const std::string &from, const std::string &to, uint64_t t0_ns, uint64_t t1_ns)
void Trace(const std::string &text)
void TraceSendQubit(const std::string &bitLabel, const std::string &from, const std::string &to, uint64_t t0_ns, uint64_t t1_ns)
void TraceCreateQubit(const std::string &node, const std::string &bitLabel)
void TraceNodeText(const std::string &node, const std::string &text)
void TraceEntangle(const std::vector< std::string > &bits)
void TraceRemoveCbit(const std::string &bitLabel, uint64_t t_ns=NowNs())
void TraceMeasure(const std::string &bitLabel, const std::string &base="Z")
void TraceGraphMeasure(const std::string &bitLabel, const std::string &base="Z", const std::string &supportNode="")
void TraceCreateCbit(const std::string &node, const std::string &bitLabel)
void TraceCreateNode(const std::string &label, int xPct, int yPct)
void TraceCreateChannel(const std::string &from, const std::string &to, const std::string &kind)
void _TraceString(const std::string &text)
void _TraceNodeTextString(const std::string &node, const std::string &text)
void TraceSendPacket(const std::string &from, const std::string &to, uint64_t t0_ns, uint64_t t1_ns, const std::string &label, const std::string &protocol="")