run_aster package

code_aster can be used as a standard Python module, see code_aster package.

For convenience and when code_aster is executed from a graphical interface, a study is usually defined by a .export file. The installation provides a script bin/run_aster to execute a study from a such file.

The run_aster package contains the Python source files used by bin/run_aster and bin/run_ctest.

bin/run_aster — Script to execute code_aster

bin/run_aster executes a code_aster study from the command line. The parameters and files used by the study are defined in a .export file (see export for description of the syntax of the .export).

For parallel executions, these two forms are equivalent (if the .export contains P mpi_nbcpu 4):

bin/run_aster path/to/file.export

or:

mpiexec -n 4 bin/run_aster path/to/file.export

Using the first syntax, bin/run_aster re-runs itself with mpiexec using the second syntax (mpiexec syntax is provided by the configuration, see config).

If the version has been configured with --use-srun, you must use:

bin/run_aster path/to/file.export

or:

srun -n 4 [options] bin/run_aster path/to/file.export

bin/run_aster can also directly execute a Python file (.py or .comm extension is expected) with code_aster commands. In this case, no data or result files are managed by run_aster and default values are used for memory and time limit (use options to change these values).

bin/run_aster path/to/file.py

Data files may be referenced in the Python file with relative paths from the parent directory of file.py using, for example, os.path.dirname(__file__).

For the parallel version:

mpiexec -n 2 bin/run_aster --only-proc0 path/to/file.py

or:

bin/run_aster -n 2 --only-proc0 path/to/file.py

bin/run_aster only runs its own version, those installed at the level of the bin directory; unlike as_run where the same instance of as_run executes several versions of code_aster. This makes bin/run_aster simpler and allows per version settings (see config for more informations about the configuration of a version).

More options are available to execute code_aster with an interactive Python interpreter, to prepare a working directory and to start manually (through a debugger for example)… For example, executing bin/run_aster with no .export file starts an interactive Python interpreter.

See bin/run_aster --help for the available options.

bin/run_ctest — Script to execute code_aster testcases using ctest

bin/run_ctest executes code_aster testcases using ctest.

Usage:

bin/run_ctest [options] [ctest-options] [other arguments...]

ctest-options and other arguments are passed to ctest.

The list of the testcases to be executed is built from --testlist argument and a filter on the labels (taken from the .export files).

The sequential label is automatically added for a sequential version.

To show the list of labels, use:

bin/run_ctest --print-labels

Note

Difference from ctest: all values passed to -L option are sorted and joined as a unique regular expression.

Example:

Using:

bin/run_ctest -L verification -L ci -N

the ctest command will be:

ctest -N -j 6 -L 'ci.*verification'

See bin/run_ctest --help for the available options.

run — Main classes for execution

This module defines the objects that prepare the working directory, copy the data files, execute code_aster and copy the result files.

run_aster.run.create_temporary_dir(dir=None)[source]

Create a temporary directory.

Returns:

Path of the directory.

Return type:

str

class run_aster.run.RunAster(export, test=False, tee=False, output=None, interactive=False, exectool=None, savedb=None, proc0id=0)[source]

Bases: object

Execute code_aster from a .export file.

Parameters:

export (Export) – Export object defining the calculation.

classmethod factory(export, test=False, env=False, tee=False, output=None, interactive=False, exectool=None, savedb=None, proc0id=0)[source]

Return a RunAster object from an Export object.

Parameters:
  • export (Export) – Export object defining the calculation.

  • test (bool) – for a testcase,

  • env (bool) – to only prepare the working directory and show command lines to be run,

  • tee (bool) – to follow execution output,

  • output (str) – Path to redirect stdout.

  • interactive (bool) – to keep Python interpreter active.

  • exectool (str) – command that preceeds code_aster command line.

  • savedb (bool) – tell if the database should be saved.

  • proc0id (int) – id of the process that replaces the proc #0.

__init__(export, test=False, tee=False, output=None, interactive=False, exectool=None, savedb=None, proc0id=0)[source]
execute(workdir)[source]

Execution in a working directory.

Parameters:

workdir (str) – Working directory.

Returns:

Status object.

Return type:

Status

_execute()[source]

Execution in the current working directory.

Returns:

Status object.

Return type:

Status

prepare_current_directory()[source]

Prepare the working directory.

execute_study()[source]

Execute the study.

Returns:

