.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "api/gallery/quantum/wave_packets/plot_quantum_revivals.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr_api_gallery_quantum_wave_packets_plot_quantum_revivals.py: Wave-packet revivals in the infinite square well =================================================== A wavepacket built from the levels of an infinite square well of width :math:`L`, :math:`E_n=n^2\pi^2\hbar^2/(2mL^2)`, disperses within a few bounces into an apparently random mess. Parker and Stroud (1986) predicted, and Yeazell, Mallalieu and Stroud (1990) observed in Rydberg atoms, that it is only dephased: because the levels grow exactly as :math:`n^2`, every phase :math:`e^{-iE_nt/\hbar}` returns to its starting value at the revival time .. math:: t_\text{rev} = \frac{4mL^2}{\pi\hbar}, and the packet reassembles. A mirror image appears at :math:`t_\text{rev}/2`, and smaller copies (fractional revivals, Averbukh and Perelman 1989) at other rational fractions. This example evolves a packet with :class:`~physicskit.quantum.chapters.wave_packets.QuantumRevival`, tracks its fidelity to the initial state, and draws the full space-time "quantum carpet". .. GENERATED FROM PYTHON SOURCE LINES 25-31 .. code-block:: Python import matplotlib.pyplot as plt import numpy as np from physicskit.quantum.chapters.wave_packets import QuantumRevival .. GENERATED FROM PYTHON SOURCE LINES 32-34 Collapse and revival ------------------------ .. GENERATED FROM PYTHON SOURCE LINES 34-58 .. code-block:: Python qr = QuantumRevival(L=1.0, n_max=300) x = np.linspace(0, qr.L, 1500) psi0_func = qr.gaussian_initial_state(x0=0.3, sigma=0.03) psi0 = psi0_func(x) coeffs = qr.eigenbasis_coefficients(psi0_func) t_rev = qr.revival_time fractions = [0.0, 0.05, 0.25, 0.5, 1.0] fig, ax = plt.subplots(figsize=(7, 5)) offset = 0 for frac in fractions: density = np.abs(qr.wavefunction(x, frac * t_rev, coeffs)) ** 2 ax.plot(x, density + offset, label=f"t = {frac:.2f} t_rev") offset += density.max() * 1.3 fid = qr.fidelity_to_initial(x, frac * t_rev, coeffs, psi0) print(f"fidelity to initial state at t = {frac:.2f} t_rev: {fid:.4f}") ax.axvline(0.0, color="black", lw=1.2) ax.axvline(qr.L, color="black", lw=1.2) ax.set_xlabel("x") ax.set_yticks([]) ax.set_title("Spread out, then rebuilt: snapshots (offset vertically)") ax.legend(fontsize=8) fig.tight_layout() .. image-sg:: /api/gallery/quantum/wave_packets/images/sphx_glr_plot_quantum_revivals_001.png :alt: Spread out, then rebuilt: snapshots (offset vertically) :srcset: /api/gallery/quantum/wave_packets/images/sphx_glr_plot_quantum_revivals_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none fidelity to initial state at t = 0.00 t_rev: 1.0000 fidelity to initial state at t = 0.05 t_rev: 0.3920 fidelity to initial state at t = 0.25 t_rev: 0.5000 fidelity to initial state at t = 0.50 t_rev: 0.0000 fidelity to initial state at t = 1.00 t_rev: 1.0000 .. GENERATED FROM PYTHON SOURCE LINES 59-61 Fidelity over one revival period ------------------------------------ .. GENERATED FROM PYTHON SOURCE LINES 61-70 .. code-block:: Python t_scan = np.linspace(0, t_rev, 400) fidelity = np.array([qr.fidelity_to_initial(x, t, coeffs, psi0) for t in t_scan]) fig2, ax2 = plt.subplots(figsize=(7, 3.5)) ax2.plot(t_scan / t_rev, fidelity, color="steelblue") ax2.set_xlabel(r"$t / t_\text{rev}$") ax2.set_ylabel(r"$|\langle\psi(0)|\psi(t)\rangle|^2$") ax2.set_title("Fidelity collapses quickly and returns at the revival time") fig2.tight_layout() .. image-sg:: /api/gallery/quantum/wave_packets/images/sphx_glr_plot_quantum_revivals_002.png :alt: Fidelity collapses quickly and returns at the revival time :srcset: /api/gallery/quantum/wave_packets/images/sphx_glr_plot_quantum_revivals_002.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 71-76 A "quantum carpet": the full space-time revival pattern ----------------------------------------------------------- Evaluating the wavefunction on a full :math:`(x,t)` grid shows the web of diagonal fractional-revival ridges between the sharp replicas at :math:`t=0`, :math:`t_\text{rev}/2` and :math:`t_\text{rev}`. .. GENERATED FROM PYTHON SOURCE LINES 76-92 .. code-block:: Python t_carpet = np.linspace(0, t_rev, 500) x_carpet = np.linspace(0, qr.L, 700) carpet = np.array([np.abs(qr.wavefunction(x_carpet, t, coeffs)) ** 2 for t in t_carpet]) fig3, ax3 = plt.subplots(figsize=(7, 5.5)) im = ax3.pcolormesh(x_carpet, t_carpet, carpet, shading="auto", cmap="inferno") for frac in (0.25, 0.5, 1.0): ax3.axhline(frac * t_rev, color="cyan", ls="--", lw=0.6) ax3.set_xlabel("x") ax3.set_ylabel("t") ax3.set_title(r"Quantum carpet: $|\psi(x,t)|^2$ in the infinite well") fig3.colorbar(im, ax=ax3, label=r"$|\psi(x,t)|^2$") fig3.tight_layout() plt.show() .. image-sg:: /api/gallery/quantum/wave_packets/images/sphx_glr_plot_quantum_revivals_003.png :alt: Quantum carpet: $|\psi(x,t)|^2$ in the infinite well :srcset: /api/gallery/quantum/wave_packets/images/sphx_glr_plot_quantum_revivals_003.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 93-97 Check ----- Full revival at t_rev, the mirror image (no overlap) at t_rev/2, and a fractional revival into two copies (fidelity 1/2) at t_rev/4. .. GENERATED FROM PYTHON SOURCE LINES 97-99 .. code-block:: Python fid = {frac: qr.fidelity_to_initial(x, frac * t_rev, coeffs, psi0) for frac in (0.25, 0.5, 1.0)} assert fid[1.0] > 0.999 and fid[0.5] < 1e-3 and abs(fid[0.25] - 0.5) < 1e-3 .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 1.387 seconds) .. _sphx_glr_download_api_gallery_quantum_wave_packets_plot_quantum_revivals.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_quantum_revivals.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_quantum_revivals.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_quantum_revivals.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_