Serialize¶
Collection of serializers that transform Python data into a BSON-compatible form.
-
class
vivarium.core.serialize.DictDeserializer(name='')[source]¶ Bases:
vivarium.core.registry.SerializerIterates through dictionaries and applies deserializers.
-
class
vivarium.core.serialize.FunctionSerializer(name='')[source]¶ Bases:
vivarium.core.registry.SerializerSerializer for function objects.
-
class
vivarium.core.serialize.NumpyBoolSerializer(name='')[source]¶ Bases:
vivarium.core.registry.SerializerSerializer for
np.bool_objects.
-
class
vivarium.core.serialize.NumpyFloat32Serializer(name='')[source]¶ Bases:
vivarium.core.registry.SerializerSerializer for
np.float32objects.
-
class
vivarium.core.serialize.NumpyInt32Serializer(name='')[source]¶ Bases:
vivarium.core.registry.SerializerSerializer for
np.int32objects.
-
class
vivarium.core.serialize.NumpyInt64Serializer(name='')[source]¶ Bases:
vivarium.core.registry.SerializerSerializer for
np.int64objects.
-
class
vivarium.core.serialize.NumpySerializer(name='')[source]¶ Bases:
vivarium.core.registry.SerializerSerializer for Numpy arrays. Numpy array serialization is lossy–we serialize to Python lists, so deserialization will produce a Python list instead of a Numpy array.
-
class
vivarium.core.serialize.ProcessSerializer[source]¶ Bases:
vivarium.core.registry.SerializerSerializer for processes if
emit_processis enabled.-
serialize(data: vivarium.core.process.Process) → str[source]¶
-
-
class
vivarium.core.serialize.SequenceDeserializer(name='')[source]¶ Bases:
vivarium.core.registry.SerializerIterates through lists and applies deserializers.
-
class
vivarium.core.serialize.SetSerializer(name='')[source]¶ Bases:
vivarium.core.registry.SerializerSerializer for set objects.
-
class
vivarium.core.serialize.UnitsSerializer[source]¶ Bases:
vivarium.core.registry.SerializerSerializes data with units into strings of the form
!units[...], where...is the result of callingstr(data). Deserializes strings of this form back into data with units.-
deserialize(data: str, unit: Optional[pint.unit.Unit] = None) → pint.quantity.Quantity[source]¶ Deserialize data with units from a human-readable string.
- Parameters
data – The data to deserialize. Providing a list here is deprecated. You should use
deserialize_valueinstead, which uses a separate list deserializer.unit – The units to convert
datato after deserializing. If omitted, no conversion occurs. This option is deprecated.
- Returns
A single deserialized object or, if
datais a list, a list of deserialized objects.
-
-
vivarium.core.serialize.deserialize_value(value: Any) → Any[source]¶ Find and apply the correct serializer for a value by calling each registered serializer’s
vivarium.core.registry.Serializer.can_deserialize()method. Returns the value as is if no compatible serializer is found.- Parameters
value (Any) – Data to be deserialized
- Raises
ValueError – Only one serializer should apply for any given value
- Returns
Deserialized data
- Return type
Any
-
vivarium.core.serialize.get_codec_options() → bson.codec_options.CodecOptions[source]¶ Returns a set of options used for serializing and deserializing BSON by collecting codecs from all registered serializers.
-
vivarium.core.serialize.serialize_value(value: Any, codec_options: Optional[bson.codec_options.CodecOptions] = None) → Any[source]¶ Apply PyMongo’s TypeCodec-based serialization routine on
value.- Parameters
value (Any) – Data to be serialized
codec_options (bson.codec_options.CodecOptions) – Options used when encoding / decoding BSON. Defaults to None, in which case options are generated from the currently registered serializer codecs.
- Returns
Serialized data
- Return type
Any