Problem
The generate_trajectories_programmatic function in gene.py currently only supports sampling OD pairs from the dataset. However, tools/generate_abnormal_od.py and python_pipeline.py are calling it with parameters that don't exist:
num_generate (should be num_gene)
od_list (doesn't exist - function samples instead)
output_file (doesn't exist - function creates its own output path)
This causes TypeError: generate_trajectories_programmatic() got an unexpected keyword argument 'num_generate' when running the abnormal OD workflow.
Current Behavior
The function currently:
- Samples OD pairs from dataset based on
od_source and num_gene
- Uses
od_to_train_indices or od_to_test_indices to get timestamps
- Generates trajectories for sampled pairs
- Creates output file with auto-generated path
Desired Behavior
Extend the function to support:
- Custom OD pairs: Accept optional
od_list parameter (List[Tuple[int, int]])
- Custom output path: Accept optional
output_file parameter (Path or str)
- Backward compatibility: When
od_list is None, use current sampling behavior
- Validation: Validate that custom OD pairs are valid (destinations are reachable)
Use Cases
- Abnormal OD workflow: Generate trajectories for specific abnormal OD pairs
- Targeted testing: Test models on specific challenging OD pairs
- Cross-dataset evaluation: Generate for OD pairs from different dataset
Implementation Approach
- Add optional parameters:
od_list: Optional[List[Tuple[int, int]]] = None, output_file: Optional[Union[Path, str]] = None
- When
od_list is provided, use it instead of sampling
- When
output_file is provided, use it instead of auto-generating path
- Validate custom OD pairs against reachable destinations
- Handle timestamp selection for custom OD pairs (use fallback if OD not in dataset)
Testing
Create comprehensive pytest tests in tests/test_generate_trajectories_programmatic.py:
- Test function signature and parameter validation
- Test backward compatibility (sampling mode)
- Test custom OD pairs mode
- Test custom output file path
- Test validation of invalid OD pairs
- Test integration with abnormal OD workflow
Related Code
gene.py:1821 - generate_trajectories_programmatic function
tools/generate_abnormal_od.py:139 - Current incorrect call
python_pipeline.py:1867 - Another incorrect call
Problem
The
generate_trajectories_programmaticfunction ingene.pycurrently only supports sampling OD pairs from the dataset. However,tools/generate_abnormal_od.pyandpython_pipeline.pyare calling it with parameters that don't exist:num_generate(should benum_gene)od_list(doesn't exist - function samples instead)output_file(doesn't exist - function creates its own output path)This causes
TypeError: generate_trajectories_programmatic() got an unexpected keyword argument 'num_generate'when running the abnormal OD workflow.Current Behavior
The function currently:
od_sourceandnum_geneod_to_train_indicesorod_to_test_indicesto get timestampsDesired Behavior
Extend the function to support:
od_listparameter (List[Tuple[int, int]])output_fileparameter (Path or str)od_listis None, use current sampling behaviorUse Cases
Implementation Approach
od_list: Optional[List[Tuple[int, int]]] = None,output_file: Optional[Union[Path, str]] = Noneod_listis provided, use it instead of samplingoutput_fileis provided, use it instead of auto-generating pathTesting
Create comprehensive pytest tests in
tests/test_generate_trajectories_programmatic.py:Related Code
gene.py:1821-generate_trajectories_programmaticfunctiontools/generate_abnormal_od.py:139- Current incorrect callpython_pipeline.py:1867- Another incorrect call