Status object.

Return type:

Status

_exec_one(comm, timeout)[source]

Show instructions for a command file.

Parameters:
  • comm (str) – Command file name.

  • timeout (float) – Remaining time.

Returns:

Status object.

Return type:

Status

_get_cmdline_exec(commfile, idx)[source]

Build the command line really executed, without redirection.

Parameters:
  • commfile (str) – Command file name.

  • idx (int) – Index of execution.

Returns:

List of command line arguments, without redirection.

Return type:

list[str]

_coredump_analysis()[source]

Process the coredump file.

_get_cmdline(idx, commfile, timeout)[source]

Build the command line.

Parameters:
  • idx (int) – Index of execution.

  • commfile (str) – Command file name.

  • timeout (float) – Remaining time.

Returns:

List of command line arguments.

Return type:

list[str]

_get_status(exitcode)[source]

Get the execution status.

Parameters:

exitcode (int) – Return code.

Returns:

Status object.

Return type:

Status

ending_execution(results_saved)[source]

Post execution phase : copying results, cleanup…

Parameters:

results_saved (bool) – True if execution did not abort and may have created results, False otherwise.

change_comm_file(comm)[source]

Change a command file.

Parameters:

comm (str) – Command file name.

Returns:

Name of the file to be executed.

Return type:

str

_log_mess(msg)[source]

Log a message into the message file.

class run_aster.run.RunOnlyEnv(*args, **kwargs)[source]

Bases: RunAster

Prepare a working directory for a manual execution.

Parameters:

export (Export) – Export object defining the calculation.

__init__(*args, **kwargs)[source]
prepare_current_directory()[source]

Prepare the working directory.

execute_study()[source]

Execute the study.

Returns:

Status object.

Return type:

Status

_exec_one(comm, timeout)[source]

Show instructions for a command file.

Parameters:
  • comm (str) – Command file name.

  • timeout (float) – Remaining time.

ending_execution(_)[source]

Nothing to do in this case.

run_aster.run.get_procid()[source]

Return the identifier of the current process.

Returns:

Process ID, -1 if a parallel version is not run under mpiexec/srun.

Return type:

int

run_aster.run.get_nbcores()[source]

Return the number of available cores.

Returns:

Number of cores.

Return type:

int

run_aster.run.set_num_threads(value)[source]

Define the number of threads to be used by OpenMP, MKL and OpenBLAS.

Parameters:

value (int) – Maximum number of threads.

run_aster.run.copy_datafiles(files, verbose=True)[source]

Copy data files into the working directory.

Parameters:
  • files (list[File]) – List of File objects.

  • verbose (bool) – Verbosity.

run_aster.run.copy_resultfiles(files, copybase, test=False)[source]

Copy result files from the working directory.

Parameters:
  • files (list[File]) – List of File objects.

  • copybase (bool) – Tell if result databases will be copied.

  • test (bool, optional) – True for a testcase, False for a study.

config — Configuration of the version

The Config object gives access to the configuration parameters of the installed version. These parameters are usually set during the waf configure step and are stored in a YAML file (or JSON for compatibility).

The configuration file is installed in <installation-prefix>/share/aster/config.yaml. It contains version parameters.

The list of the supported version parameters are (with their type):

version_tag: str        - version number
version_sha1: str       - sha1 of the revision
tmpdir: str             - temporary directory used for execution
addmem: int             - memory added to the memory limit found from export
parallel: bool          - true for a parallel version
python: str             - Python interpreter
python_interactive: str - Python interpreter for interactive executions
python_interactive_is_wrapped: bool - Tell of Python for interactive sessions is a wrapper.
mpiexec: str            - mpiexec/srun command line with arguments
mpi_get_rank: str       - command line to get the mpi rank
only-proc0: bool        - true to limit output to proc #0, false to show all
require_mpiexec: bool   - tell if mpiexec/srun is required even with one process
use_srun: bool          - true if processes are started with srun
FC: str                 - fortran compiler
FCFLAGS: list[str]      - flags for fortran compiler
exectool: dict[str]     - command lines for execution wrappers
outputdir: str          - output directory for ``waf test`` and derivated

All these parameters are set during the configure step of the installation.

They can be set during the configure step using environment variables named CONFIG_PARAMETERS_<parameter-name>.

Note

mpiexec command line needs these variables mpi_nbcpu and program following the Python Format String Syntax. For example:

