Parameter generator for projects

Advice for use can be found in section Parameter set generator in chapter Projects.

Parameter generators are stored in the generators directory.

The scope of supply of trace.check includes an example that you can find in the program directory at Templates/DefaultData/ProjectGenerators. Copy it into the generators folder in order to be able to use it.

The parameter set generator interface is documented in the Parameter Set Generator API Reference.

Info

The interface is included in the ecu.test Interface Python Library ecutest-interface.

Restrictions

For the generation of projects and the related static creation of sets of parameters the return parameters of the last package call can’t be used and setting constants is also not possible. The dynamic creation of the sets of parameters during runtime is not affected from these restrictions.

Examples

Simple example for the implementation of the API

# -*- coding: utf-8 -*-

from tts.interface.projectGenerator.ParamGenerator import ParamGenerator
import os
import wx

class PgTextParser(ParamGenerator):

    ID          = '56fe8f8f-e11d-11df-a48c-12386bddbbec'
    NAME        = 'Text file Parser'
    DESCRIPTION = 'Parses a text file line by line'
    SERIALIZE   = {'filename' : ('FILENAME', 'unicode', r'')}

    def __init__(self):
        self.filename        = r''
        self.parameterSets   = []
        self.targetItemCount = 0

    def GetDialog(self):
        return DlgFileSelector(self)

    def GetParameterText(self):
        return 'Filename: {}'.format(self.filename)

    def PreGeneration(self):
        self.parameterSets = []
        self.targetItemCount = 0
        with open(self.filename, 'r') as fileDescriptor:
            for textLine in fileDescriptor.readlines():
                paramSet = {'textLine': textLine}
                self.parameterSets.append(paramSet)
                self.targetItemCount += 1

    def GetTargetItemCount(self):
        return self.targetItemCount

    def GenerationIterator(self):
        for paramSet in self.parameterSets:
            yield self.CreateCycleData(paramSet)

    def PostGeneration(self):
        pass

    def Check(self):
        if not os.path.exists(self.filename):
            return ['File does not exist!']
        return []


class DlgFileSelector(wx.FileDialog):
    def __init__(self, generator):
        super().__init__(None,
                         'Select text file',
                         wildcard='Text files (*.txt)|*.txt',
                         style=wx.FD_OPEN | wx.FD_FILE_MUST_EXIST)
        self.generator = generator

    def ShowModal(self):
        result = super().ShowModal()
        if result == wx.ID_OK:
            self.generator.filename = self.Path
        return result

Examples provided

In order to be able to use the provided examples they have to be copied into your workspace.

Select the option Copy examples in the workspace selection dialog. Doing this, the necessary examples are copied into the current workspace.

Calculator

The parameter set Calculator illustrates the setting of parameters and constants as well as the access to return values of a loop.

The generator reads a CSV file, which contains three values in each line that are separated by semi-colon. The first and third value are numbers. The second value is an arithmetic operation. With these values a parameter set for a calculate package is created that ensures the processing of the two numbers with the respective arithmetic operation. The results are cumulated and, after the parsing of the CSV file, transferred to the calculate package to list them compactly as summary.

The generator can be found at <Project generators directory>/PgCalculator. A complete sample project that uses the generator can be found at <Package directory>/ExamplePackages/PgCalculator/Calculate.prj. You only have to assign the CSV file, which can be found at <Workspace>/ExampleData/PgCalculatorTestData.csv, to the generator. Open the settings dialog of the generator via double-click on the generator. Save the project and run it. You can view the generated runs in the report.

CheckEnvelope

The parameter generator CheckEnvelope illustrates the adding of recordings to a recording group. This example requires the trace analysis package.

The generator reads all recordings of an indicated directory and parameterizes an analysis package with it. The analysis package contains a reference signal that is used to perform an envelope calculation.

The generator can be found at <Project generators directory>/PgCheckEnvelope. A complete sample project that uses the generator can be found at <Package directory>/ExamplePackages/AnalysisExamples/ParameterGenerator/CheckEnvelope.prj. You only have to assign the directory with the sample recordings, which can be found at <Workspace>/ExampleTraces/ParameterGenerator/ActualRecordings, to the generator. Open the settings dialog of the generator via double-click on the generator. Save the project and run it. You can view the generated runs in the report.

ParticleSwarmOptimizer

The parameter set generator ParticleSwarmOptimizer illustrates the approach of a parameter feedback loop during a parameter variation.

In the case of a common parameter variation, the input parameters of all test runs are already determined before execution. In contrast, using the interface used by this optimizer, input parameters can be set dynamically based on the return values of previous runs. This approach is particularly useful if a return value should be minimized or maximized. In this example, a particle swarm algorithm is used for optimization. Since different algorithms are suited for different problem classes, in practice it is helpful to analyze the problem structure for correct algorithm choice.

The generator can be found at <Project generators directory>/PgParticleSwarmOptimizer. A complete sample project that uses the generator can be found at <Package directory>/ExamplePackages/PgParticleSwarmOptimizer/OptimizationProject.prj. It can be run without any additional configuration. It shows a basic workflow to minimize a return value of package PackageToOptimize.pkg. The history of chosen input parameters and their results can be viewed in the report.

Additional optimization algorithms

Further example implementations for different optimization algorithms can be found under <Project generators directory>.

Available examples:

  • Differential evolution

  • Simulated annealing

  • Scipy minimize