Code Overview

PyTorch API

dict_minimize.torch_api.minimize(fun: Callable, x0_dict: collections.OrderedDict, *, lb_dict: Optional[collections.OrderedDict] = None, ub_dict: Optional[collections.OrderedDict] = None, args: Sequence = (), method: Optional[str] = None, tol: Optional[float] = None, callback: Optional[Callable] = None, options: Optional[dict] = None)collections.OrderedDict[source]

Minimization of a scalar function with a dictionary of variables as the input. It can interface to functions written for torch.

This is a wrapper around scipy.optimize.minimize.

Parameters
  • fun (callable) – The objective function to be minimized, in the form of fun(x, *args) -> (float, OrderedDict) where x is an OrderedDict in the format of x0_dict, and args is a tuple of the fixed parameters needed to completely specify the function. The second returned variable is the gradients. It should be an OrderedDict with the same keys and shapes as x. The values should be torch Tensor.

  • x0_dict (OrderedDict) – Initial guess. Dictionary of variables from variable name to torch variables.

  • lb_dict (OrderedDict) – Dictionary with same keys and shapes as x0_dict with lower bounds for each variable. Set to None in an unconstrained problem.

  • ub_dict (OrderedDict) – Dictionary with same keys and shapes as x0_dict with upper bounds for each variable. Set to None in an unconstrained problem.

  • args (tuple) – Extra arguments passed to the objective function.

  • method (str) – Type of solver. Should be one of: CG, BFGS, L-BFGS-B, TNC, SLSQP, or trust-constr. If not given, chosen to be one of BFGS, L-BFGS-B, SLSQP, depending if the problem has bounds. Note, only L-BFGS-B, TNC, SLSQP seem to strictly respect the bounds lb_dict and ub_dict.

  • tol (float) – Tolerance for termination. For detailed control, use solver-specific options.

  • callback (callable) – Called after each iteration. The signature is: callback(xk) where xk is the current parameter as an OrderedDict with the same form as the final solution x.

  • options (dict) – A dictionary of solver options. All methods accept the following generic options: maxiter : int Maximum number of iterations to perform. Depending on the method each iteration may use several function evaluations. disp : bool Set to True to print convergence messages.

Returns

Final solution found by the optimizer. It has the same keys and shapes as x0_dict.

Return type

x (OrderedDict)

TensorFlow API

dict_minimize.tensorflow_api.minimize(fun: Callable, x0_dict: collections.OrderedDict, *, lb_dict: Optional[collections.OrderedDict] = None, ub_dict: Optional[collections.OrderedDict] = None, args: Sequence = (), method: Optional[str] = None, tol: Optional[float] = None, callback: Optional[Callable] = None, options: Optional[dict] = None)collections.OrderedDict[source]

Minimization of a scalar function with a dictionary of variables as the input. It can interface to functions written for tensorflow.

This is a wrapper around scipy.optimize.minimize.

Parameters
  • fun (callable) – The objective function to be minimized, in the form of fun(x, *args) -> (float, OrderedDict) where x is an OrderedDict in the format of x0_dict, and args is a tuple of the fixed parameters needed to completely specify the function. The second returned variable is the gradients. It should be an OrderedDict with the same keys and shapes as x. The values should be tensorflow variables.

  • x0_dict (OrderedDict) – Initial guess. Dictionary of variables from variable name to tensorflow variables.

  • lb_dict (OrderedDict) – Dictionary with same keys and shapes as x0_dict with lower bounds for each variable. Set to None in an unconstrained problem.

  • ub_dict (OrderedDict) – Dictionary with same keys and shapes as x0_dict with upper bounds for each variable. Set to None in an unconstrained problem.

  • args (tuple) – Extra arguments passed to the objective function.

  • method (str) – Type of solver. Should be one of: CG, BFGS, L-BFGS-B, TNC, SLSQP, or trust-constr. If not given, chosen to be one of BFGS, L-BFGS-B, SLSQP, depending if the problem has bounds. Note, only L-BFGS-B, TNC, SLSQP seem to strictly respect the bounds lb_dict and ub_dict.

  • tol (float) – Tolerance for termination. For detailed control, use solver-specific options.

  • callback (callable) – Called after each iteration. The signature is: callback(xk) where xk is the current parameter as an OrderedDict with the same form as the final solution x.

  • options (dict) – A dictionary of solver options. All methods accept the following generic options: maxiter : int Maximum number of iterations to perform. Depending on the method each iteration may use several function evaluations. disp : bool Set to True to print convergence messages.

Returns

Final solution found by the optimizer. It has the same keys and shapes as x0_dict.

Return type

x (OrderedDict)

NumPy API