mpiexec -n {mpi_nbcpu} --tag-output {program}

These version parameters can be overridden by a user file: $HOME/.config/aster/config.yaml.

The user can override these parameters depending on the server name and/or the version using filters. A server is defined by its name, a version by its path.

Parameters are read from the installation directory (share/aster/config.yaml), then, from the user file (from .config/aster directory), per-server configurations are read in the order they are listed and finally, the per-version configurations are evaluated.

Example of $HOME/.config/aster/config.yaml (for this example only tmpdir is set in different cases):

server:
  - name: eocn*
    config:
      tmpdir: /tmp_for_eocn_nodes

version:
  - path: '*/install/14*'
    config:
      tmpdir: /tmp_for_v14

  - path: '*/dev/codeaster/install/*'
    config:
      tmpdir: /tmp_for_development_version

What is the value for tmpdir on a cluster node named eocn123 running the version installed in the /projets/aster/install/14.4/mpi?

  • First, tmpdir is read from /projets/aster/install/14.4/mpi/share/aster/config.yaml.

  • Does eocn123 match "*"? Yes, so use /tmp_for_all_servers.

  • Does eocn123 match "eocn*"? Yes, so use /tmp_for_eocn_nodes.

  • Does /projets/aster/install/14.4/mpi match "*/install/14*"? Yes, so use /tmp_for_v14.

  • Does /projets/aster/install/14.4/mpi match "*/dev/codeaster/install/*"? No.

  • Finally, the working directory will be created in /tmp_for_v14.

Each block config can override one or more parameter already defined in config.yaml.

An execution wrapper is a tool, for example a debugger or valgrind, that can preceed the executed command line. Example of $HOME/.config/aster/config.yaml:

server:
  - name: '*'
    config:
      exectool:
        valgrind: valgrind --tool=memcheck --leak-check=full --error-limit=no --track-origins=yes

This valgrind command line is actually defined by default in the configuration file of the installed version and it is callable with run_aster --valgrind .... Another one is also defined by default to wrap gdb execution: run_aster --gdb ....

class run_aster.config.ConfigurationStore[source]

Bases: Store

Object that stores settings for a version.

static _new_param(name)[source]

Create a Parameter of the right type.

class run_aster.config.Config(mainfcfg)[source]

Bases: object

Configuration parameters.

Parameters:

mainfcfg (str) – File name of the configuration file.

__init__(mainfcfg)[source]
property storage

Attribute that holds the ‘storage’ property.

Type:

dict

load()[source]

Load the configuration file.

load_one(cfgfile, main=False)[source]

Load cfgfile.

Parameters:
  • cfgfile (str) – File name of the configuration file.

  • main (bool) – True for the configuration file installed for this version, False for user configuration file.

import_dict(content, with_sections)[source]

Set the configuration parameters from a dict.

Parameters:
  • content (dict) – file content

  • with_sections (bool) – True if it contains ‘server’ and/or ‘version’ subsections, False if it directly contains the version parameters.

static filter(content, section, filter_key, filter_value)[source]

Filter content by keeping sections that match the filter.

Parameters:

content (dict) – file content with optional “server” and “version” list.

Returns:

Version parameters for the current server and version.

Return type:

dict

get(key, default=None)[source]

Return the value of key parameter or default if it is not defined.

Parameters:
  • key (str) – Parameter name.

  • default (misc) – Default value, (default is None).

Returns:

Value or default value.

Return type:

misc

export — Export file object

The Export object parses .export files and provides getters and setters onto the parameters.

This object contains File and ExportParameter objects. The arguments of the code_aster command line are stored in a special ExportParameter object.

The syntax of a .export file is very simple:

P parameter-name parameter-value
A args --arg1 --arg2
F-or-R type path-to-compressed-input-output-file DRC unit

P for parameters, supported parameters are (with their type):

actions: list[str]          - for GUI, "make_env" for "--env"
expected_diag: list[str]    - for testcases that may fail
hide-command: bool          - do not show the command file before execution
interact: bool              - for GUI, same as "--interactive"
memory_limit: float         - memory limit in MB
mpi_nbcpu: int              - number of MPI processes
ncpus: int                  - number of threads (per MPI process)
no-mpi: bool                - start without mpiexec/srun (for some testcases)
time_limit: float           - time limit is seconds

