Current density operator fails with continuum.discretize
I'm using the stable 1.4.1 version, discretizing the BHZ Hamiltonian using the continuum.discretize method, attaching leads and trying to plot the current density. I'm following two approaches.
First approach
First I try by editing the example from Section 2.10 of the documentation, file discretize.py
. But it fails with the error:
File "/home/gerson/.MeusApps/anaconda3/lib/python3.8/site-packages/kwant/builder.py", line 1816, in _raise_user_error
raise UserCodeError(msg.format(func.__name__)) from exc
UserCodeError: Error occurred in user-supplied value function "hopping_1".
See the upper part of the above backtrace for more information.
To see it, start from the example on Section 2.10 of the documentation, file discretize.py
and replace the density operator in line 101 and the plot in line 109 with
prob_density = kwant.operator.Current(syst, np.eye(4))
# ...
kwant.plotter.current(syst, wf_sqr)
Second approach
In the code from discretize.py
the matrices are hard-coded in the template using kron
and sigma_n
calls. Instead, for my final code I want to pass the matrices using params
. In this case both the density and current operators return the error below, which seems to arise from the miss-definition of the norbs
parameter. It seems that the continuum.discretize
method does not account for norbs
properly if the matrices are delayed to be passed as params
.
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-37-066cccf78e37> in <module>
----> 1 kwant.plotter.density(sys, D0(psi), colorbar=False);
kwant/operator.pyx in kwant.operator._LocalOperator.__call__()
ValueError: vector is incorrect shape
I'm guessing these errors are related.