From 111356702e5d8460b3d1d25f80f4e55c4cd7ee8e Mon Sep 17 00:00:00 2001 From: Jue Xu Date: Thu, 1 Aug 2024 09:34:15 +0800 Subject: [PATCH] pauli algebra --- quantum_simulation_recipe/test.ipynb | 114 ++++++++++++++++++++++++++- 1 file changed, 112 insertions(+), 2 deletions(-) diff --git a/quantum_simulation_recipe/test.ipynb b/quantum_simulation_recipe/test.ipynb index eac674c..fdcec52 100644 --- a/quantum_simulation_recipe/test.ipynb +++ b/quantum_simulation_recipe/test.ipynb @@ -26,13 +26,14 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": 12, "id": "8c03d3e4", "metadata": {}, "outputs": [], "source": [ "from spin import *\n", - "from fermion import *" + "from fermion import *\n", + "from bounds import norm, tight_bound, commutator" ] }, { @@ -348,6 +349,115 @@ "from bounds import *" ] }, + { + "cell_type": "markdown", + "id": "9d9b79a5", + "metadata": {}, + "source": [ + "## Pauli algebra" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "id": "809c7242", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Parity grouping: \n", + " [SparsePauliOp(['IIIIZZ', 'IIZZII', 'ZZIIII', 'IIIIIX', 'IIIXII', 'IXIIII'],\n", + " coeffs=[1. +0.j, 1. +0.j, 1. +0.j, 0.2+0.j, 0.2+0.j, 0.2+0.j]), SparsePauliOp(['IIIZZI', 'IZZIII', 'ZIIIIZ', 'IIIIXI', 'IIXIII', 'XIIIII'],\n", + " coeffs=[1. +0.j, 1. +0.j, 1. +0.j, 0.2+0.j, 0.2+0.j, 0.2+0.j])]\n", + "XYZ grouping: \n", + " [SparsePauliOp(['IIIIIX', 'IIIIXI', 'IIIXII', 'IIXIII', 'IXIIII', 'XIIIII'],\n", + " coeffs=[0.2+0.j, 0.2+0.j, 0.2+0.j, 0.2+0.j, 0.2+0.j, 0.2+0.j]), SparsePauliOp(['IIIIZZ', 'IIIZZI', 'IIZZII', 'IZZIII', 'ZZIIII', 'ZIIIIZ'],\n", + " coeffs=[1.+0.j, 1.+0.j, 1.+0.j, 1.+0.j, 1.+0.j, 1.+0.j])]\n" + ] + } + ], + "source": [ + "n = 6\n", + "J, h = 1, 0.2 \n", + "tfI = Nearest_Neighbour_1d(n=n, Jz=J, hx=h, pbc=True)\n", + "print('Parity grouping: \\n', tfI.ham_par)\n", + "print('XYZ grouping: \\n', tfI.ham_xyz)" + ] + }, + { + "cell_type": "code", + "execution_count": 16, + "id": "f730b002", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "commutator of xyz grouping: \n", + " SparsePauliOp(['IIIIZY', 'ZIIIIY', 'IIIIYZ', 'IIIZYI', 'IIIYZI', 'IIZYII', 'IIYZII', 'IZYIII', 'IYZIII', 'ZYIIII', 'YZIIII', 'YIIIIZ'],\n", + " coeffs=[0.-0.4j, 0.-0.4j, 0.-0.4j, 0.-0.4j, 0.-0.4j, 0.-0.4j, 0.-0.4j, 0.-0.4j,\n", + " 0.-0.4j, 0.-0.4j, 0.-0.4j, 0.-0.4j])\n" + ] + } + ], + "source": [ + "cmm_xyz = commutator(tfI.ham_xyz[0], tfI.ham_xyz[1]).simplify()\n", + "print('commutator of xyz grouping: \\n', cmm_xyz)" + ] + }, + { + "cell_type": "code", + "execution_count": 17, + "id": "92245f95", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "SparsePauliOp(['IIIIIY', 'IIIIYI', 'IIIYII', 'IIYIII', 'IYIIII', 'YIIIII'],\n", + " coeffs=[0.-0.4j, 0.-0.4j, 0.-0.4j, 0.-0.4j, 0.-0.4j, 0.-0.4j])" + ] + }, + "execution_count": 17, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "from qiskit.quantum_info import SparsePauliOp\n", + "magn_op = SparsePauliOp.from_sparse_list([('Z', [i], 1) for i in range(0, n)], n)\n", + "corr_op = SparsePauliOp.from_sparse_list([('ZZ', [i,i+1], 1/(n-1)) for i in range(0, n-1)], n)\n", + "cmm_H_magn = commutator(tfI.ham_xyz[0], magn_op).simplify()\n", + "cmm_H_magn" + ] + }, + { + "cell_type": "code", + "execution_count": 15, + "id": "464ec272", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "spectral norm: 3.2000000000000006\n", + "induced 1-norm: 4.800000000000001\n", + "Frobenius norm: 11.085125168440818\n", + "trace (nuclear) norm: 71.65537550532244\n" + ] + } + ], + "source": [ + "print('spectral norm: ', norm(cmm_xyz, ord=2))\n", + "print('induced 1-norm: ', norm(cmm_xyz.coeffs, ord=1))\n", + "print('Frobenius norm: ', norm(cmm_xyz, ord='fro'))\n", + "print('trace (nuclear) norm: ', norm(cmm_xyz, ord='nuc'))" + ] + }, { "cell_type": "markdown", "id": "f981124d",