r/AskComputerScience • u/[deleted] • Nov 30 '18
Is Python in space? Are any rovers, probes, satellites coded in python?
25
u/Sqeaky Nov 30 '18
Not to the best of my knowledge.
The ISS has a fairly high-end system running Linux, so it might have python.
I am not in aerospace but to have read into their practices and to the best of my knowledge are built in assembly, C or C++ for the several reasons. The rad hardened hardware is old and slow. Resources are so constrained many don't even have a conventional OS and instead have an real time OS (RTOS) which are generally minimal and have certain strict performance guarantees. This also generally means inspection of the machine code to insure there aren't any surprises.
In aerospace it is also common practice to prohibit dynamic allocation of memory because if you never allocate you can never leak. Since python does reference counting or other garbage collection automatically it can be easy to accidentally tail to free memory. It is unreasonable to have the support team fly 100 million miles to bounce your probe because it exhausted memory even though you were sure that couldn't happen.
Finally, the main benefits of a language like python is rapid development time. This is super useful when the team is rapidly iterating in response to user feedback and new market opportunities arise. This is not space at the moment. The users are expert engineers. When a space probe goes to prod it physically goes away so it needs to be reliable. Currently there is no market pressure in space.
Python forgoes normal compilation and compile time safety checks to shorten development time. This isn't a benefit in space travel. When a probe costs 80 million the cost to retain a dev team for an extra few months is pretty minimal compared to the of risks that python introduces. The assurances or type checks and/or machine code verification are so much more important.
This reflects a common dynamic we see in software development, the cost of technical debt. If your team is rapidly iterating and time is more important than quality. Perhaps you are researching or testing the market, then you would choose a language and tools that allow you write sloppy code quickly. If you need to ignore good design, use globals, or use gotos to make a deadline you do it because the short term matters. This garbage code is technical debt and that is ok, because you traded that for a reduced development cycle. You also might not need to pay it back if all the code is thrown away. If you do decide to keep it then adding unit tests and refactoring will eventually be used to pay back this tech debt and reduce bugs.
If your team is refining an existing product, solving a well defined problem, or can't tolerate the risk associated with bugs then pick a language with more guarantees. In C++, Rust, and Swift it is possible to make new numeric types with unit data that would prevent adding 3 inches to 4 seconds. This takes time to do, but increases certainty the has few bugs. Code written so carefully would never have gotos, globals or to her common bad patterns. It would also take an order of magnitude longer to write.
What many do, and I suspect even NASA does, is to code prototypes in something simple and fast with less regard to quality to vet ideas. Then once an idea is good to expand it or rewrite it in something faster or more typesafe as the business, budget, or opportunity permit.
4
u/grammarpolice0fficer Nov 30 '18
This is super interesting. Do you have a source?
2
u/Sqeaky Nov 30 '18
I have read ton over the past 20 years, there are a ton of articles.
For one job I held I was reviewing government approved software guidelines and I had to read the MISRA Aerospace rules and evaluate it for use in our context which wasn't aerospace. It had a specific name that wasn't as clean as "MISRA Aerospace", but more like "MISRA axlwbtkx-2+3+;_-2016" or some other noise. So just looking into the MISRA rules rather than relying on my faulty memory is probably good: httpskipedia.org/wiki/MISRA_C
If you feel motivated and masochistic you can get you own copy of the MISRA rules: https://www.misra.org.uk/Publications/tabid/57/Default.aspx
2
u/slimjim_belushi Nov 30 '18
That's not to say there's no place for python. Like you said, it might be installed on the Linux box on the ISS, and it could be very useful for astronauts doing experiments and stuff.
It's much easier and faster to write testing scripts in an interpreted language like python, especially using python wrappers for C libraries which is more and more popular these days. So the underlying code is still optimized and efficient, but the interface is in python.
2
Dec 02 '18
It's much easier and faster to write testing scripts in an interpreted language like python
Such a bold claim needs a very convincing proof.
1
u/slimjim_belushi Dec 02 '18
In this context, python is being compared against low level languages like C. It's inherently easier to modify on the fly since it's interpreted, as opposed to having to recompile your code each time.
2
4
3
u/pas43 Nov 30 '18 edited Nov 30 '18
Good question!
Short Answer:
As someone who has looked into this, the answer is Yes!
Long Answer:
A lot of spacecraft use a special language called SCL (Spacecraft Control Language) This is a form of the programming language Ada (Named after Lady Ada who as also Lord Byron's daughter I believe and, The first so-called programmer). You might ask "but why the language ADA?"
Well I was told becuase it use of custom datatypes. Meaning you make all your own data types so you can make a 38.5 byte type. This was usefull for the non typical tasks a programming language might come across.
I also got told through the grapevine (Freenode) That a lot of either Boeings or Northrops satellites where coded in Perl. But only got told that by someone claiming to have worked there.
But this post says C and ASM which would be the obvious choice. https://space.stackexchange.com/questions/21948/what-is-the-most-popular-programming-language-in-space
This makes sense giving you have as much control and optimisation as you can get from the hardware if you use ASM. But you can also use a spin-off from the python interpreter like Mikro-Python which is designed for fast running code on embedded systems.
3
Dec 01 '18
which is designed for fast running code on embedded systems.
The word "fast" is misleading here.
2
2
1
u/Brainix Dec 01 '18
u/potatodemon has written Python code that ran (runs?) on the International Space Station.
1
u/cguess Dec 01 '18
This has been somewhat answered and yes, the answer is “probably ‘no’ but maybe on the ISS because the mission parameters between that and a Mars rover are so wildly different”
My favorite reading on this are two things: 1.) NASA’s own coding standards for C http://homepages.inf.ed.ac.uk/dts/pm/Papers/nasa-c-style.pdf. If you read it you will quickly realize there absolutely no way Python or any other related language could reach that level of specificity.
2.) This 1996 profile of NASA shuttle engineers from Fast Company gives a good insight into the fundamentally different culture of coding the organization has from, quite literally, any other group you’ve ever heard of. https://www.google.com/amp/s/amp.fastcompany.com/28121/they-write-right-stuff
If you want to learn that sort of stuff it’s actually really fun, but it’s going to require a fundamentally deeper understanding of systems and hardware.
Consider this: the Voyager probe just got a software upgrade to manage its slightly failing alignment equipment. It got this even though it’s not in the solar system anymore. It had to work, period, on 1960’s era tech (since it was fundamentally behind the time when it was launched).
-1
Nov 30 '18
Does Eve Online count?
2
Dec 01 '18
Eve online was coded in Python? Link?
3
u/Xorlev Dec 01 '18
EVE used standard Python, switched to Stackless Python ~2010: https://www.eveonline.com/article/stackless-python-2.7
46
u/MrP0tat0H3ad Nov 30 '18
Since python is an interpreted language, the interpreter needs to understand your code, check that it is valid in the current program instance then create instructions for your CPU to execute then pass it to your CPU.
On the other hand, languages like C are typically a compiled language. So, it is transformed into instructions that are specific for the machine it is compiled on, then to machine code, and then stored as an executable file. At runtime the instructions created by the compiler are 'read' and executed step by step by the CPU.
I'd imagine space probes, satellites, and the like are designed with as much optimizations as physically possible. With this in mind I'd think the extra cost from increased power consumption, slower execution speeds, and much more that I'm probably not aware of, would make python not a great choice for machines going to space.
However, I'm no engineer at NASA and this is all speculation, I'd love to learn more about the topic. +1 for awesome question