-
Notifications
You must be signed in to change notification settings - Fork 101
Fix bm.for_loop jit parameter handling and remove unused parameters
#803
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Copilot
wants to merge
7
commits into
master
Choose a base branch
from
copilot/fix-bm-for-loop-jit-handling
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Conversation
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
Co-authored-by: Routhleck <88108241+Routhleck@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix jit parameter handling in bm.for_loop
Fix Dec 5, 2025
bm.for_loop jit parameter handling and remove unused parameters
This commit improves the `progress_bar` parameter in `bm.for_loop()` and `bm.scan()` to accept ProgressBar instances and integers for advanced customization, while maintaining full backward compatibility. Changes: - Added `_convert_progress_bar_to_pbar()` helper function for parameter conversion - Updated type hints to `Union[bool, brainstate.transform.ProgressBar, int]` - Enhanced docstrings with detailed examples for all supported types - Exported `ProgressBar` from `brainpy.math` for easy access - Added 10 comprehensive test cases covering all usage patterns - Updated API documentation to include ProgressBar Supported usage: - `progress_bar=True/False` (backward compatible) - `progress_bar=bm.ProgressBar(freq=10)` (custom frequency) - `progress_bar=bm.ProgressBar(desc="Processing")` (custom description) - `progress_bar=10` (integer shorthand for freq parameter) All 37 tests in test_controls.py pass, ensuring no regressions. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
The unroll_kwargs parameter was removed from bm.for_loop() as it was never
actually implemented. Updated runners.py to use functools.partial() to bind
shared_args to _step_func_predict, following the pattern already used in
train/online.py.
Changes:
- Added functools import
- Changed for_loop call to use functools.partial(self._step_func_predict, shared_args=shared_args)
- Removed unroll_kwargs={'shared_args': shared_args} which was non-functional
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
The remat parameter was removed from bm.for_loop() as it was never implemented. Updated LoopOverTime to: 1. Remove remat from the for_loop() call 2. Keep remat parameter in __init__ for backward compatibility 3. Add deprecation warning when remat=True is passed Changes: - Removed remat=self.remat from for_loop call on line 283 - Added deprecation warning for remat parameter - Removed self.remat storage (commented out for clarity) This maintains backward compatibility while warning users that the parameter no longer has any effect. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
When jit=False is used with zero-length input arrays, JAX's disable_jit() mode cannot handle the scan operation because it cannot infer the output type. Changes: - Added check for zero-length inputs when jit=False - Automatically falls back to JIT mode for zero-length inputs - Issues a UserWarning to inform users of the fallback - Added test case to verify zero-length input handling - All 38 tests in test_controls.py pass This fix resolves: ValueError: zero-length scan is not supported in disable_jit() mode because the output type is unknown.
On Windows Python 3.13 CI environment, Tcl/Tk is not properly configured, causing matplotlib tests to fail with TclError. Setting the MPLBACKEND environment variable to 'Agg' (non-interactive backend) resolves this issue. Changes: - Added MPLBACKEND=Agg env var to all test jobs (Linux, macOS, Windows) - This ensures consistent behavior across all CI platforms - Fixes TclError in test_phase_plane.py and test_aligns.py on Windows This is a cleaner solution than modifying individual test files.
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
bm.for_loopaccepted ajitparameter but never used it. Passingjit=Falsehad no effect—code was always JIT-compiled.Type of Change
Description
What does this PR do?
Implements the
jitparameter inbm.for_loopand removes unused parametersrematandunroll_kwargs.Why is this change needed?
The
jitparameter was documented but non-functional. Users debugging code withjit=Falsestill got JIT-compiled traces instead of eager execution.How does it work?
When
jit=False, wraps thebrainstate.transform.for_loopcall injax.disable_jit()context manager. Uses identity check (is False) to distinguish explicitFalsefromNone(default) or other falsy values.Changes Made
jaximport forjax.disable_jit()accessjax.disable_jit()whenjit is Falserematandunroll_kwargsfrom function signature and documentationjitparameter documentation to clarify usageTesting
How has this been tested?
Test environment:
Test coverage:
Performance Impact
Documentation
Screenshots (if applicable)
N/A
Breaking Changes
None. Removal of unused parameters
rematandunroll_kwargsis non-breaking—they were never implemented.Checklist
Additional Notes
CodeQL security scan: 0 alerts.
Related Issues/PRs
N/A
Original prompt
bm.for_loopreceivejitparam but don't handle it #802💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.