How to write a good README?

Documenting your code might seem like a time-wasting distraction. It’s very easy to convince yourself in the moment “I’ll totally remember how this works” or “it should be obvious what this line does.” I’ve done it myself, and then been totally confused by my own code when I go back to it a few months later. Comments within the code itself are an important form of documentation, but this post will discuss a different form: the README.

What is a README?

You’ve definitely already seen a README: they’re the text files that introduce a project and briefly explain how it works. Whenever you go to a git repo on Github or Gitlab (like uni10 or Firefox) the README serves as the landing page, but you’ll also see README files almost any time you download or install software. The README is the first stop for anyone that will use your code. If you design it well, it might be the last stop too:

Your documentation is complete when someone can use your module without ever having to look at its code. … Remember: the documentation, not the code, defines what a module does.

–Ken Williams (source)

Why do I need to write a README?

Code is only as useful as its documentation. As scientists, we have an extra responsibility to document our code because our code is basically like part of an experiment. It is crucial that your code is an accurate record of what you did, even if you think you are the only person that will ever use your program. In our group the primary problem is ensuring that your code is usable by someone else after you leave. Perhaps another student will need it, or we might need to recheck some calculation.

Of course, often other people will use your code, and a well-written README can help them understand how it works, what its limitations are, and how to use it. The selfish reason to write one is for yourself in the future. Perhaps you know there is some issue with your program, like the parameter J cannot be set to a number greater than 2. That might be fine right now, but will you remember that when you have to rerun your code a year from now? Another good example are dependencies, especially if you had to install anything special. If you write those down right away it will be easy to get your code running on a different machine or after an operating system upgrade.

How to I write a README?

There is no single best answer here. The most important thing is that you do write one. You might think that its obvious how to compile and run your code, but someone new might be totally lost. Little things like compiler flags can really trip a new user up.

What should it include?

In the following subsections I provide some examples of sections you may want to include in your README file.

There is no shortage of README templates out there. These are a good place to start, but computational physics codes have unique needs, so I posted a template on Gitlab you can use as a starting point if you like.

Introduction

At the very top you should have a brief introduction that includes:

  • Program name
  • Name of author(s)
  • Contact information (email, website)
  • A brief description of what your program does
    • What technique it uses
    • The model it studies
    • What it’s for (why would someone want to use this program?)
  • Copyright notice. I’m not an expert on licenses, so I don’t have much advice here. To keep it simple you can just say “Copyright YOUR NAME YEAR”
  • Links to more extensive documentation elsewhere (papers, examples, etc).

Quick Start

