Repository navigation
feat: SLSQP constraints from Ruby; generator filters kernels by signature - #12
Merged
Merged
Conversation
…ture
Optimize.minimize(method: :slsqp, constraints: [{kind: :eq, fun: ...}])
raised "no implicit conversion of Hash into optimize.ConstraintSpec":
conv.go had no converter for the interface. Add one, mapping a Hash
{kind:/type:, fun:, m:, jac:} to optimize.Constraint (go-numerics/optimize
v0.3.1 constraints.go:31), so Result#multipliers and the generated
ConstraintKind enum are reachable. m: is bounded (resource limit, 32-bit).
internal/gen skipped special's in-place kernels by the "To" name suffix;
it now tests the signature (no result, first parameter []float64), so a
scalar named FooTo is still bound.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
tannevaled
force-pushed
the
slsqp-constraints
branch
from
November 29, 2026 17:38
5bbe231 to
6850456
Compare
…, jagged jac - flatFloats has no recursion: number | row | Array of rows, so a self-containing Array is a TypeError, not a stack overflow. - minimize refuses constraints whose summed m*n exceeds 2^26 values (division-checked, overflow-safe on 32-bit); false 32-bit comment fixed. - kind: and type: together are an ArgumentError. - each jac row must have n values. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
- cap 2^25 values: the optimizer holds two buffers, about 520 MiB. - an Array a constraint returns is all numbers or all rows. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
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.
What
Optimize.minimize(x0, method: :slsqp, constraints: [{kind: :eq, fun: ...}])raisedno implicit conversion of Hash into optimize.ConstraintSpec:conv.gohad no converter for the interface type, soResult#multiplierswas always nil and the generatedConstraintKindenum was unusable. Newconstraints.goregisters a converter from a Hash tooptimize.Constraint.internal/genfilters special's kernels by signature, not by theToname suffix: a function with no result whose first parameter is[]float64is a kernel; a scalar namedFooTo(x float64) float64is bound.Bibliography (go-numerics/optimize v0.3.1, the version this module resolves)
constraints.go:15ConstraintSpecis a sealed interface (standardizeunexported): the concrete forms areConstraint(:31),NonlinearConstraint(:47),LinearConstraint(:61).constraints.go:20-27ConstraintKind:Eq(c(x) = 0),Ineq(c(x) >= 0).constraints.go:31-41Constraint{Kind, M, Func(x, c), Jac(x, jac)}is SciPy's{'type', 'fun', 'jac'}dictionary;M(outputs of Func) is required, positive (:79);Jacis row-major M×n, forward differences when nil.minimize.go:56Options.Constraints []ConstraintSpec;types.go:71-74Result.Multipliers(SLSQP only, equalities first then inequalities).Ruby shape
kind:(type:accepted, as SciPy):eq/:ineqvia the generated enum;fun:a Proc returning a number or an Array/NDArray ofmvalues;m:(default 1, bound 1..2^20: it sizes Go buffers) because SciPy finds m by callingfunand the Go side must be told;jac:optional, an Array of rows, a flat row-major Array or an NDArray. Only theConstraint(dictionary) form is bound;NonlinearConstraint/LinearConstraintare not (follow-up if wanted). Errors (bad kind, missing kind/fun, non-Proc, wrong count, bad m, unknown key) are Ruby ArgumentError / TypeError; a raisingfunaborts the minimization and re-raises. README documents the shape.Tests
TestSLSQPEqualityConstraint(min x²+y² s.t. x+y=1 gives (0.5, 0.5), |multiplier| = 1 analytic,type:spelling, jac, identical to the Go call),TestSLSQPInequalityConstraints(x >= 1 gives (1, 0), multiplier 2 analytic; m: 2 block),TestSLSQPMixedConstraints,TestConstraintErrors(20 cases),TestKernelsAreFilteredBySignature(FooTo kept, ErfTo-shaped kernels dropped, odd signatures). 100% coverage in all three packages; gofmt clean. mutsweep: 18 mutations, 0 survived; 2 caught only by a panic (the converter'serr != nilreturns, whose mutant yields an invalid reflect.Value that cannot be asserted).No parser touched (no fuzz change). No 32-bit-width logic beyond the bounded
m:; the 32-bit CI lanes decide.🤖 Generated with Claude Code