Skip to content

Commit

Permalink
Hamiltonian class, Laplacian implementation (based on #3)
Browse files Browse the repository at this point in the history
  • Loading branch information
matteogarbellini committed Nov 23, 2021
1 parent 06caa55 commit 93e3067
Showing 1 changed file with 49 additions and 8 deletions.
57 changes: 49 additions & 8 deletions Code /QW_Search.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
from scipy.integrate import odeint, solve_ivp

import multiprocessing as mp
import ray

from numba import njit
from numba import int32, float64
Expand All @@ -43,16 +42,58 @@
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""

hamiltonian_types = [
('dimension', int32),
('dim', int32),
('type', int32),
('topology', ??), #char or numerical id?
('step_function', int32),
('topology', int32),
('step_func', int32),
('target', int32),
('laplacian', float64[:]),
('hamiltonian', float64[:]),
('laplacian', float64[:,:]),
('hamiltonian', float64[:,:]),
]

@jitclass(hamiltonian_types):
@jitclass(hamiltonian_types)
class Hamiltonian:
"""Hamiltonian class"""
def __init__(self, dimension, type, topology, target, step_function):
def __init__(self, dim, type, topology, target, step_func):

self.dim = dim
self.type = type
self.topology = topology
self.target = target
self.step_func = step_func


def build_laplacian(self):
lap = np.empty((self.dim, self.dim))
lap.fill(0)

"""Complete graph (0) """
if self.topology == 0:
lap -= 1
for i in range(self.dim):
lap[i,i] += self.dim

"""Cycle graph (1) """
if self.topology == 1:
for i in range(self.dim):
lap[i,i] = 2
lap[i,(i+1)%self.dim] -= 1
lap[i,(i-1)%self.dim] -= 1

"""Random graph (2)"""
"""Star graph (3)"""

self.laplacian = lap

def build_hamiltonian(self):



if __name__ == '__main__':

#Test hamiltonian class (dim, type, topology, target, step_func)

HC = Hamiltonian(5, 0, 0, 1, 1)
HC.build_laplacian()
HCy = Hamiltonian(5, 0, 1, 1, 1)
HCy.build_laplacian()

0 comments on commit 93e3067

Please sign in to comment.