Learning to code for PSI

! Disclaimer: This is a slightly off topic post, but I think this can be of some interest to few others here.

What are some of the good resources to rapidly learn C++, to be able to contribute to PSI?

Here are some of the resource I have already come across:

  • @crawdad has an excellent tutorial : C++ Programming Tutorial in Chemistry
  • The Sherrill group’s website hosts many links to a lot of good resources. For example, I found a reference to a nice textbook in one of the lecture slides : C++ in One Hour a Day, Sams Teach Yourself by Siddhartha Rao

PS: I have decent background in quantum chemistry, have been programming in fortran90/95 and python for a long time now. But, I don’t directly work in electronic structure theory, and mostly use python/MATLAB/Mathematica for my regular workload. I ended up using PSI4 for a side project and ever since then, have been considering to learn enough C++ to be able to contribute to the package.

This very much depends on what you mean by “contribute to the package.” I’ll make broad comments for the general audience, but I can give more specific advice to you if I knew what contributions you had in mind.

Psi is structured as a combination of C++ and Python. Ideally, we use C++ only for performance-critical operations and default to Python. We’re still finding pieces that we transition over to Python. Migrating our geometry optimization code out is an ongoing project. So the first step is to identify what you want to do and figure out if that’s done on the C++ or the Python side. You may not even need to learn C++! For the rest of the answer, I’ll assume that you really do need to use C++.

For the special case of implementing electronic structure algorithms not in Psi4, ideally, you should have either prior experience with writing production-level electronic structure algorithms, or easy access to somebody who is willing to mentor you through it. While we can explain how particular libraries work, the art of efficiency is not easy to learn. If you are aware of the risk but still want to try implementing an algorithm, consult a developer for advice. It will be a learning process.

There are some particularities of Psi that are best learned by reading code and asking questions. A developer will be happy to recommend a section of code to read if you explain what you want to learn.

If your questions are basic C++ syntax, I again recommend reading existing code, ideally something fairly simple, and look up what you don’t understand on an as-need basis. I personally learn best through taking on “stretch projects,” but this is not true for everybody. I learned the very basics of C++ from Koenig and Moo’s Accelerated C++ and like Effective Modern C++ for C++11 features.

There’s a fellow postdoc in my group that I can get to chime in, come Monday.

Let me know if that helps, and if you have any more specific questions.

Thanks a lot for the reply.

I am actually interested in pulling together my existing code into something like an psi4 extension module. It mostly contains modules for quantum dynamics simulations and other supporting routines to calculate quantities relevant for time-resolved spectroscopy. Currently, most of my code base is written in python and harnesses the power of psi4 libraries like libmints, geometric etc to get the initial electronic structure data like molecular integrals and to form a diabatic basis. At its current stage it can be shipped of as a python package with psi4 as its main dependency. I have been trying to move the computational bottle necks to Fortran(using f2py) or C(as Cpython extension). But, I have not been able to figure out a consistent way to do this. I am guessing using cmake/pybind11 combination as its done in psi4 could possible be the most scalable way to do this across different architectures.

In general I agree with your advice about sitting with existing production level code. I’ve also found the code templates in psi4 to be a really useful guide to think about programming some subroutines.

I am happy to provide you with any other details that you’d like to know.

Thanks a lot for all the help!

Oh! Extension modules are called plugins, and Psi supports this. This is a good solution for code that you are going to be personally responsible for maintaining.

Here are some example plugins. Note that the middle example already includes Fortran files as part of the plugin with no issue. First example is a relatively simple plugin. Last example is the most sophisticated, and I help maintain that particular one.