dimod.ConstrainedQuadraticModel.from_file#
- classmethod ConstrainedQuadraticModel.from_file(fp: BinaryIO | ByteString, *, check_header: bool = True) ConstrainedQuadraticModel [source]#
Construct from a file-like object.
- Parameters:
fp – File pointer to a readable, seekable file-like object.
check_header – If True, the header is checked for consistency against the deserialized model. Otherwise it is ignored.
The inverse of
to_file()
.Examples
>>> cqm1 = dimod.ConstrainedQuadraticModel() >>> x, y = dimod.Binaries(["x", "y"]) >>> cqm1.set_objective(2 * x * y - 2 * x) >>> cqm_file = cqm1.to_file() >>> cqm2 = dimod.ConstrainedQuadraticModel.from_file(cqm_file) >>> print(cqm2.objective.to_polystring()) -2*x + 2*x*y