Sergey Slizovskiy wrote: > Something strange happens... I have tried to reduce my system size > to make a profiling run shorter, but still it's taking too > long. I have only retained a call to "gauge" in the main > code. Attached is profile 7z arxiv for a really small system with > graphene trilayer of radius 5 with 6 leads attached. It still > takes around a minute to run.
It’s normal that a program runs longer with profiling enabled. The slowdown is more pronounced if the inner loop(s) involve calls to short-running functions. However, in the case of your script, the amount of slowdown when profiling is enabled is indeed extreme. The inner loop (‘gauge’) consists of Cython code. I was surprised to see the individual cython-only functions of the ‘kwant.graph.dijkstra’ module appear in the profile. I now understand the reason for this: some time in 2016 I changed [1] the way that line tracing (a more precise form of profiling) can be enabled in Kwant build configuration. Due to an oversight, this permanently enabled regular profiling of Cython functions. To get more meaningful results I changed the value of ‘size’ in the call to ‘make_system’ at the bottom of your script to 8. With regular Kwant I measure a runtime of 77.7 s. With Cython profiling disabled by changing compiler_directives={'linetrace': True} to compiler_directives={'linetrace': False} in line 428 of setup.py and rebuilding Kwant, I measure 46.4 s. That’s nice to have, however it’s not yet the dramatic speedup that would enable you to treat much bigger systems. I have profiled your script (with ‘size=8’) and Kwant with disabled Cython profiling. The runtime of the script is now unchanged by the profiling. 97% of the runtime is now spent in the gauge submodule that appears as a monolithic block. So, it seems to me, that further speed up of gauge calculations will be difficult to obtain, unless there were some (unlikely, I believe) glitches in its implementation. It looks like automatic gauge calculation has a price and should be certainly avoided for big systems and simple magnetic fields. If you are unable to build your own Kwant with the above modification to setup.py, you will have to wait for a bugfix release that will correct this problem for everybody. I guess that we will make one in the next few weeks or so. Hope this was useful to you Christoph [1] https://gitlab.kwant-project.org/kwant/kwant/-/commit/10faf93a16bee7c596283d97bb31a85b48304ea9
smime.p7s
Description: S/MIME cryptographic signature