Skip to content

Make Polyester a weak dependency (extension)#73

Merged
ChrisRackauckas merged 4 commits intoSciML:masterfrom
ChrisRackauckas-Claude:polyester-extension
Mar 29, 2026
Merged

Make Polyester a weak dependency (extension)#73
ChrisRackauckas merged 4 commits intoSciML:masterfrom
ChrisRackauckas-Claude:polyester-extension

Conversation

@ChrisRackauckas-Claude
Copy link
Copy Markdown

Summary

  • Move fast_materialize_threaded! / fast_materialize_threaded / _batch_broadcast_fn to FastBroadcastPolyesterExt
  • Polyester moves from [deps] to [weakdeps] with an [extensions] entry
  • Main module defines bare function stubs; methods are added when Polyester is loaded
  • Polyester added to [extras]/[targets] so tests still load it

Builds on #72 (runtime Bool dispatch fix).

Motivation

Polyester pulls in Static.jl, CommonWorldInvalidations, StrideArraysCore, CloseOpenIntervals, and other packages that cause significant method invalidations. Users who don't need threaded broadcasting (the common case — thread=false is the default) shouldn't pay this cost.

For OrdinaryDiffEqCore, Polyester is already a direct dependency for @threaded/@batch, so the extension loads automatically. But lighter downstream packages that only use @.. without threading avoid the entire Polyester dep tree.

Test plan

  • All 53 tests pass (with Polyester loaded in test env)

🤖 Generated with Claude Code

ChrisRackauckas and others added 3 commits March 28, 2026 23:41
…ispatch

v0.4.0 removed Static.jl but broke runtime threading dispatch — `@.. thread=var`
where `var` is a runtime variable now always takes the threaded path because the
macro checks `if threadarg` which is truthy for any non-false Symbol/Expr.

This adds:
- `Sequential` and `PolyesterThreads` exported types for explicit threading control
- Runtime-dispatched `fast_materialize!(::Sequential, dst, bc)` and
  `fast_materialize!(::PolyesterThreads, dst, bc)` methods
- Bool backwards compat methods
- Macro logic to emit runtime dispatch when `thread=` receives a non-literal value

This enables OrdinaryDiffEqCore to use these types in algorithm structs instead of
`Static.True`/`Static.False`, removing the Static.jl dependency chain which causes
~2200 method invalidations.

Co-Authored-By: Chris Rackauckas <accounts@chrisrackauckas.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
v0.4.0 removed Static.jl but broke runtime threading dispatch — `@.. thread=var`
where `var` is a runtime variable always takes the threaded path because the
macro checks `if threadarg` which is truthy for any non-false Symbol/Expr.

This adds:
- `fast_materialize!(::Bool, dst, bc)` and `fast_materialize(::Bool, bc)` methods
  for runtime dispatch (true → Polyester threaded, false → serial)
- Macro logic to emit runtime dispatch when `thread=` receives a non-literal value,
  and keep compile-time selection for literal `true`/`false`

Co-Authored-By: Chris Rackauckas <accounts@chrisrackauckas.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Move threaded broadcast implementation (`fast_materialize_threaded!`,
`fast_materialize_threaded`, `_batch_broadcast_fn`) to
FastBroadcastPolyesterExt. The main module defines bare function stubs
that get methods added when Polyester is loaded.

This removes Polyester (and its transitive deps: Static,
CommonWorldInvalidations, StrideArraysCore, CloseOpenIntervals, etc.)
from the mandatory dependency tree, reducing load time and method
invalidations for users who don't need threaded broadcasting.

Co-Authored-By: Chris Rackauckas <accounts@chrisrackauckas.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@ChrisRackauckas
Copy link
Copy Markdown
Member

@oscardssmith

@oscardssmith
Copy link
Copy Markdown
Member

needs docs, a fallback method with a good error and the code looks a little janky, but looks good in theory

- Add docstrings to fast_materialize_threaded/fast_materialize_threaded!
- Add fallback methods that error with a clear message when Polyester
  isn't loaded
- Update @.. docstring to mention Polyester requirement for threading

Co-Authored-By: Chris Rackauckas <accounts@chrisrackauckas.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@ChrisRackauckas-Claude
Copy link
Copy Markdown
Author

Addressed review:

  • Added docstrings to fast_materialize_threaded and fast_materialize_threaded!
  • Added fallback methods that error with a clear message when Polyester isn't loaded: "Threaded broadcasting requires Polyester.jl to be loaded. Add using Polyester to your code."
  • Updated @.. macro docstring to mention Polyester requirement for thread=true

@ChrisRackauckas ChrisRackauckas merged commit be4deec into SciML:master Mar 29, 2026
3 of 4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants