This guide helps you diagnose and fix common issues when working with GNN models.
| Error Type | Symptoms | Quick Fix |
|---|---|---|
| Syntax Error | Parser fails, invalid character warnings | Check GNN Syntax Reference |
| Dimension Mismatch | Type checker fails, matrix incompatibility | Verify matrix dimensions in StateSpaceBlock |
| Connection Error | Invalid variable references | Ensure all connected variables are defined |
| Parameterization Error | Probabilities don't sum to 1 | Normalize probability distributions |
| Rendering Error | Code generation fails | Check variable naming and matrix structures |
Error: Unexpected character '[' at line 15
Common Causes:
- Missing commas in variable definitions
- Incorrect bracket usage
[]vs{}vs() - Invalid variable naming (spaces, special characters)
Solutions:
-
Check variable definitions:
# ❌ Wrong s f0[2,1,type=int] # Space in variable name # ✅ Correct s_f0[2,1,type=int] # Underscore for subscripts -
Verify bracket usage:
# ❌ Wrong s_f0{2,1,type=int} # Curly braces for dimensions # ✅ Correct s_f0[2,1,type=int] # Square brackets for dimensions -
Check connection syntax:
# ❌ Wrong s_f0 -> A_m0 -> o_m0 # Chain notation not supported # ✅ Correct (s_f0) -> (A_m0) # Each connection separately (A_m0) -> (o_m0)
Error: Unknown section "StateSpace" at line 8
Solution: Use exact section names from the GNN File Structure:
# ❌ Wrong
## StateSpace
# ✅ Correct
## StateSpaceBlock
Error: A_m0 expects dimensions [3,2] but got [2,3]
Diagnosis:
- Check your StateSpaceBlock definitions
- Verify matrix structure in InitialParameterization
- Ensure observation outcomes match matrix rows
Solution:
## StateSpaceBlock
o_m0[3,1,type=int] # 3 possible observations
s_f0[2,1,type=int] # 2 possible states
# A_m0 should be [observations × states] = [3,2]
A_m0[3,2,type=float] # ✅ Correct dimensions
## InitialParameterization
A_m0={
# 3 rows (observations) × 2 columns (states)
((0.9, 0.1), # P(o=0|s=0), P(o=0|s=1)
(0.1, 0.8), # P(o=1|s=0), P(o=1|s=1)
(0.0, 0.1)) # P(o=2|s=0), P(o=2|s=1)
}
Error: B_f0 column 0 sums to 0.85, expected 1.0
Solution:
-
Check each column sums to 1:
# ❌ Wrong - columns don't sum to 1 B_f0={ ((0.7, 0.3), # Column 0: 0.7 + 0.2 = 0.9 ≠ 1.0 (0.2, 0.7)) # Column 1: 0.3 + 0.7 = 1.0 ✓ } # ✅ Correct - all columns sum to 1 B_f0={ ((0.8, 0.3), # Column 0: 0.8 + 0.2 = 1.0 ✓ (0.2, 0.7)) # Column 1: 0.3 + 0.7 = 1.0 ✓ } -
Use normalization helper:
# Python helper for normalization import numpy as np # Your unnormalized matrix B = np.array([[0.7, 0.3], [0.2, 0.7]]) # Normalize columns to sum to 1 B_normalized = B / B.sum(axis=0) print(B_normalized)
Error: Variable 'G' referenced in connections but not defined in StateSpaceBlock
Solution:
-
Add missing variables to StateSpaceBlock:
## StateSpaceBlock # Add the missing variable G[1,type=float] # Expected Free Energy ## Connections # Now this connection is valid (C_m0, A_m0, B_f0) > G -
Check for typos in variable names:
# ❌ Typo in connection (s_f0) -> (A_m0) (A_m0) -> (o_m0) (s_f0) -> (B_f0) # Should be s_f0, not s_f1 # ✅ Correct (s_f0) -> (A_m0) (A_m0) -> (o_m0) (s_f0) -> (B_f0)
Error: Circular dependency: s_f0 -> A_m0 -> s_f0
Solution: Review your model structure. Circular dependencies usually indicate:
- Incorrect causality direction
- Missing temporal distinction (use
s_f0_nextfor future states) - Conceptual modeling error
# ❌ Circular
(s_f0) -> (A_m0)
(A_m0) -> (s_f0) # Creates cycle
# ✅ Correct - temporal distinction
(s_f0) -> (A_m0)
(A_m0) -> (o_m0)
(s_f0) -> (B_f0)
(B_f0) -> s_f0_next # Next time step
Error: Variable naming conflicts with PyMDP reserved words
Solutions:
-
Avoid reserved words:
# ❌ Problematic names A[2,2,type=float] # 'A' might conflict with numpy class[3,1,type=int] # 'class' is Python keyword # ✅ Better names A_m0[2,2,type=float] # Explicit modality naming object_class[3,1,type=int] # Descriptive name -
Check matrix structure compatibility:
# Ensure matrices are properly structured for target framework # PyMDP expects specific conventions for A, B, C, D matrices
Error: Invalid LaTeX syntax in equations section
Solution:
-
Escape special characters:
## Equations # ❌ Unescaped underscore s_t = softmax(ln(D) + ln(A^T * o_t)) # ✅ Properly escaped s\_t = \text{softmax}(\ln(D) + \ln(A^T \cdot o\_t)) -
Use supported LaTeX commands:
# ✅ Standard mathematical notation \mathbf{A} # Bold matrix \mathcal{D} # Calligraphic \text{softmax} # Text function names
# Run the GNN type checker
python src/5_type_checker.py --target-dir your_model_directory- StateSpaceBlock: Verify all variables are properly defined
- Connections: Ensure all referenced variables exist
- InitialParameterization: Check matrix dimensions and probability constraints
- Equations: Validate mathematical notation
- Start with a minimal working model
- Add one component at a time
- Test after each addition
- Isolate the problematic component
# Python validation script
from src.gnn_type_checker import validate_gnn_file
result = validate_gnn_file("your_model.gnn")
if not result.is_valid:
for error in result.errors:
print(f"Error at line {error.line_number}: {error.message}")- Follow
s_f0,o_m0,A_m0conventions - Use descriptive comments
- Avoid special characters
- Run type checker after major changes
- Test with simple examples first
- Use templates for new models
- Add clear ModelAnnotation
- Comment complex parameterizations
- Include usage examples
- Track changes to your GNN files
- Tag working versions
- Document breaking changes
If you're still stuck:
- Check the examples in
doc/archive/for similar patterns - Search GitHub Issues for related problems
- Post in GitHub Discussions with:
- Your GNN file (or minimal reproducing example)
- Error messages
- What you've already tried
- Review the specification in GNN Syntax and File Structure
## GNNVersionAndFlags
GNN v1
## ModelName
Debug Test Model
## ModelAnnotation
Minimal model for debugging
## StateSpaceBlock
s_f0[2,1,type=int]
o_m0[2,1,type=int]
A_m0[2,2,type=float]
D_f0[2,type=float]
## Connections
(D_f0) -> (s_f0)
(s_f0) -> (A_m0)
(A_m0) -> (o_m0)
## InitialParameterization
A_m0={((0.9,0.1),(0.1,0.9))}
D_f0={(0.5,0.5)}
## Time
Static
## Footer
Debug Test Model
This minimal model should always parse correctly and can serve as a baseline for debugging more complex models.
ImportError: cannot import name 'parse_matrix_data' from 'visualization.processor'
Cause:
Missing import or definition in src/visualization/processor.py. This function is now correctly imported from analysis.analyzer.
Solution:
Ensure you are using the latest version of the visualization module. The function should be imported as:
from analysis.analyzer import parse_matrix_data, generate_matrix_visualizationsNameError: name 'Path' is not defined
Cause:
Missing from pathlib import Path in src/gui/__init__.py.
Solution: Add the missing import to the top of the file:
from pathlib import PathImportError: cannot import name 'run_gui' from 'gui'
Cause:
run_gui has been renamed to process_gui in the gui module public API.
Solution:
Update your code/tests to use process_gui instead:
from gui import process_gui