Quantum Phenomena Explorer 7.9.8
Interactive quantum-phenomena Explorer Tutor — source documentation
Loading...
Searching...
No Matches
quantumzeno2d_tests.cpp
Go to the documentation of this file.
1/**
2 * @file quantumzeno2d_tests.cpp
3 * @brief Implements regression and invariant tests for quantumzeno2d tests.
4 * @ingroup qpe_tests
5 *
6 * Source: @c tests/quantumzeno2d_tests.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
18
19#include <cmath>
20
21namespace qpe {
22namespace {
23
24/**
25 * @brief Performs near.
26 * @param a The a value used by the operation.
27 * @param b The b value used by the operation.
28 * @param tolerance The tolerance value used by the operation.
29 */
30bool near(double a, double b, double tolerance)
31{
32 return std::fabs(a - b) <= tolerance;
33}
34
35/**
36 * @brief Performs guided config.
37 */
39{
41 config.enabled = true;
42 config.firstMeasurementTime = 0.40;
43 config.measurementPeriod = 0.10;
44 config.laneSplitY = 0.0;
45 config.survivalBoundaryX = 0.40;
46 config.edgeWidth = 0.32;
47 return config;
48}
49
50/**
51 * @brief Performs guided initial.
52 */
54{
56 initial.centerX = -5.5;
57 initial.controlLaneY = 4.8;
58 initial.watchedLaneY = -4.8;
59 initial.sigma = 0.80;
60 initial.momentumX = 1.50;
61 return initial;
62}
63
64/**
65 * @brief Builds guided potential.
66 * @param potential Potential field used by the operation.
67 */
69{
70 const float fullWidth = 40.96f;
71 potential.addRectangle(0.0f, 0.0f, fullWidth, 0.64f, 120.0f);
72 potential.addRectangle(0.0f, 9.76f, fullWidth, 0.48f, 120.0f);
73 potential.addRectangle(0.0f, -9.76f, fullWidth, 0.48f, 120.0f);
74 potential.addRectangle(-9.0f, 4.8f, 0.64f, 8.60f, 120.0f);
75 potential.addRectangle(-9.0f, -4.8f, 0.64f, 8.60f, 120.0f);
76 potential.addRectangle(0.0f, 4.8f, 0.80f, 8.60f, 4.0f);
77 potential.addRectangle(0.0f, -4.8f, 0.80f, 8.60f, 4.0f);
78}
79
80/**
81 * @brief Performs test dual lane initialization.
82 */
84{
85 ComplexField2D field(128u, 128u, 0.32f, 0.16f);
87 const QuantumZeno2DConfig config = guidedConfig();
88 if (!QuantumZeno2D::initializeDualLane(field, initial, nullptr)) return false;
89 const double control = QuantumZeno2D::laneNorm(field, config, false);
90 const double watched = QuantumZeno2D::laneNorm(field, config, true);
91 return near(field.norm2(), 1.0, 3.0e-5) &&
92 near(control, 0.5, 2.0e-3) && near(watched, 0.5, 2.0e-3);
93}
94
95/**
96 * @brief Performs test measurement preserves control and renormalizes watched.
97 */
99{
100 ComplexField2D field(128u, 128u, 0.32f, 0.16f);
102 const QuantumZeno2DConfig config = guidedConfig();
103 if (!QuantumZeno2D::initializeDualLane(field, initial, nullptr)) return false;
104
105 const double controlBefore = QuantumZeno2D::laneNorm(field, config, false);
106 const double watchedTarget = QuantumZeno2D::laneNorm(field, config, true);
109 field, config, watchedTarget, result, nullptr)) return false;
110
111 const double controlAfter = QuantumZeno2D::laneNorm(field, config, false);
112 return result.valid && result.acceptanceProbability > 0.99 &&
113 near(controlBefore, controlAfter, 5.0e-6) &&
114 near(result.watchedNormAfterRenormalization, watchedTarget, 5.0e-5);
115}
116
117/**
118 * @brief Performs test watched escape suppression.
119 */
121{
122 ComplexField2D field(128u, 128u, 0.32f, 0.16f);
124 const QuantumZeno2DConfig config = guidedConfig();
125 if (!QuantumZeno2D::initializeDualLane(field, initial, nullptr)) return false;
126
127 PotentialField2D potential(128u, 128u, 0.32f, 0.16f);
128 buildGuidedPotential(potential);
129
131 params.mass = 1.0f;
132 params.hbar = 1.0f;
133 params.dt = 0.02f;
134 SplitStepFourierSolver2D solver(params);
135 solver.prepare(field);
136 solver.preparePotential(potential);
137
138 AbsorbingBoundary2D absorber;
140 boundary.enabled = true;
141 boundary.widthFraction = 0.12f;
142 boundary.strength = 5.0f;
143 boundary.exponent = 3.0f;
144 absorber.configure(field, params.dt, boundary);
145
146 const double targetWatched = QuantumZeno2D::laneNorm(field, config, true);
147 const double initialControl = QuantumZeno2D::laneNorm(field, config, false);
148 double cumulative = 1.0;
149 std::size_t measurementCount = 0u;
150
151 while (solver.time() < 15.0 - 1.0e-9) {
152 const double epsilon = 0.5 * static_cast<double>(params.dt) + 1.0e-9;
153 while (solver.time() + epsilon >=
154 QuantumZeno2D::scheduledMeasurementTime(config, measurementCount)) {
157 field, config, targetWatched, result, nullptr)) return false;
158 cumulative *= result.acceptanceProbability;
159 ++measurementCount;
160 }
161 solver.step(field, potential);
162 absorber.apply(field);
163 }
164
166 field, config, solver.time(), measurementCount, cumulative, initialControl);
167
168 // The watched ensemble should retain much more survival probability than
169 // the unmeasured control after the same tunnelling/escape time.
170 return measurementCount > 100u &&
171 sample.controlSurvival < 0.75 &&
172 sample.watchedCumulativeSurvival > 0.80 &&
173 sample.watchedCumulativeSurvival > sample.controlSurvival + 0.18 &&
174 sample.watchedConditionalAcceptance > 0.97 &&
175 sample.totalNorm > 0.70 && sample.totalNorm < 1.10;
176}
177
178} // namespace
179
181{
182 return testDualLaneInitialization() &&
183 testMeasurementPreservesControlAndRenormalizesWatched() &&
184 testWatchedEscapeSuppression();
185}
186
187} // namespace qpe
Declares the absorbingboundary2d physics/numerical component used by QPE experiments.
Precomputed smooth absorber for FFT domains that should behave as open.
void configure(const ComplexField2D &field, float dt, const AbsorbingBoundary2DParams &params)
Returns configure.
void apply(ComplexField2D &field) const
Performs apply.
Owning Cartesian grid of complex scalar samples.
double norm2() const noexcept
Returns the discrete integral of |psi|^2 including dx*dy.
Implements the Potential Field2D component.
void addRectangle(float centerX, float centerY, float width, float height, Value value)
Adds rectangle.
static bool runAll()
Runs all.
static QuantumZenoSample2D measure(const ComplexField2D &field, const QuantumZeno2DConfig &config, double time, std::size_t measurementCount, double watchedCumulativeSurvival, double initialControlLaneNorm) noexcept
Performs measure.
static bool initializeDualLane(ComplexField2D &field, const QuantumZenoInitialState2DConfig &config, std::string *reason=nullptr)
Initializes dual lane.
static double scheduledMeasurementTime(const QuantumZeno2DConfig &config, std::size_t measurementIndex) noexcept
Performs scheduled measurement time.
static double laneNorm(const ComplexField2D &field, const QuantumZeno2DConfig &config, bool watchedLane) noexcept
Performs lane norm.
static bool applySurvivalMeasurement(ComplexField2D &field, const QuantumZeno2DConfig &config, double targetWatchedLaneNorm, QuantumZenoMeasurementResult2D &result, std::string *reason=nullptr)
Applies survival measurement.
Symmetric split-step Fourier solver for the scalar 2D Schrodinger equation.
double time() const noexcept
Returns accumulated simulation time in solver units.
void preparePotential(const PotentialField2D &potential)
Precomputes the scalar-potential half-step phase cache.
void prepare(const ComplexField2D &field)
Precomputes spectral kinetic phase factors for a specific grid.
void step(ComplexField2D &field, const PotentialField2D &potential)
Advances the scalar wave function by one second-order Strang step.
bool testMeasurementPreservesControlAndRenormalizesWatched()
Performs test measurement preserves control and renormalizes watched.
QuantumZeno2DConfig guidedConfig()
Performs guided config.
bool testDualLaneInitialization()
Performs test dual lane initialization.
bool testWatchedEscapeSuppression()
Performs test watched escape suppression.
void buildGuidedPotential(PotentialField2D &potential)
Builds guided potential.
QuantumZenoInitialState2DConfig guidedInitial()
Performs guided initial.
Declares the potentialfield2d physics/numerical component used by QPE experiments.
Declares the quantumzeno2d physics/numerical component used by QPE experiments.
Declares regression and invariant tests for quantumzeno2d tests.
Declares the two-dimensional split-step Fourier propagator for the scalar Schrodinger branch.
Parameters controlling QPE's smooth complex absorbing boundary.
float strength
Dimensionless damping strength in the exponential mask.
bool enabled
Enables/disables damping while retaining the same API path.
float widthFraction
Fraction of each domain edge occupied by the absorbing layer.
float exponent
Smoothness exponent controlling how damping rises toward the edge.
Configuration values for Quantum Zeno2D Config.
Configuration values for Quantum Zeno Initial State2D Config.
Data structure used by the Quantum Zeno Measurement Result2D component.
Data structure used by the Quantum Zeno Sample2D component.
Physical/numerical parameters for scalar split-step propagation.
float hbar
Reduced Planck constant in simulation units.
float dt
Propagation step in simulation time units.
float mass
Particle/effective mass in simulation units.