illuminating science

27/3/2006

The importance of thinking

Filed under: — Joel @ 12:26 pm

When I’m tutoring, I always “urge” my students to think about their answers and to do back of the envelope calculations before proceeding with the bigger problem. Today I almost became a hypocrit, but fortunately redeemed myself at the last second.

So, I was working on this problem where we want to calculate the absorption spectrum of a molecule (that is, what frequencies of light it will absorb, and how strongly at each frequency) when you take into account the vibrations of the molecule itself. These vibrations, called phonons, can use up extra energy from the light, or indeed supply the extra energy needed, and “broadens” out the spectrum. (The solvent (e.g., water) around the molecule also does this, and usually on a larger scale, but here we were specifically interested in the molecule vibrations.) We then wanted to compare our prediction to some experimental results and other simulations we’d done.

Anyway, the computer simulations had identified 60 vibrational modes (ways that the molecule can vibrate) and told us how strongly each mode coupled to the system. I was then working on predicting the absorption spectrum from those modes and couplings, and after much brain straining (Yes, that’s a scientific term :)) came up with a formula for all the peaks. The catch was, you had to sum over all the possible combinations of vibrations - first, try creating one vibration in Mode 1 and three vibrations in Mode 2, then try again, this time again creating one vibration in Mode 1 but two vibrations in Mode 2. Now, repeat that for sixty modes simultaneously, where you can have as many vibrations as you want! I decided, though, to restrict it to just 3 vibrations in each mode so that the total number of combinations I needed to consider was just 360, though I would obviously like to have more than that if possible. This looked like a suspiciously large number, but when I spoke to someone else from my group, they seemed confident that it could be done in a reasonable amount of time.

So we started thinking about how one could program it, and started working on some code, while I became increasingly uncomfortable with this large number. So I started to think more logically - a typical computer does roughly 1 billion CPU cycles per second (e.g., my PC has a 2GHz processor). If every one of those cycles could compute one of my cases, it would take roughly 360/109 seconds. Convert to years and…uh oh. Roughly a trillion years of computation. Darn it. Even using a super computer won’t change that, and particularly since each calculation will take well more than a cycle. Even if I only allowed 2 possible vibrations (i.e., one vibration, or none) I’d still need about 30 years. And to store that amount of data would require an awfully big disk.

Fortunately, I think I can comfortably ignore many of the modes - only about 20 have signficant coupling (using a natural break in the data) which will take only an hour or two, I think. Unfortunately, it would produce about 3 gigabytes of data, which is bad, so I’d need to find some way of selectively keeping the data or not. (I don’t know the best way of doing that, yet, but hopefully I’ll come up with something.)

Anyway, the moral of the story is, think before you code! Fortunately, we didn’t spend much time on it before thinking, and the code we did write will still be useful, but it could easily have been different!

BrettW Says:

Good post!

The Fermi estimates have done me well too (although giving me answers I don’t want to hear). For example I calculated that one subcase of a result I’d like to find for my PhD would require something like 2^50 calculations. And there may have been multiple cases as bad as that. Although disheartening, at least I knew the limits of the calculation and real progress could only be made if I improved my code by several orders of magnitude (or parallelized it by a similar amount).

Or if I wanted some very cutting-edge results, I’d be doing a calculation on roughly 2^100 subcases. Which meant that if each calculation took an electron (ha!) then I’d use a goodly number of the electrons in the entire universe (depending on the estimate you used). Of course I wouldn’t have much luck using the electrons in Alpha Centauri, but would reuse some Earth ones a few times. And this doesn’t even include the ones I’ll need to store this gigantic calculation. If I could borrow all the genetic material of people on Earth and turned it into hard-drives, then I’d still be lacking. Aw nuts…

 

Powered by WordPress