[Kwant] Onsite and hopping values in QHE

2018-06-15 Thread elchatz

Hello everyone,

I am trying to reproduce the QHE bar device calculations

http://nbviewer.jupyter.org/github/topocm/topocm_content/blob/master/w3_pump_QHE/Laughlinargument.ipynb

However, I am having difficulty with the onsite and hopping values as  
I am using TBModels


https://github.com/Z2PackDev/TBmodels

and therefore the values are not the same for all sites.

The problem is that after the scalar values have been passed on to the  
Builder, these will then be overriden when using functions for the  
position-dependent Hamiltonian.


I tried making a deep copy of the model, which would then serve as a  
data structure where to draw the scalar values from when calling the  
Onsite and Hopping functions. The problem with this is


a) I am getting a KeyError which I am still not sure why it happens
b) It does not feel very memory-efficient.

I am wondering if there is another way that this could be done on the  
Kwant side that I have not been able to think of.



Regards

--
Dr. Eleni Chatzikyriakou
Computational Physics lab
Aristotle University of Thessaloniki
elch...@auth.gr - tel:+30 2310 998109



Re: [Kwant] Onsite and hopping values in QHE

2018-06-19 Thread Joseph Weston
HI,


>
> I am trying to reproduce the QHE bar device calculations
>
> http://nbviewer.jupyter.org/github/topocm/topocm_content/blob/master/w3_pump_QHE/Laughlinargument.ipynb
>
>
> However, I am having difficulty with the onsite and hopping values as
> I am using TBModels
>
> https://github.com/Z2PackDev/TBmodels
>
> and therefore the values are not the same for all sites.

I am unsure of the output format of TBModels. Glancing at their
documentation I can't see any way of getting the raw matrix elements
from a "Model". Looking into the source code it seems that they are
stored in a format that will be annoying to query manually.

> The problem is that after the scalar values have been passed on to the
> Builder, these will then be overriden when using functions for the
> position-dependent Hamiltonian.
>
> I tried making a deep copy of the model, which would then serve as a
> data structure where to draw the scalar values from when calling the
> Onsite and Hopping functions. The problem with this is
>
> a) I am getting a KeyError which I am still not sure why it happens
> b) It does not feel very memory-efficient.
>
> I am wondering if there is another way that this could be done on the
> Kwant side that I have not been able to think of.

I can't think of a better way to accomplish this. Using TBModels'
internal datastructures directly is IMO too much hassle unless your
systems are really big.

Did you check that the symmetry of your Kwant system and the TBModels
Model are compatible?

Joe



Re: [Kwant] Onsite and hopping values in QHE

2018-06-21 Thread elchatz

Hello Joseph,

Thank you. It is working when I copy the model and each lead after I  
have attached them.



Regards,

Eleni



Quoting Joseph Weston :


HI,




I am trying to reproduce the QHE bar device calculations

http://nbviewer.jupyter.org/github/topocm/topocm_content/blob/master/w3_pump_QHE/Laughlinargument.ipynb


However, I am having difficulty with the onsite and hopping values as
I am using TBModels

https://github.com/Z2PackDev/TBmodels

and therefore the values are not the same for all sites.


I am unsure of the output format of TBModels. Glancing at their
documentation I can't see any way of getting the raw matrix elements
from a "Model". Looking into the source code it seems that they are
stored in a format that will be annoying to query manually.


The problem is that after the scalar values have been passed on to the
Builder, these will then be overriden when using functions for the
position-dependent Hamiltonian.

I tried making a deep copy of the model, which would then serve as a
data structure where to draw the scalar values from when calling the
Onsite and Hopping functions. The problem with this is

a) I am getting a KeyError which I am still not sure why it happens
b) It does not feel very memory-efficient.

I am wondering if there is another way that this could be done on the
Kwant side that I have not been able to think of.


I can't think of a better way to accomplish this. Using TBModels'
internal datastructures directly is IMO too much hassle unless your
systems are really big.

