Compares two models

Compares two models#

In this example we show how to use polaris testing capabilities for comparing two different networks

import shutil
from pathlib import Path

from polaris import Polaris
from polaris.utils.testing.model_comparison.compare_databases import compare_databases
from polaris.utils.testing.temp_model import TempModel


# Let's copy the model we have available for testing
model_path1 = TempModel("Grid")
model_path2 = Path("/tmp/Grid_model_comparison")
if model_path2.exists():
    shutil.rmtree(model_path2)
shutil.copytree(model_path1, "/tmp/Grid_model_comparison")

project1 = Polaris.from_dir(model_path1)
project2 = Polaris.from_dir(model_path2)
⚠️ Friendly exception handler is disabled via FRIENDLY_ERRORS_DISABLED

We can compare two identical supply files We must provide the path to the supply databases

report = compare_databases(project1.supply_file, project2.supply_file)

for record in report:
    print(record)
2026-06-07 10:08:18 UTC+0000 - about_model
2026-06-07 10:08:18 UTC+0000 - area_type
2026-06-07 10:08:18 UTC+0000 - connection
2026-06-07 10:08:18 UTC+0000 - counties
2026-06-07 10:08:18 UTC+0000 - electricity_grid_transmission
2026-06-07 10:08:18 UTC+0000 - electricity_provider
2026-06-07 10:08:18 UTC+0000 - electricity_provider_pricing
2026-06-07 10:08:18 UTC+0000 - ev_charging_station_plug_types
2026-06-07 10:08:18 UTC+0000 - ev_charging_station_plugs
2026-06-07 10:08:18 UTC+0000 - ev_charging_station_pricing
2026-06-07 10:08:18 UTC+0000 - ev_charging_station_service_bays
2026-06-07 10:08:18 UTC+0000 - ev_charging_stations
2026-06-07 10:08:18 UTC+0000 - geo_consistency_controller
2026-06-07 10:08:18 UTC+0000 - land_use
2026-06-07 10:08:18 UTC+0000 - link
2026-06-07 10:08:18 UTC+0000 - link_overrides
2026-06-07 10:08:18 UTC+0000 - link_type
2026-06-07 10:08:18 UTC+0000 - location
2026-06-07 10:08:18 UTC+0000 - location_attributes
2026-06-07 10:08:18 UTC+0000 - location_links
2026-06-07 10:08:18 UTC+0000 - location_parking
2026-06-07 10:08:18 UTC+0000 - micromobility_agencies
2026-06-07 10:08:18 UTC+0000 - micromobility_docks
2026-06-07 10:08:18 UTC+0000 - micromobility_operators
2026-06-07 10:08:18 UTC+0000 - migrations
2026-06-07 10:08:18 UTC+0000 - node
2026-06-07 10:08:18 UTC+0000 - parking
2026-06-07 10:08:18 UTC+0000 - parking_pricing
2026-06-07 10:08:18 UTC+0000 - parking_rule
2026-06-07 10:08:19 UTC+0000 - phasing
2026-06-07 10:08:19 UTC+0000 - phasing_nested_records
2026-06-07 10:08:19 UTC+0000 - pocket
2026-06-07 10:08:19 UTC+0000 - popsyn_region
2026-06-07 10:08:19 UTC+0000 - restricted_lanes
2026-06-07 10:08:19 UTC+0000 - road_connectors
2026-06-07 10:08:19 UTC+0000 - roadsideunit
2026-06-07 10:08:19 UTC+0000 - sanity_check
2026-06-07 10:08:19 UTC+0000 - settings
2026-06-07 10:08:19 UTC+0000 - sign
2026-06-07 10:08:19 UTC+0000 - signal
2026-06-07 10:08:19 UTC+0000 - signal_nested_records
2026-06-07 10:08:19 UTC+0000 - timing
2026-06-07 10:08:19 UTC+0000 - timing_nested_records
2026-06-07 10:08:19 UTC+0000 - toll_pricing
2026-06-07 10:08:19 UTC+0000 - transit_agencies
2026-06-07 10:08:19 UTC+0000 - transit_bike
2026-06-07 10:08:19 UTC+0000 - transit_fare_attributes
2026-06-07 10:08:19 UTC+0000 - transit_fare_rules
2026-06-07 10:08:19 UTC+0000 - transit_links
2026-06-07 10:08:19 UTC+0000 - transit_modes
2026-06-07 10:08:19 UTC+0000 - transit_pattern_links
2026-06-07 10:08:19 UTC+0000 - transit_pattern_mapping
2026-06-07 10:08:19 UTC+0000 - transit_patterns
2026-06-07 10:08:19 UTC+0000 - transit_routes
2026-06-07 10:08:19 UTC+0000 - transit_stops
2026-06-07 10:08:19 UTC+0000 - transit_trips
2026-06-07 10:08:19 UTC+0000 - transit_trips_schedule
2026-06-07 10:08:19 UTC+0000 - transit_walk
2026-06-07 10:08:19 UTC+0000 - transit_zones
2026-06-07 10:08:19 UTC+0000 - turn_overrides
2026-06-07 10:08:19 UTC+0000 - use_code
2026-06-07 10:08:19 UTC+0000 - weather_impact
2026-06-07 10:08:19 UTC+0000 - zone
**No dropped tables**

