Repository navigation
Support global sparsity tracing through distribution constructors - #2064
Merged
Merged
Conversation
`@check_args` performs validity comparisons on the constructor arguments (e.g. `σ ≥ 0`). Under SparseConnectivityTracer's global `TracerSparsityDetector`, those comparisons run on primal-free tracers and return a tracer rather than a `Bool`, so they cannot be used in the boolean context the checks require — which prevents tracing the global sparsity pattern through any distribution construction. Introduce an overloadable per-argument predicate `_arg_checkable(x)` (default `true`). `@check_args` now forwards the explicitly-named checked arguments to `check_args`, which skips the checks when any argument is not checkable. A new `DistributionsSparseConnectivityTracerExt` extension defines `_arg_checkable(::AbstractTracer) = false`, covering the primal-free `GradientTracer`/`HessianTracer` used by global detection. Local detection (`TracerLocalSparsityDetector`) passes primal-carrying `Dual`s (`<: Real`, not `<: AbstractTracer`), so its checks run unchanged. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
devmotion
force-pushed
the
dmw/sparseconnectivitytracer
branch
from
June 8, 2026 15:42
18ad218 to
17a40a1
Compare
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #2064 +/- ##
==========================================
- Coverage 86.65% 86.65% -0.01%
==========================================
Files 148 149 +1
Lines 8919 8925 +6
==========================================
+ Hits 7729 7734 +5
- Misses 1190 1191 +1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
andreasnoack
approved these changes
Jun 13, 2026
andreasnoack
left a comment
Member
There was a problem hiding this comment.
Looks good. Based on Claude's review assistance, I've filed #2067 to keep track of possible follow-up work needed to support all distributions.
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.
Motivation
@check_argsvalidates a distribution's constructor arguments with comparisons such asσ ≥ 0. Under SparseConnectivityTracer's globalTracerSparsityDetector, those comparisons run on primal-free tracers and return a tracer rather than aBool, so they cannot be used in the boolean context the checks require. As a result, the global sparsity pattern cannot currently be traced through any distribution construction —jacobian_sparsity(x -> mean(Normal(x[1], x[2])), x, TracerSparsityDetector())errors insidecheck_args.Change
Introduce an overloadable per-argument predicate
_arg_checkable(x)(defaulttrue).@check_argsnow forwards the explicitly-named checked arguments tocheck_args, which skips the checks when any argument is not checkable:A new weak-dependency extension
DistributionsSparseConnectivityTracerExtprovides the single overload:AbstractTracercovers exactly the primal-free global tracers (GradientTracer/HessianTracer). Local sparsity detection (TracerLocalSparsityDetector) passes primal-carryingDuals, which are<: Real(not<: AbstractTracer), so their comparisons evaluate toBoolas usual and the checks run unchanged — invalid arguments are still rejected under local tracing.Ordinary numeric construction is unaffected (
argsare plain numbers,_arg_checkableistrue).Tests
test/sparseconnectivitytracer.jlchecks that global gradient and (block-off-diagonal) Hessian sparsity trace throughNormalconstruction, and that local detection still enforces argument validity.This pull request was prepared with the assistance of generative AI (Claude Code).