Optimizer Example Pipeline Details

Optimizer example pipelines demonstrate how to extend Formulation Design with generative workflows that help formulators optimize product formulations.

Virtual Companions and Generative Experiences leverage artificial intelligence (AI) technology. You should ensure prior validation of any output created using these solutions before use in production and especially in business-critical systems. Always follow your organization's best practices and data policies when using it. For more information, see https://www.3ds.com/trust/ai.

This page discusses:

See Also
Configuring to Run an Example Pipeline for Formulation Design
Design Advisor Templates and Example Pipelines

Optimizer example pipelines run in the Design Advisor app, and help formulators explore, evaluate, and optimize product formulations. They combine Design of Experiments (DOE), machine-learning prediction (based on models generated in the Machine Learning Workbench app), multi-objective ranking, and visual analytics into an interactive workflow.

The following examples are available:

  • Minimize Yogurt Fat Example: Use a generative workflow to minimize fat while maintaining selected sensory properties in a yogurt formulation in Formulation Design.
  • Minimize Yogurt Sugar Example: Use a generative workflow to minimize sugar while maintaining selected sensory properties in a yogurt formulation in Formulation Design.
  • Optimize Yogurt Formula Example: Use an optimization workflow to display a yogurt formulation in Formulation Design that optimizes on a range of fat and sugar while maintaining sensory properties.

These examples were built using the basic Design Advisor template, and share a common set of Python calculation scripts. They differ only in the Advisor Configuration component, and in which Design Advisor parameters are activated.

Top-level Pipeline

The examples use the Design Advisor template. On the top level, the main components are the Advisor Configuration subpipeline, which controls user input, and Advisor Calculation subpipeline, which performs the calculations. Both branches converge at the output anchor, which renders the output:

Pipeline Workflow

The pipeline executes the following stages:

  1. Configure the advisor: Advisor (vc_*) parameters are defined with default values. The component generates a configuration dialog that the user can use to modify the values before the calculation runs. Values are passed using global variables.
  2. Perform the advisor calculation:
    1. Generate the DOE:
      • Select features by means of Pearson correlation.
      • Create discrete levels around the reference formula.
      • Use Latin Hypercube Sampling to generate candidate formulations.
      • Define the distribution for each feature using a historical data set.
    2. Make predictions: Use pre-trained XGBoost models (trained in Machine Learning Workbench) to predict sensory scores and nutritional properties for each candidate.
    3. Rank and filter: Apply hard filters (for example, fat or sugar bounds), and then compute a composite score, which combines minimization, maximization, and deviation-from-target penalties.
  3. Generate output:
    • Combined radar chart compares all shortlisted formulations to the original.
    • Table of original and optimized formulas.
    • Scatter plot of the key trade-off.

How Parameters Are Stored

Each input in the configuration dialog corresponds to a parameter defined in the pipeline. The protocol uses Pipeline Pilot syntax to declare defaults:

If @vc_flavor_intensity Is Not Defined Then
    @vc_flavor_intensity := 1;
End if;

If @vc_sweetness Is Not Defined Then
    @vc_sweetness := 1;
End if;

If @vc_global_appreciation Is Not Defined Then
    @vc_global_appreciation := 1;
End if;

A value of 1 means that the property is enabled (maintained) by default; 0 means it is disabled. Users can toggle these on or off in the configuration dialog. The vc_ prefix distinguishes parameters specific to advisor pipelines.

Parameter Reference

The following able below lists all vc_ parameters used in the three examples. Sensory maintenance toggles use a 0/1 flag; constraint parameters use a use/amount pair.

Parameter Default Description
vc_flavor_intensity 1 Maintain flavor intensity
vc_sweetness 1 Maintain sweetness
vc_fruit_intensity 0 Maintain fruit intensity
vc_color_intensity 0 Maintain color intensity
vc_thickness 0 Maintain thickness
vc_nappant 0 Maintain nappant
vc_global_appreciation 1 Maintain global appreciation
vc_fat_content_less_use 0 Enable upper-bound filter on fat content (< operator)
vc_fat_content_less_amount 10 Upper-bound value for fat content (g per 100 g)
vc_fat_content_more_use 0 Enable lower-bound filter on fat content (> operator)
vc_fat_content_more_amount 1 Lower-bound value for fat content (g per 100 g)
vc_added_sugar_less_use 0 Enable upper-bound filter on added sugar (< operator)
vc_added_sugar_less_amount 10 Upper-bound value for added sugar (g per 100 g)
vc_added_sugar_more_use 0 Enable lower-bound filter on added sugar (> operator)
vc_added_sugar_more_amount 1 Lower-bound value for added sugar (g per 100 g)
vc_calories_per_serving_use 0 Enable calorie target (maintain-at-value objective)
vc_calories_per_serving_amount 90 Target energy value (kcal per 100 g)

