Skip to content

Conversation

@FlxPo
Copy link
Contributor

@FlxPo FlxPo commented Feb 4, 2026

This PR adds crash-safe checkpointing and automatic resume to PopulationTrips, improves determinism when resuming by rehydrating the congestion snapshot pointer, and introduces optional debug logging for the congestion pipeline. It also fixes a regex escape warning.

Motivation

  • Long PopulationTrips runs can crash mid-iteration; restarting from scratch is expensive.
  • Resume must be deterministic: after restart, the in-memory “current congestion snapshot” pointer must be restored or results can diverge.
  • Investigating congestion-related instabilities needs better observability.

Changes

  • Checkpointing + auto-resume

    • PopulationTrips now saves a checkpoint after each completed iteration (current states, remaining sinks, RNG state).
    • On start, if checkpoints exist for the same run key, the model resumes from the latest completed iteration.
    • Temp folders are preserved on resume; partial artifacts beyond the checkpoint are pruned.
  • Checkpoint lifecycle integrated with remove

    • PopulationTrips.remove(remove_checkpoints=True) deletes output caches and the checkpoints for that specific run key (weekday + weekend).
  • Clean resume helpers

    • Added mobility/choice_models/population_trips_resume.py to keep population_trips.py readable:
      • compute_resume_plan
      • try_load_checkpoint
      • restore_state_or_fresh_start
      • prune_tmp_artifacts
      • rehydrate_congestion_snapshot
    • Added Google-style docstrings for these helpers.
    • Added log lines to make the resume decision visible (“No checkpoint found…” / “Latest checkpoint found…”).
  • Deterministic congestion resume (clean API)

    • Added PathTravelCosts.apply_flow_snapshot(flow_asset) and refactored snapshot application behind _apply_flow_snapshot(...).
    • Resume now calls apply_flow_snapshot(...) instead of doing a dummy update(...) call with empty flows.
  • Optional congestion debug logs

    • When MOBILITY_DEBUG_CONGESTION=1, logs include:
      • flow asset cache hits/writes with hashes and row counts
      • snapshot selection paths/hashes
      • congested graph/cost snapshot cache hits/builds
  • Minor fix

    • Fixed invalid escape regex warning in population_trips.py by using a raw string: r"\S+/public_transport/\S+".

@codecov
Copy link

codecov bot commented Feb 4, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 70.42%. Comparing base (c8c3ac3) to head (00dc3fb).
⚠️ Report is 2 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #261   +/-   ##
=======================================
  Coverage   70.42%   70.42%           
=======================================
  Files          56       56           
  Lines        2424     2424           
=======================================
  Hits         1707     1707           
  Misses        717      717           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant