Units Killed NASA’s Mars Orbiter. Here’s how PUFF fixes it.
Why the Mars Climate Orbiter Exploded
In September of 1999 a $125 million dollar NASA space probe burned up into pieces.
The reason:
The software calculating the force the thrusters needed was in pounds. The code that read the data assumed it was in Newtons Per Square Meter. One small mistake in code and years of work and millions of dollars down the drain.
Your data science projects might not be quite so well funded, or quite so explosive, but the same fundamental problem that killed the Mars Orbiter in 1999 still destroys data science projects today.
In this post, we’re talking about how to fix that.
How Could NASA Make Such A Basic Mistake?
The Mars Climate Orbiter was launched by NASA on the 11th of December 1998 with the goal of studying the atmosphere on the red planet as part of the Mars Surveyor ‘98 mission, one in which both space probes were unfortunately lost. In the case of the latter, the Mars Polar Lander, the issue was that on landing the engine firing was turned off too early and basically crashed into the planet too hard, showing just how delicate it is to get the maths right.
There’s a reason “It’s not rocket science” is an expression to say something is not difficult, because the actual maths needed to take a 600+kg probe all the way through space to observe another planet is staggering, to say the least, but the reason I’m talking about the Mars Climate Orbiter in this video is because the problem that caused this failure was actually devastatingly simple: It was just a mismatch in units.
Picture of scientists with the Mars Climate Orbiter on one side and a rocket launch on the other
Units, like data science, funnily enough, is a concept that evolved naturally due to a need for standardisation. From what we can tell, numerous ancient societies developed their own independent units to track things like the weight of goods for buying and selling or sizes and distances.
Eventually, the metric system was defined, emerging from the French Revolution and gradually the rest of the world has adopted it, well mostly. There are a few holdouts, here in the UK I know my height in feet and inches but my weight in kilograms, but another major country is the United States of America where NASA is situated.
The US has its own form of units, the United States Customary Units and so many calculations in the US are done using the United States Customary Units. However, in many use cases, SI units, which are the International System of Units that the metric system turned into, is used in preference and a big place where they are is in science and scientific research.
Images of News articles by the BBC covering the Missing and destroyed Mars Orbiter and MPL
So what happens when you have a company, NASA, working at the cutting edge of practical space research, situated in the United States, a country that prefers to use its own unit system? The exact disaster of the Mars Climate Orbiter.
The discrepancy came from a piece of ground software supplied by Lockheed Martin which outputted results in the United States Customary Units. However, the NASA system that consumed these numbers expected the results to be in SI Units. Lockheed Martin produced numbers using pound-force seconds and NASA used them as if they were in Newton seconds.
The difference between the two was a factor of 4.45 and that incorrect number was fed into the trajectory calculation. This meant that when the orbiter entered Mars’ atmosphere, it likely went much deeper than it was designed to handle and the spacecraft was subsequently lost.
NASA didn’t blame Lockheed Martin for the error. In fact it was viewed as a system failure on NASA’s side. When you read the articles from the time, there were layers and layers of process that were either insufficient or incorrectly implemented that meant his problem wasn’t caught even though it was flagged by navigators at the time.t
And while it was probably fair to highlight systemic issues in process and management that were going on at NASA at the time, I can’t help but wonder why so much process was necessary to solve what should be a simple issue. I mean if code can throw me an error if I try to add a string to a float because they’re not compatible types, why can’t they do the same thing with units as well?
I actually tried googling for an answer for this and the topic still remains quite niche, outside of a cool programming language called Frink. So let’s talk about what putting units into code could look like and how this would have saved NASA’s Mars Climate Orbiter.
Lockheed Martin Logo
NASA logo
How Do You Code with Units?
The problem with adding units into a programming language is that you need a concept of propagating them. If you add two things together with the same unit, then you should still get the same unit on the answer. But if you start multiplying and dividing units you have to start tracking not only the numeric calculation, but that of the units as well.
And that’s not always straightforward. If I multiply a number by centimetres and then divide by kilometers, it needs to understand that these units are the same unit system and can cancel out, but the result needs to be adjusted to reflect that. Throw inches into the mix and the problem soon becomes complicated to retrofit back into a system.
However, when we were creating PUFF, our data science platform for efficiency, security and explainability, instead of tacking new functionality onto Python, we actually built data science from the ground up. There are a number of benefits to doing this, and most of them are security related which I’ll talk about in a separate video, but it does mean we had the ability to build units in from the start and propagate them through with our metadata propagation system. More about that another day.
So the way that this works is that if I have two numbers like this, say one in inches, one in centimetres, I can add them together just like this, it works out that the units are compatible and converts the output to whatever the left unit is. If I try and add a temperature of Kelvin instead however, see I get an error.
What’s cool about this is that we can then put it in a data frame and do the same exercise, I can add columns of compatible units together, I can’t when they’re not.
Now this would have saved NASA in their Mars Climate Orbiter problem so it’s unfortunate that they were nearly three decades too early, but for most modern businesses they don’t spend a lot of time working with distances or temperatures in Kelvin or even pound-force seconds, believe it or not. But what they do spend a lot of time working with is currencies.
I know it sounds simple and many of us are arrogant enough to think that we wouldn’t make that mistake, but I’ve worked as a quant and I can assure you that all of us at some point have accidentally added numbers in two different currencies, not realised and had to go back and fix it later. So we’ve implemented currencies as units as well.
If I have this dataframe with numbers in Great British Pounds and Euros and I try and add them, oh look, it’s saved me from having to explain to my traders the stupid mistake I didn’t realise I’d made earlier. If I want to convert them, I just have to make a foreign exchange rate like this, multiply and add. It’s really that simple.
We deliberately don’t source and convert exchange rates but if you have an exchange rate source, you just need to tag it with the fx units and there you go, you’re working with currency with the protection of units and all you need to do is tag it.
When I demo this I’m always a little sad that it’s not flashier because this is really cool and saves so many mistakes but it doesn’t look as impressive on my screen. So maybe let’s finish off by reimplementing NASA’s mistake.
So I have the first number here, let’s just say it’s 1 and I’m going to tag it with pound-force seconds. Let’s just keep it simple here and say it’s added to another number to calculate the predicted trajectory and let’s make that number 2 and put it in Newton-seconds.
So in NASA’s world, if I added those two numbers together, it would give me 3 Newton-seconds, which is not actually correct and caused the issue. A basic units implementation where you cannot add things of different units would have it failing because the units are wrong and at least that means someone can kick off the investigation process and make sure it goes through. But here’s the third option:
In the world of PUFF, if I add these two numbers together I get x. The NASA number, plus the Lockheed Martin number, converted into the SI units NASA expected. It’s not big and flashy, but it just works and would have saved a $125 million dollar NASA probe.
This is actually one of our more minor data science quality of life upgrades that we’ve made in PUFF, we have a tun more that tie in directly to efficiency, security and explainability for your audit trail. If you’d like to know a little more, head to our blog page to continue reading more posts or to our youtube channel to watch all our content.
Our closed beta is now Live. Sign up via the link below and keep being Evil