-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add updater from 24.11.6 to 24.11.7 to handle missing private_attribute_id of PointArray * Move compare_dicts, _lists and _values to updater_utils * Reduce the size of reference simulation json for unit test
- Loading branch information
1 parent
2297e7b
commit 11f8f4c
Showing
9 changed files
with
708 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
"""Utiliy functions for updater""" | ||
|
||
from numbers import Number | ||
|
||
import numpy as np | ||
|
||
|
||
def compare_dicts(dict1, dict2, atol=1e-15, rtol=1e-10, ignore_keys=None): | ||
"""Check two dictionaries are same or not""" | ||
if ignore_keys is None: | ||
ignore_keys = set() | ||
|
||
# Filter out the keys to be ignored | ||
dict1_filtered = {k: v for k, v in dict1.items() if k not in ignore_keys} | ||
dict2_filtered = {k: v for k, v in dict2.items() if k not in ignore_keys} | ||
|
||
if dict1_filtered.keys() != dict2_filtered.keys(): | ||
print(f"dict keys not equal, dict1 {dict1_filtered.keys()}, dict2 {dict2_filtered.keys()}") | ||
return False | ||
|
||
for key in dict1_filtered: | ||
value1 = dict1_filtered[key] | ||
value2 = dict2_filtered[key] | ||
|
||
if not compare_values(value1, value2, atol, rtol, ignore_keys): | ||
print(f"dict value of key {key} not equal dict1 {dict1[key]}, dict2 {dict2[key]}") | ||
return False | ||
|
||
return True | ||
|
||
|
||
def compare_values(value1, value2, atol=1e-15, rtol=1e-10, ignore_keys=None): | ||
"""Check two values are same or not""" | ||
if isinstance(value1, Number) and isinstance(value2, Number): | ||
return np.isclose(value1, value2, rtol, atol) | ||
if isinstance(value1, dict) and isinstance(value2, dict): | ||
return compare_dicts(value1, value2, atol, rtol, ignore_keys) | ||
if isinstance(value1, list) and isinstance(value2, list): | ||
return compare_lists(value1, value2, atol, rtol, ignore_keys) | ||
return value1 == value2 | ||
|
||
|
||
def compare_lists(list1, list2, atol=1e-15, rtol=1e-10, ignore_keys=None): | ||
"""Check two lists are same or not""" | ||
if len(list1) != len(list2): | ||
return False | ||
|
||
if list1 and not isinstance(list1[0], dict): | ||
list1, list2 = sorted(list1), sorted(list2) | ||
|
||
for item1, item2 in zip(list1, list2): | ||
if not compare_values(item1, item2, atol, rtol, ignore_keys): | ||
print(f"list value not equal list1 {item1}, list2 {item2}") | ||
return False | ||
|
||
return True |
Oops, something went wrong.