Skip to content

Commit

Permalink
pauli algebra
Browse files Browse the repository at this point in the history
  • Loading branch information
Jue-Xu committed Aug 1, 2024
1 parent 9b8ba65 commit 1113567
Showing 1 changed file with 112 additions and 2 deletions.
114 changes: 112 additions & 2 deletions quantum_simulation_recipe/test.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
]
},
{
Expand Down Expand Up @@ -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",
Expand Down

0 comments on commit 1113567

Please sign in to comment.