.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "api/gallery/quantum/adiabatic/plot_berry_phase_spin.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_adiabatic_plot_berry_phase_spin.py: Berry's geometric phase: a spin carried around a cone ===================================================== Berry (1984) showed that a quantum state carried adiabatically around a closed loop in parameter space returns with a phase that depends only on the loop's geometry, beyond the dynamical phase :math:`-\int E\,dt/\hbar`. For a spin :math:`j` aligned with a magnetic field whose direction sweeps a cone of half-angle :math:`\theta`, the phase is :math:`\gamma = -j\,\Omega`, with :math:`\Omega = 2\pi(1 - \cos\theta)` the solid angle the field encloses. :func:`~physicskit.quantum.chapters.adiabatic.berry_phase` computes it from the overlaps of neighbouring states, a product in which each state's arbitrary phase cancels. .. GENERATED FROM PYTHON SOURCE LINES 15-27 .. code-block:: Python import matplotlib.pyplot as plt import numpy as np from physicskit.quantum.chapters.adiabatic import berry_phase, spin_coherent_state def cone_loop(theta, j, n=400): phis = np.linspace(0, 2 * np.pi, n, endpoint=False) return np.array([spin_coherent_state(theta, phi, j) for phi in phis]) .. GENERATED FROM PYTHON SOURCE LINES 28-30 Berry phase against the enclosed solid angle -------------------------------------------- .. GENERATED FROM PYTHON SOURCE LINES 30-45 .. code-block:: Python thetas = np.linspace(0.02, np.pi - 0.02, 60) Omega = 2 * np.pi * (1 - np.cos(thetas)) fig, ax = plt.subplots(figsize=(8, 4.5)) gammas = {} for j, c in [(0.5, "C0"), (1.0, "C1"), (1.5, "C2")]: gammas[j] = np.array([berry_phase(cone_loop(th, j)) for th in thetas]) ax.plot(Omega, gammas[j], "o", ms=3, color=c, label=f"j = {j:g}") ax.plot(Omega, np.angle(np.exp(-1j * j * Omega)), "-", color=c, lw=1) ax.set_xlabel(r"solid angle $\Omega$ (sr)") ax.set_ylabel(r"$\gamma$ (mod $2\pi$)") ax.set_title(r"Berry phase $\gamma = -j\,\Omega$ (lines) from the overlap product (dots)") ax.legend() fig.tight_layout() .. image-sg:: /api/gallery/quantum/adiabatic/images/sphx_glr_plot_berry_phase_spin_001.png :alt: Berry phase $\gamma = -j\,\Omega$ (lines) from the overlap product (dots) :srcset: /api/gallery/quantum/adiabatic/images/sphx_glr_plot_berry_phase_spin_001.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 46-51 Convergence with the number of steps ------------------------------------ The discrete product converges to Berry's line integral as the loop is refined; the error falls as :math:`1/N^2`. .. GENERATED FROM PYTHON SOURCE LINES 51-64 .. code-block:: Python theta0 = 1.0 exact = -0.5 * 2 * np.pi * (1 - np.cos(theta0)) Ns = np.array([8, 16, 32, 64, 128, 256]) err = np.array([abs(berry_phase(cone_loop(theta0, 0.5, N)) - exact) for N in Ns]) fig2, ax2 = plt.subplots(figsize=(6, 4)) ax2.loglog(Ns, err, "o-") ax2.loglog(Ns, err[0] * (Ns[0] / Ns) ** 2, "k:", label=r"$\propto N^{-2}$") ax2.set_xlabel("number of states in the loop N") ax2.set_ylabel("error in γ") ax2.legend() fig2.tight_layout() .. image-sg:: /api/gallery/quantum/adiabatic/images/sphx_glr_plot_berry_phase_spin_002.png :alt: plot berry phase spin :srcset: /api/gallery/quantum/adiabatic/images/sphx_glr_plot_berry_phase_spin_002.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 65-70 Check ----- gamma = -j Omega (mod 2 pi) for j = 1/2, 1, 3/2 on every cone; a spin 1/2 around the equator (Omega = 2 pi) picks up pi; the discretization error falls as 1/N^2. .. GENERATED FROM PYTHON SOURCE LINES 70-75 .. code-block:: Python for j, g in gammas.items(): assert np.max(np.abs(np.angle(np.exp(1j * (g + j * Omega))))) < 1e-3 assert abs(abs(berry_phase(cone_loop(np.pi / 2, 0.5))) - np.pi) < 1e-9 slope = np.polyfit(np.log(Ns), np.log(err), 1)[0] assert abs(slope + 2) < 0.1 .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.796 seconds) .. _sphx_glr_download_api_gallery_quantum_adiabatic_plot_berry_phase_spin.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_berry_phase_spin.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_berry_phase_spin.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_berry_phase_spin.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_