Skip to content

Instantly share code, notes, and snippets.

@nickodell
Last active April 30, 2024 19:25
Show Gist options
  • Save nickodell/96a26bc739b3eed58eb37c90be8a9049 to your computer and use it in GitHub Desktop.
Save nickodell/96a26bc739b3eed58eb37c90be8a9049 to your computer and use it in GitHub Desktop.
minimal case
import numpy as np
from scipy.optimize import minimize, NonlinearConstraint
def fun(x):
return x[0]
def constraint1(x):
return [x[0], x[0]]
constraints = [
NonlinearConstraint(constraint1, [0, 0], [0, 0]),
]
x0 = np.zeros(1)
res = minimize(fun, x0, method='trust-constr', constraints=constraints)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment