def __init__(self, *, system, name): Impl.__init__(self, system=system) EditableSpaceContainerImpl.__init__(self) self.cellgraph = DependencyGraph() self.lexdep = DependencyGraph() # Lexical dependency self.spacegraph = SpaceGraph() self.currentspace = None if not name: self.name = system._modelnamer.get_next(system.models) elif is_valid_name(name): self.name = name else: raise ValueError("Invalid name '%s'." % name) data = {"__builtins__": builtins} self._global_refs = RefDict(self, data=data) self._spaces = ImplDict(self, SpaceView) self._dynamic_bases = {} self._dynamic_bases_inverse = {} self._dynamic_base_namer = AutoNamer("__Space") self._namespace = ImplChainMap(self, BaseView, [self._spaces, self._global_refs]) self.allow_none = False self.lazy_evals = self._namespace
def __init__(self, parent, name, value, container, is_derived=False, refmode=None, set_item=True): Impl.__init__(self, system=parent.system, parent=parent, name=name, interface=value) Derivable.__init__(self, is_derived) if isinstance(value, BaseDataClient): self.model.datarefmgr.add_reference(self, value) self.container = container if set_item: container.set_item(name, self) self.refmode = refmode if refmode == "absolute": self.is_relative = False else: # 'auto' or 'relative' self.is_relative = True
def restore_state(self, system): """Called after unpickling to restore some attributes manually.""" Impl.restore_state(self, system) BaseSpaceContainerImpl.restore_state(self, system) for cells in self._cells.values(): cells.restore_state(system)
def __init__(self, *, system, name): if not name: name = system._modelnamer.get_next(system.models) elif not is_valid_name(name): raise ValueError("Invalid name '%s'." % name) Impl.__init__(self, system=system, parent=None, name=name) EditableSpaceContainerImpl.__init__(self) TraceManager.__init__(self) self.spacemgr = SpaceManager(self) self.currentspace = None self._global_refs = RefDict(self) self._global_refs.set_item("__builtins__", builtins) self._named_spaces = SpaceDict(self) self._dynamic_bases = SpaceDict(self) self._all_spaces = ImplChainMap( self, SpaceView, [self._named_spaces, self._dynamic_bases]) self._dynamic_bases_inverse = {} self._dynamic_base_namer = AutoNamer("__Space") self._namespace = ImplChainMap(self, BaseView, [self._named_spaces, self._global_refs]) self.allow_none = False self.lazy_evals = self._namespace self.datarefmgr = DataClientReferenceManager()
def __init__(self, parent, name, value, container, is_derived=False, refmode=None, set_item=True): Impl.__init__(self, system=parent.system, parent=parent, name=name, interface=value) self.spacemgr = parent.spacemgr Derivable.__init__(self, is_derived) self.container = container if set_item: container.set_item(name, self) self.refmode = refmode if refmode == "absolute": self.is_relative = False else: # 'auto' or 'relative' self.is_relative = True self.on_init(value)
def __init__(self, *, space, name=None, formula=None, data=None, base=None, source=None, is_derived=False): # Determine name if base: name = base.name elif is_valid_name(name): pass elif formula: name = Formula(formula).name if is_valid_name(name): pass else: name = space.cellsnamer.get_next(space.namespace) else: name = space.cellsnamer.get_next(space.namespace) Impl.__init__(self, system=space.system, parent=space, name=name) self.spacemgr = space.spacemgr Derivable.__init__(self, is_derived) self.source = source space._cells.set_item(name, self) # Set formula if base: self.formula = base.formula elif formula is None: self.formula = NullFormula(NULL_FORMULA, name=name) elif isinstance(formula, Formula): self.formula = formula.__class__(formula, name=name) else: self.formula = Formula(formula, name=name) # Set data self.data = {} if data is None: data = {} self.data.update(data) self.input_keys = set(data.keys()) CellsNamespaceReferrer.__init__(self, space) self._namespace = self.parent._namespace if base: self.altfunc = BoundFunction(self, base.altfunc.fresh) else: self.altfunc = BoundFunction(self)
def restore_state(self, system): """Called after unpickling to restore some attributes manually.""" Impl.restore_state(self, system) BaseSpaceContainerImpl.restore_state(self, system) mapping = {} for node in self.cellgraph: if isinstance(node, tuple): name, key = node else: name, key = node, None cells = self.get_object(name) mapping[node] = get_node(cells, key, None) self.cellgraph = nx.relabel_nodes(self.cellgraph, mapping)
def __init__(self, parent, name, value, container, is_derived=False): Impl.__init__(self, system=parent.system, parent=parent, name=name, interface=value) Derivable.__init__(self) self.parent = parent self.model = parent.model self.name = name container.set_item(name, self) self.is_derived = is_derived
def __init__(self, parent, name, value, container, is_derived=False, set_item=True): Impl.__init__( self, system=parent.system, parent=parent, name=name, interface=value) Derivable.__init__(self, is_derived) if isinstance(value, BaseDataClient): self.model.datarefmgr.add_reference(self, value) self.container = container if set_item: container.set_item(name, self)
def __init__(self, *, space, name=None, formula=None, data=None, base=None, source=None): Impl.__init__(self, system=space.system) Derivable.__init__(self) self._model = space.model self.space = self.parent = space self.source = source if base: self.name = base.name elif is_valid_name(name): self.name = name elif formula: name = Formula(formula).name if is_valid_name(name): self.name = name else: self.name = space.cellsnamer.get_next(space.namespace) else: self.name = space.cellsnamer.get_next(space.namespace) if base: self.formula = base.formula elif formula is None: self.formula = NullFormula(NULL_FORMULA, name=self.name) elif isinstance(formula, Formula): self.formula = formula.__class__(formula, name=self.name) else: self.formula = Formula(formula, name=self.name) self.data = {} if data is None: data = {} self.data.update(data) self._namespace_impl = self.space._namespace_impl self.altfunc = BoundFunction(self)
def __init__(self, parent, name, formula=None, refs=None, source=None, arguments=None, doc=None): Impl.__init__(self, system=parent.system, doc=doc) BaseSpaceContainerImpl.__init__(self) Derivable.__init__(self) self.name = name self.parent = parent self.cellsnamer = AutoNamer("Cells") self._mro_cache = None self.update_mro = True if isinstance(source, ModuleType): self.source = source.__name__ else: self.source = source # ------------------------------------------------------------------ # Construct member containers self._dynamic_spaces = ImplDict(self, SpaceView) self._dynamic_subs = [] self._self_refs = RefDict(self) self._cells = CellsDict(self) self._static_spaces = SpaceDict(self) self._spaces = ImplChainMap( self, SpaceView, [self._static_spaces, self._dynamic_spaces]) self._local_refs = {"_self": self, "_space": self} self._refs = self._create_refs(arguments) self._namespace_impl = ImplChainMap( self, None, [self._cells, self._refs, self._spaces]) self.lazy_evals = self._namespace_impl # ------------------------------------------------------------------ # Add initial refs members if refs is not None: refsimpl = { name: ReferenceImpl(self, name, value) for name, value in refs.items() } self._self_refs.update(refsimpl) self._self_refs.set_update() # ------------------------------------------------------------------ # Construct altfunc after space members are crated self.param_spaces = {} self.formula = None if formula is not None: self.set_formula(formula) # ------------------------------------------------------------------ # For repr of LazyEvalDict, LazyEvalImpl self._cells.debug_name = "_cells" self._static_spaces.debug_name = "_static_spaces" self._dynamic_spaces.debug_name = "_dynamic_spaces" self._self_refs.debug_name = "_self_refs" self._refs.debug_name = "_refs" self._namespace_impl.debug_name = "_namespace_impl"