NumOpt 0.0.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- NumOpt/__init__.py +3 -0
- NumOpt/opti.py +95 -0
- numopt-0.0.1.dist-info/METADATA +31 -0
- numopt-0.0.1.dist-info/RECORD +7 -0
- numopt-0.0.1.dist-info/WHEEL +5 -0
- numopt-0.0.1.dist-info/licenses/LICENSE.txt +21 -0
- numopt-0.0.1.dist-info/top_level.txt +1 -0
NumOpt/__init__.py
ADDED
NumOpt/opti.py
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import aerosandbox.numpy as anp
|
|
2
|
+
import aerosandbox as asb
|
|
3
|
+
import casadi as cas
|
|
4
|
+
from termcolor import cprint
|
|
5
|
+
from functools import partial
|
|
6
|
+
from typing import Callable, Any, Dict
|
|
7
|
+
|
|
8
|
+
cprint_green = partial(cprint, color="green", attrs=["bold"])
|
|
9
|
+
cprint_magenta = partial(cprint, color="magenta", attrs=["bold"])
|
|
10
|
+
cprint_blue = partial(cprint, color="blue", attrs=["bold"])
|
|
11
|
+
cprint_red = partial(cprint, color="red", attrs=["bold"])
|
|
12
|
+
cprint_yellow = partial(cprint, color="yellow", attrs=["bold"])
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
# def trape(y, x):
|
|
16
|
+
# y = anp.array(y)
|
|
17
|
+
# x = anp.array(x)
|
|
18
|
+
# mid_y = (y[:-1] + y[1:]) / 2.0
|
|
19
|
+
# dx = anp.diff(x)
|
|
20
|
+
|
|
21
|
+
# I = anp.sum(mid_y * dx)
|
|
22
|
+
# return I
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
class Opti(asb.Opti):
|
|
26
|
+
def solver(
|
|
27
|
+
self,
|
|
28
|
+
max_iter: int = 1000,
|
|
29
|
+
max_runtime: float = 1e20,
|
|
30
|
+
callback: Callable[[int], Any] = None,
|
|
31
|
+
verbose: bool = True,
|
|
32
|
+
jit: bool = False,
|
|
33
|
+
detect_simple_bounds: bool = False,
|
|
34
|
+
expand: bool = True,
|
|
35
|
+
options: Dict = None,
|
|
36
|
+
):
|
|
37
|
+
if options is None:
|
|
38
|
+
options = {}
|
|
39
|
+
default_options = {
|
|
40
|
+
"ipopt.sb": "yes", # Hide the IPOPT banner.
|
|
41
|
+
"ipopt.max_iter": max_iter,
|
|
42
|
+
"ipopt.max_cpu_time": max_runtime,
|
|
43
|
+
"ipopt.mu_strategy": "adaptive",
|
|
44
|
+
"ipopt.fast_step_computation": "yes",
|
|
45
|
+
"detect_simple_bounds": detect_simple_bounds,
|
|
46
|
+
"expand": expand,
|
|
47
|
+
}
|
|
48
|
+
if jit:
|
|
49
|
+
default_options["jit"] = True
|
|
50
|
+
# options["compiler"] = "shell" # Recommended by CasADi devs, but doesn't work on my machine
|
|
51
|
+
default_options["jit_options"] = {
|
|
52
|
+
"flags": ["-O3"],
|
|
53
|
+
# "verbose": True
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
if verbose:
|
|
57
|
+
default_options["ipopt.print_level"] = 5 # Verbose, per-iteration printing.
|
|
58
|
+
else:
|
|
59
|
+
default_options["print_time"] = False # No time printing
|
|
60
|
+
default_options["ipopt.print_level"] = 0 # No printing from IPOPT
|
|
61
|
+
|
|
62
|
+
super().solver(
|
|
63
|
+
"ipopt",
|
|
64
|
+
{
|
|
65
|
+
**default_options,
|
|
66
|
+
**options,
|
|
67
|
+
},
|
|
68
|
+
)
|
|
69
|
+
if callback is not None:
|
|
70
|
+
self.callback(callback)
|
|
71
|
+
|
|
72
|
+
def solve(
|
|
73
|
+
self,
|
|
74
|
+
behavior_on_failure: str = "raise",
|
|
75
|
+
):
|
|
76
|
+
if behavior_on_failure == "raise":
|
|
77
|
+
sol = asb.OptiSol(opti=self, cas_optisol=cas.Opti.solve(self))
|
|
78
|
+
elif behavior_on_failure == "return_last":
|
|
79
|
+
try:
|
|
80
|
+
sol = asb.OptiSol(opti=self, cas_optisol=cas.Opti.solve(self))
|
|
81
|
+
except RuntimeError:
|
|
82
|
+
import warnings
|
|
83
|
+
|
|
84
|
+
warnings.warn("Optimization failed. Returning last solution.")
|
|
85
|
+
|
|
86
|
+
sol = asb.OptiSol(opti=self, cas_optisol=self.debug)
|
|
87
|
+
|
|
88
|
+
if self.save_to_cache_on_solve:
|
|
89
|
+
self.save_solution()
|
|
90
|
+
|
|
91
|
+
return sol
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
if __name__=="__main__":
|
|
95
|
+
cprint_yellow("it is ok")
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: NumOpt
|
|
3
|
+
Version: 0.0.1
|
|
4
|
+
Summary: Opti is a Python package that helps you design and optimize engineered systems.
|
|
5
|
+
Home-page: https://github.com/Zcaic/NumOpt.git
|
|
6
|
+
Author: Zcaic
|
|
7
|
+
Keywords: optimization automatic differentiation
|
|
8
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
9
|
+
Classifier: Intended Audience :: Science/Research
|
|
10
|
+
Classifier: Topic :: Scientific/Engineering :: Physics
|
|
11
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
12
|
+
Classifier: Programming Language :: Python :: 3
|
|
13
|
+
Requires-Python: >=3.9
|
|
14
|
+
License-File: LICENSE.txt
|
|
15
|
+
Requires-Dist: aerosandbox>=4.2.8
|
|
16
|
+
Requires-Dist: termcolor>=3.1.0
|
|
17
|
+
Dynamic: author
|
|
18
|
+
Dynamic: classifier
|
|
19
|
+
Dynamic: description
|
|
20
|
+
Dynamic: home-page
|
|
21
|
+
Dynamic: keywords
|
|
22
|
+
Dynamic: license-file
|
|
23
|
+
Dynamic: requires-dist
|
|
24
|
+
Dynamic: requires-python
|
|
25
|
+
Dynamic: summary
|
|
26
|
+
|
|
27
|
+
**NumOpt is a Numerical Optimization Tool Python package that helps you design and optimize engineered systems.**
|
|
28
|
+
|
|
29
|
+
```
|
|
30
|
+
pip install NumOpt
|
|
31
|
+
```
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
NumOpt/__init__.py,sha256=3p9dAyb5p-dAzV9Je-NGFdNfpLKDvbpRIA-x1gIualA,48
|
|
2
|
+
NumOpt/opti.py,sha256=R6aP9M1_LHjPurkIoC_RmAmQzK2szPVbMPUDxxMC014,2906
|
|
3
|
+
numopt-0.0.1.dist-info/licenses/LICENSE.txt,sha256=ML6LT6Q3slmAmRAEOzrSUKNw4X_PdRfYrxv5zOr768w,1073
|
|
4
|
+
numopt-0.0.1.dist-info/METADATA,sha256=oT8hygvEcQtXDAXu_GN5xxkbXMMTnvtE6zmB-VFzN4U,948
|
|
5
|
+
numopt-0.0.1.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
6
|
+
numopt-0.0.1.dist-info/top_level.txt,sha256=_J9LjnZjtRdsArwaqpVdncrMMttByD48sXuZ7i6kQnQ,7
|
|
7
|
+
numopt-0.0.1.dist-info/RECORD,,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2019-2023 Peter Sharpe
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
NumOpt
|