def preview_dict_recurse(d, depth=1): pd = PDT + cn({}) + PDT if depth > 0: pd = {} for k, v in listitems(d): if isdict(v): pd[k] = preview_dict_recurse(v, depth - 1) else: pd[k] = PDT + cn(v) + PDT return pd
def processGroup(group, rep, indent=0): for ke in listkeys(group): rep += '\t' * indent rep += ke item = group[ke] if 'Dataset' in cn(item): # c = 'Dataset' rep += f'\t\t{item.shape} {item.dtype}\n' elif 'Group' in cn(item): # c = 'Group' rep += '\n' rep = processGroup(item, rep, indent + 1) # sub = f'{item.shape} {item.dtype}' else: err(f'what is this: {cn(item)}') return rep
def __init__(self, d, forceNP=False): for a, b in d.items(): if isinstance(b, (list, tuple)): new = [ obj(x, forceNP) if isinstance(x, dict) else x for x in b ] if forceNP: new = arr(new) setattr(self, a, new) # isinstance(b, wolframclient.language.expression.WLFunction): elif 'WLFunction' in cn(b): if 'Rational[' in str(b): b = str(b).split('[')[1] b = str(b).split(']')[0] top = b.split(',')[0].strip() bot = b.split(',')[1].strip() setattr(self, a, float(top) / float(bot)) else: setattr(self, a, b) else: setattr(self, a, obj(b, forceNP) if isinstance(b, dict) else b)
def shadow_cache_im(self, a): return CELL_CACHE[cn(a)][self.__wrapped__.__name__][f'{cn(a)}_{self.__wrapped__.__name__}.png']
def shadow_cache(self, a): return CELL_CACHE[cn(a)][self.__wrapped__.__name__]['shadow.p']
def _output_cache(self, a): return CELL_CACHE[cn(a)][self.__wrapped__.__name__]['output.p']
def arr(v=(), dtype=None, ndims=None): import numpy as np # print('start arr') # mlog.log('arr1') if enable_debug: breakpoint() if ndims is None and ( isinstsafe(v, np.ndarray) or cn(v) == 'ImagingCore' or (len(v) > 0 and isinstance(v[0], Iterable) and not isstr(v[0]) and not (hasattr(v[0], '__npitr__') and v[0].__npitr__ is False))): return mparray(v, dtype=dtype) # mlog.log('arr2') if not isinstance(v, Iterable): # mlog.log('arr3') v = [v] if len(v) > 0 and not isnumber(v[0]): # mlog.log('arr4') if ndims is None: ndims = 1 if dtype is None: dtype = {str: object}.get(v[0].__class__, object) shape = [] slices = [] stopper = None # mlog.log('arr5') for d in range(ndims): if d > 0: stopper = [stopper] ref = v slices += [None] for dd in range(d): ref = ref[0] shape += [len(ref)] # mlog.log('arr6') v.append(stopper) shape[0] = shape[0] + 1 ar = np.ndarray(shape=tuple(shape), dtype=dtype) from mlib.file import File # mlog.log('arr7') try: from mlib.boot.mlog import Muffle # mlog.log('arr8') with Muffle(*listfilt(will_break_numpy, v)): # mlog.log('arr9') sli = slice(*slices) # mlog.log('arr10') old__iter__ = [] for vv in v: if hasattr(vv, '__npitr__') and (vv.__npitr__ == False): vv.stop_np_iter = True # mlog.log('arr10.1') # if hasattr(type(vv), '__iter__') and hasattr(vv, '__npitr__') and vv.__npitr__ == False: # mlog.log('arr10.2') # breakpoint() # old__iter__.append(type(vv).__dict__['__iter__']) # mlog.log('arr10.3') # delattr(type(vv), '__iter__') # mlog.log('arr10.4') # else: # mlog.log('arr10.45') # old__iter__.append(None) # mlog.log('arr10.5') if enable_debug: breakpoint() # mlog.log('arr10.6') ar[sli] = v # THIS IS WHERE THE HORRIBLE UN-INTENDED UNNECCESARY ITERATING INTO OBJECTS IS HAPPENING ... SHOULD BE FIXED NOW! # mlog.log('arr10.7') # for i, iitteerr in enum(old__iter__): # mlog.log('arr10.8') # if iitteerr is not None: # mlog.log('arr10.9') # type(v[i]).__iter__ = iitteerr for vv in v: if hasattr(vv, '__npitr__') and (vv.__npitr__ == False): vv.stop_np_iter = False # mlog.log('arr11') except File.NoLoadSupportException: import traceback traceback.print_exc() # print('here1') ar = mparray(ar, dtype=dtype) # print('here2') v.pop() ar = ar[:-1] assert len(v) == len(ar) # print('here3') return ar else: return mparray(v, dtype=dtype)
def _super_run(self, cfg_overrides=None): if cfg_overrides is None: cfg_overrides = {} from mlib.web.html import HTMLObject from mlib.web import shadow from mlib.proj.stat import py_deps, class_model_report self.prep_log_file(None) cfg = self._get_cfg() for k, v in listitems(cfg_overrides): setattr(cfg, k, v) self.cfg = cfg if ismac(): # why was this so important again? # self.daily( # self.write_reqs # ) # and this? # self.daily( # enable_py_call_graph, # Project.PYCALL_FILE # ) pass with WOLFRAM: if 'build' in cfg.FLAGS and self.mbuild: assert len(cfg.FLAGS) == 1 err('anything that depends on mlib has to push that too') build() write_README(self) self.push() elif 'readme' in cfg.FLAGS: assert len(cfg.FLAGS) == 1 write_README(self) elif any(x in cfg.FLAGS for x in self.clear_clear_cache_flags): assert len(cfg.FLAGS) == 1 clear_cell_cache() elif 'cell' in cfg.FLAGS: assert len(cfg.FLAGS) == 3 analysisFlag = cfg.FLAGS[1] cellName = cfg.FLAGS[2] analysisO = arr(ANALYSES(AnalysisMode.CELL)).first( lambda o: cn(o) == analysisFlag or mn(o).split('.')[-1] == analysisFlag ) cell = getattr(analysisO, cellName) if cell.inputs[0] is not None: inputs = cell.load_cached_input(analysisO) cell(*inputs) else: cell() else: if ismac(): # need to have dailyOrFlag # its asking me to delete nap online. not sure if I can do this so I'm commenting this out for now. # self.daily( # wolf_manager.manage # ) run_in_daemon( pingChecker) # this line wasnt nested in ismac b4 but got an error in openmind last time I ran log('about to run with cfg') self.run(cfg) self.daily( class_model_report, HTMLObject ) if ismac(): self.daily( # atexit.register, py_deps, main_mod_file(), Project.PYDEPS_OUTPUT ) # atexit.register( if ismac() and shadow.enabled: # not doing this on openmind yet because it erases docs_local/results.html which I am using. need to fix this though shadow.build_docs() # ) if ismac(): reloadIdeaFilesFromDisk()