Minimum-lengthscale constraints in Python - #12
Draft
smartalecH wants to merge 1 commit into
Draft
Conversation
Ports the geometric lengthscale constraints from the Julia package: constraint_solid and constraint_void, with the hyperparameter-free thresholds of Arrieta et al. (arXiv:2507.16108). Both are written in terms of rho_filtered and rho_projected only, so they compose with any projection order (ssp1_bilinear, ssp2, or a plain tanh projection). Includes a test suite covering the threshold functions, lengthscale detection on stripe/gap geometries, gradients against finite differences, composition with each projection, jit, and argument validation, plus a worked example that sweeps the constraint over feature widths and runs a two-stage constrained optimization.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Stacked on #11 (base branch is
docs/supported-features) — review that one first.Ports the geometric minimum-lengthscale constraints from the Julia package to
ssp_topopt, closing one of the gaps recorded indocs/features.md.What's here
ssp_topopt.constraintsaddsconstraint_solidandconstraint_void, following the Julia implementation insrc/julia/SSP/src/constrain.jl:c = 64 R^2, thresholdeps = 1e-8, and the conic-filter threshold pointseta_e/eta_dof Qian & Sigmund (2013) (eqs. 7-12 of that paper);utils.gradient) thatssp2uses;nloptinequality constraint: nonpositive means feasible.Any SSP order works. The constraints only take
rho_filteredandrho_projected, so they compose withssp1_bilinear,ssp2, or a plaintanh_projection; a test exercises all three end to end.Example
examples/python/ssp_constrained_example.pyhas two parts:FOM 1.2e-4 -> 8.7e-2.Testing
tests/python/test_constraints.py(14 tests, 20 subtests; the full suite is 21 passing):eta_e + eta_d = 1invariant;rho_filteredandrho_projectedmatch central finite differences to ~1e-7 (in float64 — the normalized constraint is O(1/eps), so single-precision differencing is pure roundoff);jitparity, and argument validation.As an extra check outside the test suite, I compared against the Julia implementation on identical arrays: solid
1.4147e6(Python) vs1.4174e6(Julia) and void1.0382e6vs1.0388e6— 0.2% and 0.06%, consistent with the two packages using different cubic interpolation schemes (interpaxcubic2vsFastInterpolationsCubicFit) for the density gradient.Not included
Dilation/erosion and cubic-interpolation SSP1 remain Julia-only;
docs/features.mdis updated to reflect only what this PR adds.