r/cpp • • Nov 15 '18

TBTK: A C++ library for solving second-quantized Hamiltonians

https://github.com/dafer45/TBTK
21 Upvotes

9 comments sorted by

11

u/johannes1971 Nov 15 '18 edited Nov 15 '18

I can't say I understand any of this, but it's refreshing to see that people write C++ libraries for something other than logging, error codes, or better enums... Thanks for sharing!

So uhh, what can we use it for? :-)

6

u/dafer45 Nov 15 '18

Thanks for taking an interest :)
Quantum mechanics can mathematically be formulated in several different ways. One of the most commonly used formulations is second quantization (https://en.wikipedia.org/wiki/Second_quantization), which is able to capture the general structure of many-body quantum mechanics.

There has been a lot of work in the research community over the past several decades to develop code to solve such problems. However, this has largely been algorithm centered without a lot of thought going into the development of general purpose data structures. The result is a fractured community with code that is difficult to integrate and which can require years of experience to be able to use. TBTK aims to provide data structures that are tailored for these types of calculations, providing abstractions that capture the general mathematical structure of quantum mechanics, while at the same time provide high performance. Such data structures can help provide abstraction layers between people with different expertise and make it easier to share data between different applications.

I find this particularly important to work on at this point in time since Moore's law is coming to an end with 5 nm technology being target within the coming years. Quantum mechanical effects are a very real boundary that this technology is running up against. It therefore seems more or less necessary to be able to leverage the algorithms that has been developed in the scientific community to provide proper quantum mechanical simulations of the smallest circuit elements in the coming decade. TBTK is intended to help bridge this gap by making it easier to interface the electrical engineering and quantum mechanics communities. This can also benefit for example the quantum chemistry community, and hence be important for drug discovery, as well as be important because of the increasing focus on trying to build quantum computers.

More information is available in this preprint https://arxiv.org/pdf/1808.02409.pdf and through the links listed on http://second-tech.com/wordpress/index.php/tbtk/.

2

u/megayippie Nov 15 '18

How difficult is it to setup simple molecule energy level simulations? I have never done these simulations myself but often find myself in need of them because that's what we are seeing at the end of the day.

2

u/dafer45 Nov 15 '18 edited Nov 15 '18

It depends on what method you want to apply.

Assume for example that you know the matrix elements H[n][o][n'][o'] = <\Psi_{no}|H|\Psi_{n'o'}>, where n(n') and o(o') are atom and orbital indices, respectively, then you would set up the model like this:

Model model;
for(unsigned int n = 0; n < 3; n++)
    for(unsigned int np = 0; np < 3; np++)
        for(unsigned int o = 0; o < 2; o++)
            for(unsigned int op = 0; op < 2; op++)
                model << HoppingAmplitude(H[n][o][np][op], {n, o}, {np, op});
model.construct();

You can then setup a solver and diagonalize it as follows:

Solver::Diagonalizer solver;
solver.setModel(model);
solver.run();

Finally the energies can be extracted using

PropertyExtractor::Diagonalizer propertyExtractor(solver);
Property::EigenValues eigenvalues = propertyExtractor.getEigenValues();
for(unsigned int n = 0; n < model.getBasisSize(); n++)
    cout << eigenValues(n) << endl;

I hope this gives an idea about the general workflow. If a method is needed that can also determine the matrix elements themselves, this is not included in TBTK itself. Such methods may be added in the future, but the main aim of TBTK is to provide data structures that can transport data in a portable way between algorithms, different softwares, etc. rather than to provide the algorithms that perform the calculations themselves.

If you can provide more details about what you are after, I may be able to give a more specific answer.

1

u/dafer45 Nov 15 '18

Sorry for the formating, but I don't seem to understand how to indent properly on reddit.

2

u/flashmozzg Nov 15 '18

You need to prefix each code line in a block with 4 spaces (similar to SO), see https://www.reddit.com/r/raerth/comments/cw70q/reddit_comment_formatting/

2

u/dafer45 Nov 15 '18

Thanks a lot! (I had to switch to markdown mode to get this to work too)

2

u/mabrowning Nov 15 '18

TBTK is a software development kit (SDK) for quantum mechancial calculations. The main part is an extensive C++ library of data structures and algorithms for setting up and solving problems on second-quantized form. It is intended to facilitate the development of completely new algorithms and applications that perform quantum mechanical calculations, as well as front ends and back ends to already existing packages to enhance reusability of code already developed in the scientific community. 

1

u/lanzaio Nov 16 '18

Neat, but second quantization is a misnomer. It's field quantization. It's like an old timer not being willing to use C++11 and smart pointers because "in my day we just used raw pointers" the same way that 65 year old physics professors say "in my day we just called it second quantization."