Instructions to quickly get started with your program, e.g. how to compile and install with default settings and how to run it (it’s useful to include an easy way to test if they compiled and installed it correctly.

Prerequisites

What does your program assume about the system? You don’t necessarily need to test rigorously, but you can at least say what system you developed your code on and what compiler you used. Write these down as you write your code so you don’t have to remember them lately. Other examples of dependencies:

  • Libraries (especially anything you had to install, like MPI)
  • Anything platform-dependent
  • A specific compiler required
  • Other external programs
  • uni10

Program Files

List your source code files and any auxiliary files, where they are located and what they are for.

Inputs

What inputs does your program require? Do you specify the parameters of the simulation as command line arguments or are they in a file? What is the format of the file? Which parameters are optional? What are the default values?

Outputs

If it runs properly your program probably produces data. Is that data displayed on screen? Written to disk? Returned by a function? What format is the data in? How is it normalized?

References

This section definitely distinguishes computational physics code from ordinary programming. You don’t need to provide a full biography, but some links to papers that describe the method you’re using in detail, or papers you wrote using this program would be great.

Known Issues

Is there anything about your code that doesn’t work? Maybe J cannot be set to zero, maybe there’s a small memory leak, or a segfault that occurs under specific conditions. Depending on the bug, you might not really need to fix it, but it’s definitely important to tell the user so they aren’t caught by surprise (in some cases the user may be you in the future).

Formatting with Markdown

You will probably want to write your README in Markdown. Markdown is a simple way to format a text document (as opposed to markUP, get it? 🤔). The idea of Markdown is to allow minimal formatting while while remaining readable as plain text. You’re probably already familiar with Markdown since it is commonly used for simple text formatting on platforms like Slack. Both Github and Gitlab support Markdown. If you use a mac you can even get “Quick Look” (using the spacebar to view a preview of a file) to display correctly formatted markdown text using my guide here.

I’m not going to do a Markdown tutorial here (instead see the links in the resource section), but as a very quick introduction:

Enclose *italic* text within asterisks and **bold** text within double asterisks. You can include inline code using single backticks `like this` or sections of code with triple backticks like so:
```
int x=5;
cout << x << endl;
```

A Markdown-formatted file will typically end in ‘.md’. A quick Google search will return countless examples of Markdown editors for any platform.

Resources

Debugging MPI with Xcode Visual Debuggers

The Xcode visual debugger is really nice and easy to use. It turns out it’s possible to get it to play well with MPI code (although it may not work for actually multithreaded processes). This seems to be pretty buggy, but it does work. I’m not sure how useful this guide is to others, but honestly I’m writing it to remember how to do this in the future.

Compiling

mpic++ is just a wrapper for the system C++ compiler, but on my system is defaults to g++ and we want to switch to c++ (the Apple C compiler). To start, we use the --show-me:compile flag with our usual compilation command
mpic++ --show-me:compile *.cpp
This doesn’t actually compile the code, it just tells you the command that would have actually been executed with the C compiler. In my case the output is:
g++ config.cpp main.cpp mtrand.cpp -I/usr/local/include -L/usr/local/lib -lmpi
We’re going to take all those flags and put them after the Apple C compiler like so:
c++ -g config.cpp main.cpp mtrand.cpp -I/usr/local/include -L/usr/local/lib -lmpi
Don’t forget to add the debugging flag -g. This command produces a binary file a.out. Before we can run it, we need to get Xcode ready.

Launching the Debugger

Open the Xcode project. On the menubar, select Debug–>Attach to Process by PID or Name…

Screenshot showing menu selection.


In the resulting window, enter the name of the executable (this this case a.out) and click “Attach”.

Screenshot of debugging attachment dialogue.

Now we’re ready to actually run our simulation using the normal command in the terminal:
mpirun -np 1 ./a.out

When you switch back to Xcode, you should be able to use the debugging interface like normal. If it doesn’t come up automatically you may have to click on the debugging logo in the navigation bar on the left side of the window (circled below).

Xcode navigation bar with the debugging tab circled.

Trouble attaching to process?

For some reason I find that Xcode cannot attach to the process using this procedure often with an error like “Message from debugger: error 1”. I haven’t been able to figure out exactly why this happens or how to avoid it altogether. My use case is way outside what Xcode is designed for (i.e. building iOS apps). Overall I found that using the stop button within Xcode to kill the process (rather than killing it from the terminal) seems to make this problem less likely, but it still happens.

Once this problem occurs, the only solution I have found is to recompile the binary, naming it something else using the -o othername.out flag (renaming an existing binary won’t work), attaching the debugger to the new binary and then running the new binary.


Article recommendation: Do quantum spin liquids exist?

I recently read this phenomenal Physics Today article by Takashi Imai and Young Lee, “Do quantum spin liquids exist?” Physics Today 69, 8, 30 (2016). It’s a couple years old, but it’s a clear, relatively non-technical description of quantum spin liquids (QSL) and why they’re interesting along with a easy-to-follow history of developments in the field up to today. This provides some much needed clarity, especially since journal articles about QSL often use varying definitions of QSL.

Gave a seminar at NCKU today

Today and tomorrow I’m visiting National Cheng Kung University (成功大學) in Tainan. I was graciously invited to give a seminar by Prof. Ching-Hao Chang (thanks!). If anyone reading this wants to chat, I’ll be visiting until Tuesday afternoon. I’m staying in the fourth-floor visitor’s office.

Title: Accessing quantum criticality with magnetic field effects: metamagnetism and deconfined quantum criticality
Abstract: Simple models of interacting quantum spins (like the Heisenberg model) are remarkable tools for understanding strong quantum fluctuations, but relatively few studies have considered the effects of external magnetic fields on these systems. I investigate the influence of magnetic fields in the J-Q model, an antiferromagnetic Heisenberg model with an added 4-spin interaction (Q). This model is known to harbor a direct, continuous phase transition between the Nel state and a valence-bond solid. This transition is believed to be an example of deconfined quantum criticality, where the excitations are exotic fractionalized particles known as spinons (S=1/2 bosons). We study the thermodynamics of the excitations and find direct evidence that they are indeed fractional. Separately, we also find that the four-spin term changes the nature of the saturation transition from “zero-scale-factor” universality to metamagnetism (magnetization jumps).

I was walking by the SpringerNature booth at the March Meeting and the agent I worked with (Sam Harrison) pointed out that a print copy of my dissertation was there, on display and for sale! Truly a surreal experience!

Me and my dissertation on display at the March Meeting

Me and my dissertation on display at the March Meeting. Thanks to Sam Harrison for taking this picture for me.

iaizzi

March 6, 2019

iaizzi's avatar

I just finished presenting my March Meeting talk, Infinite boundary conditions as a current source for impurity conductance in a quantum wire. Slides here.

 

 

March Meeting 2019

I’m about to set off to Boston for the APS March Meeting 2019 (March 4-8). I’ll be presenting my newest work on using infinite boundary conditions are current reservoirs for measuring steady-state currents in quantum wires using tensor network methods. My talk is at Wednesday 6 March at 8:48am in room 156C. If you want to chat with me at the March Meeting drop me a line.

After the March Meeting I’ll be visiting the Sandvik group at Boston University 11-20 March. I’m really looking forward to seeing all my old friends and colleagues at BU.

I’m joining the APS FECS Executive Committee!

I’m thrilled to announce that I have been elected to serve as a “Member-at-Large” on the Executive Committee of the APS Forum for Early Career Scientists (FECS).

Established just three years ago, FECS is is dedicated to helping APS meet the unique needs of early career scientists (i.e. postdocs). Early career scientists face a number of unique challenges. They often move great distances, isolating themselves from their support networks. They have neither the protection of tenure nor the comradeship of classmates, and they often occupy temporary positions with low pay, meager benefits, and few labor protections. They must balance the pressure to publish with the constant search for their next position. All of these factors put them at an elevated risk for exploitation and harassment, the worst of which often falls upon women and minorities.

I am looking forward to working to make life better for early career scientists like myself. I want to focus especially on the problems faced by underrepresented minorities as well as mental health. In addition to my own ideas, I want to hear from you, my friends and colleagues, about issues that are facing early career scientists and ideas for how FECS might be able to address them. Please contact me or comment below with your thoughts and suggestions.

If you’re an APS member who is interested in joining FECS, you can do so for free by logging into your account on aps.org. You can also join the FECS Facebook group, even if you’re not an APS member.

Back-to-Back conferences: Taiwan Physical Society

Last week I was back in Hsinchu for the three-day Annual Meeting of the Taiwan Physical Society.

This conference was very local: only about 10% of the participants were from abroad (I’m uncertain if that figure includes people like me). They were nonetheless able to get some pretty good invited speakers including my PhD supervisor, Anders Sandvik, and Nobel Laureate and former US Secretary of Energy Steven Chu. I was honored to shake Secretary Chu’s hand at the banquet (unfortunately, there is no selfie).

I gave a talk based on thermodynamics of deconfined spinons in a magnetic field, the same topic as my poster from the ICAM-NCTS.

I had great conversations with Taiwanese physicists, including some new potential collaborators. I was also able to catch up with my PhD supervisor, Anders Sandvik to discuss some aspects of the modifications I am making to my QMC code in order to measure off-diagonal imaginary-time correlations.

As a bonus, while walking from my hotel to the conference I stumbled upon the NTHU Research Reactor. I’ve always wanted to see the inside of a nuclear reactor, but I never managed to get a tour of the MIT research reactor (despite living only blocks away from it in Cambridge, MA). Hopefully I can get a tour of this one.

Me in front of the NTHU reactor building.
Photo of Nanyuan garden

ICAM-NCTS Workshop

Last week I attended the NCTS-ICAM Annual Meeting and Workshop [edit: updated link] at National Tsing-Hua University (清華大學) in Hsinchu (新竹), Taiwan. It was a delightful week of presentations and discussions with condensed matter physicists from all over the world and an excellent opportunity to build my professional network here in Taiwan. 

I presented my poster “Direct numerical observation of Bose-Einstein condensation of deconfined spinons” in which I use a magnetic field to induce a finite density of magnetic excitations at a deconfined quantum critical point and use thermodynamics to show that they must be deconfined spinons (an extension of Ch. 4 of my dissertation). I received some excellent feedback on my poster that will help improve my manuscript. 

There were fascinating talks including David Campbell, Duncan Haldane, Nic Shannon and Suchitra Sebastian. ICAM also made the wise decision to include a panel discussion on women in physics as part of the main schedule (rather than in a parallel session or as an extra event). It was a great opportunity to hear from women physicists about the challenges they face and to get some updated data from Laura Greene (former president of APS). 

Part of the conference was an excursion to 南圓 (Nanyuan), a beautiful resort in the foggy mountains near Hsinchu. We had a tour of the beautiful Chinese garden and partook in a tea ceremony.