Skip to content
Snippets Groups Projects
Select Git revision
  • f5c977ad9c04a2deea570569e9ae82eb1aae809e
  • master default protected
  • tut_ring_allen
  • docs_furo
  • docs_reorder_cable_cell
  • docs_graphviz
  • docs_rtd_dev
  • ebrains_mirror
  • doc_recat
  • docs_spike_source
  • docs_sim_sample_clar
  • docs_pip_warn
  • github_template_updates
  • docs_fix_link
  • cv_default_and_doc_clarification
  • docs_add_numpy_req
  • readme_zenodo_05
  • install_python_fix
  • install_require_numpy
  • typofix_propetries
  • docs_recipe_lookup
  • v0.10.0
  • v0.10.1
  • v0.10.0-rc5
  • v0.10.0-rc4
  • v0.10.0-rc3
  • v0.10.0-rc2
  • v0.10.0-rc
  • v0.9.0
  • v0.9.0-rc
  • v0.8.1
  • v0.8
  • v0.8-rc
  • v0.7
  • v0.6
  • v0.5.2
  • v0.5.1
  • v0.5
  • v0.4
  • v0.3
  • v0.2.2
41 results

astmanip.cpp

Blame
  • start_jobs.py 3.10 KiB
    import json
    import os
    import shutil
    
    from config import base_path, data_path
    from multiarea_model.default_params import nested_update, sim_params
    try:
        from multiarea_model.sumatra_helpers import register_record
        sumatra_found = True
    except ImportError:
        sumatra_found = False
    
    
    def start_job(label, submit_cmd, jobscript_template, sumatra=False, reason=None, tag=None):
        """
        Start job on a compute cluster.
    
        Parameters
        ----------
    
        label : str
            Simulation label identifying the simulation to be run.
            The function loads all necessary files from the subfolder
            identified by the label.
        submit_cmd : str
            Submit command of the queueing system used.
        job_script_template : formatted str
            Formatted string defining the template for the job script.
            Can include the following keyword arguments:
                sim_dir : str
                    Directory of the simulation
                label : str
                    Simulation label
                num_processes : int
                    Total number of MPI processes, defined in sim_params
                local_num_threads : int
                    Number of OpenMP threads per MPI process, defined in sim_params
                base_path : str
                    Base path of the library defined in config.py
        """
    
        # Copy run_simulation script to simulation folder
        shutil.copy2(os.path.join(base_path, 'run_simulation.py'),
                     os.path.join(data_path, label))
    
        # Load simulation parameters
        fn = os.path.join(data_path,
                          label,
                          '_'.join(('custom_params',
                                    label)))
        with open(fn, 'r') as f:
            custom_params = json.load(f)
        nested_update(sim_params, custom_params['sim_params'])
    
        # Copy custom param file for each MPI process
        for ii in range(sim_params['num_processes']):
            shutil.copy(fn, '_'.join((fn, str(ii))))
        # Collect relevant arguments for job script
        num_vp = sim_params['num_processes'] * sim_params[
            'local_num_threads']
        d = {'label': label,
             'network_label': custom_params['network_label'],
             'base_path': base_path,
             'sim_dir': os.path.join(data_path, label),
             'local_num_threads': sim_params['local_num_threads'],
             'num_processes': sim_params['num_processes'],
             'num_vp': num_vp}
    
        # Write job script
        job_script_fn = os.path.join(data_path,
                                     label,
                                     '_'.join(('job_script',
                                               '.'.join((label, 'sh')))))
        with open(job_script_fn, 'w') as f:
            f.write(jobscript_template.format(**d))
    
        # If chosen, register simulation to sumatra
        if sumatra:
            if sumatra_found:
                register_record(label, reason=reason, tag=tag)
            else:
                raise ImportWarning('Sumatra is not installed, so'
                                    'cannot register simulation record.')
    
        # Submit job
        os.system('{submit_cmd} {job_script_fn}'.format(submit_cmd=submit_cmd,
                                                        job_script_fn=job_script_fn))