Implement substitution functionality for Statements class#1768
Open
nishantraghuvanshi wants to merge 5 commits intobrian-team:masterfrom
Open
Implement substitution functionality for Statements class#1768nishantraghuvanshi wants to merge 5 commits intobrian-team:masterfrom
nishantraghuvanshi wants to merge 5 commits intobrian-team:masterfrom
Conversation
- Add __init__ method with **substitutions parameter to Statements class - Implement _substitute static method for identifier replacement - Support both name substitution (string -> string) and value substitution (identifier -> value) - Use regex with word boundaries to respect identifier boundaries - Add comprehensive test suite with 22 tests covering: - Basic value and name substitution - Multiple simultaneous substitutions - Word boundary handling - Brian2 units support - Multi-line statements - Integration with Synapses and NeuronGroup - Backward compatibility - All existing tests pass (no regression) This enables users to create reusable statement templates for on_pre, on_post, threshold, and reset parameters, similar to how Equations supports substitution for differential equations. Fixes brian-team#1219
Member
|
@nishantraghuvanshi Thank you for the PR! I did not yet have time to look at it in detail, but I will so next week. |
Change single quotes to double quotes in all test strings to comply with ruff formatting checks.
Apply ruff formatting changes: - Use double quotes consistently - Fix line wrapping for long parameter lists - Fix spacing in multiline statements - Add spaces around multiplication operators (e.g., 1*mV → 1 * mV) - Reformat parametrize decorators with proper indentation Fixes CI pre-commit hook failures
Fix repr test to match actual output format. The repr() returns double quotes around single-quoted string.
The implementation wraps value substitutions in parentheses for clarity,
e.g., Statements('g += k*w', k=0.3) produces 'g += (0.3)*w'.
Update docstring examples to match actual behavior.
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.
This enables users to create reusable statement templates for on_pre, on_post, threshold, and reset parameters, similar to how Equations supports substitution for differential equations.
Fixes #1219