Skip to content

Commit

Permalink
Added tests for pickle import
Browse files Browse the repository at this point in the history
  • Loading branch information
st4rl3ss committed Feb 5, 2024
1 parent 5659b11 commit 82319af
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
15 changes: 15 additions & 0 deletions neurodamus/utils/memory.py
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,21 @@ def export_allocation_stats(rank_allocation, filename):
logging.warning("Unable to export allocation stats: {}".format(e))


@run_only_rank0
def import_allocation_stats(filename):
"""
Import allocation dictionary from serialized pickle file.
"""
import pickle
try:
with open(filename, 'rb') as f:
rank_allocation = pickle.load(f)
return rank_allocation
except Exception as e:
logging.warning("Unable to import allocation stats: {}".format(e))
return None


class SynapseMemoryUsage:
''' A small class that works as a lookup table
for the memory used by each type of synapse.
Expand Down
10 changes: 10 additions & 0 deletions tests/integration-e2e/test_dry_run_worflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,13 @@ def test_dry_run_workflow(USECASE3):
}
assert nd._dry_run_stats.metype_counts == expected_items
assert nd._dry_run_stats.suggest_nodes(0.3) > 0

# Test that the dry run mode works with a pickle file
import pickle
try:
with open((str(USECASE3 / "allocation.bin")), 'rb') as f:
rank_allocation = pickle.load(f)
except Exception as e:
print("Unable to import allocation stats: {}".format(e))
expected_items = {'NodeA': {0: [3]}, 'NodeB': {1: [2]}}
assert rank_allocation == expected_items

0 comments on commit 82319af

Please sign in to comment.