Delete run_raytracing.py
Browse files- run_raytracing.py +0 -169
run_raytracing.py
DELETED
|
@@ -1,169 +0,0 @@
|
|
| 1 |
-
import sys
|
| 2 |
-
import os
|
| 3 |
-
import argparse
|
| 4 |
-
|
| 5 |
-
# Add project root to Python path
|
| 6 |
-
project_root = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
| 7 |
-
sys.path.insert(0, project_root)
|
| 8 |
-
|
| 9 |
-
from src.raytracer.raytracing_manager import RaytracingManager
|
| 10 |
-
from src.config_manager import ConfigManager
|
| 11 |
-
from src.utils.logging_utils import log_info, set_log_file
|
| 12 |
-
from src.utils.file_utils import ensure_directory_exists
|
| 13 |
-
|
| 14 |
-
def parse_arguments():
|
| 15 |
-
"""Parse command-line arguments"""
|
| 16 |
-
parser = argparse.ArgumentParser(description='Batch execute ray tracing')
|
| 17 |
-
|
| 18 |
-
# Config file arguments
|
| 19 |
-
parser.add_argument('--config', type=str,
|
| 20 |
-
help='Config file path (default: configs/regions_config.yaml)')
|
| 21 |
-
|
| 22 |
-
# Ray tracing parameters
|
| 23 |
-
parser.add_argument('--scenes-dir', type=str,
|
| 24 |
-
help='Scenes directory path')
|
| 25 |
-
parser.add_argument('--results-dir', type=str,
|
| 26 |
-
help='Results output directory')
|
| 27 |
-
parser.add_argument('--max-workers', type=int, default=None,
|
| 28 |
-
help='Maximum parallel workers (default uses config file)')
|
| 29 |
-
parser.add_argument('--gpu-mode', type=str,
|
| 30 |
-
choices=['auto', 'all', 'cpu_only'],
|
| 31 |
-
help='GPU usage mode')
|
| 32 |
-
|
| 33 |
-
# Scene selection parameters
|
| 34 |
-
parser.add_argument('--scene-pattern', type=str,
|
| 35 |
-
help='Scene name matching pattern')
|
| 36 |
-
parser.add_argument('--max-scenes', type=int,
|
| 37 |
-
help='Maximum number of scenes to process')
|
| 38 |
-
|
| 39 |
-
# Other parameters
|
| 40 |
-
parser.add_argument('--log-file', type=str,
|
| 41 |
-
help='Log file path')
|
| 42 |
-
parser.add_argument('--show-config', action='store_true',
|
| 43 |
-
help='Show current configuration and exit')
|
| 44 |
-
parser.add_argument('--list-scenes', action='store_true',
|
| 45 |
-
help='List available scenes and exit')
|
| 46 |
-
|
| 47 |
-
return parser.parse_args()
|
| 48 |
-
|
| 49 |
-
def safe_get_frequency(raytracing_config, default=3.66e9):
|
| 50 |
-
"""Safely get frequency value, handling string and numeric types"""
|
| 51 |
-
try:
|
| 52 |
-
frequency = raytracing_config.get('simulation', {}).get('frequency', default)
|
| 53 |
-
# If it is a string, try to convert to float
|
| 54 |
-
if isinstance(frequency, str):
|
| 55 |
-
frequency = float(frequency)
|
| 56 |
-
return frequency
|
| 57 |
-
except (ValueError, TypeError):
|
| 58 |
-
log_info(f"Warning: Failed to parse frequency value, using default {default/1e9:.2f} GHz")
|
| 59 |
-
return default
|
| 60 |
-
|
| 61 |
-
def main():
|
| 62 |
-
"""Main function"""
|
| 63 |
-
args = parse_arguments()
|
| 64 |
-
|
| 65 |
-
# Initialize config manager
|
| 66 |
-
config_manager = ConfigManager(args.config)
|
| 67 |
-
|
| 68 |
-
# Handle special commands
|
| 69 |
-
if args.show_config:
|
| 70 |
-
print("Current ray tracing configuration:")
|
| 71 |
-
raytracing_config = config_manager.get('raytracing', {})
|
| 72 |
-
print(f" Engine: {raytracing_config.get('engine', 'Not set')}")
|
| 73 |
-
print(f" GPU mode: {raytracing_config.get('gpu_config', {}).get('gpu_mode', 'Not set')}")
|
| 74 |
-
print(f" Max parallel jobs: {raytracing_config.get('max_parallel_jobs', 'Not set')}")
|
| 75 |
-
|
| 76 |
-
# Safely get frequency
|
| 77 |
-
frequency = safe_get_frequency(raytracing_config)
|
| 78 |
-
print(f" Frequency: {frequency/1e9:.2f} GHz")
|
| 79 |
-
|
| 80 |
-
# Show visualization configuration
|
| 81 |
-
viz_config = config_manager.get('visualization', {})
|
| 82 |
-
print(f" Heatmap generation: {'Enabled' if viz_config.get('enabled', False) else 'Disabled'}")
|
| 83 |
-
return True
|
| 84 |
-
|
| 85 |
-
# Merge config file and CLI args
|
| 86 |
-
effective_workers = args.max_workers if args.max_workers is not None else config_manager.get(
|
| 87 |
-
'raytracing.max_parallel_jobs', 1
|
| 88 |
-
) or 1
|
| 89 |
-
if args.gpu_mode:
|
| 90 |
-
config_manager.config.setdefault('raytracing', {}).setdefault('gpu_config', {})['gpu_mode'] = args.gpu_mode
|
| 91 |
-
config_manager.config.setdefault('raytracing', {}).setdefault('gpu_config', {})
|
| 92 |
-
config_manager.config['raytracing']['max_parallel_jobs'] = effective_workers
|
| 93 |
-
|
| 94 |
-
# Ensure visualization config exists
|
| 95 |
-
if 'visualization' not in config_manager.config:
|
| 96 |
-
config_manager.config['visualization'] = {
|
| 97 |
-
'enabled': True,
|
| 98 |
-
'point_size': 50,
|
| 99 |
-
'dpi': 300
|
| 100 |
-
}
|
| 101 |
-
|
| 102 |
-
# Fill in minimum samples ratio default
|
| 103 |
-
sim_cfg = config_manager.config.setdefault('raytracing', {}).setdefault('simulation', {})
|
| 104 |
-
sim_cfg.setdefault('min_samples_ratio', 0.5)
|
| 105 |
-
|
| 106 |
-
# Set up logging
|
| 107 |
-
log_file = args.log_file or 'logs/raytracing.log'
|
| 108 |
-
ensure_directory_exists('logs')
|
| 109 |
-
set_log_file(log_file)
|
| 110 |
-
|
| 111 |
-
# Initialize ray tracing manager
|
| 112 |
-
raytracing_manager = RaytracingManager(config_manager)
|
| 113 |
-
|
| 114 |
-
# Discover scenes
|
| 115 |
-
scenes = raytracing_manager.discover_scenes()
|
| 116 |
-
|
| 117 |
-
if args.list_scenes:
|
| 118 |
-
print(f"Found {len(scenes)} available scenes:")
|
| 119 |
-
for scene in scenes:
|
| 120 |
-
print(f" {scene['scene_name']} - ({scene['latitude']:.6f}, {scene['longitude']:.6f})")
|
| 121 |
-
return True
|
| 122 |
-
|
| 123 |
-
if not scenes:
|
| 124 |
-
log_info("No available scene files found")
|
| 125 |
-
return False
|
| 126 |
-
|
| 127 |
-
# Filter scenes
|
| 128 |
-
if args.scene_pattern:
|
| 129 |
-
scenes = [s for s in scenes if args.scene_pattern in s['scene_name']]
|
| 130 |
-
log_info(f"After filtering by pattern '{args.scene_pattern}', {len(scenes)} scenes remain")
|
| 131 |
-
|
| 132 |
-
if args.max_scenes and len(scenes) > args.max_scenes:
|
| 133 |
-
scenes = scenes[:args.max_scenes]
|
| 134 |
-
log_info(f"Limiting number of scenes to process to {args.max_scenes}")
|
| 135 |
-
|
| 136 |
-
# Display configuration info
|
| 137 |
-
raytracing_config = config_manager.get('raytracing', {})
|
| 138 |
-
log_info(f"Starting ray tracing, scene count: {len(scenes)}")
|
| 139 |
-
log_info(f"Engine: {raytracing_config.get('engine', 'sionna')}")
|
| 140 |
-
log_info(f"GPU mode: {raytracing_config.get('gpu_config', {}).get('gpu_mode', 'auto')}")
|
| 141 |
-
|
| 142 |
-
# Safely get and display frequency
|
| 143 |
-
frequency = safe_get_frequency(raytracing_config)
|
| 144 |
-
log_info(f"Frequency: {frequency/1e9:.2f} GHz")
|
| 145 |
-
log_info(f"Max parallel jobs: {raytracing_config.get('max_parallel_jobs', 1)}")
|
| 146 |
-
|
| 147 |
-
# Execute ray tracing
|
| 148 |
-
results = raytracing_manager.run_batch_raytracing(scenes, max_workers=effective_workers)
|
| 149 |
-
|
| 150 |
-
# Display results
|
| 151 |
-
successful_results = [r for r in results if r['success']]
|
| 152 |
-
log_info(f"Ray tracing completed! Success: {len(successful_results)}/{len(scenes)}")
|
| 153 |
-
|
| 154 |
-
if successful_results:
|
| 155 |
-
log_info("Successfully processed scenes:")
|
| 156 |
-
for result in successful_results:
|
| 157 |
-
scene_name = result['scene_info']['scene_name']
|
| 158 |
-
execution_time = result['execution_time']
|
| 159 |
-
num_paths = result.get('num_paths', 0)
|
| 160 |
-
num_receivers = result.get('num_receivers', 0)
|
| 161 |
-
|
| 162 |
-
log_info(f" {scene_name}: {execution_time:.1f}s, "
|
| 163 |
-
f"{num_receivers} receivers, {num_paths} paths")
|
| 164 |
-
|
| 165 |
-
return len(success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