Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Optimizer

The Optimizer explores your design's parameter space to find configurations that maximize optical performance. It leverages WebGPU acceleration to evaluate thousands of variations in real-time.

Configuring the optimizer in code

In Convex-λ, you configure the optimizer directly in your source code by assigning an optimizer variable with a struct:

optimizer = {
    algorithm: "de",
    maxIterations: 200,
    populationSize: 20,
    weights: {
        brightness: 0.4,
        contrast: 0.3,
        scintillation: 0.2,
        compactness: 0.1
    }
}

Configuration options

OptionTypeDescription
algorithmstring"de" (differential evolution), "ga" (genetic), "sa" (simulated annealing), "random"
maxIterationsnumberMaximum optimization iterations
populationSizenumberPopulation size for evolutionary algorithms
weightsstructWeights for each metric (brightness, contrast, scintillation, etc.)
crossoverRatenumberCrossover rate for DE/GA (0.0–1.0)
differentialWeightnumberDifferential weight for DE (typically 0.5–1.0)
mutationRatenumberMutation rate for GA
initialTempnumberStarting temperature for SA
finalTempnumberEnding temperature for SA
coolingRatenumberCooling rate for SA
seednumberRandom seed for reproducibility

Marking values as optimizable

Add hints after numbers to mark them as optimizable.

Syntax Note: The hint immediately follows the number. Do not enclose the hint in parentheses.

// Percentage range: +/- 10% of the value
angle = 45 +/- 10%
angle = 45 ± 10%

// Absolute range: between 3.2 and 3.6
depth = 3.4 3.2..3.6

// Plus/minus offset
width = 2.0 +/- 0.5
width = 2.0 ± 0.5

Hint formats

FormatMeaningExample
value +/- N%±N% of value45 +/- 10% → 40.5 to 49.5
value ± N%±N% of value45 ± 10% → 40.5 to 49.5
value min..maxExplicit range3.4 3.2..3.6
value +/- delta±delta2.0 +/- 0.5 → 1.5 to 2.5
value ± delta±delta2.0 ± 0.5 → 1.5 to 2.5

If no hints are present, the engine returns "No optimizable parameters found".

Launch and monitor a run

  1. Run your code and clear every error.
  2. Press Start Optimization. The button switches to "Optimization Running".
  3. The progress panel shows:
    • Current iteration and best score
    • Improvement vs. initial design
    • Live metrics (brightness, contrast, scintillation, entropy, compactness)
    • Convergence chart
    • Algorithm details (population, generation, evaluations)
    • Parameter table showing initial, current, and best values
  4. Stop & Keep Best stops and preserves the strongest candidate so far.

Compare and apply

  • The comparison panel shows side-by-side viewports labeled Original and Optimized.
  • Replace Editor with Optimized swaps the editor contents with the optimized parameters.
  • Save Optimized as New Version creates a new file while preserving the original.

Example

// Configure the optimizer
optimizer = {
    algorithm: "de",
    maxIterations: 150,
    populationSize: 15,
    weights: {
        brightness: 0.5,
        contrast: 0.3,
        scintillation: 0.2
    }
}

// Mark values as optimizable
pavilionAngle = 41.5 +/- 10%  // ±10%
crownAngle = 34.0 30..38      // range 30-38

// Basic setup
Gear(96)
Sym := Rotate(Z, 8)

// Geometry
Pavilion := Plane(Normal(pavilionAngle), 10) |> Sym
Crown := Plane(Normal(crownAngle), 10) |> Sym

Stone := Pavilion + Crown