I'm working on a python program that uses mpmath to implement the Chunovsky algorithm for computing pi. I want to make my program log its progress to a file on regular intervals, so that I can recover progress if there's a power outage or something similar, since the program will be running for a while. I'm using a dps of about a million, so converting to a decimal string is very slow. I need a way to encode an mpf object as a raw binary bytes or bytearray object. I can't seem to find anything about this in the mpmath documentation. I could serialize it with pickle, but I think it would be slower than necessary, since it would serialize more information than I need.
mpf? I've used mpmath some, but haven't studied its docs.mpmathand I've only searched the docs for a conversion/serialization to bytes function, not studied it's internal memory usage. I'm still wondering about other ways to do it.