AmesimKnowledge

Tutorial > Managing your scripts

Log file and error management

API log file and error management

Sometimes you will want to know what’s happening when you run your script. This is useful for debugging purposes. The Simcenter Amesim API can help you trace what is happening, or can produce a log file.

In this section we will load an out of date system, upgrade it, and save it under a new name. At the same time, we will see how to log what your script is doing, and how to deal with errors.

Logging what your script is doing

To turn this function on, use the AMESubscribeToLogFile

AMESubscribeToLogFile

API
AMESubscribeToLogFile

function. To turn this function off, use AMEUnSubscribeToLogFile.

Procedure

  1. Copy CentrifugalPump_out_of_date.ame and tutorial_step_3.py to your working directory from the API folder of the Simcenter Amesim tutorial directory.

  2. Edit tutorial_step_3.py to enable the log file function.

Copy# Add log file subscription AMESubscribeToLogFile('my_first_log.log')

  1. Launch your script. It will produce a log file (in this case, named my_first_log.log) with the following information:

Copy`** Information ** AME API Welcome! Begin: 08/02/2008 16:55:40.

** Warning **
"CentrifugalPump_out_of_date" circuit submodels may need
    updating. The update facility may be necessary.

** Information **
End: 08/02/2008 16:55:45
AME API Bye!.`

There are four message levels:

  • Information

  • Warning

  • Error

  • Fatal

By default, log files receive messages from the Warning to Fatal levels (except for initialization and closure messages).

You can change the filter level to catch more or fewer messages from the API.

Filtering messages from the API

Filtering messages from the API

API filtering messages

We will now change the message filter information level to catch what the update facility does when it upgrades a system.

In the tutorial_step_3.py add the following lines after # Insert check submodels code there:

Copy

# Check circuit submodels if necessary
if AMEDoesNeedCheckCircuitSubmodels():
   print ('Checking "CentrifugalPump_out_of_date" circuit submodels...')
try:
# Redirect the check submodels report into 'testFricion.log' file   
   AMESetMessageFilter('ame_info')
   AMECheckCircuitSubmodels()
except:
   print ('Unable to check "CentrifugalPump_out_of_date".')

Launch your script. The log file now contains details about the circuit update:

Copy

** Information **
    AME API Welcome!
    Begin: 04/02/2008 08:57:21.
    
    ** Warning **
    "CentrifugalPump_out_of_date" circuit submodels may need
        update. Check submodels may be necessary.
    
    ** Information **
    "CentrifugalPump_out_of_date" circuit check submodels
        report:
    PQSG1
    * Checked OK.
    UD00
    * 2 differences found:
    - number of integer stores
    circuit: 1
    submodel file: 2
    - number of integer parameters
    circuit: 0
    submodel file: 2
    
    UD00
    * Updated OK.
    
    * Checked OK.
    FXYA2
    * Checked OK.
    SPLT0
    * Checked OK.
    SGN10
    * Checked OK.
    TK000
    * Checked OK.
    PQSG2
    * Checked OK.
    VOR00
    * 5 differences found:
    - number of internal variables
    circuit: 1
    submodel file: 5
    - internal variable 1 type
    circuit: activity variable
    submodel file: basic variable
    - internal variable 1 title
    circuit: activity of hydraulic dissipation (orif)
    submodel file: flow coefficient (Cq)
    - internal variable 1 unit
    circuit: J
    submodel file: null
    - real parameter 7 title
    circuit: critical flow number laminar->turbulent
    submodel file: critical flow number (laminar ->
        turbulent)
    
    VOR00
    * Updated OK.
    
    * Checked OK.
    FX00
    * Checked OK.
    SIN0
    * Checked OK.
    TK000
    * Checked OK.
    JUN3P
    * Checked OK.
    LAG1
    * Checked OK.
    FP01
    * Checked OK.
    
    ** Information **
    There is a doubt about the value of 3 parameters:
    - nstages@signal03
    - iscyclic@signal03
    - lamc@variableorifice.
    
    ** Information **
    A backup of the original circuit has been created:
        'E:/CentrifugalPump_out_of_date.ame.bak420_1'.
    
    ** Information **
    "CentrifugalPump_out_of_date" circuit submodels have been
        updated.
    
    ** Information **
    End: 04/02/2008 08:57:25
    AME API Bye!.

Source: https://docs.sw.siemens.com/en-US/doc/254352342/PL20250521841123434.amesim_collection.Circuit_API/Log_file_and_error_management · retrieved 2026-07-17