I can get NMinimize to work with compiled functions in simple cases.
This works with a constraint:
poly1 = Compile[{{x, _Real}, {y, _Real}}, x^2 - y x + y^4,
RuntimeOptions -> {"EvaluateSymbolically" -> False}]
NMinimize[{poly1[x, y], Norm[{x, y}] < 1}, {x, y}]
NMinimize[{poly1 @@ {x, y}, Norm[{x, y}] < 1}, {x, y}]
Or, a domain specification:
NMinimize[{poly1 @@ {x, y}}, {x, y} ∈ Disk[{0, 0}, 1]]
This appears to work, but the CompiledFunction warnings makes me think that the compiled function is not being used:
poly2 = Compile[{{x, _Real, 1}}, x[[1]]^2 - x[[2]] x[[1]] + x[[2]]^4,
RuntimeOptions -> {"EvaluateSymbolically" -> False}]
NMinimize[poly2[p], p ∈ Vectors[2, Reals]]
Another attempt didn't work at all:
poly3 = FunctionCompile[
Function[{Typed[p, "NumericArray"::["Real64", 1]]},
p[[1]]^2 - p[[1]] p[[2]] + p[[2]]^2]]
NMinimize[poly3[p], p ∈ Vectors[2, Reals]]
Can anyone see a way to get compiled functions to work with the domain specifications such as Element[p,Disk[]]?
NMinimize[poly2[p], p \[Element] Disk[]]seems to work, however it spits out several error messages. I would report this to Wolfram. – Daniel Huber Jul 16 '22 at 11:05poly2is a duplicate of this post: https://mathematica.stackexchange.com/q/127693/1871 – xzczd Jul 16 '22 at 11:39cfsav.s.cfta), but the behavior is the same: a warning pops up, but it's merely a warning, theCompiledFunction[…][…]is still unevaluated. (Just observe the output ofpoly2[{a, b}],"EvaluateSymbolically" -> Falsedoes its work. ) I'm not sure if this should be considered a bug, but I agree this is worth reporting. – xzczd Jul 16 '22 at 15:27