Commit 72f12294 authored by David Hendriks's avatar David Hendriks
Browse files

added tests and updated version info parser

parent 907b6f38
Loading
Loading
Loading
Loading

binarycpython.yml

deleted100644 → 0
+0 −14
Original line number Diff line number Diff line
# /user/HS128/dh00601/.config/tmuxinator/binaryc.yml

name: binarycpython
root: <%= ENV["BINARYC_PYTHON"] %>


windows:
  - binarycpython:
      layout: tiled
      panes:
        - ls
        - subl .
        - cd $BINARYC_DIR/
        - cd $BINARYC_DATA_ROOT/
 No newline at end of file
+159 −84
Original line number Diff line number Diff line
@@ -155,90 +155,163 @@ def parse_binary_c_version_info(version_info_string):

    version_info_dict = {}

    for line in version_info_string.splitlines():
        line = line.strip()
        if line == "":
            continue
        if " is " in line:
            split = line.split(" is ")
            version_info_dict[split[0].strip()] = split[1].strip()
        else:
            if line.startswith("Binary_c/nucsyn"):
                version_info_dict["intro"] = line
            elif line.startswith("Email"):
                emails = line.split("Email ")[1].split(",")
                cleaned_emails = [email.strip() for email in emails]
                version_info_dict["emails"] = cleaned_emails
            elif line.startswith("DTlimit"):
                split = line.split(" : ")
                version_info_dict[split[0]] = ": ".join(split[1:])
            elif line.startswith("Version"):
                split = line.split("Version ")
                version_number = split[1]
                version_info_dict["version_number"] = version_number
            elif line.startswith("git URL"):
                split = line.split("git URL ")
                git_url = split[1]
                version_info_dict["git_url"] = git_url
            elif line.startswith("Build: "):
                split = line.split("Build: ")
                build = split[1]
                version_info_dict["build"] = build
            elif line.startswith("Compiled for "):
                split = line.split("Compiled for ")
                compiled_for = split[1]
                version_info_dict["compiled_for"] = compiled_for
            elif line.startswith("Stack limit "):
                split = line.split("Stack limit ")
                stack_limit = split[1]
                version_info_dict["stack_limit"] = stack_limit
            elif line.startswith("SVN URL "):
                split = line.split("SVN URL ")
                svn_url = split[1]
                version_info_dict["svn_url"] = svn_url
            elif line.startswith("git branch "):
                split = line.split("git branch ")
                git_branch = split[1]
                version_info_dict["git_branch"] = git_branch
            elif line.startswith("_SC_CLK_TCK"):
                split = line.split(" = ")
                _SC_CLK_TCK = split[1]
                version_info_dict["_SC_CLK_TCK"] = _SC_CLK_TCK
            elif line.startswith("Random number mean "):
                split = line.split("Random number mean ")
                random_number_mean = split[1]
                version_info_dict["Random number mean"] = random_number_mean
            elif line.startswith("SVN revision "):
                split = line.split("SVN revision ")
                svn_revision = split[1]
                version_info_dict["svn_revision"] = svn_revision
            elif line.startswith("Size of :"):
                split = line.split("Size of :")
                data_type_sizes = split[1]
                version_info_dict["data_type_sizes"] = data_type_sizes
            elif line.startswith("git revision "):
                split = line.split("git revision ")
                git_revision = split[1]
                version_info_dict["git_revision"] = git_revision
            elif line.startswith("BINARY_C_PRE_VERSION "):
                split = line.split("BINARY_C_PRE_VERSION ")
                binary_c_pre_version = split[1]
                version_info_dict["binary_c_pre_version"] = binary_c_pre_version
            elif line.startswith("Comenv accretion:"):
                split = line.split("Comenv accretion:")
                comenv_accretion = split[1]
                version_info_dict["comenv_accretion"] = comenv_accretion
            elif line.startswith("Compiled in parameters:"):
                split = line.split("Compiled in parameters:")
                compiled_in_parameters = split[1]
                version_info_dict["compiled_in_parameters"] = compiled_in_parameters
            elif line.startswith("__short__ is"):
                split = line.split("__short__ is")
                short_type = split[1]
                version_info_dict["short_type"] = short_type
    # Clean data and put in correct shape
    splitted = version_info_string.strip().splitlines()
    cleaned = set([el.strip() for el in splitted if not el == ""])

    ##########################
    # Isotopes:
    # Split off
    isotopes = set([el for el in cleaned if el.startswith('Isotope ')])
    cleaned = cleaned - isotopes

    isotope_dict = {}
    for el in isotopes:
        split_info = el.split("Isotope ")[-1].strip().split(" is ")

        isotope_info = split_info[-1]
        name = isotope_info.split(' ')[0].strip()

        # Get details
        mass_g = float(isotope_info.split(",")[0].split('(')[1].split("=")[-1][:-2].strip())
        mass_amu = float(isotope_info.split(",")[0].split('(')[-1].split("=")[-1].strip())
        mass_mev = float(isotope_info.split(",")[-3].split("=")[-1].replace(")", "").strip())
        A = int(isotope_info.split(",")[-1].strip().split("=")[-1].replace(")", ""))
        Z = int(isotope_info.split(",")[-2].strip().split("=")[-1])

        #
        isotope_dict[int(split_info[0])] = {'name': name, 'Z': Z, 'A': A, 'mass_mev': mass_mev, 'mass_g': mass_g, 'mass_amu': mass_amu}
    version_info_dict['isotopes'] = isotope_dict

    ##########################
    # Argpairs:
    # Split off
    argpairs = set([el for el in cleaned if el.startswith('ArgPair')])
    cleaned = cleaned - argpairs

    argpair_dict = {}
    for el in sorted(argpairs):
        split_info = el.split("ArgPair ")[-1].split(" ")

        if not argpair_dict.get(split_info[0], None):
            argpair_dict[split_info[0]] = {split_info[1]: split_info[2]}
        else:
                print("Still found unmatched items!:\n{}".format(repr(line)))
            argpair_dict[split_info[0]][split_info[1]] = split_info[2]

    version_info_dict['argpairs'] = argpair_dict

    ##########################
    # ensembles:
    # Split off
    ensembles = set([el for el in cleaned if el.startswith('Ensemble')])
    cleaned = cleaned - ensembles

    ensemble_dict = {}
    for el in ensembles:
        split_info = el.split("Ensemble ")[-1].split(" is ")
        if len(split_info)>1:
            ensemble_dict[int(split_info[0])] = split_info[-1]
    version_info_dict['ensembles'] = ensemble_dict

    ##########################
    # macros:
    # Split off
    macros = set([el for el in cleaned if el.startswith('macroxyz')])
    cleaned = cleaned - macros

    param_type_dict = {
        'STRING': str,
        'FLOAT': float,
        'MACRO': str,
        'INT': int,
        'LONG_INT': int,
    }

    macros_dict = {}
    for el in macros:
        split_info = el.split("macroxyz ")[-1].split(" : ")
        param_type = split_info[0]

        new_split = "".join(split_info[1:]).split(" is ")
        param_name = new_split[0]
        param_value = " is ".join(new_split[1:])
        # Sometimes the macros have extra information behind it. Needs an update in outputting by binary_c
        try:
            macros_dict[param_name] = param_type_dict[param_type](param_value)
        except ValueError:
            macros_dict[param_name] = str(param_value)
    version_info_dict['macros'] = macros_dict

    ##########################
    # Elements:
    # Split off:
    elements = set([el for el in cleaned if el.startswith('Element')])
    cleaned = cleaned - elements

    # Fill dict:
    elements_dict = {}
    for el in elements:
        split_info = el.split("Element ")[-1].split(" : ")
        name_info = split_info[0].split(" is ")

        # get isotope info
        isotopes = {}
        if not split_info[-1][0]=='0':
            isotope_string = split_info[-1].split(" = ")[-1]
            isotopes = {int(split_isotope.split("=")[0]):split_isotope.split("=")[1] for split_isotope in isotope_string.split(" ")}

        elements_dict[int(name_info[0])] = {'name': name_info[-1], 'atomic_number': int(name_info[0]), 'amt_isotopes': len(isotopes), 'isotopes': isotopes}
    version_info_dict['elements'] = version_info_dict

    ##########################
    # dt_limits:
    # split off
    dt_limits = set([el for el in cleaned if el.startswith('DTlimit')])
    cleaned = cleaned - dt_limits

    # Fill dict
    dt_limits_dict = {}
    for el in dt_limits:
        split_info = el.split("DTlimit ")[-1].split(" : ")
        dt_limits_dict[split_info[1].strip()] = {'index': int(split_info[0]), 'value': float(split_info[-1])}

    version_info_dict['dt_limits'] = dt_limits_dict

    ##########################
    # Nucleosynthesis sources:
    # Split off
    nucsyn_sources = set([el for el in cleaned if el.startswith('Nucleosynthesis')])
    cleaned = cleaned - nucsyn_sources

    # Fill dict
    nucsyn_sources_dict = {}
    for el in nucsyn_sources:
        split_info = el.split("Nucleosynthesis source")[-1].strip().split(" is ")
        nucsyn_sources_dict[int(split_info[0])] = split_info[-1]

    version_info_dict['nucleosynthesis_sources'] = nucsyn_sources_dict

    ##########################
    # miscellaneous:
    # All those that I didnt catch with the above filters. Could try to get some more out though.
    # TODO: filter a bit more.

    misc_dict = {}
    git_revision = [el for el in cleaned if el.startswith('git revision')]
    misc_dict['git_revision'] = git_revision[0].split("git revision ")[-1].replace("\"", '')

    git_branch = [el for el in cleaned if el.startswith('git branch')]
    misc_dict['git_branch'] = git_branch[0].split("git branch ")[-1].replace("\"", '')

    build = [el for el in cleaned if el.startswith('Build')]
    misc_dict['build'] = build[0].split("Build: ")[-1].replace("\"", '')

    email = [el for el in cleaned if el.startswith('Email')]
    misc_dict['email'] = email[0].split("Email ")[-1].split(',')

    misc_dict['uncaught'] = cleaned

    version_info_dict['miscellaneous'] = misc_dict
    return version_info_dict


