Exemplo n.º 1
0
 def testRunSupressOutput(self, subproc):
     mooseutils.run_executable('command',
                               '-arg',
                               '-arg2',
                               suppress_output=True)
     subproc.assert_called_with(['command', '-arg', '-arg2'],
                                encoding='utf-8',
                                stderr=subprocess.DEVNULL,
                                stdout=subprocess.DEVNULL)
Exemplo n.º 2
0
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)
Exemplo n.º 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)
Exemplo n.º 4
0
    def execute(self, **kwargs):
        """Perform app syntax checking"""

        # Check that the supplied content dir exists
        content_dir = mooseutils.eval_path(self.content_directory)
        if not os.path.isdir(content_dir):
            content_dir = os.path.join(self.working_dir, content_dir)
        if not os.path.isdir(content_dir):
            raise NotADirectoryError(
                "'content_directory' input is not a directory: {}".format(
                    content_dir))

        # Populate the available list of files
        file_cache = mooseutils.git_ls_files(content_dir)

        # Check that the supplied exe dir exists
        exe_dir = mooseutils.eval_path(self.exe_directory)
        if not os.path.isdir(exe_dir):
            exe_dir = os.path.join(self.working_dir, exe_dir)
        if not os.path.isdir(exe_dir):
            raise NotADirectoryError(
                "'exe_directory' input is not a directory: {}".format(exe_dir))

        # Locate the executable
        exe = mooseutils.find_moose_executable(exe_dir,
                                               name=self.exe_name,
                                               show_error=False)
        if exe is None:
            raise OSError(
                "An executable was not found in '{}' with a name '{}'.".format(
                    exe_dir, self.exe_name))

        # Build syntax tree if not provided
        if self.app_syntax is None:

            # Get the hidden/removed/alias information
            hide = self._loadYamlFiles(self.hidden)
            remove = self._loadYamlFiles(self.remove)
            alias = self._loadYamlFiles(self.alias)
            unregister = self._loadYamlFiles(self.unregister)

            # Build the complete syntax tree
            self.app_syntax = moosesyntax.get_moose_syntax_tree(
                exe,
                hide=hide,
                remove=remove,
                alias=alias,
                unregister=unregister,
                allow_test_objects=self.allow_test_objects)

        # Determine the application type (e.g., MooseTestApp)
        if self.app_types is None:
            out = mooseutils.run_executable(exe, ['--type'])
            match = re.search(r'^MooseApp Type:\s+(?P<type>.*?)$',
                              out,
                              flags=re.MULTILINE)
            if match:
                self.app_types = [
                    match.group("type").replace('TestApp', 'App')
                ]

        # Perform the checks
        kwargs.setdefault('syntax_prefix',
                          mooseutils.eval_path(self.syntax_prefix))
        kwargs.setdefault('object_prefix',
                          mooseutils.eval_path(self.object_prefix))
        logger = check_syntax(self.app_syntax, self.app_types, file_cache,
                              **kwargs)

        # Create stub pages
        if self.generate_stubs:
            func = lambda n: (not n.removed) \
                             and ('_md_file' in n) \
                             and ((n['_md_file'] is None) or n['_is_stub']) \
                             and ((n.group in self.app_types) \
                                  or (n.groups() == set(self.app_types)))
            for node in moosetree.iterate(self.app_syntax, func):
                self._createStubPage(node)

        # Dump
        if self.dump_syntax:
            print(self.app_syntax)

        return logger
Exemplo n.º 5
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)
        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)
Exemplo n.º 6
0
 def testRunMPI(self, subproc):
     mooseutils.run_executable('command', '-arg', '-arg2', mpi=2)
     subproc.assert_called_with(
         ['mpiexec', '-n', '2', 'command', '-arg', '-arg2'],
         encoding='utf-8')
Exemplo n.º 7
0
 def testRun(self, subproc):
     mooseutils.run_executable('command', '-arg', '-arg2')
     subproc.assert_called_with(['command', '-arg', '-arg2'],
                                encoding='utf-8')
Exemplo n.º 8
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])