Esempio n. 1
0
    def test_estimate_execution_time(self, connectivity_index_factory):
        """
        Test that get_execution_time_approximation considers the correct params
        """
        model = SimulatorAdapterModel()
        model.connectivity = connectivity_index_factory(self.CONNECTIVITY_NODES).gid

        self.simulator_adapter.configure(model)
        estimation1 = self.simulator_adapter.get_execution_time_approximation(model)

        # import surfaceData and region mapping
        cortex_file = path.join(path.dirname(tvb_data.surfaceData.__file__), 'cortex_16384.zip')
        surface = TestFactory.import_surface_zip(self.test_user, self.test_project, cortex_file, CORTICAL)
        rm_file = path.join(path.dirname(tvb_data.regionMapping.__file__), 'regionMapping_16k_76.txt')
        region_mapping = TestFactory.import_region_mapping(self.test_user, self.test_project, rm_file, surface.gid,
                                                           model.connectivity.hex)
        local_conn = TestFactory.create_local_connectivity(self.test_user, self.test_project, surface.gid)
        cortex_model = CortexViewModel()
        cortex_model.region_mapping_data = region_mapping.gid
        cortex_model.fk_surface_gid = surface.gid
        cortex_model.local_connectivity = local_conn.gid
        model.surface = cortex_model

        # Estimation when the surface input parameter is set
        self.simulator_adapter.configure(model)
        estimation2 = self.simulator_adapter.get_execution_time_approximation(model)

        assert estimation1 == estimation2 // 500
        model.surface = None

        # Modify integration step and simulation length:
        initial_simulation_length = model.simulation_length
        initial_integration_step = model.integrator.dt

        for factor in (2, 4, 10):
            model.simulation_length = initial_simulation_length * factor
            model.integrator.dt = initial_integration_step / factor
            self.simulator_adapter.configure(model)
            estimation3 = self.simulator_adapter.get_execution_time_approximation(model)

            assert estimation1 == estimation3 // factor // factor

        # Check that no division by zero happens
        model.integrator.dt = 0
        estimation4 = self.simulator_adapter.get_execution_time_approximation(model)
        assert estimation4 > 0

        # even with length zero, still a positive estimation should be returned
        model.simulation_length = 0
        estimation5 = self.simulator_adapter.get_execution_time_approximation(model)
        assert estimation5 > 0
Esempio n. 2
0
    def build(user=None,
              project=None,
              op=None,
              nr_regions=76,
              monitor=TemporalAverageViewModel(),
              with_surface=False,
              conn_gid=None):
        model = SimulatorAdapterModel()
        model.monitors = [monitor]
        if not op:
            op = operation_factory(test_user=user, test_project=project)
        if conn_gid:
            model.connectivity = conn_gid
        if not with_surface and not conn_gid:
            model.connectivity = connectivity_index_factory(nr_regions, op).gid
        model.simulation_length = 100
        if with_surface:
            rm_idx = region_mapping_index_factory()
            model.connectivity = rm_idx.fk_connectivity_gid
            model.surface = CortexViewModel()
            model.surface.surface_gid = rm_idx.fk_surface_gid
            model.surface.region_mapping_data = rm_idx.gid
            model.simulation_length = 10
        storage_path = FilesHelper().get_project_folder(op.project, str(op.id))
        h5.store_view_model(model, storage_path)

        return storage_path, model.gid
Esempio n. 3
0
 def fill_trait(self, datatype):
     surface_gid = self.surface.value
     if surface_gid:
         datatype.surface = CortexViewModel()
         datatype.surface.surface_gid = surface_gid
     else:
         datatype.surface = None
Esempio n. 4
0
 def fill_trait(self, datatype):
     surface_gid = self.surface.value
     if surface_gid:
         if not datatype.surface or (
                 datatype.surface
                 and datatype.surface.surface_gid != surface_gid):
             datatype.surface = CortexViewModel()
             datatype.surface.surface_gid = surface_gid
     else:
         datatype.surface = None
    def test_edit_model_parameters(self, region_mapping_index_factory):
        self.init()
        surface_m_p_c = SurfaceModelParametersController()
        simulator_controller = SimulatorController()
        simulator_controller.index()
        simulator = simulator_controller.context.simulator
        region_mapping_index = region_mapping_index_factory()
        simulator.connectivity = region_mapping_index.fk_connectivity_gid
        simulator.surface = CortexViewModel()
        simulator.surface.surface_gid = region_mapping_index.fk_surface_gid
        simulator.surface.region_mapping_data = region_mapping_index.gid

        result_dict = surface_m_p_c.edit_model_parameters()
        expected_keys = ['urlNormals', 'urlNormalsPick', 'urlTriangles', 'urlTrianglesPick',
                         'urlVertices', 'urlVerticesPick', 'mainContent', 'parametersEquationPlotForm',
                         'baseUrl', 'equationsPrefixes', 'brainCenter', 'applied_equations']
        # map(lambda x: self.assertTrue(x in result_dict), expected_keys)
        assert all(x in result_dict for x in expected_keys)
        assert result_dict['baseUrl'] == '/spatial/modelparameters/surface'
        assert result_dict['mainContent'] == 'spatial/model_param_surface_main'