def configure(self, simulator_gid): """ Make preparations for the adapter launch. """ self.log.debug("%s: Instantiating requested simulator..." % str(self)) simulator_service = SimulatorService() self.algorithm, connectivity_gid, simulation_state_gid = simulator_service.deserialize_simulator( simulator_gid, self.storage_path) self.branch_simulation_state_gid = simulation_state_gid # for monitor in self.algorithm.monitors: # if issubclass(monitor, Projection): # # TODO: add a service that loads a RM with Surface and Connectivity # pass connectivity_index = dao.get_datatype_by_gid(connectivity_gid.hex) connectivity = h5.load_from_index(connectivity_index) connectivity.gid = connectivity_gid self.algorithm.connectivity = connectivity self.simulation_length = self.algorithm.simulation_length self.log.debug("%s: Initializing storage..." % str(self)) try: self.algorithm.preconfigure() except ValueError as err: raise LaunchException( "Failed to configure simulator due to invalid Input Values. It could be because " "of an incompatibility between different version of TVB code.", err)
def __init__(self): BurstBaseController.__init__(self) self.range_parameters = SimulatorRangeParameters() self.burst_service = BurstService() self.simulator_service = SimulatorService() self.cached_simulator_algorithm = self.algorithm_service.get_algorithm_by_module_and_class( IntrospectionRegistry.SIMULATOR_MODULE, IntrospectionRegistry.SIMULATOR_CLASS) self.context = SimulatorContext() self.monitors_handler = MonitorsWizardHandler()
def __init__(self): BurstBaseController.__init__(self) self.range_parameters = SimulatorRangeParameters() self.burst_service2 = BurstService2() self.simulator_service = SimulatorService() self.files_helper = FilesHelper() self.cached_simulator_algorithm = self.flow_service.get_algorithm_by_module_and_class( IntrospectionRegistry.SIMULATOR_MODULE, IntrospectionRegistry.SIMULATOR_CLASS)
def test_load_burst_only(self): zip_path = path.join(path.dirname(tvb_data.__file__), 'connectivity', 'connectivity_66.zip') TestFactory.import_zip_connectivity(self.test_user, self.test_project, zip_path, "John") connectivity = TestFactory.get_entity(self.test_project, ConnectivityIndex) simulator_index = SimulatorIndex() simulator_index.fill_from_has_traits(self.session_stored_simulator) burst_config = BurstConfiguration(self.test_project.id, simulator_index.id) burst_config = dao.store_entity(burst_config) simulator_index.fk_from_operation = burst_config.id simulator_index = dao.store_entity(simulator_index) simulator_index.fk_parent_burst = burst_config.id simulator_index = dao.store_entity(simulator_index) burst = dao.get_bursts_for_project(self.test_project.id) self.sess_mock['burst_id'] = str(burst[0].id) self.sess_mock['_connectivity'] = connectivity.gid self.sess_mock['_conduction_speed'] = "3.0" self.sess_mock['_coupling'] = "Sigmoidal" with patch('cherrypy.session', self.sess_mock, create=True): common.add2session(common.KEY_SIMULATOR_CONFIG, self.session_stored_simulator) self.simulator_controller.set_connectivity(**self.sess_mock._data) self.simulator_controller.set_stimulus(**self.sess_mock._data) storage_path = FilesHelper().get_project_folder( self.test_project, str(simulator_index.fk_from_operation)) simulator_service = SimulatorService() SimulatorSerializer().serialize_simulator( self.session_stored_simulator, simulator_index.gid, None, storage_path) with patch('cherrypy.session', self.sess_mock, create=True): self.simulator_controller.load_burst_read_only(str(burst[0].id)) is_simulator_load = common.get_from_session(KEY_IS_SIMULATOR_LOAD) is_simulator_copy = common.get_from_session(KEY_IS_SIMULATOR_COPY) last_loaded_form_url = common.get_from_session( KEY_LAST_LOADED_FORM_URL) database_simulator = dao.get_generic_entity(SimulatorIndex, burst_config.id, 'fk_parent_burst')[0] assert simulator_index.gid == database_simulator.gid, "Simulator was not added correctly!" assert is_simulator_load, "Simulator Load Flag should be True!" assert not is_simulator_copy, "Simulator Copy Flag should be False!" assert last_loaded_form_url == '/burst/setup_pse', "Incorrect last form URL!"
def fire_simulation(project_id, simulator): project = dao.get_project_by_id(project_id) assert isinstance(simulator, Simulator) # Load the SimulatorAdapter algorithm from DB cached_simulator_algorithm = FlowService().get_algorithm_by_module_and_class(IntrospectionRegistry.SIMULATOR_MODULE, IntrospectionRegistry.SIMULATOR_CLASS) # Instantiate a SimulatorService and launch the configured simulation simulator_service = SimulatorService() launched_operation = simulator_service.async_launch_and_prepare_simulation(None, project.administrator, project, cached_simulator_algorithm, simulator, None) LOG.info("Operation launched ....") return launched_operation
def fire_simulation(project_id=1, **kwargs): project = dao.get_project_by_id(project_id) # Prepare a Simulator instance with defaults and configure it to use the previously loaded Connectivity simulator = Simulator(**kwargs) # Load the SimulatorAdapter algorithm from DB cached_simulator_algorithm = FlowService( ).get_algorithm_by_module_and_class(IntrospectionRegistry.SIMULATOR_MODULE, IntrospectionRegistry.SIMULATOR_CLASS) # Instantiate a SimulatorService and launch the configured simulation simulator_service = SimulatorService() launched_operation = simulator_service.async_launch_and_prepare_simulation( None, project.administrator, project, cached_simulator_algorithm, simulator, None) return launched_operation
def build(test_user, test_project, simulation_length=10, is_group=False): model = SimulatorAdapterModel() model.connectivity = connectivity_index_factory().gid model.simulation_length = simulation_length burst = BurstConfiguration(test_project.id, name="Sim " + str(datetime.now())) burst.start_time = datetime.now() algorithm = dao.get_algorithm_by_module(SIMULATOR_MODULE, SIMULATOR_CLASS) service = SimulatorService() if is_group: range_param = RangeParameter("conduction_speed", float, Range(lo=50.0, hi=100.0, step=20.0)) burst.range1 = range_param.to_json() burst = BurstService().prepare_burst_for_pse(burst) op = service.async_launch_and_prepare_pse(burst, test_user, test_project, algorithm, range_param, None, model) else: dao.store_entity(burst) op = service.async_launch_and_prepare_simulation(burst, test_user, test_project, algorithm, model) return op
def run_simulation(): log = get_logger(__name__) # This ID of a project needs to exists in DB, and it can be taken from the WebInterface: project = dao.get_project_by_id(1) # Find a structural Connectivity and load it in memory connectivity_index = dao.get_generic_entity( ConnectivityIndex, DataTypeMetaData.DEFAULT_SUBJECT, "subject")[0] connectivity = h5.load_from_index(connectivity_index) # Load the SimulatorAdapter algorithm from DB cached_simulator_algorithm = AlgorithmService( ).get_algorithm_by_module_and_class(IntrospectionRegistry.SIMULATOR_MODULE, IntrospectionRegistry.SIMULATOR_CLASS) # Instantiate a SimulatorService and launch the configured simulation simulator_model = SimulatorAdapterModel() simulator_model.connectivity = connectivity.gid simulator_model.simulation_length = 100 simulator_model.coupling = Scaling() simulator_service = SimulatorService() burst = BurstConfiguration(project.id, name="Simulation") dao.store_entity(burst) launched_operation = simulator_service.async_launch_and_prepare_simulation( burst, project.administrator, project, cached_simulator_algorithm, simulator_model) # wait for the operation to finish while not launched_operation.has_finished: sleep(5) launched_operation = dao.get_operation_by_id(launched_operation.id) if launched_operation.status == STATUS_FINISHED: ts = dao.get_generic_entity(TimeSeriesRegionIndex, launched_operation.id, "fk_from_operation")[0] log.info("TimeSeries result is: %s " % ts) else: log.warning( "Operation ended with problems [%s]: [%s]" % (launched_operation.status, launched_operation.additional_info))
def fire_simulation(project_id, simulator): project = dao.get_project_by_id(project_id) assert isinstance(simulator, Simulator) # Load the SimulatorAdapter algorithm from DB cached_simulator_algorithm = AlgorithmService( ).get_algorithm_by_module_and_class(IntrospectionRegistry.SIMULATOR_MODULE, IntrospectionRegistry.SIMULATOR_CLASS) # Instantiate a SimulatorService and launch the configured simulation simulator_service = SimulatorService() burst = BurstConfiguration(project.id) burst.name = "Sim " + str(datetime.now()) burst.start_time = datetime.now() dao.store_entity(burst) launched_operation = simulator_service.async_launch_and_prepare_simulation( burst, project.administrator, project, cached_simulator_algorithm, simulator) LOG.info("Operation launched ....") return launched_operation
def configure(self, simulator_gid): """ Make preparations for the adapter launch. """ self.log.debug("%s: Configuring simulator adapter..." % str(self)) self.algorithm, history_gid = SimulatorService().deserialize_simulator( simulator_gid, self.storage_path) self.branch_simulation_state_gid = history_gid # for monitor in self.algorithm.monitors: # if issubclass(monitor, Projection): # # TODO: add a service that loads a RM with Surface and Connectivity # pass try: self.algorithm.preconfigure() except ValueError as err: raise LaunchException( "Failed to configure simulator due to invalid Input Values. It could be because " "of an incompatibility between different version of TVB code.", err)
def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.logger = get_logger(self.__class__.__module__) self.simulator_service = SimulatorService() self.project_service = ProjectService()
simulator = Simulator() simulator.connectivity = connectivity # Configure the Simulator to use a Scaling type coupling simulator.coupling = Scaling() # Choose a higher value for the 'tau' parameter of the Generic2dOscillator model simulator.model.tau = numpy.array([2.0]) # Configure the simulation length simulator.simulation_length = 100 # Load the SimulatorAdapter algorithm from DB cached_simulator_algorithm = AlgorithmService( ).get_algorithm_by_module_and_class(IntrospectionRegistry.SIMULATOR_MODULE, IntrospectionRegistry.SIMULATOR_CLASS) # Instantiate a SimulatorService and launch the configured simulation simulator_service = SimulatorService() launched_operation = simulator_service.async_launch_and_prepare_simulation( BurstConfiguration(project.id), project.administrator, project, cached_simulator_algorithm, simulator) # wait for the operation to finish while not launched_operation.has_finished: sleep(5) launched_operation = dao.get_operation_by_id(launched_operation.id) if launched_operation.status == STATUS_FINISHED: ts = dao.get_generic_entity(TimeSeriesRegionIndex, launched_operation.id, "fk_from_operation")[0] log.info("TimeSeries result is: %s " % ts) else:
def __init__(self): self.logger = get_logger(self.__class__.__module__) self.simulator_service = SimulatorService() self.project_service = ProjectService()