A is a special parameter that stores command line arguments passed to the code_aster command file.

F-or-R: F for files, R for directories.

DRC: one or more characters meaning D data file, R result file, C for compressed (using gzip). Example (from sslv139a testcase):

P time_limit 60
P memory_limit 512
P testlist submit ci verification sequential
F comm sslv139a.comm D 1
F datg sslv139a.datg D 16
F mmed sslv139a.mmed D 20

Paths are relative to the parent directory of the .export file (sslv139a.comm is in the same directory as sslv139a.export).

class run_aster.export.ExportParameter(name)[source]

Bases: AbstractParameter

A parameter defined in a Export object.

name

Parameter name.

Type:

str

value

Value of the parameter.

Type:

misc

static _typed_subclasses(typ)[source]

Return the subclass for the expected type or None if not found.

__repr__()[source]

Simple representation

class run_aster.export.ExportParameterStr(name)[source]

Bases: ExportParameter, ParameterStr

A parameter defined in a Export object of type string.

class run_aster.export.ExportParameterBool(name)[source]

Bases: ExportParameter, ParameterBool

A parameter defined in a Export object of type boolean.

__repr__()[source]

Simple representation

class run_aster.export.ExportParameterInt(name)[source]

Bases: ExportParameter, ParameterInt

A parameter defined in a Export object of type integer.

class run_aster.export.ExportParameterFloat(name)[source]

Bases: ExportParameter, ParameterFloat

A parameter defined in a Export object of type float.

class run_aster.export.ExportParameterListStr(name)[source]

Bases: ExportParameter, ParameterListStr

A parameter defined in a Export object of type list of strings.

__repr__()[source]

Simple representation

class run_aster.export.File(path, filetype='libr', unit=0, isdir=False, data=False, resu=False, compr=False)[source]

Bases: object

A file or directory defined in a Export object.

Parameters:
  • path (str) – File or directory path.

  • filetype (str, optional) – File type (“comm”, “libr”, “nom”, “repe”…).

  • unit (int, optional) – Logical unit number.

  • isdir (bool, optional) – True for a directory, False for a file. If the file or directory exists, it is automatically set.

  • data (bool, optional) – True if it is an input. If neither data or resu is set, data is automatically set to True.

  • resu (bool, optional) – True if it is an output.

  • compr (bool, optional) – True if it is compressed.

__init__(path, filetype='libr', unit=0, isdir=False, data=False, resu=False, compr=False)[source]
property path

Attribute that holds the ‘path’ property.

Type:

str

property filetype

Attribute that holds the ‘filetype’ property.

Type:

str

property is_tests_data

Attribute that tells if this is a data file for testcase. It is taken from a specific directory.

Type:

bool

property unit

Attribute that holds the ‘unit’ property.

Type:

int

property compr

Attribute that holds the ‘compr’ property.

Type:

bool

property isdir

Attribute that holds the ‘isdir’ property.

Type:

bool

property data

Attribute that holds the ‘data’ property.

Type:

bool

property resu

Attribute that holds the ‘resu’ property.

Type:

bool

property as_argument

String to be passed on command_line

Type:

str

classmethod from_argument(line)[source]

Create a File object by decoding a line as formatted by File.as_argument.

Parameters:

line (str) – Line as formatted by File.as_argument

__repr__()[source]

Simple representation

class run_aster.export.Export(filename=None, from_string=None, test=False, check=True)[source]

Bases: Store

This object represents a .export file.

Parameters:
  • export_file (str, optional) – File name of the export file.

  • from_string (str, optional) – Export content as string.

  • test (bool, optional) – True for a testcase, False for a study.

  • check (bool, optional) – True to automatically check the consistency. False if it will be run manually.

__init__(filename=None, from_string=None, test=False, check=True)[source]
copy()[source]

Return a copy of the current object.

Returns:

Copy.

Return type:

Export

static _new_param(name)[source]

Create a Parameter of the right type.

property filename

Path to the export file or None if initialized from a text.

Type:

str

property commfiles

List of input ‘comm’ File objects.

Type:

list[File]

property datafiles

List of input File objects (except ‘comm’ files).

Type:

list[File]

property resultfiles

List of output File objects.

Type:

list[File]

files_of_type(typ)[source]

Return the list of files of the given type.

Parameters:

typ (str) – Expected type.

Returns:

List of output File objects.

