There are enough tensor-network/DMRG packages that support python (ALPS, OpenMPS, pyUni10) that it would seem (to an outsider) that it's possible to do some substantial work with DMRG without messing with C or any other languages. Are these packages sufficiently fast and full-featured that students could do meaningful research work using just python?

  • 2
    $\begingroup$ ALPS seems to be written in C++ (based just on the front page of their website). OpenMPS seems to be written in Python and FORTRAN 2003 (based on their paper's abstract). pyUni10 seems to be a Python wrapper for Uni10 which is in C++. Sure if a student wants to do meaningful research without learning C, C++ or FORTRAN, they can just run the above C++/FORTRAN codes from Python. Why not? Even though I misinterpreted the question at the time of writing my answer, it's still relevant: I argued that NumPy/MATLAB/Julia is also ok for the whole code. $\endgroup$ – Nike Dattani Jul 26 '20 at 23:47

There probably are good Python bindings to various DMRG implementations, which allow one to run DMRG from Python. Since the implementations typically rely on lower-level C/C++/Fortran routines, the calculations run quite quickly. E.g. PySCF appears to have bindings to various DMRG programs, see https://sunqm.github.io/pyscf/dmrgscf.html.

If you're talking about developing a new Python-only DMRG code, I doubt you'll succeed: the overhead is just too great. Julia might be an interesting alternative, though.

  • $\begingroup$ Thanks! I'm talking about using one of these existing packages to do research, not writing a code totally from scratch in python. $\endgroup$ – taciteloquence Jul 27 '20 at 3:29

I would argue that you can use a package like DMRG++, which is written in C++, without knowing much C/C++ or indeed any language. It has its own input format that takes some getting used to (unfortunately it isn't overly well documented), but the outputs are provided in text and hdf5 formats that you can then manipulate with your favorite scripting language - e.g. python. Yet all heavy lifting, so to speak, is done by the provided C++ code. Unless you need to modify or troubleshoot that code, perhaps to add a non-standard model, you can definitively avoid messing with C++. Also, the code is actively maintained so even in such cases it might be possible to avoid messing with C++ yourself.


I've heard people talking about working on tensor networks for electronic structure since the 2000s, but here in the 2020s I'm aware of no code that can help me solve the problems in which I'm interested. I think "serious" tensor network codes for electronic structure are still a "dream", and I'm becoming more and more doubtful that any time in the next few years we'll see (more general) tensor networks become "mainstream" in (almost) the way DMRG did.

I have heard of progress with PEPS and MERA but mainly for spin Hamiltonians. I see that the Wikipedia page for DMRG currently provides links to iTensor, and Uni10 for which Adam Iaizzi (one of our favorite people, here at Matter Modeling SE) is a co-author. I can't quite figure out based on the documentation, how general of a tensor network iTensor supports, but it seems that whatever tensor networks they implement, can only be applied to spin Hamiltonians "models" rather than the "electronic structure Hamiltonian" in which I am personally interested. Uni10 seems to be able to do PEPS and MERA in addition to DMRG and maybe more, but again I cannot figure out to which Hamiltonians it can be applied. Both iTensor and Uni10 are written in C++.

"Is python sufficient for serious tensor network/DMRG calculations?"

In 2011 Martin Plenio told me at a Royal Society meeting that he coded a basic DMRG program himself in MATLAB (which you can imagine, is very doable). This means that NumPy too, can suffice for some purposes, since MATLAB and NumPy both call BLAS to do the heavy lifting (matrix arithmetic).

I wrote a very similar code called FeynDyn (Feynman Dynamics) for calcualting Feynman integrals numerically using the "tensor propagation algorithm", which involves extremely high-rank tensors, organized in such a way that all necessary calculations can be done using matrix arithmetic (so the whole program is written in MATLAB which is about as fast as you can get for matrix arithmetic on either CPUs or GPUs). This is as far as I know, the fastest tensor propagation code for Feynman integrals based on all comparisons I've done to FORTRAN codes written by leading colleagues in the field: Not only does it get the calculations done faster than all FORTRAN codes I've compared it to, when I run both my code and their code on a CPU, but thanks to the GPU programmers working at MathWorks my code benefits from a major speed-up, while none of the FORTRAN or C++ codes do can run on GPUs (they could probably get their codes working on GPUs with OpenACC or some CUDA wrapper but only someone who knows their code well enough can do it, and based on what I understand, those codes were not vectorized like mine, so they'll probably have to write the code from scratch to compete with my GPU performance). I had never heard of NumPy when I started writing FeynDyn, but my understanding is that it could be similar in performance but might not get the same GPU acceleration (at least not nearly as easily!).

Closing thoughts:

  • If the fastest tensor propagation code for Feynman integrals is written in MATLAB, and beats the FORTRAN codes written by other world leaders in the field, then NumPy may also do reasonably well on CPUs.
  • This is because the tensor propagation algorithm (not too different from what happens in a tensor network code, in terms of core low-level arithmetic used) can be vectorized so that it can pretty much be done using only BLAS functions that were written by people whose job was to make BLAS as fast as possible.
  • As far as I know, Python (and Octave!) have not caught up to MATLAB in terms of GPU computing. It can be frustrating to work with MATLAB due to licensing issues and the amount of time it takes to load (it doesn't sound like the most important thing, but it's still a problem for me even in 2020). Nevertheless, even my present MSc student who was born in the mid-90s prefers MATLAB for some of the things we're doing.
  • I am one of the most anti-Python people you'll meet, and when I first saw this question I immediately thought of pointing to the fact that all "serious" electronic structure codes use FORTRAN or C++, at least for the numerically expensive parts, but halfway through writing this answer I remembered the similarity between my tensor propagation code and tensor networks, and have come to the conclusion that NumPy is sufficient, but MATLAB is better for the GPU support and Julia might be the best thing in the middle.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.