{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Calculate Von Neumann Entropy and Purity for Dicke-Basis density matrix in presence of homogeneous local dissipation\n", "\n", "Author: Nathan Shammah, nathan.shammah@gmail.com\n", "\n", "We provide a tutorial for the task of calculating nonlinear functions of the denisty matrix, such as the Von Neumann entropy and purity, using the Dicke-Basis formalism in an open Lindblad dynamics characterized by (collective and) homogeneous local incoherent processes [1,2].\n", "\n", "For an introduction to the qutip.piqs module, see [The Introductory Notebook](https://nbviewer.jupyter.org/github/qutip/qutip-notebooks/blob/master/examples/piqs-overview.ipynb) or see Ref. [1].\n", "\n", "We provide an example of three bases that can be used the dynamics of a spin system on a lattice with all-to-all connectivity or of an ensemble of two-level systems in cavity QED. " ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "from time import clock\n", "import matplotlib.pyplot as plt\n", "import numpy as np\n", "from qutip import *\n", "from qutip.piqs import *\n", "from scipy.sparse import block_diag\n", "from scipy.sparse.linalg import eigsh, eigs\n", "from scipy import log" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Define some auxiliary functions" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "def plot_rho(rho, title=None):\n", " \"\"\"\n", " Plot the image show of the real values of a Qobj operator.\n", " \n", " Input:\n", " ------\n", " rho : :class: qutip.Qobj\n", " Density matrix or operator.\n", " Returns:\n", " ------\n", " figure : matplotlib.pyplot.figure\n", " Figure showing real part of matrix elements of the density matrix.\n", " \"\"\" \n", " plt.figure()\n", " plt.imshow(np.real(rho.full()))\n", " if title is not None:\n", " plt.title(title)\n", " plt.show()" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [], "source": [ "def spin_hamiltonian(N,h,basis=\"jmat\"):\n", " \"\"\"\n", " Calculate generalized spin Hamiltonian in the jmat, dicke or uncoupled basis.\n", " \n", " Input:\n", " ------\n", " N : int\n", " Number of spins.\n", " h : float\n", " Magnitude of transverse (Jx) external magnetic field, of size (N+1).\n", " basis : string, (default='jmat')\n", " Basis of the Hamiltonian. \n", " Can be 'jmat' (N+1), 'dicke' (O(N^2)), or \"uncoupled\" (2^N). \n", " Returns:\n", " ------\n", " hamiltonian_spin : qutip.Qobj()\n", " Hamiltonian of the system in the given basis (default is jmat).\n", " \"\"\"\n", " if basis==\"jmat\":\n", " jx,jy,jz = jmat(N/2)\n", " elif basis==\"dicke\":\n", " jx,jy,jz = jspin(N, basis=\"dicke\")\n", " elif basis==\"uncoupled\":\n", " jx,jy,jz = jspin(N, basis=\"uncoupled\")\n", " \n", " hamiltonian_spin = (jz**2)-h*jx\n", " return hamiltonian_spin" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Visualizing the density matrix structure" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "data": { "image/png": "iVBORw0KGgoAAAANSUhEUgAAAPgAAAEKCAYAAAA//JitAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDMuMC4zLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvnQurowAADx5JREFUeJzt3XuMXOV9xvHvUxswGFOHQKL4EiANNaFuYyODkrqgFEjBhJBWqRRQk6aoUoQUbhFtQtJKaZJWolJLEykoqcutErc0XFpCuaoBRTTUXIwpYIMKBmNjiO0SwDgxxubpH3OcrKfr3TM753hmXz8faeSds++8+5v1PvueOXP2d2SbiCjTrwy6gIhoTwIeUbAEPKJgCXhEwRLwiIIl4BEFS8AjCpaARxQsAW+JpCclfaTGuOclndzA12tknq45az2HGF4J+ARUYfq5pM2SXpX0Y0nnSPrF99P2b9i+b4Bl9q2J5yDpHZIs6YGu7f8o6R/6KnDX+Y6UtFXSNU3NWYIEfOI+bnsGcBhwCfAl4IrBljSUFgAvA0dLek/X9hUNfp3LgIcanK8ICXifbL9m+1bgU8BnJc2HXXeZJc2VdLOkjZL+V9K3R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