Did you check that the symmetry of your Kwant system and the TBModels
Model are compatible?

Joe




--
Dr. Eleni Chatzikyriakou
Computational Physics lab
Aristotle University of Thessaloniki
elch...@auth.gr - tel:+30 2310 998109



Re: [Kwant] Onsite and hopping values in QHE

2018-07-02 Thread elchatz

Hello everyone,

While this is working in a system with leads, I am getting an error in  
the case of a closed system.



sym = kwant.TranslationalSymmetry(
lattice.vec((1, 0, 0)),
lattice.vec((0, 1, 0)),
lattice.vec((0, 0, 1))
)

[]

#Hall bar
def onsite(site, B):
  (x, y, z) = site.pos
  return stored_model[site]

def hopping_Ax(site1, site2, B):
  x1, y1, z1 = site1.pos
  x2, y2, z2 = site2.pos
  return stored_model[site1,site2] * np.exp(-0.5j * B * (x1 + x2)  
* (y1 - y2))


kwant_model[lattice.shape(shape, (0, 0, 15))] = onsite
kwant_model[lattice.neighbors()] = hopping_Ax

kwant_sys = wraparound.wraparound(kwant_model).finalized()

 B = 0.02
# Obtain the Hamiltonian as a dense matrix
ham_mat = kwant_sys.hamiltonian_submatrix(args=[B], sparse=True)

---
TypeError Traceback (most recent call last)
~\Anaconda3\lib\site-packages\kwant\builder.py in hamiltonian(self, i,  
j, params, *args)

   2000 try:
-> 2001 value = value(self.sites[i], *args)
   2002 except Exception as exc:

~\Anaconda3\lib\site-packages\wraparound.py in (*args)
 81 return lambda *args: sum((val(*args) if callable(val)  
else val)

---> 82  for val in vals)
 83

~\Anaconda3\lib\site-packages\wraparound.py in (.0)
 81 return lambda *args: sum((val(*args) if callable(val)  
else val)

---> 82  for val in vals)
 83

~\Anaconda3\lib\site-packages\wraparound.py in (a, *args)
 59 assert callable(val)
---> 60 return lambda a, *args: val(a, *args[:mnp])
 61

TypeError: onsite() missing 1 required positional argument: 'B'

The above exception was the direct cause of the following exception:

UserCodeError Traceback (most recent call last)
 in ()
  1 B = 0.02
  2 # Obtain the Hamiltonian as a dense matrix
> 3 ham_mat = kwant_sys.hamiltonian_submatrix(args=[B], sparse=True)
  4

kwant\_system.pyx in kwant._system.hamiltonian_submatrix()

~\Anaconda3\lib\site-packages\kwant\builder.py in hamiltonian(self, i,  
j, params, *args)

   2001 value = value(self.sites[i], *args)
   2002 except Exception as exc:
-> 2003 _raise_user_error(exc, value)
   2004 else:
   2005 edge_id = self.graph.first_edge_id(i, j)

~\Anaconda3\lib\site-packages\kwant\builder.py in _raise_user_error(exc, func)
   1883 msg = ('Error occurred in user-supplied value function "{0}".\n'
   1884'See the upper part of the above backtrace for  
more information.')

-> 1885 raise UserCodeError(msg.format(func.__name__)) from exc
   1886
   1887

UserCodeError: Error occurred in user-supplied value function "".
See the upper part of the above backtrace for more information.










Eleni


Quoting elch...@auth.gr:


Hello Joseph,

Thank you. It is working when I copy the model and each lead after I  
have attached them.



Regards,

Eleni



Quoting Joseph Weston :


HI,




I am trying to reproduce the QHE bar device calculations

http://nbviewer.jupyter.org/github/topocm/topocm_content/blob/master/w3_pump_QHE/Laughlinargument.ipynb


However, I am having difficulty with the onsite and hopping values as
I am using TBModels

https://github.com/Z2PackDev/TBmodels

and therefore the values are not the same for all sites.


I am unsure of the output format of TBModels. Glancing at their
documentation I can't see any way of getting the raw matrix elements
from a "Model". Looking into the source code it seems that they are
stored in a format that will be annoying to query manually.


The problem is that after the scalar values have been passed on to the
Builder, these will then be overriden when using functions for the
position-dependent Hamiltonian.

I tried making a deep copy of the model, which would then serve as a
data structure where to draw the scalar values from when calling the
Onsite and Hopping functions. The problem with this is

a) I am getting a KeyError which I am still not sure why it happens
b) It does not feel very memory-efficient.

