Skip to content

Add network_inspectors.py module in LANfactory#82

Open
mariama-design wants to merge 3 commits into
lnccbrown:mainfrom
mariama-design:add-network-inspectors
Open

Add network_inspectors.py module in LANfactory#82
mariama-design wants to merge 3 commits into
lnccbrown:mainfrom
mariama-design:add-network-inspectors

Conversation

@mariama-design

@mariama-design mariama-design commented Jun 15, 2026

Copy link
Copy Markdown

Port network-inspector visualizations to LANfactory using
ssms.basic_simulators.simulator,
ssms.config.ModelConfigBuilder, ssms.support_utils.kde_class.LogKDE, and
LoadTorchMLPInfer.

Summary by CodeRabbit

Release Notes

  • New Features
    • Added a new network inspection and visualization module to compare Torch MLP likelihood predictions with simulator-based likelihoods.
    • Includes KDE-vs-MLP comparison plots and a 3D likelihood manifold view for parameter sweeps.
    • Exposed the module in the public package interface with lazy loading.
  • Chores
    • Added seaborn to the project’s main dependencies to support improved plotting.

  Port network-inspector visualizations to LANfactory using
  ssms.basic_simulators.simulator,
  ssms.config.ModelConfigBuilder, ssms.support_utils.kde_class.LogKDE, and
  LoadTorchMLPInfer.
@coderabbitai

coderabbitai Bot commented Jun 15, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 4d0e829b-dfa1-4925-989e-e5454b04eda9

📥 Commits

Reviewing files that changed from the base of the PR and between 800a0b5 and 06d6d6c.

📒 Files selected for processing (2)
  • src/lanfactory/__init__.py
  • src/lanfactory/network_inspectors.py
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/lanfactory/init.py
  • src/lanfactory/network_inspectors.py

📝 Walkthrough

Walkthrough

A new network_inspectors module adds Torch MLP loading and two plotting utilities for KDE/MLP likelihood comparisons and a 3D likelihood manifold. seaborn>=0.13.2 is added as a dependency, and the module is exported from lanfactory.

Changes

network_inspectors module and wiring

