Skip to content

Feature/nn diagram#65

Open
DaoudiNadia wants to merge 13 commits intodevelopfrom
feature/nn-diagram
Open

Feature/nn diagram#65
DaoudiNadia wants to merge 13 commits intodevelopfrom
feature/nn-diagram

Conversation

@DaoudiNadia
Copy link
Copy Markdown
Collaborator

@DaoudiNadia DaoudiNadia commented Mar 6, 2026

Neural Network Diagram Editor & Code Generation

This release introduces the Neural Network (NN) Diagram Editor, a visual drag-and-drop interface
for designing neural network architectures directly in the BESSER Web Modeling Editor, along with
PyTorch and TensorFlow code generation capabilities.

New Features and Improvements

Neural Network Diagram Editor

  • Added a new NN Diagram Editor component enabling users to visually design neural network architectures using a drag-and-drop interface.
  • Implemented support for a comprehensive set of layer types:
    • Convolutional layers: Conv1D, Conv2D, Conv3D with configurable kernel, stride, padding, channels, and activation function
    • Recurrent layers: RNN, LSTM, GRU with configurable hidden size, bidirectionality, dropout, and return type
    • Linear & regularization layers: Linear, Flatten, Dropout, LayerNormalization, BatchNormalization
    • Embedding layer: with configurable vocabulary size and embedding dimension
    • Tensor operations: TensorOp with support for concatenation, reshape, transpose, multiply, matmultiply, and permute
    • Training configuration: Configuration block with optimizer, loss function, learning rate, epochs, batch size, and metrics
  • Added support for NN containers and references for modular architecture design.
  • Added section elements (titles and separators) for sidebar organization.
  • Added Neural Network Diagram as a new diagram type in the sidebar navigation.
  • Extended project types to support NNDiagram alongside existing UML diagram types.

Code Generation

  • Added PyTorch code generation support for NN diagrams (both Subclassing and Sequential).
  • Added TensorFlow code generation support for NN diagrams (both Subclassing and Sequential).
  • Integrated NN code generation into the Web Modeling Editor's Generate menu.
  • Extended the backend to support pytorch and tensorflow as new generator types.

Copy link
Copy Markdown
Collaborator

@ArmenSl ArmenSl left a comment

Choose a reason for hiding this comment

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

Great feature, the NN editor looks solid overall. Some things to address before merge:

NNElementRegistry concerns

The singleton registry tracks container/config IDs but never cleans up when elements are deleted. The FIFO eviction at 100 entries doesn't guarantee correctness. Since this duplicates what Redux already knows (element types are in state.elements), consider querying the store directly instead.

Dead code

renderOldPanel() in nn-association-update.tsx is explicitly marked "unused but kept for reference" — should be removed before merge along with its associated onChange/onUpdate handlers.

Input validation

Numeric attributes (epochs, learning_rate, hidden_size, batch_size, etc.) accept any string through <Textfield> with no validation. Invalid values will propagate to the backend and produce broken PyTorch/TensorFlow code. Add type="number" or validate on change.

Smaller things

  • NNRelationshipType re-exports all Class* relationship types — the NN enum should only define NNNext and NNComposition
  • Throwing plain strings in nn-unidirectional.ts (throw 'NNNext cannot connect...') instead of Error objects — loses stack traces
  • No-op bounds assignment in nn-preview.ts (spreads then overwrites with same values)
  • Various as any casts that could be properly typed
  • OptionalAttributeRow at 618 lines could use a config-driven approach instead of string matching for each attribute type

@DaoudiNadia DaoudiNadia closed this Mar 9, 2026
Replace NNElementRegistry singleton with direct Redux state queries (NNCompositionComponent, NNNext)
Remove nn-association-update.tsx including renderOldPanel() dead code
Validation for int/float/List attribute types
Remove Class* entries from NNRelationshipType (keep only NNNext, NNComposition)
Remove throw string literals in NNNext constructor. validation moved to NNAssociationMonitor
Remove no-op bounds assignments and unused imports in nn-preview.ts
Eliminate as any casts: add INNAttribute interface, type UMLClass.supportedRelationships as UMLRelationshipType, use PreviewElement for .styles
Refactor OptionalAttributeRow to config-driven widget lookup via nn-attribute-widget-config.ts
Remove dead code: nn-association-wrapper.tsx, unreachable isNNLayer logic in monitor
Auto-increment layer and container names on drop to avoid duplicate names in code generation
@DaoudiNadia DaoudiNadia reopened this Apr 9, 2026
@DaoudiNadia
Copy link
Copy Markdown
Collaborator Author

Comments addressed:

NNElementRegistry: Removed NNElementRegistry. Now NNCompositionComponent reads element types directly from Redux state; NNNext constructor no longer validates connections; NNAssociationMonitor reactively deletes invalid NNNext connections instead.

Dead code: Deleted nn-association-update.tsx including renderOldPanel() and all associated handlers.

Input validation: Validation for int, float, and List types is implemented, covering all numeric inputs.

Smaller things
Removed Class* entries from NNRelationshipType.
Removed the throw 'string' pattern from NNNext constructor.
Removed no-op bounds assignments in nn-preview.ts.
Added INNAttribute interface; typed UMLClass.supportedRelationships as UMLRelationshipType; replaced all NN-introduced as any with typed alternatives.
Extracted nn-attribute-widget-config.ts; OptionalAttributeRow now config-driven, pooling dimension-aware defaults encoded as getInitialValue functions in config.

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