I am wondering if there is another way that this could be done on the
Kwant side that I have not been able to think of.


I can't think of a better way to accomplish this. Using TBModels'
internal datastructures directly is IMO too much hassle unless your
systems are really big.

Did you check that the symmetry of your Kwant system and the TBModels
Model are compatible?

Joe




--
Dr. Eleni Chatzikyriakou
Computational Physics lab
Aristotle University of Thessaloniki
elch...@auth.gr

Re: [Kwant] Onsite and hopping values in QHE

2018-07-03 Thread Joseph Weston
Hi


> sym = kwant.TranslationalSymmetry(
>     lattice.vec((1, 0, 0)),
>     lattice.vec((0, 1, 0)),
> lattice.vec((0, 0, 1))
> )
>
> []
>
> #Hall bar
> def onsite(site, B):
>   (x, y, z) = site.pos
>   return stored_model[site]
>
> def hopping_Ax(site1, site2, B):
>   x1, y1, z1 = site1.pos
>   x2, y2, z2 = site2.pos
>   return stored_model[site1,site2] * np.exp(-0.5j * B * (x1 + x2)
> * (y1 - y2))
>
> kwant_model[lattice.shape(shape, (0, 0, 15))] = onsite
> kwant_model[lattice.neighbors()] = hopping_Ax
>
> kwant_sys = wraparound.wraparound(kwant_model).finalized()
>
>  B = 0.02
> # Obtain the Hamiltonian as a dense matrix
> ham_mat = kwant_sys.hamiltonian_submatrix(args=[B], sparse=True)

The docstring for 'wraparound' [1] says that the wrapped around system will
have additional parameters, corresponding to the momenta. As you have a 3D
system and have wrapped around all 3 dimensions, the parameters will be
'k_x', 'k_y', and 'k_z'.

As you have only supplied a single argument (B) to your system, an error
is raised.
You will need to provide all the arguments to your system:

    kwant_sys.hamiltonian_submatrix(params=dict(k_x=0, k_y=0, k_z=0,
B=B), sparse=True)

Happy Kwanting,

Joe


[1]:
https://kwant-project.org/doc/1/reference/generated/kwant.wraparound.wraparound#kwant.wraparound.wraparound



Re: [Kwant] Onsite and hopping values in QHE

2018-07-06 Thread elchatz

Hello Joseph,

Thank you for replying. I still can't make this work.


---
ham_mat = kwant_sys.hamiltonian_submatrix(params=dict(k_x=0, k_y=0,  
k_z=0, B=0.02), sparse=True)

---
ValueErrorTraceback (most recent call last)
~\Anaconda3\lib\site-packages\kwant\builder.py in hamiltonian(self, i,  
j, params, *args)

   1995 try:
-> 1996 value = value(self.sites[i], **params)
   1997 except Exception as exc:

~\Anaconda3\lib\site-packages\wraparound.py in (*args)
 81 return lambda *args: sum((val(*args) if callable(val)  
else val)

---> 82  for val in vals)
 83

~\Anaconda3\lib\site-packages\wraparound.py in (.0)
 81 return lambda *args: sum((val(*args) if callable(val)  
else val)

---> 82  for val in vals)
 83

~\Anaconda3\lib\site-packages\wraparound.py in f(a, *args)
 64 def f(a, *args):
