QuadraticModel.to_file(*, spool_size: int = 1000000000) SpooledTemporaryFile[source]#

Serialize the QM to a file-like object.


spool_size – Defines the max_size passed to the constructor of tempfile.SpooledTemporaryFile. Determines whether the returned file-like’s contents will be kept on disk or in memory.

Format Specification (Version 1.0):

This format is inspired by the NPY format

The first 7 bytes are a magic string: exactly “DIMODQM”.

The next 1 byte is an unsigned byte: the major version of the file format.

The next 1 byte is an unsigned byte: the minor version of the file format.

The next 4 bytes form a little-endian unsigned int, the length of the header data HEADER_LEN.

The next HEADER_LEN bytes form the header data. This is a json-serialized dictionary. The dictionary is exactly:

data = dict(shape=qm.shape,
            variables=not qm.variables._is_range(),

it is terminated by a newline character and padded with spaces to make the entire length of the entire header divisible by 64.

The quadratic model data comes after the header.