1
- from collections .abc import Callable , Iterable , Mapping , Sequence
2
- from typing import Any , Final , Literal , TypeAlias , TypeVar
1
+ from collections .abc import Callable , Iterable , Sequence
2
+ from typing import Concatenate , Literal , TypeAlias , TypedDict , TypeVar , type_check_only
3
3
4
4
import numpy as np
5
- import numpy .typing as npt
6
5
import optype .numpy as onp
7
- from scipy . _typing import EnterSelfMixin , Untyped , UntypedArray , UntypedCallable
6
+ from . _constraints import Bounds
8
7
from ._optimize import OptimizeResult as _OptimizeResult
9
- from ._typing import Constraints
8
+ from ._typing import Constraints , MinimizerKwargs
10
9
11
10
__all__ = ["shgo" ]
12
11
13
- _MinimizerKwargs : TypeAlias = Mapping [str , object ] # TODO(jorenham): TypedDict
14
- _Options : TypeAlias = Mapping [str , object ] # TODO(jorenham): TypedDict
15
-
16
- _SamplingMethodName : TypeAlias = Literal ["simplicial" , "halton" , "sobol" ]
17
- _SamplingMethodFunc : TypeAlias = Callable [[int , int ], onp .ArrayND [np .float64 ]]
18
- _SamplingMethod : TypeAlias = _SamplingMethodName | _SamplingMethodFunc
19
-
20
12
_VT = TypeVar ("_VT" )
21
13
_RT = TypeVar ("_RT" )
22
14
15
+ _Float : TypeAlias = float | np .float64
16
+ _Float1D : TypeAlias = onp .Array1D [np .float64 ]
17
+ _Fun1D : TypeAlias = Callable [Concatenate [_Float1D , ...], _RT ]
18
+
19
+ @type_check_only
20
+ class _SHGOOptions (TypedDict , total = False ):
21
+ f_min : _Float
22
+ f_tol : _Float
23
+ maxiter : int
24
+ maxfev : int
25
+ maxev : int
26
+ mmaxtime : _Float
27
+ minhgrd : int
28
+ symmetry : Sequence [int ] | onp .ToBool
29
+ jac : _Fun1D [onp .ToFloat1D ] | onp .ToBool # gradient
30
+ hess : _Fun1D [onp .ToFloat2D ]
31
+ hessp : Callable [Concatenate [_Float1D , _Float1D , ...], onp .ToFloat1D ]
32
+ minimize_every_iter : onp .ToBool
33
+ local_iter : int
34
+ infty_constraints : onp .ToBool
35
+ disp : onp .ToBool
36
+
37
+ ###
38
+
23
39
class OptimizeResult (_OptimizeResult ):
24
- x : onp . ArrayND [ np . float64 ]
25
- xl : list [ onp . ArrayND [ np . float64 ] ]
26
- fun : float | np . float64
27
- funl : list [ float | np . float64 ]
40
+ x : _Float1D
41
+ xl : Sequence [ _Float1D ]
42
+ fun : _Float
43
+ funl : Sequence [ _Float ]
28
44
success : bool
29
45
message : str
30
46
nfev : int
@@ -33,151 +49,17 @@ class OptimizeResult(_OptimizeResult):
33
49
nlhev : int # undocumented
34
50
nit : int
35
51
36
- ###
37
-
38
- class SHGO (EnterSelfMixin ):
39
- func : UntypedCallable
40
- bounds : Untyped
41
- args : tuple [object , ...]
42
- callback : UntypedCallable
43
- dim : int
44
- constraints : Constraints
45
- min_cons : Untyped
46
- g_cons : Untyped
47
- g_args : Untyped
48
- minimizer_kwargs : _MinimizerKwargs
49
- f_min_true : Untyped
50
- minimize_every_iter : bool
51
- maxiter : int
52
- maxfev : int
53
- maxev : Untyped
54
- maxtime : Untyped
55
- minhgrd : Untyped
56
- symmetry : Untyped
57
- infty_cons_sampl : bool
58
- local_iter : bool
59
- disp : bool
60
- min_solver_args : Untyped
61
- stop_global : bool
62
- break_routine : bool
63
- iters : int
64
- iters_done : int
65
- n : int
66
- nc : int
67
- n_prc : int
68
- n_sampled : int
69
- fn : int
70
- hgr : int
71
- qhull_incremental : bool
72
- HC : Untyped
73
- iterate_complex : Untyped
74
- sampling_method : Untyped
75
- qmc_engine : Untyped
76
- sampling : Untyped
77
- sampling_function : Untyped
78
- stop_l_iter : bool
79
- stop_complex_iter : bool
80
- minimizer_pool : Untyped
81
- LMC : Untyped
82
- res : Untyped
83
- init : Untyped
84
- f_tol : Untyped
85
- f_lowest : Untyped
86
- x_lowest : Untyped
87
- hgrd : Untyped
88
- Ind_sorted : Untyped
89
- Tri : Untyped
90
- points : Untyped
91
- minimizer_pool_F : Untyped
92
- X_min : Untyped
93
- X_min_cache : Untyped
94
- Y : Untyped
95
- Z : Untyped
96
- Ss : Untyped
97
- ind_f_min : Untyped
98
- C : Untyped
99
- Xs : Untyped
100
- def __init__ (
101
- self ,
102
- / ,
103
- func : UntypedCallable ,
104
- bounds : Untyped ,
105
- args : tuple [object , ...] = (),
106
- constraints : Constraints | None = None ,
107
- n : Untyped | None = None ,
108
- iters : Untyped | None = None ,
109
- callback : UntypedCallable | None = None ,
110
- minimizer_kwargs : Mapping [str , Any ] | None = None ,
111
- options : Mapping [str , Any ] | None = None ,
112
- sampling_method : _SamplingMethod = "simplicial" ,
113
- workers : int = 1 ,
114
- ) -> None : ...
115
- def init_options (self , / , options : Untyped ) -> None : ...
116
- def iterate_all (self , / ) -> None : ...
117
- def find_minima (self , / ) -> None : ...
118
- def find_lowest_vertex (self , / ) -> None : ...
119
- def finite_iterations (self , / ) -> Untyped : ...
120
- def finite_fev (self , / ) -> Untyped : ...
121
- def finite_ev (self , / ) -> None : ...
122
- def finite_time (self , / ) -> None : ...
123
- def finite_precision (self , / ) -> Untyped : ...
124
- def finite_homology_growth (self , / ) -> Untyped : ...
125
- def stopping_criteria (self , / ) -> Untyped : ...
126
- def iterate (self , / ) -> None : ...
127
- def iterate_hypercube (self , / ) -> None : ...
128
- def iterate_delaunay (self , / ) -> None : ...
129
- def minimizers (self , / ) -> Untyped : ...
130
- def minimise_pool (self , / , force_iter : bool = False ) -> None : ...
131
- def sort_min_pool (self , / ) -> None : ...
132
- def trim_min_pool (self , / , trim_ind : Untyped ) -> None : ...
133
- def g_topograph (self , / , x_min : Untyped , X_min : Untyped ) -> Untyped : ...
134
- def construct_lcb_simplicial (self , / , v_min : Untyped ) -> Untyped : ...
135
- def construct_lcb_delaunay (self , / , v_min : Untyped , ind : Untyped | None = None ) -> Untyped : ...
136
- def minimize (self , / , x_min : Untyped , ind : Untyped | None = None ) -> Untyped : ...
137
- def sort_result (self , / ) -> Untyped : ...
138
- def fail_routine (self , / , mes : str = "Failed to converge" ) -> None : ...
139
- def sampled_surface (self , / , infty_cons_sampl : bool = False ) -> None : ...
140
- def sampling_custom (self , / , n : Untyped , dim : Untyped ) -> Untyped : ...
141
- def sampling_subspace (self , / ) -> None : ...
142
- def sorted_samples (self , / ) -> Untyped : ...
143
- def delaunay_triangulation (self , / , n_prc : int = 0 ) -> Untyped : ...
144
-
145
- # undocumented
146
- class LMap :
147
- v : Untyped
148
- x_l : Untyped
149
- lres : Untyped
150
- f_min : Untyped
151
- lbounds : list [Untyped ]
152
- def __init__ (self , / , v : Untyped ) -> None : ...
153
-
154
- # undocumented
155
- class LMapCache :
156
- cache : Final [dict [tuple [np .number [Any ], ...], Untyped ]]
157
- xl_maps_set : Final [set [Untyped ]]
158
- v_maps : Final [list [Untyped ]]
159
- lbound_maps : Final [list [Untyped ]]
160
-
161
- xl_maps : list [Untyped ] | UntypedArray
162
- f_maps : list [Untyped ]
163
- size : int
164
-
165
- def __init__ (self , / ) -> None : ...
166
- def __getitem__ (self , v : npt .ArrayLike , / ) -> Untyped : ...
167
- def add_res (self , / , v : Untyped , lres : Untyped , bounds : Untyped | None = None ) -> None : ...
168
- def sort_cache_result (self , / ) -> dict [str , Untyped ]: ... # TODO(jorenham): TypedDict
169
-
170
52
def shgo (
171
- func : UntypedCallable ,
172
- bounds : Untyped ,
53
+ func : _Fun1D [ onp . ToFloat ] ,
54
+ bounds : tuple [ onp . ToFloat | onp . ToFloat1D , onp . ToFloat | onp . ToFloat1D ] | Bounds ,
173
55
args : tuple [object , ...] = (),
174
56
constraints : Constraints | None = None ,
175
- n : int = 100 ,
176
- iters : int = 1 ,
177
- callback : Callable [[onp . Array1D [ np . float64 ] ], None ] | None = None ,
178
- minimizer_kwargs : _MinimizerKwargs | None = None , # TODO(jorenham): TypedDict
179
- options : _Options | None = None , # TODO(jorenham): TypedDict
180
- sampling_method : _SamplingMethod = "simplicial" ,
57
+ n : onp . ToJustInt = 100 ,
58
+ iters : onp . ToJustInt = 1 ,
59
+ callback : Callable [[_Float1D ], None ] | None = None ,
60
+ minimizer_kwargs : MinimizerKwargs | None = None ,
61
+ options : _SHGOOptions | None = None ,
62
+ sampling_method : Callable [[ int , int ], onp . ToFloat2D ] | Literal [ "simplicial" , "halton" , "sobol" ] = "simplicial" ,
181
63
* ,
182
- workers : int | Callable [[Callable [[_VT ], _RT ], Iterable [_VT ]], Sequence [_RT ]] = 1 ,
64
+ workers : onp . ToJustInt | Callable [[Callable [[_VT ], _RT ], Iterable [_VT ]], Sequence [_RT ]] = 1 ,
183
65
) -> OptimizeResult : ...
0 commit comments