[{"data":1,"prerenderedAt":405},["ShallowReactive",2],{"dev-\u002Fdeveloper\u002Fguides\u002Fglobal-optimization":3},{"id":4,"title":5,"body":6,"description":386,"extension":387,"faq":388,"meta":398,"navigation":399,"noindex":400,"path":401,"seo":402,"stem":403,"__hash__":404},"content\u002Fdeveloper\u002Fguides\u002Fglobal-optimization.md","Global optimization in Python — escape local minima",{"type":7,"value":8,"toc":380},"minimark",[9,13,26,31,34,38,50,299,304,308,327,330,334,360,371,376],[10,11,5],"h1",{"id":12},"global-optimization-in-python-escape-local-minima",[14,15,16,17,21,22,25],"p",{},"Many real objectives are ",[18,19,20],"strong",{},"smooth but non-convex",": a landscape of hills and\nvalleys where the best point hides among many almost-as-good ones. A plain\ngradient descent from a single start slides into the\nnearest local minimum and stops. ",[18,23,24],{},"quicopt"," is built to search past local\nminima, and it takes the model directly in Python.",[27,28,30],"h2",{"id":29},"the-naive-approach","The naive approach",[14,32,33],{},"The common patch is to run a gradient minimizer from many random starts, or reach\nfor basin-hopping \u002F a coarse grid search, and hope one run lands in the global\nbasin. That is expensive and still offers no coverage guarantee.",[27,35,37],{"id":36},"model-it-and-solve","Model it and solve",[14,39,40,41,44,45,49],{},"Here is Himmelblau's function — a standard non-convex test with four separate\nglobal minima (all with value 0) — under a linear constraint, modeled in\n",[18,42,43],{},"Pyomo"," (",[46,47,48],"code",{},"pip install \"quicopt[pyomo]\"","):",[51,52,58],"pre",{"className":53,"code":54,"filename":55,"language":56,"meta":57,"style":57},"language-python shiki shiki-themes github-dark","import pyomo.environ as pyo\nfrom quicopt import Client\n# Himmelblau: a smooth non-convex objective with four separate global minima.\nm = pyo.ConcreteModel()\nm.x = pyo.Var(bounds=(-5, 5))\nm.y = pyo.Var(bounds=(-5, 5))\nm.c = pyo.Constraint(expr=m.x + m.y \u003C= 5)\nm.obj = pyo.Objective(expr=(m.x**2 + m.y - 11)**2 + (m.x + m.y**2 - 7)**2, sense=pyo.minimize)\nprint(Client(\"https:\u002F\u002Ftry.quicoptapi.pgi.fz-juelich.de\").solve(m).display)\n","global_opt.py","python","",[46,59,60,79,93,100,112,147,173,206,283],{"__ignoreMap":57},[61,62,65,69,73,76],"span",{"class":63,"line":64},"line",1,[61,66,68],{"class":67},"snl16","import",[61,70,72],{"class":71},"s95oV"," pyomo.environ ",[61,74,75],{"class":67},"as",[61,77,78],{"class":71}," pyo\n",[61,80,82,85,88,90],{"class":63,"line":81},2,[61,83,84],{"class":67},"from",[61,86,87],{"class":71}," quicopt ",[61,89,68],{"class":67},[61,91,92],{"class":71}," Client\n",[61,94,96],{"class":63,"line":95},3,[61,97,99],{"class":98},"sAwPA","# Himmelblau: a smooth non-convex objective with four separate global minima.\n",[61,101,103,106,109],{"class":63,"line":102},4,[61,104,105],{"class":71},"m ",[61,107,108],{"class":67},"=",[61,110,111],{"class":71}," pyo.ConcreteModel()\n",[61,113,115,118,120,123,127,129,132,135,139,142,144],{"class":63,"line":114},5,[61,116,117],{"class":71},"m.x ",[61,119,108],{"class":67},[61,121,122],{"class":71}," pyo.Var(",[61,124,126],{"class":125},"s9osk","bounds",[61,128,108],{"class":67},[61,130,131],{"class":71},"(",[61,133,134],{"class":67},"-",[61,136,138],{"class":137},"sDLfK","5",[61,140,141],{"class":71},", ",[61,143,138],{"class":137},[61,145,146],{"class":71},"))\n",[61,148,150,153,155,157,159,161,163,165,167,169,171],{"class":63,"line":149},6,[61,151,152],{"class":71},"m.y ",[61,154,108],{"class":67},[61,156,122],{"class":71},[61,158,126],{"class":125},[61,160,108],{"class":67},[61,162,131],{"class":71},[61,164,134],{"class":67},[61,166,138],{"class":137},[61,168,141],{"class":71},[61,170,138],{"class":137},[61,172,146],{"class":71},[61,174,176,179,181,184,187,189,191,194,197,200,203],{"class":63,"line":175},7,[61,177,178],{"class":71},"m.c ",[61,180,108],{"class":67},[61,182,183],{"class":71}," pyo.Constraint(",[61,185,186],{"class":125},"expr",[61,188,108],{"class":67},[61,190,117],{"class":71},[61,192,193],{"class":67},"+",[61,195,196],{"class":71}," m.y ",[61,198,199],{"class":67},"\u003C=",[61,201,202],{"class":137}," 5",[61,204,205],{"class":71},")\n",[61,207,209,212,214,217,219,221,224,227,230,233,235,237,240,243,245,247,249,252,254,257,259,261,264,267,269,271,273,275,278,280],{"class":63,"line":208},8,[61,210,211],{"class":71},"m.obj ",[61,213,108],{"class":67},[61,215,216],{"class":71}," pyo.Objective(",[61,218,186],{"class":125},[61,220,108],{"class":67},[61,222,223],{"class":71},"(m.x",[61,225,226],{"class":67},"**",[61,228,229],{"class":137},"2",[61,231,232],{"class":67}," +",[61,234,196],{"class":71},[61,236,134],{"class":67},[61,238,239],{"class":137}," 11",[61,241,242],{"class":71},")",[61,244,226],{"class":67},[61,246,229],{"class":137},[61,248,232],{"class":67},[61,250,251],{"class":71}," (m.x ",[61,253,193],{"class":67},[61,255,256],{"class":71}," m.y",[61,258,226],{"class":67},[61,260,229],{"class":137},[61,262,263],{"class":67}," -",[61,265,266],{"class":137}," 7",[61,268,242],{"class":71},[61,270,226],{"class":67},[61,272,229],{"class":137},[61,274,141],{"class":71},[61,276,277],{"class":125},"sense",[61,279,108],{"class":67},[61,281,282],{"class":71},"pyo.minimize)\n",[61,284,286,289,292,296],{"class":63,"line":285},9,[61,287,288],{"class":137},"print",[61,290,291],{"class":71},"(Client(",[61,293,295],{"class":294},"sU2Wk","\"https:\u002F\u002Ftry.quicoptapi.pgi.fz-juelich.de\"",[61,297,298],{"class":71},").solve(m).display)\n",[300,301],"term-result",{":rows":302,"cmd":303},"[\"├── status:     optimal\",\"├── feasible:   true\",\"├── objective:  1.6040127473878978e-20\",\"├── x:          x1=-2.8051, x2=3.1313  (2 variables)\",\"└── solve_time: 0.0105 s\"]","$ python global_opt.py",[27,305,307],{"id":306},"what-you-get","What you get",[14,309,310,311,314,315,318,319,322,323,326],{},"quicopt reaches a global minimum at ",[46,312,313],{},"(-2.805, 3.131)"," with objective ",[46,316,317],{},"≈ 0"," (the\n",[46,320,321],{},"e-20"," is numerical zero) — one of Himmelblau's four global optima — rather than\nstalling in a nearby local basin. No restart loop, no grid. (",[46,324,325],{},"status: optimal","\nreports that the solver converged; for a non-convex objective that is a strong\nglobal search, not a mathematical certificate of global optimality.)",[14,328,329],{},"Non-convex objectives with dense or implicit Hessians are quicopt's structural\nstrength: it needs only to feel the slope, not a full second-derivative map. The\nsame call handles higher-dimensional, tangled landscapes where Newton-class\nmethods slow down.",[27,331,333],{"id":332},"next","Next",[335,336,337,346,353],"ul",{},[338,339,340,341],"li",{},"The problem class behind this: ",[342,343,345],"a",{"href":344},"\u002Fproblems\u002Fnonconvex-nlp","Nonlinear programming (NLP)",[338,347,348,349],{},"A runnable model for every supported class: ",[342,350,352],{"href":351},"\u002Fdeveloper\u002Fexamples","Examples",[338,354,355,356],{},"Set up the client and solve your first model: ",[342,357,359],{"href":358},"\u002Fdeveloper\u002Fgetting-started","Getting started",[14,361,362,365,366,370],{},[18,363,364],{},"Reference:"," D. M. Himmelblau, ",[367,368,369],"em",{},"Applied Nonlinear Programming",", McGraw-Hill,\n1972.",[372,373],"contact-cta",{"sub":374,"title":375},"Tell us what you're optimizing. We'll help you model it and point you at the right approach.","A harder landscape — or a different problem?",[377,378,379],"style",{},"html pre.shiki code .snl16, html code.shiki .snl16{--shiki-default:#F97583}html pre.shiki code .s95oV, html code.shiki .s95oV{--shiki-default:#E1E4E8}html pre.shiki code .sAwPA, html code.shiki .sAwPA{--shiki-default:#6A737D}html pre.shiki code .s9osk, html code.shiki .s9osk{--shiki-default:#FFAB70}html pre.shiki code .sDLfK, html code.shiki .sDLfK{--shiki-default:#79B8FF}html pre.shiki code .sU2Wk, html code.shiki .sU2Wk{--shiki-default:#9ECBFF}html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}",{"title":57,"searchDepth":81,"depth":81,"links":381},[382,383,384,385],{"id":29,"depth":81,"text":30},{"id":36,"depth":81,"text":37},{"id":306,"depth":81,"text":307},{"id":332,"depth":81,"text":333},"Minimize a smooth non-convex function with constraints in Python without getting trapped in a local minimum — global optimization solved with quicopt, instead of grid search or random multi-start.","md",[389,392,395],{"q":390,"a":391},"Why does a gradient-based minimizer get stuck?","Gradient methods converge to whatever local minimum is nearest the start point. On a non-convex landscape that is often not the global one, which is why people bolt on random multi-start or basin-hopping.",{"q":393,"a":394},"Does quicopt guarantee the global optimum?","No solver guarantees the global optimum of a general non-convex problem cheaply. quicopt's quantum-inspired search is built to escape local minima and, on this problem, reaches a global minimum (objective ≈ 0). Treat it as a strong global search, not a proof.",{"q":396,"a":397},"Is quicopt free to use?","Yes — pip install quicopt and your first call sets up a free key, no license.",{},true,false,"\u002Fdeveloper\u002Fguides\u002Fglobal-optimization",{"title":5,"description":386},"developer\u002Fguides\u002Fglobal-optimization","_tEzDpIPlQ6JE5MOavgFS1QaOl0WFvBRUIATAzioLVw",1784110685996]