---> 65 phase = cmath.exp(1j * ta.dot(elem, args[mnp:]))
 66 v = val(a, sym.act(elem, a), *args[:mnp]) if  
callable(val) else val


ValueError: Both arguments must have same length.

The above exception was the direct cause of the following exception:

UserCodeError Traceback (most recent call last)
 in ()
> 1 ham_mat = kwant_sys.hamiltonian_submatrix(params=dict(k_x=0,  
k_y=0, k_z=0, B=0.02), sparse=True)


kwant\_system.pyx in kwant._system.hamiltonian_submatrix()

~\Anaconda3\lib\site-packages\kwant\builder.py in hamiltonian(self, i,  
j, params, *args)

   1996 value = value(self.sites[i], **params)
   1997 except Exception as exc:
-> 1998 _raise_user_error(exc, value)
   1999 else:
   2000 try:

~\Anaconda3\lib\site-packages\kwant\builder.py in _raise_user_error(exc, func)
   1883 msg = ('Error occurred in user-supplied value function "{0}".\n'
   1884'See the upper part of the above backtrace for  
more information.')

-> 1885 raise UserCodeError(msg.format(func.__name__)) from exc
   1886
   1887

UserCodeError: Error occurred in user-supplied value function "".
See the upper part of the above backtrace for more information.
-



Eleni



Quoting Joseph Weston :


Hi



sym = kwant.TranslationalSymmetry(
    lattice.vec((1, 0, 0)),
    lattice.vec((0, 1, 0)),
lattice.vec((0, 0, 1))
)

[]

#Hall bar
def onsite(site, B):
  (x, y, z) = site.pos
  return stored_model[site]

def hopping_Ax(site1, site2, B):
  x1, y1, z1 = site1.pos
  x2, y2, z2 = site2.pos
  return stored_model[site1,site2] * np.exp(-0.5j * B * (x1 + x2)
* (y1 - y2))

kwant_model[lattice.shape(shape, (0, 0, 15))] = onsite
kwant_model[lattice.neighbors()] = hopping_Ax

kwant_sys = wraparound.wraparound(kwant_model).finalized()

 B = 0.02
# Obtain the Hamiltonian as a dense matrix
ham_mat = kwant_sys.hamiltonian_submatrix(args=[B], sparse=True)


The docstring for 'wraparound' [1] says that the wrapped around system will
have additional parameters, corresponding to the momenta. As you have a 3D
system and have wrapped around all 3 dimensions, the parameters will be
'k_x', 'k_y', and 'k_z'.

As you have only supplied a single argument (B) to your system, an error
is raised.
You will need to provide all the arguments to your system:

    kwant_sys.hamiltonian_submatrix(params=dict(k_x=0, k_y=0, k_z=0,
B=B), sparse=True)

Happy Kwanting,

Joe


[1]:
https://kwant-project.org/doc/1/reference/generated/kwant.wraparound.wraparound#kwant.wraparound.wraparound




--
Dr. Eleni Chatzikyriakou
Computational Physics lab
Aristotle University of Thessaloniki
elch...@auth.gr - tel:+30 2310 998109



Re: [Kwant] Onsite and hopping values in QHE

2018-07-11 Thread elchatz

Hello,


Just as a note I chose a system with no symmetry (and no leads) to  
check the spectrum which gives no errors and is easier to work with.


I used the code from the tutorial\closed_system.py

The subtle point here was that: When defining a shape (with no  
symmetry), all three dimensions of the system need to be defined  
otherwise TBModels hangs.


Regards,

Eleni



Quoting elch...@auth.gr:


Hello Joseph,

Thank you for replying. I still can't make this work.


---
ham_mat = kwant_sys.hamiltonian_submatrix(params=dict(k_x=0, k_y=0,  
k_z=0, B=0.02), sparse=True)

---
ValueErrorTraceback (most recent call last)
~\Anaconda3\lib\site-packages\kwant\builder.py in hamiltonian(self,  
i, j, params, *args)

   1995 try:
-> 1996 value = value(self.sites[i], **params)
   1997 except Exception as exc:

~\Anaconda3\lib\site-packages\wraparound.py in (*args)
 81 return lambda *args: sum((val(*args) if  
callable(val) else val)

---> 82  for val in vals)
 83

~\Anaconda3\lib\site-packages\wraparound.py in (.0)
 81 return lambda *args: sum((val(*args) if  
callable(val) else val)

---> 82  for val in vals)
 83

~\Anaconda3\lib\site-packages\wraparound.py in f(a, *args)
 64 def f(a, *args):
---> 65 phase = cmath.exp(1j * ta.dot(elem, args[mnp:]))
 66 v = val(a, sym.act(elem, a), *args[:mnp]) if  
callable(val) else val


ValueError: Both arguments must have same length.

The above exception was the direct cause of the following exception:

UserCodeError Traceback (most recent call last)
 in ()
> 1 ham_mat = kwant_sys.hamiltonian_submatrix(params=dict(k_x=0,  
k_y=0, k_z=0, B=0.02), sparse=True)


kwant\_system.pyx in kwant._system.hamiltonian_submatrix()

~\Anaconda3\lib\site-packages\kwant\builder.py in hamiltonian(self,  
i, j, params, *args)

   1996 value = value(self.sites[i], **params)
   1997 except Exception as exc:
-> 1998 _raise_user_error(exc, value)
   1999 else:
   2000 try:

~\Anaconda3\lib\site-packages\kwant\builder.py in  
_raise_user_error(exc, func)

   1883 msg = ('Error occurred in user-supplied value function "{0}".\n'
   1884'See the upper part of the above backtrace for  
more information.')

-> 1885 raise UserCodeError(msg.format(func.__name__)) from exc
   1886
   1887

UserCodeError: Error occurred in user-supplied value function "".
See the upper part of the above backtrace for more information.
-



Eleni



Quoting Joseph Weston :


Hi



sym = kwant.TranslationalSymmetry(
    lattice.vec((1, 0, 0)),
    lattice.vec((0, 1, 0)),
lattice.vec((0, 0, 1))
)

[]

#Hall bar
def onsite(site, B):
  (x, y, z) = site.pos
  return stored_model[site]

def hopping_Ax(site1, site2, B):
  x1, y1, z1 = site1.pos
  x2, y2, z2 = site2.pos
  return stored_model[site1,site2] * np.exp(-0.5j * B * (x1 + x2)
* (y1 - y2))

kwant_model[lattice.shape(shape, (0, 0, 15))] = onsite
kwant_model[lattice.neighbors()] = hopping_Ax

kwant_sys = wraparound.wraparound(kwant_model).finalized()

 B = 0.02
# Obtain the Hamiltonian as a dense matrix
ham_mat = kwant_sys.hamiltonian_submatrix(args=[B], sparse=True)


The docstring for 'wraparound' [1] says that the wrapped around system will
have additional parameters, corresponding to the momenta. As you have a 3D
system and have wrapped around all 3 dimensions, the parameters will be
'k_x', 'k_y', and 'k_z'.

As you have only supplied a single argument (B) to your system, an error
is raised.
You will need to provide all the arguments to your system:

    kwant_sys.hamiltonian_submatrix(params=dict(k_x=0, k_y=0, k_z=0,
B=B), sparse=True)

Happy Kwanting,

Joe


[1]:
https://kwant-project.org/doc/1/reference/generated/kwant.wraparound.wraparound#kwant.wraparound.wraparound




--
Dr. Eleni Chatzikyriakou
Computational Physics lab
Aristotle University of Thessaloniki
elch...@auth.gr - tel:+30 2310 998109




--
Dr. Eleni Chatzikyriakou
Computational Physics lab
Aristotle University of Thessaloniki
elch...@auth.gr - tel:+30 2310 998109



Re: [Kwant] Onsite and hopping values in QHE

2018-09-15 Thread elchatz

Hello again,

For the translation vectors, I managed to do some progress. I don't  
know how I should declare by arguments so that they get where they are  
supposed to. Here is what I have until now:


-
kwant_model = kwant.Builder()
kwant_model[lattice.shape(shape, (0, 0, 15))] = 0
model.add_hoppings_kwant(kwant_model)

def onsite(site, params=dict(B=0, k_x=0, k_y=0, k_z=0)):
  return kwant_model[site]

def hopx(site1, site2, params=dict(B=0, k_x=0, k_y=0, k_z=0)):
  x1, y1, z1 = site1.pos
  x2, y2, z2 = site2.pos
  for key, value in params.items():
if key == 'B':
  B=value
  return kwant_model[site1,site2] * np.exp(-0.5j * B * (x1 + x2) * (y1 - y2))

#Make a new model pointing in the previous model
new_model = kwant.Builder(sym)
#Change the on-site elements
new_model[lattice.shape(shape, (0, 0, 15))] = onsite

#Change the lattice hoppings
for i in (range(len(lattice.sublattices))):
  kwant_model[lattice.sublattices[i].neighbors()] = hopx

for R, mat in model.hop.items():
  dir = tuple(np.array(R))
  for i, s1 in enumerate(lattice.sublattices):
for j, s2 in enumerate(lattice.sublattices):
  if i !=j:
new_model[kwant.builder.HoppingKind(dir,  
lattice.sublattices[i],lattice.sublattices[j])] = hopx


# Finalize the system.
sys = wraparound.wraparound(new_model).finalized()


--

But I am still getting errors.


So my questions are:

1) Do I have to use a dictionary in the onsite and hopping function  
definitions? From what I understand, if I only use the B argument,  
maybe it gets 'eaten' in the memoize and I get a 'missing positional  
arguments error'.


2) What do you think the symmetry of the original model should be and  
what of the new_model so that I can write on the momentum operator  
arguments properly?



