11from collections import OrderedDict , deque
22from collections .abc import Callable , Iterable , MutableSet , Mapping , Set
33from functools import reduce , cached_property
4+ import json
45
56import numpy as np
67from multidict import MultiDict
@@ -672,6 +673,11 @@ class MemoryEstimate(frozendict):
672673 human_readable: frozendict
673674 The mapper, albeit with human-readable memory usage (MB, GB, etc)
674675 rather than raw bytes.
676+
677+ Methods
678+ -------
679+ to_json(path)
680+ Write the memory estimate to a JSON for scheduler ingestion.
675681 """
676682
677683 def __init__ (self , * args , ** kwargs ):
@@ -690,6 +696,21 @@ def human_readable(self):
690696 def __repr__ (self ):
691697 return f'{ self .__class__ .__name__ } ({ self .name } ): { self .human_readable ._dict } '
692698
699+ def to_json (self , path ):
700+ """
701+ Write the MemoryEstimate to JSON for ingestion by a scheduler.
702+
703+ Arguments
704+ ---------
705+ path: str
706+ The path to which the memory estimate should be written.
707+ """
708+ summary = {'name' : self .name , ** self ._dict }
709+ json_object = json .dumps (summary , indent = 4 )
710+
711+ with open (path , "w" ) as outfile :
712+ outfile .write (json_object )
713+
693714
694715class UnboundTuple (tuple ):
695716 """
0 commit comments