-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup_environment.py
More file actions
197 lines (162 loc) · 6.01 KB
/
Copy pathsetup_environment.py
File metadata and controls
197 lines (162 loc) · 6.01 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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
"""
BrainGraphNet - Environment Setup Script
Automated installation and verification of dependencies
"""
import subprocess
import sys
import os
from pathlib import Path
def print_header(text):
"""Print formatted header"""
print("\n" + "="*60)
print(f" {text}")
print("="*60)
def check_python_version():
"""Check if Python version is compatible"""
print_header("Checking Python Version")
version = sys.version_info
print(f"Python {version.major}.{version.minor}.{version.micro}")
if version.major < 3 or (version.major == 3 and version.minor < 8):
print("❌ ERROR: Python 3.8 or higher is required")
print(f" Current version: {version.major}.{version.minor}.{version.micro}")
sys.exit(1)
else:
print("✅ Python version is compatible")
def create_directories():
"""Create necessary directories"""
print_header("Creating Directory Structure")
dirs = [
"data/raw/synthetic",
"data/raw/HCP",
"data/raw/custom",
"data/processed",
"data/splits",
"outputs/checkpoints",
"outputs/logs",
"outputs/logs/tensorboard",
"outputs/predictions",
"outputs/figures"
]
for dir_path in dirs:
Path(dir_path).mkdir(parents=True, exist_ok=True)
print(f"✅ Created: {dir_path}")
def install_dependencies():
"""Install required packages"""
print_header("Installing Dependencies")
print("This may take 5-10 minutes...")
print("Installing core packages...")
try:
# Install PyTorch (CPU version)
print("\n[1/3] Installing PyTorch...")
subprocess.check_call([
sys.executable, "-m", "pip", "install",
"torch==2.0.1", "--index-url", "https://download.pytorch.org/whl/cpu",
"--quiet"
])
print("✅ PyTorch installed")
# Install PyTorch Geometric dependencies
print("\n[2/3] Installing PyTorch Geometric dependencies...")
subprocess.check_call([
sys.executable, "-m", "pip", "install",
"torch-scatter", "torch-sparse", "torch-geometric",
"-f", "https://data.pyg.org/whl/torch-2.0.1+cpu.html",
"--quiet"
])
print("✅ PyTorch Geometric installed")
# Install remaining requirements
print("\n[3/3] Installing remaining packages...")
subprocess.check_call([
sys.executable, "-m", "pip", "install", "-r", "requirements.txt",
"--quiet"
])
print("✅ All packages installed")
except subprocess.CalledProcessError as e:
print(f"❌ ERROR during installation: {e}")
print("\nTry manual installation:")
print(" pip install -r requirements.txt")
sys.exit(1)
def verify_installation():
"""Verify that all key packages are importable"""
print_header("Verifying Installation")
packages = [
("torch", "PyTorch"),
("torch_geometric", "PyTorch Geometric"),
("nilearn", "Nilearn"),
("networkx", "NetworkX"),
("numpy", "NumPy"),
("pandas", "Pandas"),
("matplotlib", "Matplotlib"),
("yaml", "PyYAML")
]
all_ok = True
for package, name in packages:
try:
__import__(package)
print(f"✅ {name}")
except ImportError:
print(f"❌ {name} - FAILED")
all_ok = False
if not all_ok:
print("\n❌ Some packages failed to import")
print("Try reinstalling: pip install -r requirements.txt")
sys.exit(1)
else:
print("\n✅ All packages verified successfully!")
def check_dataset():
"""Check if datasets are available"""
print_header("Checking Datasets")
synthetic_exists = Path("data/raw/synthetic").exists()
hcp_exists = Path("data/raw/HCP").exists() and any(Path("data/raw/HCP").iterdir())
if synthetic_exists:
print("✅ Synthetic data directory ready")
if hcp_exists:
print("✅ HCP data detected")
else:
print("ℹ️ HCP data not found (optional)")
print(" Download from: https://zenodo.org/records/6770120")
print(" Extract to: data/raw/HCP/")
print("\n💡 Synthetic data will be generated automatically if no dataset is found")
def display_next_steps():
"""Display next steps for the user"""
print_header("Setup Complete! 🎉")
print("""
Next Steps:
1. Quick Test (5 minutes):
python train.py --config config.yaml --epochs 10
2. Full Training (15-20 minutes):
python train.py --config config.yaml
3. Explore Notebooks:
jupyter notebook notebooks/01_data_exploration.ipynb
4. View Configuration:
cat config.yaml
5. Get Help:
python train.py --help
Documentation: See README.md for detailed usage
Happy brain network modeling! 🧠
""")
def main():
"""Main setup function"""
print("""
╔════════════════════════════════════════════════════════╗
║ ║
║ 🧠 BrainGraphNet Setup 🧠 ║
║ ║
║ Dynamic GNNs for Brain Connectivity Evolution ║
║ ║
╚════════════════════════════════════════════════════════╝
""")
try:
check_python_version()
create_directories()
install_dependencies()
verify_installation()
check_dataset()
display_next_steps()
except KeyboardInterrupt:
print("\n\n❌ Setup interrupted by user")
sys.exit(1)
except Exception as e:
print(f"\n\n❌ Unexpected error: {e}")
sys.exit(1)
if __name__ == "__main__":
main()