Kind Regards,


Eleni





Quoting Joseph Weston :


Hi



sym = kwant.TranslationalSymmetry(
    lattice.vec((1, 0, 0)),
    lattice.vec((0, 1, 0)),
lattice.vec((0, 0, 1))
)

[]

#Hall bar
def onsite(site, B):
  (x, y, z) = site.pos
  return stored_model[site]

def hopping_Ax(site1, site2, B):
  x1, y1, z1 = site1.pos
  x2, y2, z2 = site2.pos
  return stored_model[site1,site2] * np.exp(-0.5j * B * (x1 + x2)
* (y1 - y2))

kwant_model[lattice.shape(shape, (0, 0, 15))] = onsite
kwant_model[lattice.neighbors()] = hopping_Ax

kwant_sys = wraparound.wraparound(kwant_model).finalized()

 B = 0.02
# Obtain the Hamiltonian as a dense matrix
ham_mat = kwant_sys.hamiltonian_submatrix(args=[B], sparse=True)


The docstring for 'wraparound' [1] says that the wrapped around system will
have additional parameters, corresponding to the momenta. As you have a 3D
system and have wrapped around all 3 dimensions, the parameters will be
'k_x', 'k_y', and 'k_z'.

As you have only supplied a single argument (B) to your system, an error
is raised.
You will need to provide all the arguments to your system:

    kwant_sys.hamiltonian_submatrix(params=dict(k_x=0, k_y=0, k_z=0,
B=B), sparse=True)

Happy Kwanting,

Joe


[1]:
https://kwant-project.org/doc/1/reference/generated/kwant.wraparound.wraparound#kwant.wraparound.wraparound




--
Dr. Eleni Chatzikyriakou
Computational Physics lab
Aristotle University of Thessaloniki
elch...@auth.gr - tel:+30 2310 998109