Commit 651a50b4 authored by Giovanni La Mura's avatar Giovanni La Mura
Browse files

Implement attempts command line argument for model_maker.py

parent 72061d14
Loading
Loading
Loading
Loading
+27 −20
Original line number Original line Diff line number Diff line
@@ -54,7 +54,8 @@ def main():
    if (config['help_mode'] or config['yml_file_name'] == ""):
    if (config['help_mode'] or config['yml_file_name'] == ""):
        print_help()
        print_help()
    else:
    else:
        sconf, gconf = load_model(config['yml_file_name'])
        rnd_attempts = config['attempt_limit']
        sconf, gconf = load_model(config['yml_file_name'], rnd_attempts)
        if (sconf is not None) and (gconf is not None):
        if (sconf is not None) and (gconf is not None):
            result = write_legacy_sconf(sconf)
            result = write_legacy_sconf(sconf)
            if (result == 0):
            if (result == 0):
@@ -140,9 +141,10 @@ def interpolate_constants(sconf):
## \brief Create tha calculation configuration structure from YAML input.
## \brief Create tha calculation configuration structure from YAML input.
#
#
#  \param model_file: `str` Full path to the YAML input file.
#  \param model_file: `str` Full path to the YAML input file.
#  \param rnd_attempts: `int` Limiting number of attempts to randomly place a sphere.
#  \return sconf, gconf: `tuple` A dictionary tuple for scatterer and
#  \return sconf, gconf: `tuple` A dictionary tuple for scatterer and
#                        geometric configurations.
#                        geometric configurations.
def load_model(model_file):
def load_model(model_file, rnd_attempts):
    sconf = None
    sconf = None
    gconf = None
    gconf = None
    model = None
    model = None
@@ -419,7 +421,7 @@ def load_model(model_file):
                    # use compact generator, if no specification is given
                    # use compact generator, if no specification is given
                    rnd_engine = "COMPACT"
                    rnd_engine = "COMPACT"
                if (rnd_engine == "COMPACT"):
                if (rnd_engine == "COMPACT"):
                    check = random_compact(sconf, gconf, rnd_seed, max_rad)
                    check = random_compact(sconf, gconf, rnd_seed, max_rad, rnd_attempts)
                    if (check == -1):
                    if (check == -1):
                        print("ERROR: compact random generator works only when all sphere types have the same radius.")
                        print("ERROR: compact random generator works only when all sphere types have the same radius.")
                        return (None, None)
                        return (None, None)
@@ -431,7 +433,7 @@ def load_model(model_file):
                        return (None, None)
                        return (None, None)
                elif (rnd_engine == "LOOSE"):
                elif (rnd_engine == "LOOSE"):
                    # random_aggregate() checks internally whether application is INCLUSION
                    # random_aggregate() checks internally whether application is INCLUSION
                    check = random_aggregate(sconf, gconf, rnd_seed, max_rad)
                    check = random_aggregate(sconf, gconf, rnd_seed, max_rad, rnd_attempts)
                else:
                else:
                    print("ERROR: unrecognized random generator engine.")
                    print("ERROR: unrecognized random generator engine.")
                    return (None, None)
                    return (None, None)
@@ -552,6 +554,7 @@ def match_grid(sconf):
#  \returns config: `dict` A dictionary containing the script configuration.
#  \returns config: `dict` A dictionary containing the script configuration.
def parse_arguments():
def parse_arguments():
    config = {
    config = {
        'attempt_limit': 100,
        'yml_file_name': "",
        'yml_file_name': "",
        'help_mode': False,
        'help_mode': False,
    }
    }
@@ -559,6 +562,9 @@ def parse_arguments():
    for arg in argv[1:]:
    for arg in argv[1:]:
        if (arg.startswith("--help")):
        if (arg.startswith("--help")):
            config['help_mode'] = True
            config['help_mode'] = True
        elif (arg.startswith("--attempts=")):
            split_arg = arg.split('=')
            config['attempt_limit'] = int(split_arg[1])
        elif (not yml_set):
        elif (not yml_set):
            if (not arg.startswith("--")):
            if (not arg.startswith("--")):
                config['yml_file_name'] = arg
                config['yml_file_name'] = arg
@@ -582,6 +588,7 @@ def print_help():
    print("CONFIG must be a valid YAML configuration file.           ")
    print("CONFIG must be a valid YAML configuration file.           ")
    print("                                                          ")
    print("                                                          ")
    print("Valid options are:                                        ")
    print("Valid options are:                                        ")
    print("--attempts=N          Try to place a sphere up to N times.")
    print("--help                Print this help and exit.           ")
    print("--help                Print this help and exit.           ")
    print("                                                          ")
    print("                                                          ")


@@ -905,7 +912,7 @@ def test_system_resources(model, gconf, sconf):
        matrix_dim = 2 * gconf['nsph'] * gconf['li'] * (gconf['li'] + 2)
        matrix_dim = 2 * gconf['nsph'] * gconf['li'] * (gconf['li'] + 2)
        matrix_size_bytes = 16 * matrix_dim * matrix_dim
        matrix_size_bytes = 16 * matrix_dim * matrix_dim
        matrix_size_Gb = float(matrix_size_bytes) / 1024.0 / 1024.0 / 1024.0
        matrix_size_Gb = float(matrix_size_bytes) / 1024.0 / 1024.0 / 1024.0
        print("INFO: estimated matrix size is {0:.3g} Gb.".format(matrix_size_Gb))
        print("INFO: estimated matrix size is {0:.3g} GiB.".format(matrix_size_Gb))
        if (max_gpu_ram > 0):
        if (max_gpu_ram > 0):
            max_gpu_ram_bytes = max_gpu_ram * 1024 * 1024 * 1024
            max_gpu_ram_bytes = max_gpu_ram * 1024 * 1024 * 1024
            if (matrix_size_bytes < max_gpu_ram_bytes):
            if (matrix_size_bytes < max_gpu_ram_bytes):