**No new tables**

**Tables with no changes**:

about_model, area_type, connection, counties, electricity_grid_transmission, electricity_provider, electricity_provider_pricing, ev_charging_station_plug_types, ev_charging_station_plugs, ev_charging_station_pricing, ev_charging_station_service_bays, ev_charging_stations, geo_consistency_controller, land_use, link, link_overrides, link_type, location, location_attributes, location_links, location_parking, micromobility_agencies, micromobility_docks, micromobility_operators, migrations, node, parking, parking_pricing, parking_rule, phasing, phasing_nested_records, pocket, popsyn_region, restricted_lanes, road_connectors, roadsideunit, sanity_check, settings, sign, signal, signal_nested_records, timing, timing_nested_records, toll_pricing, transit_agencies, transit_bike, transit_fare_attributes, transit_fare_rules, transit_links, transit_modes, transit_pattern_links, transit_pattern_mapping, transit_patterns, transit_routes, transit_stops, transit_trips, transit_trips_schedule, transit_walk, transit_zones, turn_overrides, use_code, weather_impact, zone

Or we can do something drastic like remove all transit data and then compare them

project2.network.transit.purge()

report = compare_databases(project1.supply_file, project2.supply_file)

for record in report:
    print(record)

project1.close()
project2.close()
2026-06-07 10:08:20 UTC+0000 - Working with file on /tmp/Grid_model_comparison/Grid-Supply.sqlite
2026-06-07 10:08:20 UTC+0000 - Clearing transit tables
2026-06-07 10:08:20 UTC+0000 - Table "TRANSIT_RAW_SHAPES" does not exist in the network
2026-06-07 10:08:21 UTC+0000 - about_model
2026-06-07 10:08:21 UTC+0000 - area_type
2026-06-07 10:08:21 UTC+0000 - connection
2026-06-07 10:08:21 UTC+0000 - counties
2026-06-07 10:08:21 UTC+0000 - electricity_grid_transmission
2026-06-07 10:08:21 UTC+0000 - electricity_provider
2026-06-07 10:08:21 UTC+0000 - electricity_provider_pricing
2026-06-07 10:08:21 UTC+0000 - ev_charging_station_plug_types
2026-06-07 10:08:21 UTC+0000 - ev_charging_station_plugs
2026-06-07 10:08:21 UTC+0000 - ev_charging_station_pricing
2026-06-07 10:08:21 UTC+0000 - ev_charging_station_service_bays
2026-06-07 10:08:21 UTC+0000 - ev_charging_stations
2026-06-07 10:08:21 UTC+0000 - geo_consistency_controller
2026-06-07 10:08:21 UTC+0000 - land_use
2026-06-07 10:08:21 UTC+0000 - link
2026-06-07 10:08:21 UTC+0000 - link_overrides
2026-06-07 10:08:21 UTC+0000 - link_type
2026-06-07 10:08:21 UTC+0000 - location
2026-06-07 10:08:21 UTC+0000 - location_attributes
2026-06-07 10:08:21 UTC+0000 - location_links
2026-06-07 10:08:21 UTC+0000 - location_parking
2026-06-07 10:08:21 UTC+0000 - micromobility_agencies
2026-06-07 10:08:21 UTC+0000 - micromobility_docks
2026-06-07 10:08:21 UTC+0000 - micromobility_operators
2026-06-07 10:08:21 UTC+0000 - migrations
2026-06-07 10:08:21 UTC+0000 - node
2026-06-07 10:08:21 UTC+0000 - parking
2026-06-07 10:08:21 UTC+0000 - parking_pricing
2026-06-07 10:08:21 UTC+0000 - parking_rule
2026-06-07 10:08:21 UTC+0000 - phasing
2026-06-07 10:08:21 UTC+0000 - phasing_nested_records
2026-06-07 10:08:21 UTC+0000 - pocket
2026-06-07 10:08:21 UTC+0000 - popsyn_region
2026-06-07 10:08:21 UTC+0000 - restricted_lanes
2026-06-07 10:08:21 UTC+0000 - road_connectors
2026-06-07 10:08:21 UTC+0000 - roadsideunit
2026-06-07 10:08:21 UTC+0000 - sanity_check
2026-06-07 10:08:21 UTC+0000 - settings
2026-06-07 10:08:21 UTC+0000 - sign
2026-06-07 10:08:21 UTC+0000 - signal
2026-06-07 10:08:21 UTC+0000 - signal_nested_records
2026-06-07 10:08:21 UTC+0000 - timing
2026-06-07 10:08:21 UTC+0000 - timing_nested_records
2026-06-07 10:08:21 UTC+0000 - toll_pricing
2026-06-07 10:08:21 UTC+0000 - transit_agencies
2026-06-07 10:08:21 UTC+0000 - transit_bike
2026-06-07 10:08:21 UTC+0000 - transit_fare_attributes
2026-06-07 10:08:22 UTC+0000 - transit_fare_rules
2026-06-07 10:08:22 UTC+0000 - transit_links
2026-06-07 10:08:22 UTC+0000 - transit_modes
2026-06-07 10:08:22 UTC+0000 - transit_pattern_links
2026-06-07 10:08:22 UTC+0000 - transit_pattern_mapping
2026-06-07 10:08:22 UTC+0000 - transit_patterns
2026-06-07 10:08:22 UTC+0000 - transit_routes
2026-06-07 10:08:22 UTC+0000 - transit_stops
2026-06-07 10:08:22 UTC+0000 - transit_trips
2026-06-07 10:08:22 UTC+0000 - transit_trips_schedule
2026-06-07 10:08:22 UTC+0000 - transit_walk
2026-06-07 10:08:22 UTC+0000 - transit_zones
2026-06-07 10:08:22 UTC+0000 - turn_overrides
2026-06-07 10:08:22 UTC+0000 - use_code
2026-06-07 10:08:22 UTC+0000 - weather_impact
2026-06-07 10:08:22 UTC+0000 - zone
**No dropped tables**

