コード例 #1
0
ファイル: execute.py プロジェクト: LiuPengPeter/moose-1
def runner(infile, outfile, n_start, n_stop, mode, mpi):

    data = dict(n_samples=[], total=[], per_proc=[], max_proc=[], time=[])

    exe = mooseutils.find_moose_executable_recursive()
    for n in xrange(n_start, n_stop + 1):
        n_samples = 2**n
        exe_args = [
            '-i', infile, 'Samplers/mc/n_samples={}'.format(n_samples),
            'MultiApps/runner/mode={}'.format(mode),
            'Outputs/file_base={}'.format(mode)
        ]

        print('{} {}'.format(exe, ' '.join(exe_args)))
        t = time.time()
        out = mooseutils.run_executable(exe,
                                        exe_args,
                                        mpi=mpi,
                                        suppress_output=True)
        t = time.time() - t

        local = pandas.read_csv('{}.csv'.format(mode))
        data['n_samples'].append(n_samples)
        data['total'].append(local['total'].iloc[-1])
        data['per_proc'].append(local['per_proc'].iloc[-1])
        data['max_proc'].append(local['max_proc'].iloc[-1])
        data['time'].append(t)

    df = pandas.DataFrame(
        data, columns=['n_samples', 'total', 'per_proc', 'max_proc', 'time'])
    df.to_csv('{}_{}.csv'.format(outfile, mode), index=False)
コード例 #2
0
def run_app(args=[]):
    """
    Run the app and return the output.
    Exits if the app failed to run for any reason.
    """
    proc = None
    app_name = mooseutils.find_moose_executable_recursive()
    args.insert(0, app_name)
    #  "-options_left 0" is used to stop the debug version of PETSc from printing
    # out WARNING messages that sometime confuse the json parser
    args.insert(1, "-options_left")
    args.insert(2, "0")
    cmd_line = ' '.join(args)
    try:
        proc = subprocess.Popen(args,
                                stdout=subprocess.PIPE,
                                stderr=subprocess.STDOUT)
    except OSError as e:
        print("Problem running '%s'\nError: %s" % (cmd_line, e))
        sys.exit(1)

    data = proc.communicate()
    stdout_data = data[0].decode("utf-8")
    if proc.returncode != 0:
        print("Failed with exit code %s" % proc.returncode)
        sys.exit(proc.returncode)
    return stdout_data
コード例 #3
0
def execute(infile, outfile, n_samples, processors, test_type):
    """Helper for running a memory study with increasing MPI ranks."""

    data = dict(n_procs=[], n_samples=[], total=[], per_proc=[], max_proc=[], time=[])
    exe = mooseutils.find_moose_executable_recursive()

    for n_procs in processors:
        file_base = '{}_{}'.format(infile[:-2], n_procs)
        exe_args = ['-i', infile,
                    'Outputs/file_base={}'.format(file_base),
                    'Postprocessors/test/test_type={}'.format(test_type),
                    'Samplers/sampler/num_rows={}'.format(int(n_samples))]

        print('mpiexec -n {} {} {}'.format(n_procs, exe, ' '.join(exe_args)))
        t = time.time()
        out = mooseutils.run_executable(exe, *exe_args, mpi=n_procs, suppress_output=True)
        t = time.time() - t

        local = pandas.read_csv('{}.csv'.format(file_base))
        data['n_procs'].append(n_procs)
        data['n_samples'].append(n_samples)
        data['total'].append(local['total'].iloc[-1])
        data['per_proc'].append(local['per_proc'].iloc[-1])
        data['max_proc'].append(local['max_proc'].iloc[-1])
        data['time'].append(t)

    df = pandas.DataFrame(data, columns=['n_procs', 'n_samples', 'total', 'per_proc', 'max_proc', 'time'])
    df.to_csv('{}.csv'.format(outfile), index=False)
