Implement AST-based in-place sync and plotting state guardrails#253
Open
google-labs-jules[bot] wants to merge 1 commit into
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
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.
Overview
This PR addresses the state drift between the console and the GUI that occurs during interactive analysis. Previously, state synchronization was only triggered by explicit variable reassignments, leaving in-place modifications (e.g.,
EEG.data[0] = ...) or direct attribute edits undetected. Furthermore, because plotting functions often trigger UI repaints before the standardpost_run_cellhook, users frequently encountered "visual drift" where plot windows displayed stale data.Key Changes
1. Expanded AST Analysis for In-Place Edits
The
_workspace_assignment_targetslogic inconsole.pyhas been overhauled. It no longer just looks forast.Assignnodes.EEGandALLEEGidentifiers.ast.Callnodes for common mutating methods (e.g.,.pop(),.append(),.update()) andast.Deleteoperations.2. Pre-Plotting Synchronization Guardrails
To eliminate visual inconsistencies when plotting, I implemented a new IPython AST transformer,
_PlotSyncInjector.eegplot,eeg_browser,pop_...).3. Manual Synchronization Hook (
refresh)A new
refresh()command has been exported to the IPython namespace.eeg_store, and mandates a GUI redraw.refresh()provides a safety valve for edge-case recovery or complex scripts where static analysis might fail.Performance & Constraints
post_run_cellhooks and do not impact the performance of non-EEG variable assignments (e.g., standard math operations remain fast).Validation
EEG.setname = 'test'updates the GUI title immediately.eegplot(EEG)displays updated data even if modified in the same cell.