Convert a `TensorBoardInfo` to string form to be stored on disk. The format returned by this function is opaque and should only be interpreted by `_info_from_string`. Args: info: A valid `TensorBoardInfo` object. Raises: ValueError: If any field on `info` is not of the
(info)
| 97 | |
| 98 | |
| 99 | def _info_to_string(info): |
| 100 | """Convert a `TensorBoardInfo` to string form to be stored on disk. |
| 101 | |
| 102 | The format returned by this function is opaque and should only be |
| 103 | interpreted by `_info_from_string`. |
| 104 | |
| 105 | Args: |
| 106 | info: A valid `TensorBoardInfo` object. |
| 107 | |
| 108 | Raises: |
| 109 | ValueError: If any field on `info` is not of the correct type. |
| 110 | |
| 111 | Returns: |
| 112 | A string representation of the provided `TensorBoardInfo`. |
| 113 | """ |
| 114 | field_name_to_type = typing.get_type_hints(TensorBoardInfo) |
| 115 | for key, field_type in field_name_to_type.items(): |
| 116 | if not isinstance(getattr(info, key), field_type): |
| 117 | raise ValueError( |
| 118 | "expected %r of type %s, but found: %r" |
| 119 | % (key, field_type, getattr(info, key)) |
| 120 | ) |
| 121 | if info.version != version.VERSION: |
| 122 | raise ValueError( |
| 123 | "expected 'version' to be %r, but found: %r" |
| 124 | % (version.VERSION, info.version) |
| 125 | ) |
| 126 | json_value = dataclasses.asdict(info) |
| 127 | return json.dumps(json_value, sort_keys=True, indent=4) |
| 128 | |
| 129 | |
| 130 | def _info_from_string(info_string): |
no test coverage detected
searching dependent graphs…