Main Content

Reduce Variant Models Using Variant Reducer

Note

This functionality requires Variant Manager for Simulink®.

A model might contain several variant blocks, each with many variant choices. A variant configuration is used to represent a combination of such variant choices across the model hierarchy. For example, in a system with a plant and a controller, a linear controller with an internal plant with no noise and a nonlinear controller with an external low fidelity plant represent two different configurations of the system.

You can use Variant Manager to create and manage variant configurations for a model. Variant Manager defines a variant configuration as a set of variant control variables and their values that can activate a specific variation in the model hierarchy. For more information on variant configurations, see Variant Configurations. For an overview of Variant Manager, see Variant Manager for Simulink.

Variant Reducer

You can use the Variant Reducer tool in Variant Manager to automatically generate a simplified, standalone model that contains only a subset of variant configurations from the input model. The generated model is called a reduced model. The reduced model retains the variant configurations that you choose from the parent variant model. For example, you can generate a reduced model that represents a specific product from a product line (single configuration reduction) or one that corresponds to a product line from a product line family (multi-configuration reduction).

 Example of Reducing a Simple Variant Model

Steps in Reduction Process

Variant Reducer performs these high-level operations during the reduction process:

  • Removes inactive model components based on the variant configurations that you choose to retain in the reduced model.

  • Removes or modifies model components such as blocks, variant parameter objects, masks, model references, subsystem references, libraries, dependent files such as MAT or SLDD files, and variables in the input model. For information on model components that are modified or not reduced, see Considerations and Limitations for Variant Reduction.

  • Packages the reduced artifacts into a user-specified output folder.

  • Generates a detailed summary of the reduction process that helps you to analyze these changes.

Modes and Options for Reduction

Variant Reducer provides different modes and options that you can set before reducing the model.

ModePurpose

Reduction mode

Provides multiple ways to specify the configurations to be retained in the reduced model.

You can choose configurations based on:

  • Current values of variant control variables in the global workspace

  • Named variant configurations created for the model

  • Specified values of variant control variables

Compile mode

Compile the input model in simulation or code generation mode as part of the reduction process.

OptionPurpose

Files to exclude

Exclude Simulink data dictionary files (*.sldd) and MAT-files (*.mat) outside the matlabroot folder during reduction.

Output folder

Folder to place the reduced model and artifacts

Model suffix

Suffix to append to the name of reduced model and artifacts

Preserve signal attributesTry to preserve compiled signal attributes between the original and the reduced model by adding signal specification blocks in the reduced model.
Open reduced modelChange the current working folder to the output folder specified for reduction and open the reduced model.
Generate detailed summaryGenerate a detailed summary for the reduced model. This requires a Simulink Report Generator™ license.

