Пример #1
0
 def wrap_analysis_main(argv=None):
     """
     Actual main function for analysis code, deals with parsers and
     logging
     """
     if argv is None:
         argv = sys.argv[1:]
     cmd_args = {}
     parser = argparse.ArgumentParser(
         description=cmd_description,
         argument_default=argparse.SUPPRESS,
     )
     parser.add_argument(
         '--version', action='version',
         version='%(prog)s ' + skw_version
     )
     parser.add_argument("soln_file")
     logging_options(parser)
     cmd_parser = cmd_parser_func(parser)
     args = vars(cmd_parser.parse_args(argv))
     for name, func in cmd_parser_splitters.items():
         cmd_args[name] = func(args)
     with log_handler(args):
         with redirected_warnings(), redirected_logging():
             with h5open(args["soln_file"], registries) as soln_file:
                 solutions = soln_file["run"].solutions.values()
                 return cmd(
                     *solutions, **cmd_args
                 )
Пример #2
0
def resolve(
    *, output_file, sonic_method, soln_filename, soln_range, output_dir,
    store_internal, overrides=None, **kwargs
):
    """
    Main function to generate solution
    """
    with h5open(soln_filename, registries, mode='r') as soln_file:
        old_run = soln_file["run"]
        old_solution = get_solutions(old_run, soln_range)

    new_config_input, new_soln_input = new_inputs_with_overrides(
        config_input=old_run.config_input, overrides=overrides,
        solution_input=old_solution.solution_input,
    )

    run = Run(
        config_input=new_config_input,
        config_filename=old_run.config_filename,
        disc_solver_version=ds_version,
        float_type=str(float_type),
        sonic_method=sonic_method,
        use_E_r=new_soln_input.use_E_r
    )

    if output_file is None:
        output_file = Path(
            old_run.config_input.label + str(arrow.now()) + ".hdf5"
        )
    output_file = expanded_path(output_dir / output_file)

    with h5open(output_file, registries, mode='x') as f:
        f["run"] = run
        sonic_solver = SONIC_METHOD_MAP.get(sonic_method)
        if sonic_solver is None:
            raise SolverError("No method chosen to cross sonic point")
        succeeded = sonic_solver(
            new_soln_input, run, store_internal=store_internal, **kwargs
        )
        run.finalise()

    return output_file, succeeded
Пример #3
0
def get_all_solutions(files):
    """
    Load all the solutions from a file, including the final one, for every file
    in `files`.
    """
    for file in files:
        try:
            with h5open(file, registries, mode='r') as soln_file:
                try:
                    run = soln_file["run"]
                    for soln_name, soln in run.solutions.items():
                        yield file, soln_name, soln
                    yield file, "final", run.final_solution
                except KeyError as e:
                    log.notice(f"Failed to read stats from file {file}: {e}")
        except OSError as e:
            log.warning(f"Failed to read stats from file {file}: {e}")
Пример #4
0
def solve(*, output_file, config_file, output_dir, overrides=None):
    """
    Main function to generate solution
    """
    config_input = get_input_from_conffile(config_file=config_file,
                                           overrides=overrides)
    run = Run(
        config_input=config_input,
        config_filename=str(config_file),
        skw_full_code_version=skw_full_code_version,
        float_type=str(float_type),
    )

    if output_file is None:
        output_file = Path(config_input.label + str(arrow.now()) + ".hdf5")
    output_file = expanded_path(output_dir / output_file)

    with h5open(output_file, registries) as f:
        f["run"] = run
        solver(config_input_to_soln_input(config_input), run)

    return output_file
Пример #5
0
 def wrap_analysis_main(argv, parser):
     """
     Actual main function for analysis code, deals with parsers and
     logging
     """
     cmd_args = {}
     parser.add_argument("soln_file")
     cmd_parser = cmd_parser_func(parser)
     args = vars(cmd_parser.parse_args(argv))
     for name, func in cmd_parser_splitters.items():
         cmd_args[name] = func(args)
     with log_handler(args):
         with redirected_warnings(), redirected_logging():
             with h5open(
                 args["soln_file"], registries, mode='r'
             ) as soln_file:
                 solutions = sorted(
                     soln_file["run"].solutions.items(),
                     key=lambda x: int(x[0])
                 )
                 return cmd(
                     solutions, **cmd_args
                 )
Пример #6
0
def solve(*,
          output_file,
          sonic_method,
          config_file,
          output_dir,
          store_internal,
          overrides=None,
          **kwargs):
    """
    Main function to generate solution
    """
    config_input = get_input_from_conffile(config_file=config_file,
                                           overrides=overrides)
    soln_input = config_input.to_soln_input()
    run = Run(config_input=config_input,
              config_filename=str(config_file),
              disc_solver_version=ds_version,
              float_type=str(float_type),
              sonic_method=sonic_method,
              use_E_r=soln_input.use_E_r)

    if output_file is None:
        output_file = Path(config_input.label + str(arrow.now()) + ".hdf5")
    output_file = expanded_path(output_dir / output_file)

    with h5open(output_file, registries, mode='x') as f:
        f["run"] = run
        sonic_solver = SONIC_METHOD_MAP.get(sonic_method)
        if sonic_solver is None:
            raise SolverError("No method chosen to cross sonic point")
        succeeded = sonic_solver(soln_input,
                                 run,
                                 store_internal=store_internal,
                                 **kwargs)
        run.finalise()

    return output_file, succeeded
Пример #7
0
 def wrapper(filename, *args, **kwargs):
     """
     wrapper for analysis_func_wrapper
     """
     with h5open(filename, registries, mode='r') as soln_file:
         return func(soln_file["run"], *args, filename=filename, **kwargs)
Пример #8
0
 def file_loader(pairs):
     for filename, index_str in pairs:
         with h5open(filename, registries, mode='r') as soln_file:
             yield soln_file["run"], index_str, filename
Пример #9
0
 def file_loader(pairs):
     for filename, index_str in pairs:
         with h5open(filename, ds_and_skw_registries) as soln_file:
             yield soln_file["run"], index_str