Skip to content

Commit

Permalink
iqp circuit
Browse files Browse the repository at this point in the history
  • Loading branch information
Jue-Xu committed Aug 6, 2024
1 parent 7b75ace commit 3371303
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 3 deletions.
4 changes: 2 additions & 2 deletions quantum_simulation_recipe/plot_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ def set_fontsize(small=SMALL_SIZE, medium=MEDIUM_SIZE, large=LARGE_SIZE, linewid
mpl.rcParams['xtick.major.width'] = linewidth
mpl.rcParams['ytick.major.width'] = linewidth
mpl.rcParams['ytick.minor.width'] = linewidth
mpl.rcParams['lines.linewidth'] = linewidth
mpl.rcParams['lines.markeredgewidth'] = linewidth
mpl.rcParams['lines.linewidth'] = linewidth+0.5
mpl.rcParams['lines.markeredgewidth'] = linewidth+0.5

set_fontsize()

Expand Down
33 changes: 33 additions & 0 deletions quantum_simulation_recipe/spin.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,30 @@
from qiskit.quantum_info import SparsePauliOp
import random

class IQP:
def __init__(self, n: int, theta=0, verbose=False):
self.n = n
if theta == 0:
self.pstr = [(''.join(random.choices(['I','Z'], k=n)), 2*np.pi*random.random()) for _ in range(1*n)]
else:
self.pstr = [(''.join(random.choices(['I','Z'], k=n)), theta) for _ in range(1*n)]

if verbose: print('pstr: ', self.pstr)
self.ham = SparsePauliOp.from_list(self.pstr)
# return SparsePauliOp.from_list(pstr)

# if H_type == 0:
# J = 2
# ising_str = 'ZZ' + 'I' * (n-2)
# uni_ising = [(ising_str[i:]+ising_str[:i], J) for i in range(n)]
# del uni_ising[1]
# print(uni_ising)
# H = SparsePauliOp.from_list(uni_ising)
# else:
# # H = get_hamiltonian(L=n, J=1.0, h=0.2, g=0.0, verbose=True)
# H = IQP_H(n, theta, verbose=True)


class Nearest_Neighbour_1d:
def __init__(self, n: int, Jx=0, Jy=0, Jz=0, hx=0, hy=0, hz=0, pbc=False, verbose=False, rand_field=[]):
self.n = n
Expand Down Expand Up @@ -88,6 +112,15 @@ def xyz_group(self):
# print('todo')
# return self.ham.to_matrix().todense()










# class TF_Ising_1d:
# def __init__(self, n: int, J=1, h=0.2, g=0.0, pbc=False, verbose=False):
# self.n = n
Expand Down
26 changes: 25 additions & 1 deletion quantum_simulation_recipe/test.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": 1,
"id": "8c03d3e4",
"metadata": {},
"outputs": [],
Expand All @@ -36,6 +36,30 @@
"from bounds import norm, tight_bound, commutator"
]
},
{
"cell_type": "code",
"execution_count": 70,
"id": "2cefc7ad",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"SparsePauliOp(['ZZIIZZ', 'IIZIIZ', 'ZZZIIZ', 'IIZZIZ', 'IZZIZZ', 'IIZZIZ'],\n",
" coeffs=[5.807428+0.j, 2.03521 +0.j, 1.718245+0.j, 0.451692+0.j, 4.762469+0.j,\n",
" 1.399856+0.j])"
]
},
"execution_count": 70,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"iqp = IQP(6)\n",
"iqp.ham"
]
},
{
"cell_type": "code",
"execution_count": 3,
Expand Down

0 comments on commit 3371303

Please sign in to comment.