Reduce Variant Model Using Variant Manager

  1. Open Variant Manager for the model that must be reduced. Here, open the slexVariantReducer model using the following command.

    addpath(fullfile(matlabroot,'examples','simulink_variants','main'));
    open_system('slexVariantReducer');

    On the Modeling tab, open the Design section and click Variant Manager. Alternatively, right-click the variant badge on any variant block in the model and select Open in Variant Manager.

    Context menu open on variant badge of variant block, with Open in Variant Manager option selected

    This image shows the Variant Manager window for the slexVariantReducer model. The model has two predefined variant configurations named config1 (V==1 && W==2) and config2 (V==2 && W==2).

    Variant Manager window for the model

  2. Open Variant Reducer. In the Variant Manager toolstrip, in the Apps section, click Variant Reducer.

    This image shows the Variant Reducer window.

    Variant Reducer window.

  3. Specify the different settings for reduction in the Mode and Options sections of the Variant Reducer toolstrip. If you do not modify the settings, Variant Reducer uses default values for reduction. The purpose of each setting is detailed in the following steps.

  4. Select a Reduction mode option:

    • Current variant control values: Reduce the model based on the variant control variable values in the global workspace. If the model does not have any predefined named configurations, Variant Reducer uses this mode by default.

    • Specify variant configurations: Reduce the model for the named configurations defined in a variant configuration data object associated with the model.

      Note

      In this mode, Variant Reducer stores the variant control variable values from the last selected configuration in the global workspace.

      Select the required configurations from the Configurations tab.

      Variant Reducer dialog box with Reduction mode specified as Specify variant configurations.

    • Specify variant control values: Reduce the model by specifying values for the variant control variables. You can create multiple variable groups that correspond to different variant configurations to be retained in the reduced model. In each variable group, you must specify the variant control variables and the values to be considered for each variable.

      Note

      In this mode, the reduced model has a new variant configuration data object that contains the specified variable groups.

      Variant Reducer dialog box with Reduction mode specified as Specify variant control values.

      To add a new variable group, click Add variable group in the Variable Groups table.

      In the Group table, in the Values column, you can either specify a value for the variant control variable or select Full-range or Ignored from the list.

      • Variant control value as a vector — Reduce the model for all combinations of the specified values. For example, if you specify values V = 1 and W = [1,2], then the model is reduced for the configurations {V==1,W==1} and {V==1,W==2}.

      • Full-range — Reduce the model for all valid values of the specified variant control variable. In the Reference value column, you must enter a reference value for the variable for which the model compiles successfully.

      • Ignored — The variant control variable is not considered while reducing the model.

      Note

      • To use a full-range variant control variable, you must set the Variant activation time in the block parameters dialog of the block that uses that variant control variable to code compile.

      • You can specify at most one full-range variant control variable in a variant block.

      • Specifying the value of a variant control variable as full-range during reduction is not supported if the variable is used by variant parameters visible to the model, even if the parameter is not used in the model hierarchy.

  5. For Compile mode, select sim to compile the model for simulation or codegen to compile the model in code generation mode as part of reducing the model. If the model contains variant blocks with the Variant control mode parameter set to sim codegen switching, you can select codegen to retain the code generation branches of the blocks in the reduced model. For the default value sim, Variant Reducer compiles and retains the simulation branches in the top-level model.

  6. Select Preserve signal attributes to preserve the compiled signal attributes between the original and reduced model. When this option is selected, the Variant Reducer tries to preserve the compiled signal attributes between the original and reduced models by adding signal specification blocks at appropriate block ports in the reduced model. Compiled signal attributes include signal data types, signal dimensions, and compiled sample times.

  7. Select Generate detailed summary to generate the Variant Reducer summary report in the output folder. The Variant Reducer summary contains a summary of Variant Reducer Options, Original and Reduced Model Differences, Dependent Artifacts, Callbacks, and Warnings. For more information, see Explore Variant Reducer Summary.

    Note

    To generate a detailed summary, you must have a Simulink Report Generator license.

  8. Use the Files to exclude box to specify any dependent Simulink data dictionary files (*.sldd) and MAT-files (*.mat) outside the MATLAB® root folder to exclude during reduction. Value must be a cell array of character vectors.

    You can specify the full path of the directory or the specific files that must be skipped. You can also provide wildcard characters, for example, {'*.sldd'} or {'topData.sldd'}.

  9. Specify a value for Model suffix. The model suffix value is appended to the names of the reduced models, data dictionaries, and related artifacts. By default, the suffix is _r.

  10. In the Output folder box, browse for or enter the output folder in which to store the reduced model and related artifacts. The output folder must not be under matlabroot. By default, the reduced artifacts are generated in a folder named reducedModel within the original model folder.

    If the output folder contains the variant_reducer.log file from a previous model reduction, then Variant Reducer overwrites all the files available in that folder during any subsequent reduction.

  11. Select Open reduced model to change the current working folder to the output folder and open the reduced model.

  12. Click Reduce Model.

    This image shows the result of reducing the model for the configuration config1 with values V=1 and W=2.

    Original and reduced models

  13. To return to the Manage tab of Variant Manager, click Close Reducer.

