Repository navigation
fix(population): compile the Ensemble solver template lazily - #50
Merged
Merged
Conversation
Since 6fd257a, linkage_to_solver_data() refuses dyads the numba solver cannot represent instead of mistyping them. Ensemble compiled that template in __init__, and an Ensemble is what every optimizer returns, so particle_swarm_optimization() and multi_objective_optimization() raised NotImplementedError for any linkage holding a PPDyad, a cam follower, or a duck-typed container such as leggedsnake's Walker -- mechanisms 1.1.1 optimized without complaint, because the optimizer never touches the solver. The template is now compiled on first access (Ensemble.template), which simulate(), simulate_member() and topology_key go through. n_joints comes from the positions array and from_agents()/from_pareto_front() count the linkage's parts, so an Ensemble of an unsupported linkage holds its members and scores as before; only batch simulation raises, with the same message. Slices share the compiled template. Also declares typing_extensions for Python < 3.11: mechanism.builder imports Self from it, so a bare install on 3.10 could not import the package at all (present in 1.1.1). Released leggedsnake 0.6.0 against this tree: 627 passed, was 5 failed.
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.
Summary
Two release blockers found while testing the 1.2.0 tree against released consumers. Neither is in 1.1.1's public behaviour; both would have shipped.
Optimizers refused linkages the numba solver cannot represent
Since 6fd257a,
linkage_to_solver_data()raisesNotImplementedErrorfor a dyad it cannot type, instead of mistyping it into NaN. That is right for the solver — butEnsemble.__init__compiled the solver template eagerly, and anEnsembleis what every optimizer returns. So on this tree:for any linkage holding a
PPDyad, a cam follower, or leggedsnake'sWalker(a duck-typed container whose parts aremechanismjoints). On 1.1.1 all of those optimize. Released leggedsnake 0.6.0 against this tree: 5 failures (multi_objective_optimization,chain_optimizers, NSGA walking optimization), all this.The template is now compiled on first use —
Ensemble.template, whichsimulate(),simulate_member()andtopology_keygo through.n_jointscomes from the positions array;from_agents()/from_pareto_front()count the linkage's parts. An Ensemble of an unsupported linkage holds its members and scores exactly as before, and only batch simulation raises, with the same message. Slices share the compiled template.pip install pylinkagefailed on Python 3.10mechanism.builderimportsSelffromtyping_extensionsbelow 3.11; the package never declared it. A bare install on 3.10 could notimport pylinkageat all. Present in 1.1.1 too. Now declared with apython_version < '3.11'marker.Verification
-W error::DeprecationWarning; ruff, mypy clean. Two regression tests added.DeprecationWarningfrom pylinkage.