Return type:

list[File]

add_file(fileobj)[source]

Add a File object.

Parameters:

fileobj (File) – File object to be added.

remove_file(fileobj)[source]

Remove a File object.

Parameters:

fileobj (File) – File object to be removed.

remove_all_commfiles()[source]

Remove all ‘comm’ File objects.

import_file_argument(line)[source]

Add a File object by decoding a line as formatted by File.as_argument.

Parameters:

line (str) – Line as formatted by File.as_argument

parse(check)[source]

Parse the export content.

Parameters:

check (bool) – Check the consistency of the export file.

set_argument(opts)[source]

Add command line arguments. The caller must check if the options are not already present or if they can appear several times.

Parameters:

opts (list[str]) – List of arguments (for example: “-c”, “–abort”, “–memory=1024”…).

_abspath()[source]

Absolutize path of File objects.

check()[source]

Check consistency, fill arguments from parameter, add arguments that replace deprecated ones…

__repr__()[source]

Return a representation of the Export object.

Returns:

Representation of the content.

Return type:

str

write_to(filename)[source]

Write the content to a file.

Parameters:

filename (str) – Destination file.

property args

Return the arguments list.

Returns:

List of arguments.

Return type:

list[str]

get_argument_value(key, typ)[source]

Return the value of a command line argument.

Parameters:
  • key (str) – Argument name.

  • typ (str|int|float|bool) – Type of expected value.

remove_args(key, add)[source]

Remove a command line argument.

Parameters:
  • key (str) – Argument name.

  • add (int) – Number of additional argument to remove.

set_time_limit(value)[source]

Define the time limit value.

Parameters:

value (float) – New time limit.

set_memory_limit(value)[source]

Define the memory limit value.

Parameters:

value (float) – New memory limit.

run_aster.export.split_export(export)[source]

Return a different Export object for each ‘comm’ file.

Returns:

List of Export objects.

Return type:

list[Export]

settings — Objects to deal with settings

Store is a general storage object that holds various kinds of settings as typed parameters.

The base object is the AbstractParameter object from which are derivated objects to store values of type str, int, float, bool and list of str.

class run_aster.settings.AbstractParameter(name)[source]

Bases: object

An abstract parameter that must be subclassed to hold a typed value.

__init__(name)[source]
property name

Parameter name.

Type:

str

property value

Value of the parameter.

Type:

misc

convert(value)[source]

Convert a value for the parameter type.

set(value)[source]

Convert and set the value.

Parameters:

value (misc) – New value.

classmethod factory(store_typed_params, name)[source]

Create a Parameter of the right type.

Parameters:
  • store_typed_params (dict) – Dict of parameters supported by the Store giving the excpected type.

  • name (str) – Parameter name.

static _typed_subclasses(typ)[source]

Return the subclass for the expected type or None if not found.

class run_aster.settings.ParameterStr(name)[source]

Bases: AbstractParameter

A parameter defined in a Export object of type string.

It may use environment variable “${VAR}”, substitution is only done once when the value is assigned.

class run_aster.settings.VarMixin[source]

Bases: object

Mixin class for a parameter that may be overridden by environment.

set(value)[source]

Convert and set the value.

Parameters:

value (misc) – New value.

class run_aster.settings.ParameterVarStr(name)[source]

Bases: VarMixin, ParameterStr

A parameter defined in a Export object of type string that may be overridden by an environment variable.

class run_aster.settings.ParameterBool(name)[source]

Bases: AbstractParameter

A parameter defined in a Export object of type boolean.

class run_aster.settings.ParameterInt(name)[source]

Bases: AbstractParameter

A parameter defined in a Export object of type integer.

class run_aster.settings.ParameterFloat(name)[source]

Bases: AbstractParameter

A parameter defined in a Export object of type float.

class run_aster.settings.ParameterListStr(name)[source]

Bases: AbstractParameter

A parameter defined in a Export object of type list of strings.

class run_aster.settings.ParameterVarListStr(name)[source]

Bases: VarMixin, ParameterListStr

A parameter defined in a Export object of type list of strings that may be overridden by an environment variable.

class run_aster.settings.ParameterDictStr(name)[source]

Bases: AbstractParameter

A parameter defined in a Export object of type dict of strings.

set(value)[source]

Convert and update the dict.

Parameters:

value (dict) – New value.

class run_aster.settings.Store[source]

