Checking a model for critical errors

Contents

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_walk()

chkr.connectivity_auto()
# If your network is too large and/or your system does not have sufficient memory, you can perform this test in low-memory mode
chkr.connectivity_auto(low_memory_mode=True)
print(chkr.errors)

# If you used low-memory mode
# print(chkr.auto_network_islands)
['      Your active network is disconnected. There are 3 islands', '      There are 9 nodes disconnected from the main active network portion.', '        Found 3 islands', 'All disconnected: {3112, 3145, 3562, 3563, 2604, 2605, 2607, 3192, 2621}', {3112, 3145, 3562, 3563, 2604, 2605, 2607, 3192, 2621}]

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 10.514 seconds)

Gallery generated by Sphinx-Gallery