Using args in hamiltonian-function
Dear Kwant team, (am using the development version, 1.3) I am trying to plot the potential of my system and I want to use the hamiltonian(ind,ind,*args) function, but I don't understand how to use the args. Normally, I would give a vector with the values of the args as input, but this doesn't work in the case of hamiltonian (it does with hamiltonian_submatrix). What am I doing wrong? I also have a problem using the kwant.plot(sys) after I switched to Linux, I get the error message "NameError: name 'mplot3d' is not defined", is there something I need to install? Sincerely, Camilla
Hi Camilla,
(am using the development version, 1.3)
I am trying to plot the potential of my system and I want to use the hamiltonian(ind,ind,*args) function, but I don't understand how to use the args. Normally, I would give a vector with the values of the args as input, but this doesn't work in the case of hamiltonian (it does with hamiltonian_submatrix). What am I doing wrong?
if you are using 'hamiltonian' directly then you pass extra arguments directly to the function like so: syst.hamiltonian(i, j, param1, param2) I guess the confusion comes from the fact that usually you package up 'param1' and 'param2' into a sequence like all_params = [param1, param2] In this case you can use Python's argument unpacking [1] syntax: syst.hamiltonian(i, j, *all_params) The '*' will unpack the contents of 'all_params' in the call to 'syst.hamiltonian'.
I also have a problem using the kwant.plot(sys) after I switched to Linux, I get the error message "NameError: name 'mplot3d' is not defined", is there something I need to install?
Under what circumstances, precisely, do you see this? Please provide a backtrace and what version of matplotlib you have installed, and how it was installed (distribution package manager [which distro, which version], pip, conda, etc.) Thanks, Joe [1]: https://docs.python.org/3/tutorial/controlflow.html#tut-unpacking-arguments
participants (2)
-
Camilla Espedal
-
Joseph Weston