How Design Advisor Parameters Flow from Pipeline to Scripts

Understanding how Design Advisor parameters go from definition through to the Python calculation scripts is essential for customizing or extending the advisor. This section traces the full lifecycle using the Minimize Yogurt Fat Example.

  1. Define the defaults: The protocol contains initialization expressions that declare each Design Advisor parameter and assign a default value. These expressions are evaluated before the configuration dialog is presented. They use the Pipeline Pilot conditional syntax:
    If @vc_flavor_intensity Is Not Defined Then
        @vc_flavor_intensity := 1;
    End if;
    

    This ensures that the parameter exists with a known default (1 = enabled) even if the user has never opened the configuration dialog. The @ prefix denotes a global property in Pipeline Pilot.

  2. Collect user input: When the user opens the advisor configuration dialog, each input is bound to a corresponding @vc_ parameter. Turning Sweetness off specifies @vc_sweetness = 0. Entering 10 in the Added Sugar upper-bound field specifies @vc_added_sugar_less_amount = 10 and @vc_added_sugar_less_use = 1 (checked). These values are stored as global properties of the protocol run.
  3. Read Python scripts: When the Advisor Calculation branch executes, each Python script accesses the parameters through the plp_globals dictionary. Pipeline Pilot automatically populates this dictionary with all global properties. They are read as follows:
    maintain_flags = {
        "Flavor_intensity": int(plp_globals["vc_flavor_intensity"]),
        "sweetness":        int(plp_globals["vc_sweetness"]),
        "Fruit_intensity":  int(plp_globals["vc_fruit_intensity"]),
        "Color_intensity":  int(plp_globals["vc_color_intensity"]),
        "thickness":        int(plp_globals["vc_thickness"]),
        "nappant":          int(plp_globals["vc_nappant"]),
        "Global Appreciation": int(plp_globals["vc_global_appreciation"]),
    }
    
    targets_maintain = [col for col, flag in maintain_flags.items()
                        if flag != 0]
    

    The int() conversion ensures that the values are treated as integers regardless of how Pipeline Pilot passes them (they may arrive as strings). A non-zero flag means “maintain this property,” zero means “ignore it.”

  4. Use parameters to shape the computation

    Once read, the flags control every stage of the pipeline:

    • DOE Generator: The targets_maintain value determines which target columns are used for Pearson correlation-based feature selection. Only features that correlate with at least one active target are varied in the design.
    • Formulation Ranking: Each maintained property receives a deviation-from-reference penalty in the composite score. Properties with flag = 0 are excluded from the objective function entirely.
    • Radar Plot: Only properties with flag ≠ 0 appear as axes on the radar chart.
    • Constraint filters: In the Optimize Yogurt Formula Example, use/amount pairs control hard filters applied before scoring.

Example Workflow for Minimize Yogurt Fat Example

In the following example, a user runs the Minimize Yogurt Fat Example with the defaults, Flavor intensity, Sweetness, and Global appreciation:

  1. The pipeline specifies @vc_flavor_intensity = 1, @vc_sweetness = 1, @vc_global_appreciation = 1, and all others are 0.
  2. The DOE Generator builds targets = ["Fat g per 100g", "Flavor_intensity", "sweetness", "Global Appreciation"]. It selects ingredients whose correlation with any of these targets exceeds the threshold.
  3. Latin Hypercube Sampling generates ~100 candidate formulations by varying the selected ingredients around the reference formula values.
  4. XGBoost models predict Fat g per100g_XGB, Flavor_intensity_XGB, sweetness_XGB, and Global Appreciation_XGB for each candidate.
  5. The ranking script minimizes Fat g per100g_XGB (weight = 1.0) and penalizes deviation from the reference values of the three maintained properties (weight = 0.3 each). The top eight formulas are returned.
  6. The Radar Plot component draws all four properties as axes, with the original formula in bold red and eight optimized formulas as dashed colored lines.

Advisor Calculation Scripts

The Advisor Calculation subprotocol contains three Python scripts executed in sequence. Each script reads the VC parameters from plp_globals and operates on a shared DataFrame (plp_df).

