invrs-opt 0.5.2__py3-none-any.whl → 0.7.0__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.
- invrs_opt/__init__.py +14 -3
- invrs_opt/experimental/client.py +2 -3
- invrs_opt/{base.py → optimizers/base.py} +10 -0
- invrs_opt/{lbfgsb → optimizers}/lbfgsb.py +293 -153
- invrs_opt/optimizers/wrapped_optax.py +300 -0
- invrs_opt/parameterization/__init__.py +0 -0
- invrs_opt/parameterization/base.py +148 -0
- invrs_opt/parameterization/filter_project.py +92 -0
- invrs_opt/parameterization/gaussian_levelset.py +643 -0
- invrs_opt/parameterization/pixel.py +45 -0
- invrs_opt/{lbfgsb/transform.py → parameterization/transforms.py} +76 -11
- {invrs_opt-0.5.2.dist-info → invrs_opt-0.7.0.dist-info}/METADATA +11 -10
- invrs_opt-0.7.0.dist-info/RECORD +20 -0
- {invrs_opt-0.5.2.dist-info → invrs_opt-0.7.0.dist-info}/WHEEL +1 -1
- invrs_opt-0.5.2.dist-info/RECORD +0 -14
- /invrs_opt/{lbfgsb → optimizers}/__init__.py +0 -0
- {invrs_opt-0.5.2.dist-info → invrs_opt-0.7.0.dist-info}/LICENSE +0 -0
- {invrs_opt-0.5.2.dist-info → invrs_opt-0.7.0.dist-info}/top_level.txt +0 -0
@@ -62,6 +62,20 @@ def density_gaussian_filter_and_tanh(
|
|
62
62
|
return transformed_density
|
63
63
|
|
64
64
|
|
65
|
+
def _gaussian_kernel(fwhm: float, fwhm_size_multiple: float) -> jnp.ndarray:
|
66
|
+
"""Returns a Gaussian kernel with the specified full-width at half-maximum."""
|
67
|
+
with jax.ensure_compile_time_eval():
|
68
|
+
kernel_size = max(1, int(jnp.ceil(fwhm * fwhm_size_multiple)))
|
69
|
+
# Ensure the kernel size is odd, so that there is always a central pixel which will
|
70
|
+
# contain the peak value of the Gaussian.
|
71
|
+
kernel_size += (kernel_size + 1) % 2
|
72
|
+
d = jnp.arange(0.5, kernel_size) - kernel_size / 2
|
73
|
+
x = d[:, jnp.newaxis]
|
74
|
+
y = d[jnp.newaxis, :]
|
75
|
+
sigma = fwhm / (2 * jnp.sqrt(2 * jnp.log(2)))
|
76
|
+
return jnp.exp(-(x**2 + y**2) / (2 * sigma**2))
|
77
|
+
|
78
|
+
|
65
79
|
def normalized_array_from_density(density: types.Density2DArray) -> jnp.ndarray:
|
66
80
|
"""Returns an array with values scaled to the range `(-1, 1)`."""
|
67
81
|
value_mid = (density.upper_bound + density.lower_bound) / 2
|
@@ -154,15 +168,66 @@ def _pad_mode_for_density(density: types.Density2DArray) -> Union[str, Tuple[str
|
|
154
168
|
)
|
155
169
|
|
156
170
|
|
157
|
-
def
|
158
|
-
|
171
|
+
def resample(
|
172
|
+
x: jnp.ndarray,
|
173
|
+
shape: Tuple[int, ...],
|
174
|
+
method: jax.image.ResizeMethod = jax.image.ResizeMethod.LINEAR,
|
175
|
+
) -> jnp.ndarray:
|
176
|
+
"""Resamples `x` to have the specified `shape`.
|
177
|
+
|
178
|
+
The algorithm first upsamples `x` so that the pixels in the output image are
|
179
|
+
comprised of an integer number of pixels in the upsampled `x`, and then
|
180
|
+
performs box downsampling.
|
181
|
+
|
182
|
+
Args:
|
183
|
+
x: The array to be resampled.
|
184
|
+
shape: The shape of the output array.
|
185
|
+
method: The method used to resize `x` prior to box downsampling.
|
186
|
+
|
187
|
+
Returns:
|
188
|
+
The resampled array.
|
189
|
+
"""
|
190
|
+
if x.ndim != len(shape):
|
191
|
+
raise ValueError(
|
192
|
+
f"`shape` must have length matching number of dimensions in `x`, "
|
193
|
+
f"but got {shape} when `x` had shape {x.shape}."
|
194
|
+
)
|
195
|
+
|
159
196
|
with jax.ensure_compile_time_eval():
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
197
|
+
factor = [int(jnp.ceil(dx / d)) for dx, d in zip(x.shape, shape)]
|
198
|
+
upsampled_shape = tuple([d * f for d, f in zip(shape, factor)])
|
199
|
+
|
200
|
+
x_upsampled = jax.image.resize(
|
201
|
+
image=x,
|
202
|
+
shape=upsampled_shape,
|
203
|
+
method=method,
|
204
|
+
)
|
205
|
+
|
206
|
+
return box_downsample(x_upsampled, shape)
|
207
|
+
|
208
|
+
|
209
|
+
def box_downsample(x: jnp.ndarray, shape: Tuple[int, ...]) -> jnp.ndarray:
|
210
|
+
"""Downsamples `x` to a coarser resolution array using box downsampling.
|
211
|
+
|
212
|
+
Box downsampling forms nonoverlapping windows and simply averages the
|
213
|
+
pixels within each window. For example, downsampling `(0, 1, 2, 3, 4, 5)`
|
214
|
+
with a factor of `2` yields `(0.5, 2.5, 4.5)`.
|
215
|
+
|
216
|
+
Args:
|
217
|
+
x: The array to be downsampled.
|
218
|
+
shape: The shape of the output array; each axis dimension must evenly
|
219
|
+
divide the corresponding axis dimension in `x`.
|
220
|
+
|
221
|
+
Returns:
|
222
|
+
The output array with shape `shape`.
|
223
|
+
"""
|
224
|
+
if x.ndim != len(shape) or any([(d % s) != 0 for d, s in zip(x.shape, shape)]):
|
225
|
+
raise ValueError(
|
226
|
+
f"Each axis of `shape` must evenly divide the corresponding axis "
|
227
|
+
f"dimension in `x`, but got shape {shape} when `x` has shape "
|
228
|
+
f"{x.shape}."
|
229
|
+
)
|
230
|
+
shape = sum([(s, d // s) for d, s in zip(x.shape, shape)], ())
|
231
|
+
axes = list(range(1, 2 * x.ndim, 2))
|
232
|
+
x = x.reshape(shape)
|
233
|
+
return jnp.mean(x, axis=axes)
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.1
|
2
2
|
Name: invrs_opt
|
3
|
-
Version: 0.
|
3
|
+
Version: 0.7.0
|
4
4
|
Summary: Algorithms for inverse design
|
5
5
|
Author-email: "Martin F. Schubert" <mfschubert@gmail.com>
|
6
6
|
Maintainer-email: "Martin F. Schubert" <mfschubert@gmail.com>
|
@@ -34,22 +34,23 @@ Requires-Dist: jax
|
|
34
34
|
Requires-Dist: jaxlib
|
35
35
|
Requires-Dist: numpy
|
36
36
|
Requires-Dist: requests
|
37
|
+
Requires-Dist: optax
|
37
38
|
Requires-Dist: scipy
|
38
39
|
Requires-Dist: totypes
|
39
40
|
Requires-Dist: types-requests
|
40
41
|
Provides-Extra: dev
|
41
|
-
Requires-Dist: bump-my-version
|
42
|
-
Requires-Dist: darglint
|
43
|
-
Requires-Dist: mypy
|
44
|
-
Requires-Dist: pre-commit
|
42
|
+
Requires-Dist: bump-my-version; extra == "dev"
|
43
|
+
Requires-Dist: darglint; extra == "dev"
|
44
|
+
Requires-Dist: mypy; extra == "dev"
|
45
|
+
Requires-Dist: pre-commit; extra == "dev"
|
45
46
|
Provides-Extra: tests
|
46
|
-
Requires-Dist: parameterized
|
47
|
-
Requires-Dist: pytest
|
48
|
-
Requires-Dist: pytest-cov
|
49
|
-
Requires-Dist: pytest-subtests
|
47
|
+
Requires-Dist: parameterized; extra == "tests"
|
48
|
+
Requires-Dist: pytest; extra == "tests"
|
49
|
+
Requires-Dist: pytest-cov; extra == "tests"
|
50
|
+
Requires-Dist: pytest-subtests; extra == "tests"
|
50
51
|
|
51
52
|
# invrs-opt - Optimization algorithms for inverse design
|
52
|
-
`v0.
|
53
|
+
`v0.7.0`
|
53
54
|
|
54
55
|
## Overview
|
55
56
|
|
@@ -0,0 +1,20 @@
|
|
1
|
+
invrs_opt/__init__.py,sha256=cRGTL0pWiEmPY26dG0bfKaS_RV5I5N3FdFkKLM8Z-Wk,585
|
2
|
+
invrs_opt/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
3
|
+
invrs_opt/experimental/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
4
|
+
invrs_opt/experimental/client.py,sha256=t4XxnditYbM9DWZeyBPj0Sa2acvkikT0ybhUdmH2r-Y,4852
|
5
|
+
invrs_opt/experimental/labels.py,sha256=dQDAMPyFMV6mXnMy295z8Ap205DRdVzysXny_Be8FmY,562
|
6
|
+
invrs_opt/optimizers/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
7
|
+
invrs_opt/optimizers/base.py,sha256=ol9skiS4_itx6pmqTx49fqqRZGzHHSxjKPKguy6602s,1199
|
8
|
+
invrs_opt/optimizers/lbfgsb.py,sha256=d7i02NZZ3yYdJg7wkERDMPpdBD3GaRPhmQexGrZPz_Y,34597
|
9
|
+
invrs_opt/optimizers/wrapped_optax.py,sha256=L836gwzWbwxPNWh8Y7PSgFHV4PZluSklnbh3BR5djlc,11859
|
10
|
+
invrs_opt/parameterization/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
11
|
+
invrs_opt/parameterization/base.py,sha256=QTnhOfMYbDchZOFzk9graryMd6rYHlyd7E2T1TtucB8,3570
|
12
|
+
invrs_opt/parameterization/filter_project.py,sha256=XCPqQ2ECv7DDTLRtVGJePfnjKYB2XndI6DssSr-4MZw,3239
|
13
|
+
invrs_opt/parameterization/gaussian_levelset.py,sha256=OYXPNC3GIGqCxea-u7rTXCOAEERLoict9kqnjYvGGto,24838
|
14
|
+
invrs_opt/parameterization/pixel.py,sha256=4qCYDUCcFPr8W94whX5YFllrXgyZbPBVIJBf8m_Dv4k,1173
|
15
|
+
invrs_opt/parameterization/transforms.py,sha256=8GzaIsUuuXvMCLiqAEEfxmi9qE9KqHzbuTj_m0GjH3w,8216
|
16
|
+
invrs_opt-0.7.0.dist-info/LICENSE,sha256=ty6jHPvpyjHy6dbhnu6aDSY05bbl2jQTjnq9u1sBCfM,1078
|
17
|
+
invrs_opt-0.7.0.dist-info/METADATA,sha256=EBEC3SgXD2hwdZ5s-z2dydbr5oSPSsgB34iMSdhaLeE,3339
|
18
|
+
invrs_opt-0.7.0.dist-info/WHEEL,sha256=R0nc6qTxuoLk7ShA2_Y-UWkN8ZdfDBG2B6Eqpz2WXbs,91
|
19
|
+
invrs_opt-0.7.0.dist-info/top_level.txt,sha256=hOziS2uJ_NgwaW9yhtOfeuYnm1X7vobPBcp_6eVWKfM,10
|
20
|
+
invrs_opt-0.7.0.dist-info/RECORD,,
|
invrs_opt-0.5.2.dist-info/RECORD
DELETED
@@ -1,14 +0,0 @@
|
|
1
|
-
invrs_opt/__init__.py,sha256=TPyc9kznbXNbM67XmXpnFIGTmGFQmYzPojKRueSZelU,309
|
2
|
-
invrs_opt/base.py,sha256=dSX9QkMPzI8ROxy2cFNmMwk_89eQbk0rw94CzvLPQoY,907
|
3
|
-
invrs_opt/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
4
|
-
invrs_opt/experimental/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
5
|
-
invrs_opt/experimental/client.py,sha256=td5o_YqqbcSypDrWCVrHGSoF8UxEdOLtKU0z9Dth9lA,4842
|
6
|
-
invrs_opt/experimental/labels.py,sha256=dQDAMPyFMV6mXnMy295z8Ap205DRdVzysXny_Be8FmY,562
|
7
|
-
invrs_opt/lbfgsb/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
8
|
-
invrs_opt/lbfgsb/lbfgsb.py,sha256=EKNTDTwEHcO_JeOIckMHVer5hxYcaNuqq9EZgnFnWJk,27820
|
9
|
-
invrs_opt/lbfgsb/transform.py,sha256=a_Saj9Wq4lvqCJBrg5L2Z9DZ2NVs1xqrHLqha90a9Ws,5971
|
10
|
-
invrs_opt-0.5.2.dist-info/LICENSE,sha256=ty6jHPvpyjHy6dbhnu6aDSY05bbl2jQTjnq9u1sBCfM,1078
|
11
|
-
invrs_opt-0.5.2.dist-info/METADATA,sha256=SgIEqMR9ybcipS1NnHi-KSVTSZ3BzWKrv1ctw4jfqcE,3326
|
12
|
-
invrs_opt-0.5.2.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
|
13
|
-
invrs_opt-0.5.2.dist-info/top_level.txt,sha256=hOziS2uJ_NgwaW9yhtOfeuYnm1X7vobPBcp_6eVWKfM,10
|
14
|
-
invrs_opt-0.5.2.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|