Note
Go to the end to download the full example code.
Checking a model for critical errors#
When creating and editing supply models in Polaris, it is useful to check for potential errors that would surface when running simulations, as that can help prevent crashes multiple hours into a simulation run.
This example shows how to check a supply model for critical errors and basic connectivity testing
Imports#
# Figure out where our polaris directory is (so we can get some test data)
from pathlib import Path
from polaris import Polaris
from polaris.utils.testing.temp_model import TempModel
Open the project and get the Network object for checking sphinx_gallery_thumbnail_path = ‘../../examples/model_building/checking_cartoon.svg’
project = Polaris.from_dir(TempModel("Bloomington"))
supply = project.network
2025-05-09 02:18:50 UTC+0000 - Upgrading Freight database at location /tmp/polaris_studio_testing/2025-05-09_02-18-49--0754/Bloomington-Freight.sqlite
2025-05-09 02:18:50 UTC+0000 - Upgrading Demand database at location /tmp/polaris_studio_testing/2025-05-09_02-18-49--0754/Bloomington-Demand.sqlite
2025-05-09 02:18:50 UTC+0000 - Upgrading Supply database at location /tmp/polaris_studio_testing/2025-05-09_02-18-49--0754/Bloomington-Supply.sqlite
/venv-py312/lib/python3.12/site-packages/geopandas/_compat.py:7: DeprecationWarning: The 'shapely.geos' module is deprecated, and will be removed in a future version. All attributes of 'shapely.geos' are available directly from the top-level 'shapely' namespace (since shapely 2.0.0).
import shapely.geos
2025-05-09 02:18:51 UTC+0000 - Working with file on /tmp/polaris_studio_testing/2025-05-09_02-18-49--0754/Bloomington-Supply.sqlite
2025-05-09 02:18:51 UTC+0000 - Creating active links for your network
The most important check, one that Polaris-Studio performs at the beginning of every convergence run, is the critical tests
chkr = supply.checker
chkr.critical()
print(chkr.errors)
[]
But connectivity tests are also critical to prevent mid-simulation crashes For more detail please refer to https://polaris.taps.anl.gov/polaris-studio/supply/network_checker.html
chkr.connectivity_auto()
print(chkr.errors)
# If you used low-memory mode
# print(chkr.auto_network_islands)
[]
The network still doesn’t have zones, locations or other things, so we won;t bother about running consistency checks
supply.close(clear_issues=False)
2025-05-09 02:18:52 UTC+0000 - Creating active links for your network
2025-05-09 02:18:52 UTC+0000 - Network closed at /tmp/polaris_studio_testing/2025-05-09_02-18-49--0754/Bloomington-Supply.sqlite
Total running time of the script: (0 minutes 2.818 seconds)