Check num_chan_per_chip to avoid ZeroDivisionError#1830
Open
MGAMZ wants to merge 2 commits intoNeuralEnsemble:masterfrom
Open
Check num_chan_per_chip to avoid ZeroDivisionError#1830MGAMZ wants to merge 2 commits intoNeuralEnsemble:masterfrom
num_chan_per_chip to avoid ZeroDivisionError#1830MGAMZ wants to merge 2 commits intoNeuralEnsemble:masterfrom
Conversation
There was a problem hiding this comment.
Pull request overview
Adds a guard when reading SpikeGadgets XML headers to prevent a ZeroDivisionError during channel-ID generation when chanPerChip is present but set to a non-positive value.
Changes:
- Validate
chanPerChipafter parsing and fall back to the Intan default (32) when the value is non-positive.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
Well, I think it may be OK to add a warning letting users know something is wrong... but I doubt the necessarity to “replace with the original default value for Intan chips”, replacing is a dangerous action. |
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.
In some scenarios, spikegadgets' recording have missing
chanPerChipvalues, neo will default to 32 in this case.In our practice, this value can be mistakenly recorded to zero, and will cause
ZeroDivisionErrorwhile parsing header:This PR adds a simple check for
num_chan_per_chip, when it appears to be non-positive, raise KeyError which will be caught and replace with the original default value for Intan chips.Further Discussion
The related codes are introduced in #1496. In that PR, the @khl02007 assumes the
num_chan_per_chipis reliable and it influces the channel mapping. But in fact this value can be wrong due to Trodes BUGs, It can be zero or an abormally large value.If the value is mistakenly recorded as zero, a
ZeroDivisionErrorwill be triggered (as seen in this PR). If it is recorded as a large value (such as 1645402192), the conditionnum_ephy_channels % num_chan_per_chip == 0is evaluated to True. Consequently,python-neowill treat it as a valid value and trigger the remapping ofchannel_ids. This is potentially dangerous because the data could be inaccurate without the user's awareness.This PR only introduces some simple checks and overwrite the wrong value to defaults. However, the default values may still deviate from the actual situation. The judgment
num_ephy_channels % num_chan_per_chip == 0seems to be not good for robustness. But I am not sure how to improve this. Also hoping @jnjnnjzch can give some suggestions.