Bases: object

A base object to store some settings.

This class must be subclassed and a _new_param class method must be added to make set() method usable.

__init__()[source]
__len__()[source]

Return the storage size.

Returns:

Number of stored parameters.

Return type:

int

add(param)[source]

Add a parameter.

Parameters:

param (Parameter) – Parameter object.

has_param(name)[source]

Tell if name is a known parameter.

Parameters:

name (str) – Parameter name.

Returns:

True it the parameter is defined, False otherwise.

Return type:

bool

get_param(name)[source]

Return a parameter.

Parameters:

name (str) – Parameter name.

Returns:

Parameter or None if the parameter does not exist.

Return type:

misc

get(name, default=None)[source]

Return a parameter value.

Parameters:
  • name (str) – Parameter name.

  • default (misc, optional) – Default value if the parameter does not exist.

Returns:

Parameter value.

Return type:

misc

set(name, value)[source]

Automatically add a parameter of the expected type.

Parameters:
  • name (str) – Parameter name.

  • value (misc) – Parameter value.

static _new_param(name)[source]

Create a Parameter of the right type.

status — Extract the state of a code_aster execution

The execution state is computed from the exit code of the execution (null if the execution ends normally or !=0 otherwise) and the content of the output of the execution (from .mess file).

For testcases, the execution may end normally but with a state not Ok if there is no TEST_RESU or if it is NOOK.

class run_aster.status.Status(state=0, exitcode=-1)[source]

Bases: object

Object that represents the status of an execution.

__init__(state=0, exitcode=-1)[source]
property state

State of the execution.

Type:

StateOptions

property diag

State of the execution as string (diagnostic).

Type:

str

property exitcode

Exit code.

Type:

int

property times

List of 4 values (cpu, sys, tot, elapsed time).

Type:

list[float]

is_completed()[source]

