Skip to content

fix: correct bernoulli_loader kwarg, remove duplicate import, fix mutable default#743

Open
haoyu-haoyu wants to merge 1 commit intoBindsNET:masterfrom
haoyu-haoyu:fix/code-quality-bugs
Open

fix: correct bernoulli_loader kwarg, remove duplicate import, fix mutable default#743
haoyu-haoyu wants to merge 1 commit intoBindsNET:masterfrom
haoyu-haoyu:fix/code-quality-bugs

Conversation

@haoyu-haoyu
Copy link
Copy Markdown
Contributor

Summary

  • Fix bernoulli_loader reading wrong kwarg in bindsnet/encoding/loaders.py: kwargs.get("dt", 1.0) should be kwargs.get("max_prob", 1.0). The docstring documents max_prob as the parameter for maximum spike probability per Bernoulli trial, but the code was reading dt instead.

  • Remove duplicate import numpy as np in bindsnet/network/monitors.py.

  • Fix mutable default argument pipeline: list = []pipeline: Optional[list] = None in MulticompartmentConnection.__init__ (bindsnet/network/topology.py). Mutable defaults are shared across all instances.

Test plan

  • bernoulli_loader now correctly reads max_prob parameter
  • No behavioral change for existing code that doesn't pass max_prob (default remains 1.0)
  • Existing tests should pass without modification

…able default

- Fix bernoulli_loader reading 'dt' instead of 'max_prob' from kwargs
  in encoding/loaders.py. The docstring documents max_prob but the
  code was fetching the wrong key.

- Remove duplicate 'import numpy as np' in network/monitors.py.

- Fix mutable default argument pipeline=[] in
  MulticompartmentConnection.__init__. Changed to None with guard.
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes a parameter handling bug in the Bernoulli encoder loader, removes a redundant import in monitors, and updates a connection constructor to avoid a shared mutable default.

Changes:

  • Fix bernoulli_loader to read max_prob from kwargs instead of incorrectly reading dt.
  • Remove a duplicate numpy import (and duplicated adjacent imports) in bindsnet/network/monitors.py.
  • Change MulticompartmentConnection.__init__ default pipeline from [] to None to avoid mutable default sharing.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
bindsnet/encoding/loaders.py Corrects bernoulli_loader kwarg lookup for max_prob.
bindsnet/network/monitors.py Removes duplicated import block to clean up module imports.
bindsnet/network/topology.py Updates pipeline default to avoid shared mutable default (but currently introduces a runtime issue when pipeline is omitted).
Comments suppressed due to low confidence (1)

bindsnet/network/topology.py:417

  • Changing pipeline default to None here will pass None into AbstractMulticompartmentConnection.__init__, which currently iterates for feature in pipeline: (using the argument, not self.pipeline). That will raise a TypeError when callers omit pipeline (now the default). Consider normalizing pipeline to an empty list before calling super().__init__ (e.g., pipeline = [] if pipeline is None else pipeline) or updating the base class to iterate over self.pipeline instead of the raw argument.
        pipeline: Optional[list] = None,
        manual_update: bool = False,
        traces: bool = False,
        **kwargs,
    ) -> None:

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants