feat(frontend-python): implement dumping/loading of auto rounders

This commit is contained in:
Umut
2023-10-16 13:33:05 +02:00
parent 76b72b7feb
commit 8a3ac78fca
2 changed files with 68 additions and 1 deletions

View File

@@ -4,7 +4,7 @@ Declaration of `round_bit_pattern` function, to provide an interface for rounded
import threading
from copy import deepcopy
from typing import Any, Callable, Iterable, List, Tuple, Union
from typing import Any, Callable, Dict, Iterable, List, Tuple, Union
import numpy as np
@@ -123,6 +123,36 @@ class AutoRounder:
# pylint: enable=protected-access,too-many-branches
def dump_dict(self) -> Dict:
"""
Dump properties of the rounder to a dict.
"""
return {
"target_msbs": self.target_msbs,
"is_adjusted": self.is_adjusted,
"input_min": self.input_min,
"input_max": self.input_max,
"input_bit_width": self.input_bit_width,
"lsbs_to_remove": self.lsbs_to_remove,
}
@classmethod
def load_dict(cls, properties: Dict) -> "AutoRounder":
"""
Load previously dumped rounder.
"""
result = AutoRounder(target_msbs=properties["target_msbs"])
result.is_adjusted = properties["is_adjusted"]
result.input_min = properties["input_min"]
result.input_max = properties["input_max"]
result.lsbs_to_remove = properties["lsbs_to_remove"]
result.input_bit_width = properties["input_bit_width"]
return result
def round_bit_pattern(
x: Union[int, np.integer, List, np.ndarray, Tracer],