Script Purpose Key Outputs
DOE Generator Use Latin Hypercube Sampling to generate a DOE. Select features correlated with active targets, create discrete levels around the reference formula, and produce candidate formulations. DataFrame of candidate formulations with varied ingredient compositions.
Formulation Ranking Score and rank candidates using a composite objective function that supports minimize, maximize, and maintain-at-target goals, with optional hard filters on nutritional properties. Top eight ranked formulations with composite scores and predicted properties.
Radar Plot Visualize property profiles by overlaying all candidate formulations against the original on a single radar chart. Normalize nutritional values to a 0–5 scale for visual comparability. Base64-encoded PNG image for display in the Advisor output tabs.

DOE Generator Script

The DOE generator script creates a diverse set of candidate formulations for evaluation by the models. It runs in the following stages:

  1. Correlate features and targets: Compute the Pearson correlation between each numeric ingredient and every active target. Only features whose maximum absolute correlation exceeds a configurable threshold (default 0.3) are selected for variation.
  2. Create discrete levels: For each selected ingredient, create n_steps discrete levels spanning a percentage range (step_pct) around the reference value. If the ingredient distribution passes a Shapiro-Wilk normality test, levels are drawn from a normal distribution. Otherwise, from a uniform distribution.
  3. Perform Latin Hypercube Sampling: Generate a space-filling design across all ingredient dimensions using scipy.stats.qmc.LatinHypercube. Each sample is mapped to the nearest discrete level to produce realizable formulations.
  4. Balance ingredient adjustment: Adjust a designated balance ingredient (for example water or skimmed milk) so that the total composition sums to the correct amount. Formulations where the balance ingredient falls outside its feasible range are removed.
  5. Insert the reference row: Insert the original reference formula as the first row (rank 0) of the output DataFrame for downstream.

The following script reads key configuration values from plp_globals:

features = plp_df.columns                          # All available features
process  = plp_globals["Instructions"]              # Process parameters (not varied)
csv_path = "$(driveFolder)/yougurt_optimizers.csv"  # Historical dataset

# Fat Minimiser target:
targets_min = ["Fat g per 100g"]

# Sugar Minimiser target:
targets_min = ["Added_sugar"]

Formulation Ranking Script

After the prediction, this script scores and ranks the candidate formulations. The core function get_best_formulations accepts three objective dictionaries and an optional filter dictionary:

def get_best_formulations(
    exp_df,
    targets_to_min=None,      # {column: weight}
    targets_to_max=None,      # {column: weight}
    targets_to_maintain=None,  # {column: (weight, target_value)}
    filters=None,             # {column: {upper:, lower:}}
    n_formulas=8,
):

The composite score is calculated as follows:

Score = Σ(maximize_weights × values) − Σ(minimize_weights × values) − Σ(maintain_weights × |value − target|)

Hard filters are applied before scoring. If a filter specifies an upper bound, all rows with a predicted value above that bound are removed. Rows below it are removed if it specifies a lower bound. This two-phase approach (filter, then score) ensures that only feasible formulations participate in ranking.

The following is from the Minimize Yogurt Fat Example configuration:

targets_to_min = {"Fat g per100g_XGB": 1.0}
targets_to_maintain = {
    "Flavor_intensity_XGB":    (0.3, reference_value),
    "sweetness_XGB":           (0.3, reference_value),
    "Global Appreciation_XGB": (0.3, reference_value),
}

The Optimize Yogurt Formula Example configuration adds hard filters and a calorie maintenance target:

filters = {}
if int(plp_globals["vc_fat_content_less_use"]):
    filters["Fat g per100g_XGB"] = {
        "upper": float(plp_globals["vc_fat_content_less_amount"])
    }
if int(plp_globals["vc_calories_per_serving_use"]):
    targets_to_maintain["Energy kcal per100g_XGB"] = (
        0.5, float(plp_globals["vc_calories_per_serving_amount"]))

Radar Plot Script

The radar plot provides a visual comparison of all shortlisted formulations against the original. The function create_combined_radar_plot accepts the ranked DataFrame and the list of target columns:

  • The original formula (rank 0) is drawn as a bold red solid line with a filled semi-transparent area.
  • Candidate formulas (ranks 1–8) are overlaid as dashed lines using distinct colors from the tab10 colormap.
  • Nutritional values (for example fat in grams) are normalized to a 0–5 scale using min–max binning so they are visually comparable with sensory scores.
  • Axis labels are cleaned by removing the _XGB suffix and capitalizing the first letter.

The plot is rendered as a PNG by matplotlib, encoded as Base64, and returned in a single-row DataFrame with an imageRadarBase64 column for display in the advisor output.