{
 "nbformat": 4,
 "nbformat_minor": 5,
 "metadata": {
  "kernelspec": {
   "name": "python3",
   "language": "python",
   "display_name": "Python 3"
  },
  "language_info": {
   "name": "python"
  },
  "fundamentals": {
   "title": "Measure geometric phase from three spin overlaps",
   "lead": "A numerical eigensolver is free to choose a new complex phase for every eigenvector. A product of three measured overlaps removes these arbitrary choices. Relate its argument to a spherical triangle, then see why a vanishing overlap destroys phase information.",
   "unit_slug": "geometric-phase-from-three-overlaps"
  }
 },
 "cells": [
  {
   "cell_type": "markdown",
   "id": "beaf49c9a916",
   "metadata": {},
   "source": [
    "# Measure geometric phase from three spin overlaps\n",
    "\n",
    "A numerical eigensolver is free to choose a new complex phase for every eigenvector. A product of three measured overlaps removes these arbitrary choices. Relate its argument to a spherical triangle, then see why a vanishing overlap destroys phase information."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "6495c5c6343e",
   "metadata": {
    "fundamentals": {
     "section": "derive-the-model"
    }
   },
   "source": [
    "## Close a loop before assigning a phase\n",
    "\n",
    "Choose three normalised spinors $|A\\rangle,|B\\rangle,|C\\rangle$. Their individual phases change under $|j\\rangle\\mapsto e^{i\\gamma_j}|j\\rangle$. In the cyclic product $Z=\\langle A|B\\rangle\\langle B|C\\rangle\\langle C|A\\rangle$ every phase occurs once with each sign. This product is a gauge-independent complex quantity although none of the three overlap phases separately is.\n",
    "\n",
    "Take $A$ at the north pole of the Bloch sphere, $B$ on its equator at longitude zero and $C$ on the equator at longitude $\\varphi$ with $-\\pi<\\varphi<\\pi$. Choose $A=(1,0)$, $B=(1,1)/\\sqrt2$ and $C=(1,e^{i\\varphi})/\\sqrt2$. Direct multiplication gives\n",
    "\n",
    "$$Z=\\frac{1+e^{i\\varphi}}4=\\frac{\\cos(\\varphi/2)}2 e^{i\\varphi/2}.$$\n",
    "\n",
    "The oriented triangle bounded by the two meridians and the shortest equator arc has solid angle $\\Omega=\\int_0^\\varphi d\\phi\\int_0^{\\pi/2}\\sin\\theta\\,d\\theta=\\varphi$. The overlap product therefore has argument $+\\Omega/2$ for this order. The geometric phase of a ket parallel-transported along the oriented shortest geodesics is the negative of this overlap-product argument. Stating which sign is reported prevents an apparent contradiction. This construction requires no arbitrary differentiation of eigenvector phases."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "4eea5c5f6994",
   "metadata": {
    "fundamentals": {
     "section": "worked-prediction"
    }
   },
   "source": [
    "## Separate a well-defined angle from an observable signal\n",
    "\n",
    "At 90 degrees longitude the triangle encloses $\\pi/2$ steradians. The complex product is $(1+i)/4$, its magnitude is about 0.354 and its argument is $\\pi/4$. As longitude approaches 180 degrees, the equatorial states approach orthogonality. The magnitude tends to zero, and even a small absolute uncertainty in the measured complex product yields a large angular uncertainty. Exactly at orthogonality there is no unique shortest equatorial arc or measurable phase of the zero complex number."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "acd68c026493",
   "metadata": {
    "fundamentals": {
     "section": "choose-inputs",
     "notebook_only": true
    }
   },
   "source": [
    "## Set the experimental inputs\n",
    "\n",
    "Edit these values, then run the calculation and both figures again."
   ]
  },
  {
   "cell_type": "code",
   "id": "711d54464cea",
   "metadata": {},
   "source": [
    "import numpy as np\n",
    "import matplotlib.pyplot as plt\n",
    "\n",
    "teal, orange, blue = \"#19596a\", \"#aa462a\", \"#3868a0\"\n",
    "def axes(xlabel, ylabel):\n",
    "    fig, ax = plt.subplots(figsize=(7, 4), constrained_layout=True)\n",
    "    ax.set(xlabel=xlabel, ylabel=ylabel)\n",
    "    ax.grid(alpha=0.2)\n",
    "    return fig, ax"
   ],
   "execution_count": null,
   "outputs": []
  },
  {
   "cell_type": "code",
   "id": "9213758ef241",
   "metadata": {},
   "source": [
    "longitude_deg=90.\n",
    "extra_phases=np.array([.42,-1.1,.73])"
   ],
   "execution_count": null,
   "outputs": []
  },