Skip to content

Extend generate_trajectories_programmatic to accept custom OD pairs #62

@matercomus

Description

@matercomus

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:

  1. Samples OD pairs from dataset based on od_source and num_gene
  2. Uses od_to_train_indices or od_to_test_indices to get timestamps
  3. Generates trajectories for sampled pairs
  4. Creates output file with auto-generated path

Desired Behavior

Extend the function to support:

  1. Custom OD pairs: Accept optional od_list parameter (List[Tuple[int, int]])
  2. Custom output path: Accept optional output_file parameter (Path or str)
  3. Backward compatibility: When od_list is None, use current sampling behavior
  4. 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

  1. Add optional parameters: od_list: Optional[List[Tuple[int, int]]] = None, output_file: Optional[Union[Path, str]] = None
  2. When od_list is provided, use it instead of sampling
  3. When output_file is provided, use it instead of auto-generating path
  4. Validate custom OD pairs against reachable destinations
  5. 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions