src.blocks.Simulator module
This module is responsible for executing simulations and reading measurement files.
It includes one class for the simulations and experiments. See details in its own documentation.
Contact person: Stefan Riedmaier Creation date: 20.04.2020 Python version: 3.8
- class src.blocks.Simulator.Simulator(config, domain, instance)
Bases:
objectThis class is responsible for executing simulations and reading measurement files.
It includes a main method called “run_simulation_process” that calls the other class methods. See more details in the documentation of the run_simulation_process method.
- add_measurement_noise(scenarios_da, results_da)
This function adds artifical measurement noise to scenario parameters and simulation results.
It is only relevant for system simulations in the validation domain that emulate a real system. By adding artificial noise for the measurement procedure, it can be made more realisitic. This function adds noise to the quantities. It also adds noise to the scenario parameters directly (since they only depend on the quantities in the data-driven pipeline).
Attention: We currently do not update the csv file again, since we want to store the actual scenario parameters the simulations were conducted with. However, this means that the result plots at the end do not correspond to the values in the csv files (without noise offset). Nevertheless, it will affect the KPIs in the csv file since they are calculated based on the noisy quantities later.
- Parameters:
scenarios_da (xr.DataArray) – array of scenarios
results_da (xr.DataArray) – array of simulation results
- Returns:
array of scenarios and simulation results with added measurement noise
- Return type:
tuple(xr.DataArray, xr.DataArray)
- archive_carmaker_files()
This function archives important CarMaker project files.
It archives: - the testrun file - the vehicle file - the testseries file
- static convert_parameters(scenarios_da)
This function converts selected scenario parameters to a simulator-specific representation.
This is e.g. required for the UNECE-R79, since the scenario design is based on velocity and lateral acceleration, but the simulator requires the target velocity and curve radius. Thus, the lateral acceleration has to be converted to a curve radius before the simulations.
We currently use a leading underscore to indicate that a parameter has to be converted. We currently have a conversion defined for the following parameters: - _ay_norm: normalized lateral acceleration to curve radius - _ay: (absolute) lateral acceleration to curve radius
- Parameters:
scenarios_da (xr.DataArray) – array with scenarios
- Returns:
array with scenarios after conversion of selected parameters for the simulator
- Return type:
xr.DataArray
- create_erg_filepaths(scenarios_da, space_scenarios_da)
This function creates an erg file path for each scenario and returns the paths list.
It does not actually create directories. It just creates the paths. The simulator will create the files. If the file names already exist, the simulator will overwrite them!
It analyses the dimensions of the scenario array: - 2 dimensions: deterministic - 3 dimensions: (experimental) repetitions - 4 dimensions: nested uncertainty propagation
Details on the conventions of the paths are located at the main documentation in the section “Data Folder Structure” of the csv.rst file.
- Parameters:
scenarios_da (xr.DataArray) – array of the scenarios
space_scenarios_da (xr.DataArray) – array of space scenarios
- Returns:
list of erg file paths for each scenario: relative postfix, rel/abs from python, rel/abs from CarMaker
- Return type:
tuple(list, list, list)
- run_simulation_process(scenarios_da, space_scenarios_da)
This function performs multiple simulations, reads the results and returns a result array.
The process consists of the following steps: 1) In the first step, it either performs actual simulations and stores them at defined relult paths or it reads the result paths from a csv file or folder. In the first case it uses several functions: 1.1) create_erg_filepaths: automatically generate result paths where the simulation results shall be stored, 1.2) convert_parameters: convert selected scenario parameters to a simulator-specific representation, 1.3) remote.execute_testseries: execute a CarMaker test series, 1.4) simulator_csv_handler.save: save the result paths. 2) In the second step, it reads the results from the defined result paths. It supports different namespaces and measurement file formats. 3) Finally, artifical measurement noise can be added to simulation results to minimize the gap to reality.
The result array has similar dimensions as the scenario array: 1) It has a ‘quantities’-dimension instead of the ‘parameter’-dimension 2) The other dimensions are the same n) It has an additional ‘timesteps’-dimension
- Parameters:
scenarios_da (xr.DataArray) – array of scenarios
space_scenarios_da (xr.DataArray) – array of space scenarios
- Returns:
array of results and array of scenarios (due to experimental noise)
- Return type:
tuple(xr.DataArray, xr.DataArray)