Conversation
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #289 +/- ##
===========================================
+ Coverage 59.06% 73.25% +14.18%
===========================================
Files 129 143 +14
Lines 6738 6068 -670
===========================================
+ Hits 3980 4445 +465
+ Misses 2758 1623 -1135 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
…ta.cquest.org is down
… avoid circular imports
Mind-the-Cap
left a comment
There was a problem hiding this comment.
Overall, a great improvement! Thanks @FlxPo for the huge work on that.
I'm approving but I would greatly prefer if we kept CarMode, PublicTransportMode, BicycleMode, etc. and WorkActivity, etc., not just Car and Work. It would me much clearer what theses classes are about (modes and activities structured in the very same way). It would avoid future confusion (out of my mind: would Train be a mode specifically for trains, a very precise activity of going to sport trainings, or a future class for machine learning?)
I would be keen to have more precise docstrings in many cases (I highlighted some of them). It would avoid some documentation debt!
| congestion_state: CongestionState | None = None, | ||
| ): | ||
|
|
||
| # Hack to match the current API and compute the GHG emissions from |
There was a problem hiding this comment.
Do we have an issue for that todo?
There was a problem hiding this comment.
Not yet ! For a better separation of concerns, I think we should put impact calculations in specific classes or functions in the new impacts folder.
| .with_columns(exp_u=pl.col("cost").neg().exp()) | ||
| .with_columns(prob=pl.col("exp_u")/pl.col("exp_u").sum().over(["from", "to"])) | ||
|
|
||
| # Keep only the first 99.9 % of the distribution |
There was a problem hiding this comment.
Would it be interesting to have a parameter to control this percentage? Do we know the effect of using 99% or 99.99% instead?
There was a problem hiding this comment.
Yes we could have a parameter. The idea is to prune modes with very low probability.
| iteration=None, | ||
| mode_name: str, | ||
| ): | ||
| """Persist congestion flows as a period-scoped snapshot asset.""" |
There was a problem hiding this comment.
I think I woudl understand better with a more detailed asset.
What's unclear to me:
- what is a snapshot in that context?
- what means period-scoped, and which period?
- what means "persist", notably as the function is called "create"?
There was a problem hiding this comment.
Naming could be improved, I agree ! I dropped all "snapshot" terms in #296 in favor of more explicit terms. Period scoped in this context means the value of flows for a given iteration. They are persisted in a "snapshot" asset at each iteration because we need to be able to resume calculations from the middle of a run.
| from mobility.transport.modes.core.transport_mode import TransportMode | ||
|
|
||
|
|
||
| class GroupDayTrips: |
There was a problem hiding this comment.
I find this name quite unclear to be fair!
There was a problem hiding this comment.
Yes we talked about PopulationGroupsTrips in #155. I wanted to add the concept of time period to differentiate between this population level run for week days and weekends from the individual level run over a year. So I tried PopulationGroupsDayTrips, DemandGroupsDayTrips, PopSegmentDayTrips... But I was trying to avoid long class names for users, so went with GroupDayTrips.
Any suggestions ?
| from ..transitions.transition_metrics import state_waterfall as _state_waterfall | ||
|
|
||
|
|
||
| class RunResults: |
There was a problem hiding this comment.
should probably be a little more precise!
There was a problem hiding this comment.
Can you be more specific ?
|
|
||
|
|
||
| @dataclass | ||
| class RunState: |
There was a problem hiding this comment.
would be great to have a little doc on this class!
| rng_state: object | ||
|
|
||
|
|
||
| class Iteration: |
There was a problem hiding this comment.
this name might be confusing as we have other kinds of interations (notably for congestion)
Motivation
The package and class structure has drifted over time through accumulated PRs. Many of those PRs introduced local changes, new classes, and new files without enough attention to the overall project structure, naming conventions, and core concepts. It's getting difficult to follow the logic of the package, fix bugs, or add new features.
Related issues:
Changes
This PR is a big refactor that redefines the core concepts of the package, and groups the files by conceptual proximity. The modelling workflow remains the same overall: define transport zones, generate a population, derive activity schedules from surveys, compute transport costs, and simulate mobility behaviors iteratively.
The package now uses submodules to have a folder structure that is easier to understand and navigate for users. Even if most previous concepts still exist, a lot of classes were renamed, broken up and moved around, so breaking changes are to be expected.
The project is now organized around the following concepts, aligned as much as possible with mobility and transport science concepts :
mobility.spatial: spatial definition of the model. This module now groups the classes and helpers used to define the study area and its zoning:StudyArea,TransportZones, local administrative units and categories, administrative boundaries, and theosmsubmodule for raw OpenStreetMap extracts and borders. The R script used to prepare transport zones also lives here.mobility.population: population generation and localization. This module contains the mainPopulationclass together with the data assets it depends on, such asCityLegalPopulationandCensusLocalizedIndividuals.mobility.surveys: survey-based behavioural inputs. This module contains the genericMobilitySurveyabstraction, theMobilitySurveyAggregator, and country-specific implementations undersurveys.france(EMP,ENTD).mobility.activities: activity concepts and their opportunity models. We used to call them "motives" because the french mobility survey has a trip oriented terminology, but I think it makes sense to organize our concepts around the activity schedule concept, which is now central in Mobility. The commonActivitybase class is now separated from the concrete activitiesHome,Other,Work,Study,Shop, andLeisure. Activity-specific subpackages group each activity class with the data assets that describe its spatial opportunities and flows, for example jobs for work, schools for studies, shops for shopping, and leisure facilities for leisure.mobility.transport: transport supply and generalized costs. This module is split into three complementary parts:transport.modes: transport mode definitions such asWalk,Bicycle,Car,Carpool, andPublicTransport, plus shared mode concepts incore, choice utilities inchoice, and GTFS / intermodal public transport logic underpublic_transport.transport.graphs: the graph-building pipeline, organized by graph state:simplified,modified,congested,contracted, pluscoregraph utilities.transport.costs: travel cost computation and aggregation, including routing and generalized-cost parameters, path travel costs, congestion-related OD flow assets, and theTransportCostsAggregator.mobility.trips: trip and day-plan generation. This module is now split between:trips.individual_year_trips, for annual trip sampling at the individual level;trips.group_day_trips, for the iterative grouped day-plan model. Insidegroup_day_trips, the code is further organized by role:corefor the mainGroupDayTrips/Runlogic and parameters,plansfor activity, destination and mode sequence construction,iterationsfor persisted iteration state,transitionsfor congestion and transition metrics, andevaluationfor result analysis.mobility.impacts: post-processing of transport impacts. This module groups the carbon-related logic, includingcarbon_computation, default GHG values, and the ADEME Base Carbone integration.mobility.runtime: technical infrastructure that supports the domain modules. This module now isolates the package internals that are not mobility concepts themselves: cachedAssetabstractions (asset,file_asset,in_memory_asset), file download and I/O helpers, R integration, and bundled static resources used at runtime.At the package root, the remaining files are limited to package entry points and configuration:
__init__.pyexposes the public API, andconfig.pycontainsset_paramsand environment setup.Breaking changes
mobility.Car), but direct imports based on the previous file structure will likely need to be updated.mobility.spatial,mobility.activities,mobility.transport,mobility.trips,mobility.population,mobility.surveys,mobility.impacts, andmobility.runtime.motives,parsers,transport_modes,transport_graphs,transport_costs,study_area, andtransport_zoneswere reorganized and may need to be updated.PopulationTripsbecomesGroupDayTrips, which is a wrapper around a weekdayRunand an optional weekendRun. EachRunexposes outputs and evaluation methods similar to those previously associated withPopulationTrips.TripsbecomesIndividualYearTrips.Motiveclasses becomeActivityclasses.CarModebecomesCar, and activity classes now use names such asHome,Work,Study,Shop,Leisure, andOther.experiments/folder when they were kept for reference.set_paramsis still available asmobility.set_params, but the underlying module is nowmobility.configinstead ofmobility.set_paramsfor direct imports.Example
From the quickstart :
AI-assisted contribution
Select one:
If substantial, briefly describe:
Checklist