|
4 | 4 | Serialization (with Graphs!)
|
5 | 5 | ==============================
|
6 | 6 |
|
7 |
| -Taurus objects link together to form graphs with directional edges. |
8 |
| -For example, a :class:`~taurus.entity.object.material_run.MaterialRun` links back to the :class:`~taurus.entity.object.process_run.ProcessRun` that produced it. |
| 7 | +GEMD objects link together to form graphs with directional edges. |
| 8 | +For example, a :class:`~gemd.entity.object.material_run.MaterialRun` links back to the :class:`~gemd.entity.object.process_run.ProcessRun` that produced it. |
9 | 9 | Some of these links are bi-directional.
|
10 |
| -For example, a :class:`~taurus.entity.object.process_run.ProcessRun` also links forward to the :class:`~taurus.entity.object.material_run.MaterialRun` that it produces, if there is one. |
| 10 | +For example, a :class:`~gemd.entity.object.process_run.ProcessRun` also links forward to the :class:`~gemd.entity.object.material_run.MaterialRun` that it produces, if there is one. |
11 | 11 | Other links are uni-directional.
|
12 |
| -For example, a :class:`~taurus.entity.object.material_run.MaterialRun` links to its :class:`~taurus.entity.object.material_spec.MaterialSpec` but that :class:`~taurus.entity.object.material_spec.MaterialSpec` doesn't link back. |
| 12 | +For example, a :class:`~gemd.entity.object.material_run.MaterialRun` links to its :class:`~gemd.entity.object.material_spec.MaterialSpec` but that :class:`~gemd.entity.object.material_spec.MaterialSpec` doesn't link back. |
13 | 13 | Uni-directional links are typically used when the multiplicity of a relationship can be large.
|
14 | 14 | For example, a material may be referenced in thousands of ingredients.
|
15 | 15 |
|
16 |
| -In taurus, bi-directional links are readable but only a single direction is writable. |
17 |
| -For example, a :class:`~taurus.entity.object.measurement_run.MeasurementRun` can set the :class:`~taurus.entity.object.material_run.MaterialRun` material that it was performed on, |
18 |
| -but a :class:`~taurus.entity.object.material_run.MaterialRun` cannot set the :class:`~taurus.entity.object.measurement_run.MeasurementRun`s it contains. |
19 |
| -Each time a :class:`~taurus.entity.object.measurement_run.MeasurementRun`'s ``material`` field is set, |
20 |
| -that :class:`~taurus.entity.object.material_run.MaterialRun` has the :class:`~taurus.entity.object.measurement_run.MeasurementRun` appended to its ``measurements`` field. |
| 16 | +In GEMD, bi-directional links are readable but only a single direction is writable. |
| 17 | +For example, a :class:`~gemd.entity.object.measurement_run.MeasurementRun` can set the :class:`~gemd.entity.object.material_run.MaterialRun` material that it was performed on, |
| 18 | +but a :class:`~gemd.entity.object.material_run.MaterialRun` cannot set the :class:`~gemd.entity.object.measurement_run.MeasurementRun`s it contains. |
| 19 | +Each time a :class:`~gemd.entity.object.measurement_run.MeasurementRun`'s ``material`` field is set, |
| 20 | +that :class:`~gemd.entity.object.material_run.MaterialRun` has the :class:`~gemd.entity.object.measurement_run.MeasurementRun` appended to its ``measurements`` field. |
21 | 21 |
|
22 | 22 | This linking structure presents several challenges for serialization and deserialization:
|
23 | 23 |
|
24 | 24 | a. The graph cannot be traversed through uni-directional links in the wrong direction.
|
25 | 25 | b. Only the writeable side of bi-directional links can be persisted.
|
26 | 26 | c. Objects that are referenced by multiple objects must be deserialized to the same object.
|
27 | 27 |
|
28 |
| -These challenges are addressed by a custom json serialization procedure and the special :class:`~taurus.entity.link_by_uid.LinkByUID` class. |
| 28 | +These challenges are addressed by a custom json serialization procedure and the special :class:`~gemd.entity.link_by_uid.LinkByUID` class. |
29 | 29 |
|
30 | 30 | 1. Each entity that doesn't already have at least one unique identifier is assigned a unique identifier so it can be referenced.
|
31 |
| -2. The graph is flattened by traversing it while maintaining a seen list and replacing object references to other entities with :class:`~taurus.entity.link_by_uid.LinkByUID` objects, producing the set of entities that are reachable. |
| 31 | +2. The graph is flattened by traversing it while maintaining a seen list and replacing object references to other entities with :class:`~gemd.entity.link_by_uid.LinkByUID` objects, producing the set of entities that are reachable. |
32 | 32 | 3. The objects are sorted into a special "writable" order that ensures that link targets are created when deserializing.
|
33 | 33 | 4. This sorted list of entities is assigned to the "context" field in the serialization output.
|
34 | 34 | 5. The original object (which may contain multiple entities) is assigned to the "object" field in the serialization output.
|
35 |
| -6. The serialization output is serialized with a special :class:`~json.JSONEncoder`, :class:`~taurus.json.taurus_encoder.TaurusEncoder`, that skips the soft side of links. |
| 35 | +6. The serialization output is serialized with a special :class:`~json.JSONEncoder`, :class:`~gemd.json.gemd_encoder.GEMDEncoder`, that skips the soft side of links. |
36 | 36 |
|
37 |
| -Here's an example of the serialized output for a :class:`~taurus.entity.object.material_spec.MaterialSpec` and :class:`~taurus.entity.object.process_spec.ProcessSpec`: |
| 37 | +Here's an example of the serialized output for a :class:`~gemd.entity.object.material_spec.MaterialSpec` and :class:`~gemd.entity.object.process_spec.ProcessSpec`: |
38 | 38 |
|
39 | 39 | ::
|
40 | 40 |
|
@@ -81,10 +81,10 @@ Here's an example of the serialized output for a :class:`~taurus.entity.object.m
|
81 | 81 | The deserialization is a comparatively simple two-step process.
|
82 | 82 | First, the string or file is deserialized with python's builtin deserializer and a custom object hook.
|
83 | 83 | This hook does three things:
|
84 |
| -it knows how to build taurus entities and other :class:`~taurus.entity.dict_serializable.DictSerializable` objects, |
85 |
| -it creates an index with the unique identifiers of the taurus entities that it has seen so far, |
86 |
| -and it replaces any :class:`~taurus.entity.link_by_uid.LinkByUID` that it encounters with objects from that index. |
| 84 | +it knows how to build GEMD entities and other :class:`~gemd.entity.dict_serializable.DictSerializable` objects, |
| 85 | +it creates an index with the unique identifiers of the gemd entities that it has seen so far, |
| 86 | +and it replaces any :class:`~gemd.entity.link_by_uid.LinkByUID` that it encounters with objects from that index. |
87 | 87 | The only thing left to do is return the ``"object"`` item from the resulting dictionary.
|
88 | 88 |
|
89 |
| -This strategy is implemented in the :class:`~taurus.json.taurus_json.TaurusJson` class |
90 |
| -and conveniently exposed in the :py:mod:`taurus.json` module, which provides the familiar `json` interface. |
| 89 | +This strategy is implemented in the :class:`~gemd.json.gemd_json.GEMDJson` class |
| 90 | +and conveniently exposed in the :py:mod:`gemd.json` module, which provides the familiar `json` interface. |
0 commit comments