agentleFS
90184479018447/julia-pro-p/skills/advanced-optimization/SKILL.md

advanced-optimization

Skill0 starsChanged 2 days agoMITView on GitHub

Choose a Julia optimiser by problem form: JuMP for constrained programs, Optimization.jl for differentiable residuals, surrogates for a black-box simulation. Use when the solver is the decision.

The file

Files
SKILL.md

Advanced Optimization

The form of the problem picks the stack, and the form is decided before any code: a least-squares fit is not a general NLP, and a binary decision is not a continuous relaxation you can round afterwards.

Pick by form

FormJuliaSign you are in this row
model equations are differentiable, residuals existOptimization.jl with AutoForwardDiffyou can write r(p) and its Jacobian
convex objective and constraints (LP, QP, SOCP, SDP)JuMP.jl + HiGHS / ClarabelDCP rules hold; the solution is global
integer or binary decisionsJuMP.jl + HiGHS, Cbcthe answer is a schedule, a selection, a count
objective is a black box (a simulation run)Surrogates.jl, BayesianOptimization.jlone evaluation costs minutes and has no gradient
several objectives with a real trade-offJuMP epsilon-constraint, PlatEMO.jltwo metrics, neither substitutable for the other
parameters of a differential equationOptimization.jl over a SciML solveeach residual requires a solve

The pages under Depth carry the working API for a constrained program and for a fit.

Read the solver's answer

TERMINATED_BY_LIMIT and OPTIMAL are different results, and a rounded continuous relaxation is not a feasible integer point. Check, in this order: the status; the constraint violation recomputed from the solution (not reported by the solver); the gap, if integer; and the objective recomputed independently.

using JuMP, HiGHS
m = Model(HiGHS.Optimizer)
set_silent(m)
set_optimizer_attribute(m, "mip_rel_gap", 1e-4)
set_optimizer_attribute(m, "time_limit", 60.0)
@variable(m, 0 <= x[1:5] <= 1, Int)
@objective(m, Max, sum(v .* x))
@constraint(m, sum(w .* x) <= capacity)
optimize!(m)
@assert termination_status(m) == MOI.OPTIMAL
@assert sum(w .* value.(x)) <= capacity + 1e-9

Black box: spend the budget on information

A grid search on a 5-parameter simulator is a waste of a week. Bayesian optimisation earns its complexity when each evaluation is expensive and the response surface is smooth enough for a GP; when it is not, use a space-filling design (Latin hypercube) and accept that you are mapping, not optimising. For a batch of parallel workers, ask for q > 1 points per round — sequential BO leaves the cluster idle.

Traps

  • Rounding a relaxation. An LP relaxation of a knapsack rounds to an infeasible set more often than not; if the integrality matters, model it.
  • A non-convex model in a convex solver. JuMP will reject it (good) or produce garbage (worse) depending on how it is written; prove convexity or move to a local NLP solver with multi-start.
  • Tuned hyperparameters reported as the model's performance. The optimum of 100 trials on a noisy validation metric is biased upward; report a fresh-seed evaluation.
  • Optimiser tolerance as accuracy. The parameter values inherit the solver's tolerance; a fit reported to 6 digits from rel_tol=1e-3 claims precision the solve does not have.
  • Multi-objective collapsed into a weighted sum without saying the weights. The Pareto front is the answer; a single weighted point hides the trade-off you were asked to expose.

Depth

PageOpen when
optimization-patternsparameters are fit to data — least squares, multiple shooting, an OptimizationProblem over a SciML solve
jump-optimizationthe problem is a program with constraints: LP, QP, NLP, MIP written as a JuMP model

Done when

The formulation is named and defended, the solver's status and recomputed constraint violation are recorded, and the reported precision matches the tolerance the solve actually achieved.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.