Quantum Phenomena Explorer 7.9.8
Interactive quantum-phenomena Explorer Tutor — source documentation
Loading...
Searching...
No Matches
quantumlandauzenerplotwidget.cpp
Go to the documentation of this file.
1/**
2 * @file quantumlandauzenerplotwidget.cpp
3 * @brief Implements the quantumlandauzenerplotwidget visualization component used by QPE.
4 * @ingroup qpe_graphics
5 *
6 * Source: @c graphics/renderer/quantumlandauzenerplotwidget.cpp. This file is part of Quantum Phenomena Explorer (QPE),
7 * maintained by Officina Turini. See LICENSE_IT.txt / LICENSE.txt for the
8 * QPE freeware source-available terms and THIRD_PARTY_NOTICES.txt for
9 * third-party components.
10 */
11
13
14#include <QPaintEvent>
15#include <QPainter>
16#include <QPainterPath>
17
18#include <algorithm>
19#include <cmath>
20
22 : QWidget(parent)
23{
24 setMinimumHeight(220);
25 setAutoFillBackground(false);
26}
27
29 const std::vector<qpe::ObservablesTimeSeries2DSample> &samples)
30{
31 samples_ = samples;
32 update();
33}
34
36{
37 theory_ = theory;
38 update();
39}
40
42{
43 sweep_ = sweep;
44 update();
45}
46
54
56{
57 return QSize(520, 220);
58}
59
61{
62 Q_UNUSED(event);
63 QPainter painter(this);
64 painter.setRenderHint(QPainter::Antialiasing, true);
65 painter.setRenderHint(QPainter::TextAntialiasing, true);
66 painter.fillRect(rect(), QColor(15, 18, 23));
67
68 const QRectF probRect(58.0, 28.0,
69 std::max(10.0, width() - 80.0),
70 std::max(80.0, height() - 108.0));
71 const QRectF biasRect(probRect.left(), probRect.bottom() + 18.0,
72 probRect.width(), 34.0);
73
74 double tMin = 0.0;
75 double tMax = sweep_.enabled ? sweep_.startTime + sweep_.duration : 1.0;
76 bool haveSamples = false;
77 for (const qpe::ObservablesTimeSeries2DSample &sample : samples_) {
78 if (!sample.hasLandauZener) continue;
79 if (!haveSamples) tMin = std::min(0.0, sample.time);
80 tMax = std::max(tMax, sample.time);
81 haveSamples = true;
82 }
83 if (!(tMax > tMin)) tMax = tMin + 1.0;
84
85 const auto mapX = [probRect, tMin, tMax](double t) {
86 return probRect.left() + (t - tMin) / (tMax - tMin) * probRect.width();
87 };
88 const auto mapP = [probRect](double p) {
89 const double q = std::max(0.0, std::min(1.0, p));
90 return probRect.bottom() - q * probRect.height();
91 };
92
93 painter.setPen(QPen(QColor(75, 84, 94), 1.0));
94 for (int i = 0; i <= 4; ++i) {
95 const double u = static_cast<double>(i) / 4.0;
96 painter.drawLine(QPointF(probRect.left() + u * probRect.width(), probRect.top()),
97 QPointF(probRect.left() + u * probRect.width(), probRect.bottom()));
98 painter.drawLine(QPointF(probRect.left(), probRect.top() + u * probRect.height()),
99 QPointF(probRect.right(), probRect.top() + u * probRect.height()));
100 }
101 painter.setPen(QPen(QColor(170, 180, 190), 1.0));
102 painter.drawRect(probRect);
103
104 if (theory_.valid && theory_.crossingTime >= tMin && theory_.crossingTime <= tMax) {
105 painter.setPen(QPen(QColor(210, 210, 220, 120), 1.0, Qt::DashDotLine));
106 painter.drawLine(QPointF(mapX(theory_.crossingTime), probRect.top()),
107 QPointF(mapX(theory_.crossingTime), biasRect.bottom()));
108 }
109
110 QPainterPath lowerPath;
111 QPainterPath upperPath;
112 QPainterPath leftPath;
113 QPainterPath rightPath;
114 QPainterPath capturedPath;
115 bool first = true;
116 for (const qpe::ObservablesTimeSeries2DSample &sample : samples_) {
117 if (!sample.hasLandauZener) continue;
118 const QPointF lower(mapX(sample.time), mapP(sample.landauZenerLowerPopulation));
119 const QPointF upper(mapX(sample.time), mapP(sample.landauZenerUpperPopulation));
120 const QPointF left(mapX(sample.time), mapP(sample.landauZenerLeftPopulation));
121 const QPointF right(mapX(sample.time), mapP(sample.landauZenerRightPopulation));
122 const QPointF captured(mapX(sample.time), mapP(sample.landauZenerCapturedPopulation));
123 if (first) {
124 lowerPath.moveTo(lower);
125 upperPath.moveTo(upper);
126 leftPath.moveTo(left);
127 rightPath.moveTo(right);
128 capturedPath.moveTo(captured);
129 first = false;
130 } else {
131 lowerPath.lineTo(lower);
132 upperPath.lineTo(upper);
133 leftPath.lineTo(left);
134 rightPath.lineTo(right);
135 capturedPath.lineTo(captured);
136 }
137 }
138
139 if (!first) {
140 painter.setPen(QPen(QColor(105, 220, 255), 2.3));
141 painter.drawPath(lowerPath);
142 painter.setPen(QPen(QColor(255, 165, 100), 2.1));
143 painter.drawPath(upperPath);
144 painter.setPen(QPen(QColor(120, 235, 150, 180), 1.5, Qt::DashLine));
145 painter.drawPath(leftPath);
146 painter.setPen(QPen(QColor(225, 135, 245, 180), 1.5, Qt::DashLine));
147 painter.drawPath(rightPath);
148 painter.setPen(QPen(QColor(185, 190, 200), 1.0, Qt::DotLine));
149 painter.drawPath(capturedPath);
150 } else {
151 painter.setPen(QColor(190, 195, 205));
152 painter.drawText(probRect, Qt::AlignCenter,
153 QStringLiteral("Load a Landau-Zener sweep preset and press Play"));
154 }
155
156 painter.setPen(QPen(QColor(80, 88, 98), 1.0));
157 painter.drawRect(biasRect);
158 const double maxBias = std::max(1.0e-12,
159 std::max(std::abs(sweep_.startValue), std::abs(sweep_.endValue)));
160 const auto mapBiasY = [biasRect, maxBias](double value) {
161 const double q = std::max(-1.0, std::min(1.0, value / maxBias));
162 return biasRect.center().y() - 0.45 * q * biasRect.height();
163 };
164 painter.setPen(QPen(QColor(105, 115, 125), 1.0, Qt::DashLine));
165 painter.drawLine(QPointF(biasRect.left(), biasRect.center().y()),
166 QPointF(biasRect.right(), biasRect.center().y()));
167 if (sweep_.enabled) {
168 QPainterPath biasPath;
169 const int segments = 240;
170 for (int i = 0; i <= segments; ++i) {
171 const double t = tMin + (tMax - tMin) * static_cast<double>(i) /
172 static_cast<double>(segments);
173 const double value = qpe::TimeDependentPotential2D::sweepValue(sweep_, t);
174 const QPointF point(mapX(t), mapBiasY(value));
175 if (i == 0) biasPath.moveTo(point); else biasPath.lineTo(point);
176 }
177 painter.setPen(QPen(QColor(240, 215, 105), 1.8));
178 painter.drawPath(biasPath);
179 }
180
181 painter.setPen(QColor(210, 215, 222));
182 painter.drawText(QRectF(probRect.left(), 2.0, probRect.width(), 22.0),
183 Qt::AlignCenter,
184 QStringLiteral("Landau-Zener sweep: adiabatic and localized populations"));
185 painter.setPen(QColor(160, 168, 178));
186 painter.drawText(QRectF(2.0, probRect.top() - 8.0, 52.0, 18.0),
187 Qt::AlignRight | Qt::AlignVCenter, QStringLiteral("1.0"));
188 painter.drawText(QRectF(2.0, probRect.bottom() - 10.0, 52.0, 18.0),
189 Qt::AlignRight | Qt::AlignVCenter, QStringLiteral("0.0"));
190 painter.drawText(QRectF(2.0, biasRect.top() + 6.0, 52.0, 18.0),
191 Qt::AlignRight | Qt::AlignVCenter, QStringLiteral("bias"));
192 painter.drawText(QRectF(probRect.left(), biasRect.bottom() + 3.0,
193 probRect.width(), 18.0),
194 Qt::AlignCenter, QStringLiteral("simulation time"));
195
196 painter.setPen(QColor(105, 220, 255));
197 painter.drawText(QRectF(probRect.left() + 8.0, probRect.top() + 4.0, 105.0, 18.0),
198 Qt::AlignLeft, QStringLiteral("P(lower)"));
199 painter.setPen(QColor(255, 165, 100));
200 painter.drawText(QRectF(probRect.left() + 92.0, probRect.top() + 4.0, 105.0, 18.0),
201 Qt::AlignLeft, QStringLiteral("P(upper)"));
202 painter.setPen(QColor(120, 235, 150));
203 painter.drawText(QRectF(probRect.left() + 176.0, probRect.top() + 4.0, 90.0, 18.0),
204 Qt::AlignLeft, QStringLiteral("P(left)"));
205 painter.setPen(QColor(225, 135, 245));
206 painter.drawText(QRectF(probRect.left() + 246.0, probRect.top() + 4.0, 95.0, 18.0),
207 Qt::AlignLeft, QStringLiteral("P(right)"));
208}
QSize minimumSizeHint() const override
Performs minimum size hint.
void setSamples(const std::vector< qpe::ObservablesTimeSeries2DSample > &samples)
Sets samples.
void paintEvent(QPaintEvent *event) override
Paints event.
std::vector< qpe::ObservablesTimeSeries2DSample > samples_
qpe::LinearPotentialSweep2DConfig sweep_
void setSweep(const qpe::LinearPotentialSweep2DConfig &sweep)
Sets sweep.
QuantumLandauZenerPlotWidget(QWidget *parent=nullptr)
Performs quantum landau zener plot widget.
void setTheory(const qpe::LandauZenerTheory2D &theory)
Sets theory.
static double sweepValue(const LinearPotentialSweep2DConfig &config, double time) noexcept
Performs sweep value.
Declares the quantumlandauzenerplotwidget visualization component used by QPE.
Data structure used by the Landau Zener Theory2D component.
Configuration values for Linear Potential Sweep2D Config.
Data record containing Observables Time Series2D Sample.