[docs]classSimulationResult:def__init__(self,simulation,filename=None):fromneoimportBlocktree=simulation.__tree__()withcontextlib.suppress(KeyError):deltree["post_prepare"]self.recorders=[]self.filename=filenameblock=Block(name=simulation.name,config=tree)block.rec_datetime=datetime.now()iffilename:fromneoimportioself._block=Nonewithio.NixIO(filename,mode="rw")asout:run_index=sum(1fornbinout.nix_file.blocksifnb.metadataand"neo_name"innb.metadataandnb.metadata["neo_name"]==simulation.name)block.annotate(sim_name=simulation.name,run_index=run_index)out.write_block(block)self.block_key=block.annotations["nix_name"]else:self._block=block@propertydefblock(self):ifself._blockisNone:raiseRuntimeError(f"Results were streamed to '{self.filename}'; read them back from ""the file, not from the result object.")returnself._block