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#
sphinx_gallery_thumbnail_path = ‘../../examples/model_building/checking_cartoon.svg’
from pathlib import Path
from tempfile import mkdtemp
import pandas as pd
from polaris.network.create.triggers import create_network_triggers, delete_network_triggers
from polaris.network.network import Network
from polaris.utils.database.db_utils import commit_and_close
# Figure out where our polaris directory is (so we can get some test data)
from polaris import __file__ as polaris_dir
from pathlib import Path
from polaris import Polaris
from polaris.network.network import Network
from polaris.runs.convergence.convergence_iteration import ConvergenceIteration
from polaris.runs.scenario_compression import ScenarioCompression
from polaris.utils.database.migration_manager import MigrationManager
from polaris.utils.database.standard_database import DatabaseType
Open the project and get the Network object for checking sphinx_gallery_thumbnail_path = ‘../../examples/model_building/marshalltown.png’
project = Polaris.from_dir(Path("/tmp/Bloomington"))
supply = project.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)
Total running time of the script: (0 minutes 0.359 seconds)