serialization
Serialization utilities for BWD objects.
deserialize(json_str)
Deserialize a balancer object from JSON string
Reconstructs a balancer object from its serialized JSON representation, restoring both its definition and state.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
json_str
|
str
|
JSON string containing the serialized balancer |
required |
Returns:
| Type | Description |
|---|---|
BWD, BWDRandom, MultiBWD, or Online
|
The deserialized balancer object with restored state |
Source code in src/bwd/serialization.py
normalize(to_serialize)
Normalize data structures for JSON serialization
Recursively converts numpy arrays to lists and normalizes nested dictionaries to ensure all data types are JSON-serializable.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
to_serialize
|
dict
|
Dictionary containing data to normalize |
required |
Returns:
| Type | Description |
|---|---|
dict
|
Normalized dictionary with JSON-compatible types |
Source code in src/bwd/serialization.py
serialize(obj)
Serialize a balancer object to JSON string
Serializes the balancer's definition and state to a JSON-formatted string that can be saved and later deserialized.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
obj
|
BWD, BWDRandom, MultiBWD, or Online
|
The balancer object to serialize |
required |
Returns:
| Type | Description |
|---|---|
str
|
JSON string representation of the object |