**No new tables**

**Tables with no changes**:

about_model, area_type, connection, counties, electricity_grid_transmission, electricity_provider, electricity_provider_pricing, ev_charging_station_plug_types, ev_charging_station_plugs, ev_charging_station_pricing, ev_charging_station_service_bays, ev_charging_stations, land_use, link, link_overrides, link_type, location, location_attributes, location_links, location_parking, micromobility_agencies, micromobility_docks, micromobility_operators, migrations, node, parking, parking_pricing, parking_rule, phasing, phasing_nested_records, pocket, popsyn_region, restricted_lanes, road_connectors, roadsideunit, sanity_check, settings, sign, signal, signal_nested_records, timing, timing_nested_records, toll_pricing, transit_modes, transit_pattern_mapping, turn_overrides, use_code, weather_impact, zone



**Tables with changes**:

geo_consistency_controller:

     * 2 records added to table

transit_agencies:

     * 7 records deleted from table

transit_bike:

     * 530 records deleted from table

transit_fare_attributes:

     * 6 records deleted from table

transit_fare_rules:

     * 18 records deleted from table

transit_links:

     * 46 records deleted from table

transit_pattern_links:

     * 46 records deleted from table

transit_patterns:

     * 15 records deleted from table

transit_routes:

     * 6 records deleted from table

transit_stops:

     * 38 records deleted from table

transit_trips:

     * 3,923 records deleted from table

transit_trips_schedule:

     * 16,743 records deleted from table

transit_walk:

     * 530 records deleted from table

transit_zones:

     * 6 records deleted from table

Total running time of the script: (0 minutes 5.872 seconds)

Gallery generated by Sphinx-Gallery