@@ -727,7 +800,9 @@ def inspect_dict(dict_1, indent=0, print_structure=True):
        if print_structure:
            print("\t" * indent, key, type(value))
        if isinstance(value, dict):
            structure_dict[key] = inspect_dict(value, indent=indent + 1, print_structure=print_structure)
            structure_dict[key] = inspect_dict(
                value, indent=indent + 1, print_structure=print_structure
            )
    return structure_dict


+292 −151

File changed.

Preview size limit exceeded, changes collapsed.

+29 −34
Original line number Diff line number Diff line
@@ -17,7 +17,6 @@ grid_options_defaults_dict = {
    "main_pid": -1,  # Placeholder for the main process id of the run.
    # "output_dir":
    "commandline_input": "",

    ##########################
    # Execution log:
    ##########################
@@ -125,13 +124,13 @@ grid_options_defaults_dict = {
    "slurm_command": "",  # Command that slurm runs (e.g. evolve or join_datafiles)
    "slurm_dir": "",  # working directory containing scripts output logs etc.
    "slurm_njobs": 0,  # number of scripts; set to 0 as default
    "slurm_jobid": '', # slurm job id (%A)
    "slurm_jobid": "",  # slurm job id (%A)
    "slurm_memory": 512,  # in MB, the memory use of the job
    "slurm_warn_max_memory": 1024,  # in MB : warn if mem req. > this
    "slurm_use_all_node_CPUs": 0,  # 1 = use all of a node's CPUs. 0 = use a given amount of CPUs
    "slurm_postpone_join": 0,  # if 1 do not join on slurm, join elsewhere. want to do it off the slurm grid (e.g. with more RAM)
    "slurm_jobarrayindex": '', # slurm job array index (%a)
    "slurm_jobname": 'binary_grid', # default
    "slurm_jobarrayindex": "",  # slurm job array index (%a)
    "slurm_jobname": "binary_grid",  # default
    "slurm_partition": None,
    "slurm_time": 0,  # total time. 0 = infinite time
    "slurm_postpone_sbatch": 0,  # if 1: don't submit, just make the script
@@ -144,23 +143,20 @@ grid_options_defaults_dict = {
    "slurm_array": None,  # override for --array, useful for rerunning jobs
    "slurm_partition": None,  # MUST be defined
    "slurm_extra_settings": {},  # Place to put extra configuration for the SLURM batch file. The key and value of the dict will become the key and value of the line in te slurm batch file. Will be put in after all the other settings (and before the command). Take care not to overwrite something without really meaning to do so.


    ########################################
    # Condor stuff
    ########################################
    "condor": 0,  # 1 to use condor, 0 otherwise
    "condor_command": '', # condor command e.g. "evolve", "join"
    "condor_dir": '', # working directory containing e.g. scripts, output, logs (e.g. should be NFS available to all)
    "condor_njobs": '', # number of scripts/jobs that CONDOR will run in total
    "condor_jobid": '', # condor job id
    "condor_command": "",  # condor command e.g. "evolve", "join"
    "condor_dir": "",  # working directory containing e.g. scripts, output, logs (e.g. should be NFS available to all)
    "condor_njobs": "",  # number of scripts/jobs that CONDOR will run in total
    "condor_jobid": "",  # condor job id
    "condor_postpone_join": 0,  # if 1, data is not joined, e.g. if you want to do it off the condor grid (e.g. with more RAM)
    # "condor_join_machine": None, # if defined then this is the machine on which the join command should be launched (must be sshable and not postponed)
    "condor_join_pwd": '', # directory the join should be in (defaults to $ENV{PWD} if undef)
    "condor_join_pwd": "",  # directory the join should be in (defaults to $ENV{PWD} if undef)
    "condor_memory": 1024,  # in MB, the memory use (ImageSize) of the job
    "condor_universe": 'vanilla', # usually vanilla universe
    "condor_universe": "vanilla",  # usually vanilla universe
    "condor_extra_settings": {},  # Place to put extra configuration for the CONDOR submit file. The key and value of the dict will become the key and value of the line in te slurm batch file. Will be put in after all the other settings (and before the command). Take care not to overwrite something without really meaning to do so.

    # snapshots and checkpoints
    # condor_snapshot_on_kill=>0, # if 1 snapshot on SIGKILL before exit
    # condor_load_from_snapshot=>0, # if 1 check for snapshot .sv file and load it if found
@@ -180,7 +176,6 @@ grid_options_defaults_dict = {
    # condor_resubmit_submitted=>0,
    # condor_resubmit_running=>0,
    # condor_resubmit_crashed=>0,

    ##########################
    # Unordered. Need to go through this. Copied from the perl implementation.
    ##########################
+21 −6
Original line number Diff line number Diff line
@@ -12,6 +12,7 @@ import time
import subprocess
import __main__ as main


def get_slurm_version():
    """
    Function that checks whether slurm is installed and returns the version if its installed.
@@ -23,7 +24,7 @@ def get_slurm_version():

    try:
        slurm_version = (
            subprocess.run(['sinfo', "-V"], stdout=subprocess.PIPE, check=True)
            subprocess.run(["sinfo", "-V"], stdout=subprocess.PIPE, check=True)
            .stdout.decode("utf-8")
            .split()
        )[1]
@@ -38,6 +39,7 @@ def get_slurm_version():

    return slurm_version


def get_condor_version():
    """
    Function that checks whether slurm is installed and returns the version if its installed.
@@ -51,7 +53,9 @@ def get_condor_version():

    try:
        condor_version = (
            subprocess.run(['condor_q', "--version"], stdout=subprocess.PIPE, check=True)
            subprocess.run(
                ["condor_q", "--version"], stdout=subprocess.PIPE, check=True
            )
            .stdout.decode("utf-8")
            .split()
        )[1]
@@ -66,6 +70,7 @@ def get_condor_version():

    return condor_version


def create_directories_hpc(working_dir):
    """
    Function to create a set of directories, given a root directory
@@ -78,7 +83,15 @@ def create_directories_hpc(working_dir):
        print("Error. Working directory {} does not exist! Aborting")
        raise ValueError

    directories_list = ['scripts', 'stdout', 'stderr', 'results', 'logs', 'status', 'joining']
    directories_list = [
        "scripts",
        "stdout",
        "stderr",
        "results",
        "logs",
        "status",
        "joining",
    ]

    # Make directories.
    for subdir in directories_list:
@@ -100,6 +113,7 @@ def create_directories_hpc(working_dir):
                directories_exist = False
    print("..Finished! Directories exist.")


def path_of_calling_script():
    """
    Function to get the name of the script the user executes.
@@ -107,6 +121,7 @@ def path_of_calling_script():

    return main.__file__


def get_python_details():
    """
    Function to get some info about the used python version and virtualenv etc
@@ -115,8 +130,8 @@ def get_python_details():
    python_info_dict = {}

    #
    python_info_dict['virtualenv'] = os.getenv('VIRTUAL_ENV')
    python_info_dict['executable'] = sys.executable
    python_info_dict['version'] = sys.version
    python_info_dict["virtualenv"] = os.getenv("VIRTUAL_ENV")
    python_info_dict["executable"] = sys.executable
    python_info_dict["version"] = sys.version

    return python_info_dict
Loading