Explore Variant Reducer Summary

If you set the Generate detailed summary option for a reduction, Variant Reducer generates a detailed report of the reduction process as an HTML file. The report is saved in the output folder where reduced artifacts are saved.

Note

A Simulink Report Generator license is required to generate a Variant Reducer summary.

Use the Variant Reducer summary to:

  • Verify the input and output options used for reduction, for example, the input variant configuration and the output folder location.

  • Analyze the differences between the original model and the reduced model, for example:

    • Blocks that have been inserted, deleted, or modified

    • Masks that have been modified

    • Dependent data files or Simulink cache files that have been modified

  • Identify any warnings.

  • Identify components that are not reduced and determine the manual updates that might be required, for example, callback code and Stateflow® variant transitions.

  • Navigate the interactive views of the original and reduced models.

Variant reducer summary report

Reduce a Model Programmatically

To reduce a model programmatically, see Simulink.VariantManager.reduceModel.

Considerations and Limitations for Variant Reduction

Limitations

  • Reduction of models that contain the Variant Connector block is not supported.

  • Reduction of models that contain variant blocks with the Variant activation time parameter set to startup is not supported.

  • Specifying the value of a variant control variable as full-range during reduction is not supported if the variable is used by variant parameters visible to the model, even if the parameter is not used in the model hierarchy.

Variant Conditions on Simulink Function Blocks After Reduction

If a model that contains a Simulink Function block is reduced for any or a combination of the available variant conditions on the block, then the Simulink Function block in the reduced model becomes unconditional.

Consider a model that contains a Simulink Function block with the value of the Variant control parameter set to V==1 || V==2 || V==3 || V==4.

  • If the model is reduced for the variant control values V=1, V=2, and V=3, then the Simulink Function block in the reduced model is unconditional.

  • If the model is reduced for the variant control values V=1, V=2, and V=5, then the Simulink Function block in the reduced model remains conditional with the value of the Variant control parameter set to V==1 || V==2.

Modifications to Model Components

  • Additional blocks are added automatically to the reduced model to ensure consistent simulation semantics. Additional blocks include Signal Specification blocks for consistent signal attributes (data type, dimensions, complexity) or the Ground and the Terminator blocks for unconnected signals.

  • Variant parameter objects (instance of the Simulink.VariantVariable class) are reduced.

  • Referenced models and library blocks present in the model hierarchy are reduced.

  • If the model contains resolved library links, the corresponding parent is reduced for the specified configuration and is referenced in the model.

  • Reduced models are saved with a MAT-file that contains saved variant configurations. The file loads during the PostLoadFcn callback of the reduced model.

  • Variant subsystem and Model Variant blocks with only one choice are converted to normal Subsystem or Model blocks.

  • Single-input, single-output Variant Source and Variant Sink blocks are removed if they are active across all specified configurations.

  • During model reduction, commented blocks present on the active path are retained. Commented blocks present on an inactive path are removed.

  • Signal attributes such as data type, complexity, or dimensions that come from the inactive elements in Stateflow charts might not be retained in the reduced model.

Model Components That Are Not Reduced

These model components are not reduced automatically and might require manual intervention. To identify such artifacts, use the Variant Reducer summary report.

  • Callback code:

    • Callbacks such as InitFcn, PreLoad, PostLoad, mask initialization code, and mask parameter callback code must be modified manually.

    • Callback code in the inactive variant components is removed. This action can cause unexpected behavior in the reduced model.

  • During model reduction, elements in the Stateflow canvas, including variant transitions, are not modified.

  • If a model has dependencies on files that are located under matlabroot (Simulink libraries, .m files, .mat files, or .sldd files), the files are not modified or copied to the output folder during model reduction.

  • Library blocks under the MATLAB root are not reduced.

See Also

| |

Related Topics