コード例 #4
0
def execute(infile,
            outfile,
            mode,
            samples,
            mpi=None,
            replicates=1,
            write=True):
    data = collections.defaultdict(list)
    if mpi is None: mpi = [1] * len(samples)
    exe = mooseutils.find_moose_executable_recursive()
    for n_cores, n_samples in zip(mpi, samples):
        cmd = [
            'mpiexec', '-n',
            str(n_cores), exe, '-i', infile,
            'Samplers/mc/num_rows={}'.format(int(n_samples)),
            'Executioner/num_steps={}'.format(replicates),
            'MultiApps/runner/mode={}'.format(mode),
            'Outputs/file_base={}'.format(mode)
        ]

        print(' '.join(cmd))
        out = subprocess.run(cmd,
                             stdout=subprocess.DEVNULL,
                             stderr=subprocess.DEVNULL)

        local = pandas.read_csv('{}.csv'.format(mode))
        data['n_ranks'].append(n_cores)
        data['n_samples'].append(n_samples)
        data['mem_total'].append(local['total'].iloc[1])
        data['mem_per_proc'].append(local['per_proc'].iloc[1])
        data['mem_max_proc'].append(local['max_proc'].iloc[1])
        data['run_time'].append(statistics.mean(local['run_time'].iloc[1:]))
        data['run_time_min'].append(min(local['run_time'].iloc[1:]))
        data['run_time_max'].append(max(local['run_time'].iloc[1:]))

        df = pandas.DataFrame(data, columns=data.keys())
        if write:
            df.to_csv('results/{}_{}.csv'.format(outfile, mode))
コード例 #5
0
ファイル: runner.py プロジェクト: yashkondajisonawane/moose
def _runner(input_file, num_refinements, *args, **kwargs):
    """
    Helper class for running MOOSE-based application input file for convergence study.

    Inputs:
        input_file[str]: The name of the input file to run
        num_refinements: The number of refinements to perform

    Optional Key-Value Options:
        x_pp[str]: The Postprocessor to use for the x-axis; ignored for rtype=TEMPORAL (default: 'h')
        y_pp[str]: The Postprocessor to use for the y-axis (default: 'error')
        executable[str]: The executable to run, if not provided the executable is automatically
                         detected
        csv[str]: The name of the CSV containing the Postprocessor data, if not provided the name
                  is assumed to be the standard output name if Outputs/csv=true in the input file
        rtype[int]: SPATIAL or TEMPORAL
        dt[float]: The initial timestep, only used with rtype=TEMPORAL (default: 1)
        file_base[str]: A string pattern for outputting files

    All additional arguments are passed to the executable
    """

    x_pp = kwargs.get('x_pp', 'h')
    y_pp = kwargs.get('y_pp', ['error'])

    if not isinstance(y_pp, list):
        y_pp = [y_pp]

    executable = kwargs.get('executable', None)
    csv = kwargs.get('csv', None)
    console = kwargs.get('console', True)
    mpi = kwargs.get('mpi', None)
    rtype = kwargs.get('rtype')  # SPATIAL or TEMPORAL
    dt = kwargs.pop('dt', 1)  # only used with rtype=TEMPORAL
    file_base = kwargs.pop('file_base', None)

    # Check that input file exists
    if not os.path.isfile(input_file):
        raise IOError(
            "The supplied file, '{}', does not exist.".format(input_file))

    # Assume output CSV file, if not specified
    if csv is None:
        fcsv = input_file.replace('.i', '_out.csv')

    # Locate the executable
    if executable is None:
        executable = mooseutils.find_moose_executable_recursive(os.getcwd())
    elif os.path.isdir(executable):
        executable = mooseutils.find_moose_executable(executable)
    elif not os.path.isfile(executable):
        raise IOError("Unable to locate executable: {}".format(executable))

    if executable is None:
        raise IOError("No application executable found.")

    # Build custom arguments
    cli_args = ['-i', input_file]
    cli_args += args

    # Run input file and build up output
    x = []
    y = [[] for _ in range(len(y_pp))]

    if not isinstance(num_refinements, list):
        num_refinements = list(range(num_refinements))

    for step in num_refinements:
        a = copy.copy(cli_args)
        if rtype == SPATIAL:
            a.append('Mesh/uniform_refine={}'.format(step))
        elif rtype == TEMPORAL:
            a.append('Executioner/dt={}'.format(dt))
            dt = dt / 2.

        if file_base:
            fbase = file_base.format(step)
            a.append('Outputs/file_base={}'.format(fbase))
            if csv is None:
                fcsv = '{}.csv'.format(fbase)

        print('Running:', executable, ' '.join(a))
        out = mooseutils.run_executable(executable,
                                        *a,
                                        mpi=mpi,
                                        suppress_output=not console)

        # Check that CSV file exists
        if not os.path.isfile(fcsv):
            raise IOError("The CSV output does not exist: {}".format(csv))

        # Load data for h and error
        current = pandas.read_csv(fcsv)

        if rtype == SPATIAL:
            x.append(current[x_pp].iloc[-1])
            for index, pp in enumerate(y_pp):
                y[index].append(current[pp].iloc[-1])
        elif rtype == TEMPORAL:
            x.append(dt)
            for index, pp in enumerate(y_pp):
                y[index].append(current[pp].iloc[-1])

    if rtype == SPATIAL:
        x_pp == 'dt'

    df_dict = {x_pp: x}
    df_columns = [x_pp]
    for i in range(len(y_pp)):
        df_dict.update({y_pp[i]: y[i]})
        df_columns.append(y_pp[i])

    return pandas.DataFrame(df_dict, columns=df_columns)
