pygsti.baseobjs.mongoserializable.prepare_doc_for_existing_doc_check

pygsti.baseobjs.mongoserializable.prepare_doc_for_existing_doc_check#

prepare_doc_for_existing_doc_check(doc, existing_doc, set_id=True, convert_tuples_to_lists=True, convert_numpy_dtypes=True, round_to_sigfigs=6)#

Prepares a to-be inserted document for comparison with an existing document.

Optionally (see parameters): 1. sets _id of doc to that of existing_doc . This is useful in cases where the _id

field is redundant with other uniquely identifying fields in the document, and so inserted documents don’t need to match this field.

  1. converts all of doc ‘s tuples to lists, as the existing_doc is typically read from a MongoDB which only stores lists and doesn’t distinguish between lists and tuples.

  2. converts numpy datatypes to native python types

  3. rounds floating point values

Parameters:
  • doc (dict) – the document to prepare

  • existing_doc (dict) – the existing document

  • set_id (bool, optional) – when True, add an ‘_id’ field to doc matching existing_doc when one is not already present.

  • convert_tuples_to_lists (bool, optional) – when True convert all of the tuples within doc to lists.

  • convert_numpy_dtypes (bool, optional) – when True convert numpy data types to native python types, e.g. np.float64 -> float.

Returns:

the prepared document.

Return type:

dict