serialize
Canonical encoding, decoding and hashing for workflow objects, and the files those documents are written to.
A Task is identified by a fingerprint: a digest of what it is and what it was given. That only works if the same parameters always encode to the same bytes, so this module turns arbitrary python values into a JSON tree with a fixed shape, then hashes its canonical text.
Two modes exist. "fingerprint" encodes values for hashing: an array becomes a digest of its bytes and a value left at None is dropped. "document" encodes values for storage: an array becomes a nested list and nothing is dropped, so most values read back. A function, a partial, or a value with no encoding of its own is named rather than reproduced in either mode, and a dataframe has no document form at all; decoding any of them raises. write_workflow and read_workflow put a document on disk in the format its suffix names, refusing a suffix which names none.
Stability rests on json, repr of a float, numpy’s byte layout and blake2b, none of which change between python versions, and – for frames and quantities only – on pandas’ object hash and pint’s short unit format. Python’s own hash is never used: it is salted per process.
Functions
| Name | Description |
|---|---|
| canonical_json | Return the canonical JSON text of an object. |
| combine_hashes | Return one digest standing for an ordered series of digests. |
| decode | Return the object a document-mode encoding stands for. |
| digest | Return a stable 16 character digest of any encodable object. |
| encode | Return a JSON-safe tree standing for an object. |
| model_values | Return a model’s fields and extras, as the objects they are. |
| read_workflow |
Return the workflow document a file holds; see write_workflow.
|
| write_workflow | Write a workflow document to a file, in the format its suffix names. |