dimod.ConstrainedQuadraticModel.to_file

ConstrainedQuadraticModel.to_file(*, spool_size: int = 1000000000) tempfile.SpooledTemporaryFile[source]

Serialize to a file-like object.

Parameters

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.1):

This format is inspired by the NPY format

The first 8 bytes are a magic string: exactly “DIMODCQM”.

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:

dict(num_variables=len(cqm.variables),
     num_constraints=len(cqm.constraints),
     num_biases=cqm.num_biases(),
     num_quadratic_variables=cqm.num_quadratic_variables(),
     )

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

The constraint quadratic model data comes after the header. It is encoded as a zip file. The zip file will contain one file named objective, containing the objective as encoded as a file view. It will also contain a directory called constraints. The constraints directory will contain one subdirectory for each constraint, each containing lhs, rhs and sense encoding the lhs as a fileview, the rhs as a float and the sense as a string. Each directory will also contain a discrete file, encoding whether the constraint represents a discrete variable.

Format Specification (Version 1.0):

This format is the same as Version 1.1, except that the data dict does not have num_quadratic_variables.