Layer / File(s) Summary
Dependency addition and package export
pyproject.toml, src/lanfactory/__init__.py
Adds seaborn>=0.13.2 to project dependencies and adds network_inspectors to the package export list with lazy attribute loading.
Module imports and get_torch_mlp factory
src/lanfactory/network_inspectors.py
Adds guarded imports for LoadTorchMLPInfer and implements get_torch_mlp to return its predict_on_batch callable or raise ImportError when unavailable.
kde_vs_lan_likelihoods plotting function
src/lanfactory/network_inspectors.py
Builds RT/choice grids, runs the Torch MLP and LAN simulator across parameter rows and repetitions, computes KDE likelihoods, and renders the comparison figure with optional save or show behavior.
lan_manifold 3D surface plotting function
src/lanfactory/network_inspectors.py
Builds a parameter sweep over one varying value, evaluates MLP likelihoods on RT/choice grids, and renders the 3D likelihood surface with optional save or show behavior.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐇 Hop hop, the plots take flight,
MLP and KDE dance left and right.
A seaborn carrot, fresh and bright,
Makes the LAN burrow feel just right.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 75.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly describes the main change: adding the new network_inspectors.py module to LANfactory.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
⚔️ Resolve merge conflicts
  • Resolve merge conflict in branch add-network-inspectors

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 7

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/lanfactory/__init__.py`:
- Around line 7-9: The eager import of network_inspectors at the top of the
__init__.py file forces scikit-learn to be loaded when the lanfactory package is
imported, even though sklearn is not in the project dependencies. Remove the
`from . import network_inspectors` statement on line 7 to prevent the transitive
import of sklearn for users who don't need the inspectors module. Additionally,
remove `"network_inspectors"` from the __all__ list on line 9, or if the module
needs to remain part of the public API, implement lazy loading for it instead of
eager importing.

In `@src/lanfactory/network_inspectors.py`:
- Line 121: The plt.subplots() calls at lines 121, 193, 206, 218, and 233 in
src/lanfactory/network_inspectors.py squeeze the axes when rows equals 1 or cols
equals 1, returning a 1D array instead of a 2D array. This causes the subsequent
2D indexing ax[row_tmp, col_tmp] to fail. Add the squeeze=False parameter to all
five plt.subplots() calls to ensure axes are always returned as a 2D array
regardless of the number of rows or columns, preventing indexing crashes.
- Around line 68-80: The kde_vs_lan_likelihoods function and other public
plotting functions accept parameter_df, model, and torch_mlp_predict with None
defaults but immediately dereference these values throughout the function body
(causing opaque runtime errors). Add early validation checks at the start of
each affected function to verify that these required parameters are not None,
and raise a clear, actionable ValueError or TypeError with a descriptive message
if they are missing, rather than allowing them to fail later with cryptic
attribute or type errors.
- Line 119: The sns.set() call on line 119 uses a hardcoded font_scale=2 value,
which ignores the font_scale parameter that is passed to the function (defined
on line 78). Replace the hardcoded font_scale=2 with the font_scale parameter
variable so that the caller's configuration is respected and takes effect in the
visualization settings.
- Around line 360-367: The code at line 360 calls .shape[0] on an element from
vary_dict, expecting it to be a numpy array, but the default value of vary_dict
uses Python lists instead, which lack the .shape attribute and cause an
AttributeError. Find where vary_dict is defined with its default value and
convert the default from using Python lists to using numpy arrays so that the
.shape[0] access at line 360 works correctly with default parameters.
- Around line 139-153: The input_batch array is initialized with a hardcoded
size of 4000 rows on line 151, but the plot_data array is dynamically sized to
len(config["choices"]) * 1000 rows. When len(config["choices"]) is not equal to
2, this causes a shape mismatch when attempting to assign plot_data to the
input_batch slicing operation on line 152. Replace the hardcoded 4000 value in
the input_batch initialization with len(config["choices"]) * 1000 to make the
row count dynamic and match the actual size of plot_data.
- Around line 14-21: The bare except clause at line 17 catches all exceptions
during the import of LoadTorchMLPInfer, not just ImportError. This masks the
actual error when import fails. Replace the bare except with except ImportError
to only catch import-related errors. Additionally, add a check in the
get_torch_mlp function (around line 59) before using LoadTorchMLPInfer to
validate that the import was successful, and raise an appropriate error if it
was not, rather than allowing a delayed NameError to occur.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 87480f93-721c-46ca-8e09-93545249dc66

📥 Commits

Reviewing files that changed from the base of the PR and between 357a1c3 and bdcec15.

⛔ Files ignored due to path filters (1)
  • uv.lock is excluded by !**/*.lock
📒 Files selected for processing (3)
  • pyproject.toml
  • src/lanfactory/__init__.py
  • src/lanfactory/network_inspectors.py

Comment thread src/lanfactory/__init__.py Outdated
Comment thread src/lanfactory/network_inspectors.py
Comment thread src/lanfactory/network_inspectors.py
Comment thread src/lanfactory/network_inspectors.py Outdated
Comment thread src/lanfactory/network_inspectors.py Outdated
Comment thread src/lanfactory/network_inspectors.py
Comment thread src/lanfactory/network_inspectors.py Outdated

@cpaniaguam cpaniaguam left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This is a great start, thanks @mariama-design! Two things to consider:

  • I think it'd be a good idea to add a new version of the old tutorial -- either in ipynb notebook format or marimo. It'd be a nice way to interactively make sure everything works as it did before.

  • Later we should discuss adding test coverage to these features

Comment thread uv.lock

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This file should not be included in the PR. Add it to the .gitignore file so Git doesn't track changes to it.

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