[docs]defsimulate(self,*simulations,post_prepare=None,comm=None):""" Simulate the given simulations. """withExitStack()ascontext:forsimulationinsimulations:context.enter_context(simulation.scaffold.storage.read_only())alldata=[]forsimulationinsimulations:data=self.prepare(simulation)alldata.append(data)forhookinsimulation.post_prepare:hook(self,simulation,data)ifpost_prepare:post_prepare(self,simulations,alldata)results=self.run(*simulations)return[self.collect(simulation,data,result)forsimulation,resultinzip(simulations,results)]
[docs]@abc.abstractmethoddefprepare(self,simulation,comm=None):""" Reset the simulation backend and prepare for the given simulation. :param simulation: The simulation configuration to prepare. :type simulation: ~bsb.simulation.simulation.Simulation :param comm: The mpi4py MPI communicator to use. Only nodes in the communicator will participate in the simulation. The first node will idle as the main node. """pass
[docs]@abc.abstractmethoddefrun(self,*simulations,comm=None):""" Fire up the prepared adapter. """pass
[docs]defcollect(self,simulation,simdata,simresult,comm=None):""" Collect the output of a simulation that completed """simresult.flush()returnsimresult