Tell if the calculation was completed (the result databases should be available.

Returns:

True if the calculation was completed, False otherwise.

Return type:

bool

results_saved()[source]

Tell if the result databases should be saved (the calculation is completed or stopped properly).

Returns:

True if the calculation was completed, False otherwise.

Return type:

bool

update(other)[source]

Update the status with a new one (from a following execution). It keeps the effective state, the worst exit code and the sum of elapsed times.

Parameters:

other (Status) – Status of a following execution.

save(filename='__status__')[source]

Save the status content to a file.

Parameters:

filename (str) – Filename to be written.

static load(filename='__status__')[source]

Restore a status object from a file.

Parameters:

filename (str) – Filename to be read.

class run_aster.status.StateOptions(value)[source]

Bases: IntFlag

Enumerator for result state.

Warn

Execution emitted a warning.

Nook

Invalid testcase execution (incorrect value).

NoTest

Invalid testcase execution (no value checked).

Ok

Execution was finished successfully.

CpuLimit

Execution ended with cpu time error.

Convergence

Execution ended with no convergence error.

Memory

Execution ended with a memory error.

Except

Execution ended with an exception.

Syntax

Execution ended with a syntax error.

Fatal

Execution ended with a fatal error.

Abort

Execution ended abnormally.

Completed

Execution run up to the end, the results files should be available.

Error

Execution failed, results files may be missing or corrupted.

static effective(state)[source]

Return the effective and consistent state.

Returns:

The effective state.

Return type:

StateOptions

static name(state)[source]

Convert result state to string representation.

Parameters:

state (int) – Result state (StateOptions).

Returns:

String representation of state.

Return type:

str

run_aster.status.get_status(exitcode, output, test=False)[source]

Return the diagnostic after a Code_Aster execution.

Parameters:
  • output (str) – Output file name or content. If the filename does not exist, the string is used as file content.

  • test (bool, optional) – True for a testcase, False for a study.

Returns:

Status object.

Return type:

Status

error_messages — Extract error messages from an execution

This module defines functions to extract the error messages from the output file of an execution.

run_aster.error_messages.search_msg(text, maxlines=100000)[source]

Return all messages found in a text.

Parameters:
  • text (str) – Output of a code_aster execution.

  • maxlines (int) – Parse only the last maxlines lines.

Returns:

Ordered Dict of list of messages, indexed by command identifier.

Return type:

dict

run_aster.error_messages._remove_decoration(text)[source]

Remove the message decoration.

Parameters:

text (str) – Text of a message.

Returns:

Message without its decoration.

Return type:

str

run_aster.error_messages._regexp_decoration()[source]

Return regular expressions to search for the horizontal and vertical markers of decorated messages

run_aster.error_messages._add_line_numbers(text)[source]

Insert line numbers at the beginning of the log of code_aster execution.

Parameters:

text (str) – Log (output) of code_aster execution.

command_files — Changing commands files

This modules provides some functions that change commands files.

run_aster.command_files.add_import_commands(text)[source]

Add import of code_aster commands if not present.

Parameters:

text (str) – Text of a command file.

Returns:

Changed content.

Return type:

str

run_aster.command_files.add_coding_line(text)[source]

Ensure to have ‘coding’ line at the beginning.

Parameters:

text (str) – Text of a command file.

Returns:

Changed content.

Return type:

str

run_aster.command_files.stop_at_end(text, last=True)[source]

Stop execution for interactive commands instead of calling FIN().

Parameters:
  • text (str) – Text of a command file.

  • last (bool) – Tell if this is the last file to be executed. If False, ‘FIN()’ must be preserved.

Returns:

Changed content.

Return type:

str

run_aster.command_files.file_changed(text, original)[source]

Additional modifications when the command file was changed.

Parameters:
  • text (str) – Text of a command file.

  • original (str) – Path of original file.

Returns:

Changed content.

Return type:

str

run_aster.command_files.change_procdir(text)[source]

Insert command to change into the ‘proc.N’ directory with N the rank of the MPI process.

Parameters:

text (str) – Text of a command file.

Returns:

Changed content.

Return type:

str

toolbox — Toolbox for the developers

run_aster.toolbox.make_shared(lib, src, *args)[source]

Build a shared library from a fortran source file.

Parameters:
  • lib (str) – Result library.

  • src (str) – Fortran source file.

  • args (list[str]) – Optional arguments passed to the linker.

Returns:

exit code.

Return type:

int

utils — Utilities

This module provides convenient utilities for files manipulation, system command execution, templates…

run_aster.utils.copy(src, dst, verbose=False)[source]

Copy the file or directory src to the file or directory dst. If src is a file, dst can be an existing directory or the destination file name. If src is a directory and dst is an existing directory, the files will be copied into dst. Parent directory of dst is created if necessary.

If dst specifies a directory, the files will be copied into dst using the base filenames from src.

Parameters:
  • src (str) – File or directory to be copied.

  • dst (str) – Destination.

  • verbose (bool) – Verbosity.

run_aster.utils.compress(path, verbose=False)[source]

Compress a file or the content of a directory.

Parameters:
  • path (str) – File or directory path.

  • verbose (bool) – Verbosity.

run_aster.utils.uncompress(path, verbose=False)[source]

Decompress a file or the content of a directory.

Parameters:
  • path (str) – File or directory path.

  • verbose (bool) – Verbosity.

run_aster.utils.make_writable(filename)[source]

Force a file to be writable by the current user.

Parameters:

filename (str) – File name.

run_aster.utils.run_command(cmd, exitcode_file=None)[source]

Execute a command and duplicate output to logfile.

Parameters:
  • cmd (list) – Command line arguments.

  • exitcode_file (str, optional) – Read exit code from this file if it exists.

Returns:

exit code.

Return type:

int

run_aster.utils._waitstatus_to_exitcode(status)[source]

Replacement for waitstatus_to_exitcode function added in Python 3.9.

Parameters:

status (int) – status as returned by os.wait()/os.waitpid().

Returns:

exit code.

Return type:

int

run_aster.utils.cmd_abspath(prog)[source]

Return the absolute path of a program as found in PATH.

If prog contains a ‘/’, it is returned unchanged.

Parameters:

prog (str) – Executable or script.

Returns:

Absolute path to run prog.

Return type:

str

class run_aster.utils.PercTemplate(template)[source]

Bases: Template

Template with ‘%’ as delimiter.

logger — Logging and messages output

This module defines a logger object and error functions. All message outputs should pass by this object. Probably additional levels should be added to distinguish low-debug messages, debug messages that may be interesting for the user (equivalent to INFO=2)… It might be necessary to refactor it in C++ for better performance and a global access (no C interface currently)…

class run_aster.logger.PerLevelFormatter(fmt=None, datefmt=None, style='%', validate=True)[source]

Bases: Formatter

Formatter for messages

format(record)[source]

Enhance error and warning messages

class run_aster.logger.PerLevelColorFormatter(fmt=None, datefmt=None, style='%', validate=True)[source]

Bases: PerLevelFormatter

Formatter for messages

_adjust_color(level)[source]

Choose a color function according to the level

format(record)[source]

Enhance error and warning messages

class run_aster.logger.HgStreamHandler(stream=None)[source]

Bases: StreamHandler

StreamHandler switching between sys.stdout and sys.stderr like the mercurial ui does

_adjust_stream(level)[source]

Adjust the stream according to the given level

emit(record)[source]

Enhance error and warning messages

run_aster.logger.build_logger(level=20, raise_exception=True)[source]

Initialize the logger with its handlers.

Parameters:
  • level (int) – Logging level.

  • raise_exception (bool) – If True (default), an exception is raised in case of error.

Returns:

logger object.

Return type:

Logger

run_aster.logger._colorize(color, string)[source]

Return the colored string

run_aster.logger.red(string)

Return the colored string

run_aster.logger.green(string)

Return the colored string

run_aster.logger.blue(string)

Return the colored string

run_aster.logger.magenta(string)

Return the colored string

run_aster.logger.cyan(string)

Return the colored string

run_aster.logger.yellow(string)

Return the colored string

run_aster.logger.grey(string)

Return the colored string

timer — Simple timer

This module defines the simple timer object to store elapsed times during different steps of an execution.

class run_aster.timer.Measure(cpu, system, total, elapsed)

Bases: tuple

cpu

Alias for field number 0

elapsed

Alias for field number 3

system

Alias for field number 1

total

Alias for field number 2

class run_aster.timer.Timer(title='Total')[source]

Bases: object

Object to trace the time spent during execution.

__init__(title='Total')[source]
start(title)[source]

Start a new timer.

Parameters:

title (str) – Title, also used as identifier for the timer.

stop(title=None)[source]

Stop a timer. If no timer is provided, it stops the last started one.

Parameters:

title (str, optional) – Title, also used as identifier for the timer.

stop_all()[source]

Stop all non stopped timers.

report()[source]

Return a report of the measures.

Returns:

Report.

Return type:

str

static deltat(start, end)[source]

Return a tuple of (cpu, sys, total, elapsed) between start and end.

Parameters:
  • start (times_result) – Initial time as return by timer().

  • end (times_result) – End time.

Returns:

Tuple of 4 floats: (cpu, system, total, elapsed).

Return type:

Measure

static add(measure, other)[source]

Cumulate two measures.

Parameters:
  • measure (Measure) – First measure.

  • other (Measure) – Second measure, that may be null (None).

save(filename)[source]

Save timer content to a file.

Parameters:

filename (str) – Filename to be written.

load(filename)[source]

Restore timer content from a file.

Parameters:

filename (str) – Filename to be read.

ctest2junit — Convert a CTest execution report to JUnit

This module converts a report from CTest to JUnit format.

This creates a XML file that can be presented by Continous Integration tools.

class run_aster.ctest2junit.XUnitReport(resudir, legend='')[source]

Bases: object

Represents a report to be exported at the xUnit format.

Parameters:

resudir (str) – Directory containing the result files.

__init__(resudir, legend='')[source]
read_ctest(resudir=None)[source]

Read the CTest report.

It reads the list of testcases that passed and that failed from the CTestCostData.txt file and extracts detailed informations (error messages, OK/NOOK results) from .mess files. LastTest.log is also parsed to get the elapsed time of testcases in failure.

write_xml(filename)[source]

Export the report in XML.

Parameters:

filename (str) – Output XML file (relative to the base directory).

run_aster.ctest2junit.get_state(txt)[source]

Extract the test state for a ‘message’ file content.

Parameters:

txt (str) – ‘.mess’ file content.

Returns:

Error messages.

Return type:

str

run_aster.ctest2junit.get_err_msg(txt)[source]

Extract the error message for a ‘message’ file content.

Parameters:

txt (str) – ‘.mess’ file content.

Returns:

Error messages.

Return type:

str

run_aster.ctest2junit.get_nook(txt)[source]

Extract NOOK values from a ‘message’ file content.

Parameters:

txt (str) – ‘.mess’ file content.

Returns:

Text of OK/NOOK values.

Return type:

str