コード例 #6
0
def _runner(input_file, num_refinements, *args, **kwargs):
    """
    Helper class for running MOOSE-based application input file for convergence study.

    Inputs:
        input_file[str]: The name of the input file to run
        num_refinements: The number of refinements to perform

    Optional Key-Value Options:
        x_pp[str]: The Postprocessor to use for the x-axis; ignored for rtype=TEMPORAL (default: 'h')
        y_pp[str]: The Postprocessor to use for the y-axis (default: 'error')
        executable[str]: The executable to run, if not provided the executable is automatically
                         detected
        csv[str]: The name of the CSV containing the Postprocessor data, if not provided the name
                  is assumed to be the standard output name if Outputs/csv=true in the input file
        rtype[int]: SPATIAL or TEMPORAL
        dt[float]: The initial timestep, only used with rtype=TEMPORAL (default: 1)

    All additional arguments are passed to the executable
    """

    x_pp = kwargs.get('x_pp', 'h')
    y_pp = kwargs.get('y_pp', 'error')
    executable = kwargs.get('executable', None)
    csv = kwargs.get('csv', None)
    console = kwargs.get('console', True)
    mpi = kwargs.get('mpi', None)
    rtype = kwargs.get('rtype')  # SPATIAL or TEMPORAL
    dt = kwargs.pop('dt', 1)  # only used with rtype=TEMPORAL

    # Check that input file exists
    if not os.path.isfile(input_file):
        raise IOError(
            "The supplied file, '{}', does not exist.".format(input_file))

    # Assume output CSV file, if not specified
    if csv is None:
        csv = input_file.replace('.i', '_out.csv')

    # Locate the executable
    if executable is None:
        executable = mooseutils.find_moose_executable_recursive(os.getcwd())

    if executable is None:
        raise IOError("No application executable found.")

    # Build custom arguments
    cli_args = ['-i', input_file]
    cli_args += args

    # Run input file and build up output
    x = []
    y = []
    for step in xrange(0, num_refinements):
        a = copy.copy(cli_args)
        if rtype == SPATIAL:
            a.append('Mesh/uniform_refine={}'.format(step))
        elif rtype == TEMPORAL:
            a.append('Executioner/dt={}'.format(dt))
            dt = dt / 2.

        print 'Running:', executable, ' '.join(a)
        out = mooseutils.run_executable(executable,
                                        a,
                                        mpi=mpi,
                                        suppress_output=not console)

        # Check that CSV file exists
        if not os.path.isfile(csv):
            raise IOError("The CSV output does not exist: {}".format(csv))

        # Load data for h and error
        current = pandas.read_csv(csv)

        if rtype == SPATIAL:
            x.append(current[x_pp].iloc[-1])
            y.append(current[y_pp].iloc[-1])
        elif rtype == TEMPORAL:
            x.append(dt)
            y.append(current[y_pp].iloc[-1])

    if rtype == SPATIAL:
        x_pp == 'dt'

    return pandas.DataFrame({x_pp: x, y_pp: y}, columns=[x_pp, y_pp])