
  {
   "cell_type": "code",
   "id": "e783e4dba23d",
   "metadata": {},
   "source": [
    "assert -180<longitude_deg<180\n",
    "phi=np.deg2rad(longitude_deg)\n",
    "states=np.array([[1,0],[1/np.sqrt(2),1/np.sqrt(2)],[1/np.sqrt(2),np.exp(1j*phi)/np.sqrt(2)]],dtype=complex)\n",
    "def cyclic(v):\n",
    "    return np.vdot(v[0],v[1])*np.vdot(v[1],v[2])*np.vdot(v[2],v[0])\n",
    "product=cyclic(states)\n",
    "assert np.allclose(cyclic(states*np.exp(1j*extra_phases)[:,None]),product)\n",
    "print(f\"|Z|={abs(product):.5f}; overlap phase={np.angle(product):.5f} rad; transported phase={-np.angle(product):.5f} rad\")"
   ],
   "execution_count": null,
   "outputs": []
  },
  {
   "cell_type": "code",
   "id": "9ec7d855213b",
   "metadata": {
    "fundamentals": {
     "figure": {
      "file": "quantum-mechanics-quantum-theory-1.png",
      "alt": "A north-polar view of the Bloch triangle shows two meridians connected by the shortest equator arc.",
      "caption": "The north pole projects to the centre and the equator to the rim. The filled planar region illustrates the path, whereas its solid angle is integrated on the sphere."
     }
    }
   },
   "source": [
    "circle=np.linspace(0,2*np.pi,241);arc=np.linspace(0,phi,151)\n",
    "fig,ax=axes(\"Projected Bloch coordinate x\",\"Projected Bloch coordinate y\")\n",
    "ax.plot(np.cos(circle),np.sin(circle),color=\"grey\",lw=1)\n",
    "ax.fill(np.r_[0,np.cos(arc),0],np.r_[0,np.sin(arc),0],color=teal,alpha=.18)\n",
    "ax.plot(np.r_[0,np.cos(arc),0],np.r_[0,np.sin(arc),0],color=teal)\n",
    "for xx,yy,name in [(0,0,\"A\"),(1,0,\"B\"),(np.cos(phi),np.sin(phi),\"C\")]:\n",
    "    ax.plot(xx,yy,\"o\",color=orange);ax.annotate(name,(xx,yy),xytext=(4,4),textcoords=\"offset points\")\n",
    "ax.set_aspect(\"equal\",adjustable=\"box\")\n",
    "plt.show()"
   ],
   "execution_count": null,
   "outputs": []
  },
  {
   "cell_type": "markdown",
   "id": "f7c1b65aac94",
   "metadata": {
    "fundamentals": {
     "notebook_only": true
    }
   },
   "source": [
    "The north pole projects to the centre and the equator to the rim. The filled planar region illustrates the path, whereas its solid angle is integrated on the sphere."
   ]
  },
  {
   "cell_type": "code",
   "id": "9787d8c53ed5",
   "metadata": {
    "fundamentals": {
     "figure": {
      "file": "quantum-mechanics-quantum-theory-2.png",
      "alt": "The complex cyclic overlap moves on a circle through the origin as the third spinor changes longitude.",
      "caption": "At the origin the overlap phase is undefined. Reversing the circuit reflects the complex product across the real axis."
     }
    }
   },
   "source": [
    "angles=np.linspace(-np.pi,np.pi,301); locus=(1+np.exp(1j*angles))/4\n",
    "fig,ax=axes(\"Real cyclic overlap\",\"Imaginary cyclic overlap\")\n",
    "ax.plot(locus.real,locus.imag,color=teal);ax.plot([0,product.real],[0,product.imag],color=orange,label=\"Selected overlap\")\n",
    "ax.plot(product.real,product.imag,\"o\",color=orange);ax.set_aspect(\"equal\",adjustable=\"box\");ax.legend()\n",
    "plt.show()"
   ],
   "execution_count": null,
   "outputs": []
  },
  {
   "cell_type": "markdown",
   "id": "337365182f8d",
   "metadata": {
    "fundamentals": {
     "notebook_only": true
    }
   },
   "source": [
    "At the origin the overlap phase is undefined. Reversing the circuit reflects the complex product across the real axis."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c41b5465e7c2",
   "metadata": {
    "fundamentals": {
     "section": "problem-1"
    }
   },
   "source": [
    "## Exercise · reverse the circuit\n",
    "\n",
    "What happens to amplitude and phase if the experiment uses $A,C,B$ in place of $A,B,C$?"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "29a3f542005b",
   "metadata": {
    "fundamentals": {
     "solution": true
    }
   },
   "source": [
    "Hermitian symmetry conjugates every overlap while the scalar factors can be reordered. The new product equals $Z^*$. Its magnitude stays fixed and both signed phase conventions reverse."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "0f8c03233538",
   "metadata": {
    "fundamentals": {
     "section": "problem-2"
    }
   },
   "source": [
    "## Exercise · estimate the angular uncertainty\n",
    "\n",
    "A measured overlap has magnitude 0.02 and a small perpendicular complex uncertainty of magnitude 0.002. What is the first-order phase uncertainty? Compare with a magnitude of 0.4."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "f0bfaac67384",
   "metadata": {
    "fundamentals": {
     "solution": true
    }
   },
   "source": [
    "For a small transverse displacement the angular change is $\\delta\\theta\\simeq|\\delta Z_\\perp|/|Z|$. The answers are 0.10 rad and 0.005 rad. Identical absolute detector noise therefore gives very different phase precision near an orthogonal pair."
   ]
  }
 ]
}
