forked from sedtrails/sedtrails
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdebug_sedtrails.py
More file actions
161 lines (122 loc) · 6.14 KB
/
debug_sedtrails.py
File metadata and controls
161 lines (122 loc) · 6.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
#!/usr/bin/env python3
"""
Debug script for SedTRAILS simulation
This script allows you to run a SedTRAILS simulation in debug mode within VS Code.
You can set breakpoints, step through the code, and inspect variables to troubleshoot issues.
Usage:
1. Set breakpoints in this file or in the SedTRAILS source code
2. Run this script in VS Code debugger (F5 or Run -> Start Debugging)
3. The debugger will stop at breakpoints allowing you to inspect the simulation
This script replicates the behavior of:
sedtrails run -c U:\\MangroveConnectivity\\pyST\\02_soulsby-debugging\\001_defaults\\config.example_soulsby.yaml
"""
import sys
import logging
from pathlib import Path
# Add the source directory to the path so we can import sedtrails
sys.path.insert(0, str(Path(__file__).parent / 'src'))
def main():
"""Main debug function that runs the SedTRAILS simulation."""
# Configuration
#config_file = r"C:\surfdrive\650_SedTRAILS\pyTesting\02_soulsby-debugging\005_finer\config.example_soulsby.yaml"
#config_file = r"C:\surfdrive\650_SedTRAILS\pyTesting\02_soulsby-debugging\006_coarser\config.example_soulsby.yaml"
#config_file = r"C:\surfdrive\650_SedTRAILS\pyTesting\02_soulsby-debugging\007_finer_hidExp_off\config.example_soulsby.yaml"
#config_file = r"C:\surfdrive\650_SedTRAILS\pyTesting\02_soulsby-debugging\008_coarser_hidExp_off\config.example_soulsby.yaml"
#config_file = r"C:\surf\650_SedTRAILS\pyTesting\02_soulsby-debugging\004_grain-size-test\config.example_soulsby.yaml"
config_file = r"C:\surf\650_SedTRAILS\pyTesting\02_soulsby-debugging\009_missingGrainSizeField\config.example_soulsby.yaml"
# Set up logging for verbose output (equivalent to CLI verbose mode)
logging.basicConfig(
level=logging.INFO,
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s'
)
print("Debug: Starting SedTRAILS simulation...")
print(f"Debug: Configuration file: {config_file}")
print(f"Debug: Working directory: {Path.cwd()}")
# Check if config file exists
config_path = Path(config_file)
if not config_path.exists():
print(f"ERROR: Configuration file not found: {config_file}")
return 1
try:
# Import SedTRAILS (this is where initial import errors might occur)
print("Debug: Importing SedTRAILS...")
import sedtrails
print(f"Debug: SedTRAILS version: {sedtrails.__version__}")
# This is equivalent to what the CLI does:
# sedtrails.application_interfaces.api.run_simulation(config_file=config_file, verbose=True)
print("Debug: Starting simulation...")
# You can set a breakpoint here to step into the run_simulation function
output_dir = sedtrails.run_simulation(
config_file=config_file,
verbose=True
)
print("Debug: Simulation completed successfully!")
print(f"Debug: Results saved to: {output_dir}")
return 0
except ImportError as e:
print(f"ERROR: Failed to import SedTRAILS: {e}")
print("This might be due to missing dependencies or environment issues.")
return 1
except Exception as e:
print(f"ERROR: Simulation failed: {e}")
print(f"ERROR Type: {type(e).__name__}")
# Print the full stack trace for debugging
import traceback
print("\nFull traceback:")
traceback.print_exc()
return 1
def debug_config_loading():
"""Debug function to test just the configuration loading part."""
config_file = r"C:\surf\650_SedTRAILS\pyTesting\02_soulsby-debugging\005_finer\config.example_soulsby.yaml"
try:
print("Debug: Testing configuration loading...")
import sedtrails
# Test configuration loading
config = sedtrails.load_configuration(config_file)
print("Debug: Configuration loaded successfully!")
print(f"Debug: Config keys: {list(config.keys())}")
# Test configuration validation
is_valid = sedtrails.validate_configuration(config_file)
print(f"Debug: Configuration valid: {is_valid}")
return config
except Exception as e:
print(f"ERROR: Configuration loading failed: {e}")
import traceback
traceback.print_exc()
return None
def debug_simulation_creation():
"""Debug function to test just the simulation object creation."""
config_file = r"C:\surf\650_SedTRAILS\pyTesting\02_soulsby-debugging\005_finer\config.example_soulsby.yaml"
try:
print("Debug: Testing simulation creation...")
# Import the Simulation class directly
from sedtrails.simulation_orchestrator.simulation_manager import Simulation
# Create simulation instance (this is where many issues occur)
print("Debug: Creating Simulation instance...")
simulation = Simulation(config_file, enable_dashboard=None)
print("Debug: Simulation instance created successfully!")
# You can inspect the simulation object here
print(f"Debug: Simulation config loaded: {simulation.config is not None}")
print(f"Debug: Data manager created: {simulation.data_manager is not None}")
return simulation
except Exception as e:
print(f"ERROR: Simulation creation failed: {e}")
import traceback
traceback.print_exc()
return None
if __name__ == "__main__":
"""
Main entry point for debugging.
You can uncomment different debug functions to test specific parts:
"""
# Uncomment one of these debug functions to test specific parts:
# 1. Full simulation (equivalent to CLI command)
exit_code = main()
# 2. Test just configuration loading (uncomment to test config only)
# config = debug_config_loading()
# exit_code = 0 if config is not None else 1
# 3. Test just simulation creation (uncomment to test simulation creation only)
# simulation = debug_simulation_creation()
# exit_code = 0 if simulation is not None else 1
# Exit with the appropriate code
sys.exit(exit_code)