bachelor_thesis/presentation/spin_chain/time_evolution.ipynb

121 lines
41 KiB
Plaintext
Raw Permalink Normal View History

2020-02-25 13:21:31 +00:00
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\n",
"simulating... 99 % \n",
"done.\n"
]
},
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAZkAAAEWCAYAAAC0Q+rDAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4xLjEsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy8QZhcZAAAgAElEQVR4nOydd3gVRdfAfye9J4QECAm9ioCgSFEU1FcFEcGCWLCigv2zl9cGir3yIipWQEVQUUCxgSAqiNK7INIDoaT3dr4/ZoOXmITckJvcwPyeZ5+7Ozvl7N7dPVPOnBFVxWKxWCwWT+BT2wJYLBaL5ejFKhmLxWKxeAyrZCwWi8XiMaySsVgsFovHsErGYrFYLB7DKhmLxWKxeAyrZGoYEckUkZa1LMObIvJoNefZV0R2VjFtU+e++FanTKXKuFJEvq/gfJXltxhE5FoR+cXluNaf9aMNEdkqIv8p51ywiMwSkTQR+fRwz3yptB+IyFMVnFcRaV0Vma2SqSQi8qGI7BaRdBHZKCI3VCUfVQ1T1b+dPCv8Yz2Fqo5U1SdrutzyUNXtzn0p8mAZH6nqOSXHR/LSVCci0kVElopItvPbpZx4gSLyrohsE5EMEVkhIv1rWl53cH3WqxMReUJEPqzufCtRbnPnufGr6bIrySVAQ6C+qg4p/czXFlbJVJ5ngOaqGgFcADwlIifVskyWOoyIBAAzgA+BesBEYIYTXho/YAfQB4gEHgGmiUjzGhHWcsTUgHJqBmxU1UIPl+Meqmo3NzegHbAbuLSc862Bn4A0YD8w1eWcOudvAgqAfCATmOWcbwx8DuwDtgB3VCDHecA6IAPYBdzrhPcFdgIPO+VvBa50S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YiviJyLqaLYG458YeISMlLkoJ5aIrLiJqEGXcp4XcgQ0QecGzefUWko4icXEYZAY4dfKTzsUkvo4xRTrzTMM3lT9257tKo6m7gG4zSrCci/iJyeiWTh2Nqm7ki0h244khkKcVPmFp9SdfY/FLHZVH63lcap9tpCfCEc397AQNLxQmrYHvaRc4i4A7HRLmkZfJjOUW/gen7H1iq66Us3gHuFZGTxNDa6cJZjKk53+/8f30d2T9x0q0ALhKREKdiNLyMvO9z/v8mGOU+9TCyHI6vgU4iMtixwLqVspVbCUlA8xJFqao7MBWLZ0QkSEQ6O3L/y8zZacG9DbwiIg0ARCTeeadxWsDvYLobrwEGikhJJW8f5h1zfW7eBB4SkeOd9JEiUlYXVGUJx7Rw00QkHjMAXx18hWnxX+X87/4icrKIHFdG3GnAtSLSwalIPX4kBVslUzkU0zW2E6M0XgT+T1VnlhP/ZGCxiGRiau93atnzBd7FjKmkisiXauaJnI/p9tmCqXW9gzFZLYurgK1Os3okpvlbwh5H1kRM//fICvrv3eEqzNjFBowV1v9VMt0twGgRycAYNkw7THx3+Anzci4o57gsngAmOve+vLGqirgSU9s9ADyF+dCWN0ZXJk6razBmDCAVY8Uz2AlHRB4WkW+c/WaYVnEXYI9Lq+jKcvL+FBiDaUFmYFq60U7eAzFja/sxg+VXuzwbr2C64pIwJtUflZH9DEzrcQVGQbzrznWXIet+zNjA85j72QGjxMu7nyWVpQMiUjIOeTmmeysR+AJ4XFXnlJP+Acxg/W/OuzOHf8beJgAzVHW2qh7AKKt3RKS+02oeA/zqPDc9VfUL4DngEyevNZh7W1VGASdixua+xoz9HjFOV+I5mLGnRMz34TmMgUHpuN9gxtp+xNyn8io9laLEbM5yFOHUTj9U1Yq6HCzViIhMBTao6hHV+rwdEVGgjar+5cEyfDAVuitVdZ6nyrHUDLYlY7FUAaeroZWI+IhIP4wp65e1LVddRUTOFZE
"text/plain": [
"<Figure size 432x288 with 1 Axes>"
]
},
"metadata": {
"needs_background": "light"
},
"output_type": "display_data"
}
],
"source": [
"%matplotlib inline\n",
"import numpy as np\n",
"import matplotlib.pyplot as plt\n",
"\n",
"from pyqcs import State, sample\n",
"from transfer_matrix import T_time_slice\n",
"from hamiltonian import H\n",
"\n",
"from scipy.linalg import expm\n",
"\n",
"nqbits = 3\n",
"g = 0.20\n",
"N = 50\n",
"t_stop = 5\n",
"delta_t = 0.05\n",
"qbits = list(range(nqbits))\n",
"\n",
"n_sample = 400\n",
"measure = 0b10\n",
"\n",
"\n",
"results_qc = []\n",
"results_np = []\n",
"print()\n",
"for t in np.arange(0, t_stop, delta_t):\n",
" # QC simulation\n",
" state = State.new_zero_state(nqbits)\n",
"\n",
" for _ in range(N):\n",
" state = T_time_slice(qbits, t, g, N) * state\n",
"\n",
" #result = sample(state, measure, n_sample)\n",
"\n",
" #results_qc.append(result[0] / n_sample)\n",
"\n",
" amplitude = np.sqrt(np.sum(np.abs(state._qm_state[[False if (i & measure) else True for i in range(2**nqbits)]])**2))\n",
" results_qc.append(amplitude)\n",
"\n",
" # Simulation using matrices\n",
" np_zero_state = np.zeros(2**nqbits)\n",
" np_zero_state[0] = 1\n",
"\n",
" itH = np.matrix(-1j * t * H(nqbits, g))\n",
" T = expm(itH)\n",
"\n",
" np_state = T.dot(np_zero_state)\n",
" amplitude = np.sqrt(np.sum(np.abs(np_state[[False if (i & measure) else True for i in range(2**nqbits)]])**2))\n",
" results_np.append(amplitude)\n",
"\n",
" print(f\"simulating... {int(t/t_stop*100)} % \", end=\"\\r\")\n",
"print()\n",
"print(\"done.\")\n",
"\n",
"errors_trotter = np.arange(0, t_stop, delta_t)**2 / N**2\n",
"\n",
"\n",
"h0 = plt.errorbar(np.arange(0, t_stop, delta_t), results_qc, yerr=errors_trotter, label=f\"Quantum computing ({n_sample} samples, {N} trotterization steps)\")\n",
"h1, = plt.plot(np.arange(0, t_stop, delta_t), results_np, label=\"Classical simulation using explicit transfer matrix\")\n",
"plt.xlabel(\"t\")\n",
"plt.ylabel(r\"$|0\\rangle$ probability amplitude for second spin\")\n",
"plt.title(f\"{nqbits} site spin chain with g={g} coupling to external field\")\n",
"plt.legend(handles=[h0, h1])\n",
"\n",
"plt.show()\n",
"\n"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.3"
}
},
"nbformat": 4,
"nbformat_minor": 2
}