dict_minimize.numpy_api.minimize(fun: Callable, x0_dict: collections.OrderedDict, *, lb_dict: Optional[collections.OrderedDict] = None, ub_dict: Optional[collections.OrderedDict] = None, args: Sequence = (), method: Optional[str] = None, tol: Optional[float] = None, callback: Optional[Callable] = None, options: Optional[dict] = None)collections.OrderedDict[source]

Minimization of a scalar function with a dictionary of variables as the input.

This is a wrapper around scipy.optimize.minimize.

Parameters
  • fun (callable) – The objective function to be minimized, in the form of fun(x, *args) -> (float, OrderedDict) where x is an OrderedDict in the format of x0_dict, and args is a tuple of the fixed parameters needed to completely specify the function. The second returned variable is the gradients. It should be an OrderedDict with the same keys and shapes as x. The values should be numpy ndarray variables.

  • x0_dict (OrderedDict) – Initial guess. Dictionary of variables from variable name to numpy variables.

  • lb_dict (OrderedDict) – Dictionary with same keys and shapes as x0_dict with lower bounds for each variable. Set to None in an unconstrained problem.

  • ub_dict (OrderedDict) – Dictionary with same keys and shapes as x0_dict with upper bounds for each variable. Set to None in an unconstrained problem.

  • args (tuple) – Extra arguments passed to the objective function.

  • method (str) – Type of solver. Should be one of: CG, BFGS, L-BFGS-B, TNC, SLSQP, or trust-constr. If not given, chosen to be one of BFGS, L-BFGS-B, SLSQP, depending if the problem has bounds. Note, only L-BFGS-B, TNC, SLSQP seem to strictly respect the bounds lb_dict and ub_dict.

  • tol (float) – Tolerance for termination. For detailed control, use solver-specific options.

  • callback (callable) – Called after each iteration. The signature is: callback(xk) where xk is the current parameter as an OrderedDict with the same form as the final solution x.

  • options (dict) – A dictionary of solver options. All methods accept the following generic options: maxiter : int Maximum number of iterations to perform. Depending on the method each iteration may use several function evaluations. disp : bool Set to True to print convergence messages.

Returns

Final solution found by the optimizer. It has the same keys and shapes as x0_dict.

Return type

x (OrderedDict)

JAX API

dict_minimize.jax_api.minimize(fun: Callable, x0_dict: collections.OrderedDict, *, lb_dict: Optional[collections.OrderedDict] = None, ub_dict: Optional[collections.OrderedDict] = None, args: Sequence = (), method: Optional[str] = None, tol: Optional[float] = None, callback: Optional[Callable] = None, options: Optional[dict] = None)collections.OrderedDict[source]

Minimization of a scalar function with a dictionary of variables as the input. It can interface to functions written for jax.

This is a wrapper around scipy.optimize.minimize.

Parameters
  • fun (callable) – The objective function to be minimized, in the form of fun(x, *args) -> (float, OrderedDict) where x is an OrderedDict in the format of x0_dict, and args is a tuple of the fixed parameters needed to completely specify the function. The second returned variable is the gradients. It should be an OrderedDict with the same keys and shapes as x. The values should be jax ndarray variables.

  • x0_dict (OrderedDict) – Initial guess. Dictionary of variables from variable name to jax ndarray.

  • lb_dict (OrderedDict) – Dictionary with same keys and shapes as x0_dict with lower bounds for each variable. Set to None in an unconstrained problem.

  • ub_dict (OrderedDict) – Dictionary with same keys and shapes as x0_dict with upper bounds for each variable. Set to None in an unconstrained problem.

  • args (tuple) – Extra arguments passed to the objective function.

  • method (str) – Type of solver. Should be one of: CG, BFGS, L-BFGS-B, TNC, SLSQP, or trust-constr. If not given, chosen to be one of BFGS, L-BFGS-B, SLSQP, depending if the problem has bounds. Note, only L-BFGS-B, TNC, SLSQP seem to strictly respect the bounds lb_dict and ub_dict.

  • tol (float) – Tolerance for termination. For detailed control, use solver-specific options.

  • callback (callable) – Called after each iteration. The signature is: callback(xk) where xk is the current parameter as an OrderedDict with the same form as the final solution x.

  • options (dict) – A dictionary of solver options. All methods accept the following generic options: maxiter : int Maximum number of iterations to perform. Depending on the method each iteration may use several function evaluations. disp : bool Set to True to print convergence messages.

Returns

Final solution found by the optimizer. It has the same keys and shapes as x0_dict.

Return type

x (OrderedDict)

Internals

The dict minimize core routines.

Utility for minimization of a scalar function with a dictionary of variables as the input. It can interface to functions written outside of numpy (e.g., tensorflow, torch or jax).

This is a wrapper around scipy.optimize.minimize.