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
| Option | Type | Description |
|---|---|---|
algorithm | string | "de" (differential evolution), "ga" (genetic), "sa" (simulated annealing), "random" |
maxIterations | number | Maximum optimization iterations |
populationSize | number | Population size for evolutionary algorithms |
weights | struct | Weights for each metric (brightness, contrast, scintillation, etc.) |
crossoverRate | number | Crossover rate for DE/GA (0.0–1.0) |
differentialWeight | number | Differential weight for DE (typically 0.5–1.0) |
mutationRate | number | Mutation rate for GA |
initialTemp | number | Starting temperature for SA |
finalTemp | number | Ending temperature for SA |
coolingRate | number | Cooling rate for SA |
seed | number | Random 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
| Format | Meaning | Example |
|---|---|---|
value +/- N% | ±N% of value | 45 +/- 10% → 40.5 to 49.5 |
value ± N% | ±N% of value | 45 ± 10% → 40.5 to 49.5 |
value min..max | Explicit range | 3.4 3.2..3.6 |
value +/- delta | ±delta | 2.0 +/- 0.5 → 1.5 to 2.5 |
value ± delta | ±delta | 2.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
- Run your code and clear every error.
- Press Start Optimization. The button switches to "Optimization Running".
- 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
- 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