Skip to content
3 changes: 2 additions & 1 deletion activitysim/abm/models/input_checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

from activitysim.core import workflow
from activitysim.core.input import read_input_table
from activitysim.core.exceptions import ModelConfigurationError

logger = logging.getLogger(__name__)
file_logger = logger.getChild("logfile")
Expand Down Expand Up @@ -468,6 +469,6 @@ def input_checker(state: workflow.State):

if input_check_failure:
logger.error("Run is killed due to input checker failure!!")
raise RuntimeError(
raise ModelConfigurationError(
"Encountered error in input checker, see input_checker.log for details"
)
5 changes: 3 additions & 2 deletions activitysim/abm/models/joint_tour_participation.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
from activitysim.core.configuration.base import ComputeSettings, PreprocessorSettings
from activitysim.core.configuration.logit import LogitComponentSettings
from activitysim.core.util import assign_in_place, reindex
from activitysim.core.exceptions import InvalidTravelError

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -218,11 +219,11 @@ def participants_chooser(
non_choice_col = [col for col in probs.columns if col != choice_col][0]
probs[non_choice_col] = 1 - probs[choice_col]
if iter > MAX_ITERATIONS + 1:
raise RuntimeError(
raise InvalidTravelError(
f"{num_tours_remaining} tours could not be satisfied even with forcing participation"
)
else:
raise RuntimeError(
raise InvalidTravelError(
f"{num_tours_remaining} tours could not be satisfied after {iter} iterations"
)

Expand Down
3 changes: 2 additions & 1 deletion activitysim/abm/models/location_choice.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from activitysim.core.interaction_sample import interaction_sample
from activitysim.core.interaction_sample_simulate import interaction_sample_simulate
from activitysim.core.util import reindex
from activitysim.core.exceptions import DuplicateWorkflowTableError

"""
The school/workplace location model predicts the zones in which various people will
Expand Down Expand Up @@ -1125,7 +1126,7 @@ def iterate_location_choice(
assert len(save_sample_df.index.get_level_values(0).unique()) == len(choices_df)
# lest they try to put school and workplace samples into the same table
if state.is_table(sample_table_name):
raise RuntimeError(
raise DuplicateWorkflowTableError(
"dest choice sample table %s already exists" % sample_table_name
)
state.extend_table(sample_table_name, save_sample_df)
Expand Down
3 changes: 2 additions & 1 deletion activitysim/abm/models/parking_location_choice.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
from activitysim.core.interaction_sample_simulate import interaction_sample_simulate
from activitysim.core.tracing import print_elapsed_time
from activitysim.core.util import assign_in_place, drop_unused_columns
from activitysim.core.exceptions import DuplicateWorkflowTableError

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -500,7 +501,7 @@ def parking_location(

# lest they try to put tour samples into the same table
if state.is_table(sample_table_name):
raise RuntimeError("sample table %s already exists" % sample_table_name)
raise DuplicateWorkflowTableError("sample table %s already exists" % sample_table_name)
state.extend_table(sample_table_name, save_sample_df)

expressions.annotate_tables(
Expand Down
3 changes: 2 additions & 1 deletion activitysim/abm/models/settings_checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
eval_nest_coefficients,
read_model_coefficient_template,
)
from activitysim.core.exceptions import ModelConfigurationError

# import model settings
from activitysim.abm.models.accessibility import AccessibilitySettings
Expand Down Expand Up @@ -760,7 +761,7 @@ def check_model_settings(
for e in all_errors:
logger.error(f"\t{str(e)}")
file_logger.error(f"\t{str(e)}")
raise RuntimeError(
raise ModelConfigurationError(
f"Encountered one or more errors in settings checker. See f{log_file} for details."
)
msg = f"Setting Checker Complete. No runtime errors were raised. Check f{log_file} for warnings. These *may* prevent model from successfully running."
Expand Down
3 changes: 2 additions & 1 deletion activitysim/abm/models/trip_departure_choice.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
from activitysim.core.skim_dataset import SkimDataset
from activitysim.core.skim_dictionary import SkimDict
from activitysim.core.util import reindex
from activitysim.core.exceptions import SegmentedSpecificationError

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -219,7 +220,7 @@ def choose_tour_leg_pattern(
)

if len(spec.columns) > 1:
raise RuntimeError("spec must have only one column")
raise SegmentedSpecificationError("spec must have only one column")

# - join choosers and alts
# in vanilla interaction_simulate interaction_df is cross join of choosers and alternatives
Expand Down
5 changes: 3 additions & 2 deletions activitysim/abm/models/trip_destination.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
from activitysim.core.skim_dictionary import DataFrameMatrix
from activitysim.core.tracing import print_elapsed_time
from activitysim.core.util import assign_in_place, reindex
from activitysim.core.exceptions import InvalidTravelError, DuplicateWorkflowTableError

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -1664,7 +1665,7 @@ def trip_destination(
# testing feature t0 make sure at least one trip fails so trip_purpose_and_destination model is run
if state.settings.testing_fail_trip_destination and not trips_df.failed.any():
if (trips_df.trip_num < trips_df.trip_count).sum() == 0:
raise RuntimeError(
raise InvalidTravelError(
"can't honor 'testing_fail_trip_destination' setting because no intermediate trips"
)

Expand Down Expand Up @@ -1745,7 +1746,7 @@ def trip_destination(

# lest they try to put tour samples into the same table
if state.is_table(sample_table_name):
raise RuntimeError("sample table %s already exists" % sample_table_name)
raise DuplicateWorkflowTableError("sample table %s already exists" % sample_table_name)
state.extend_table(sample_table_name, save_sample_df)

expressions.annotate_tables(
Expand Down
3 changes: 2 additions & 1 deletion activitysim/abm/models/trip_purpose.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
)
from activitysim.core.configuration.base import PreprocessorSettings, PydanticReadable
from activitysim.core.util import reindex
from activitysim.core.exceptions import InvalidTravelError

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -134,7 +135,7 @@ def choose_intermediate_trip_purpose(
state.tracing.write_csv(
unmatched_choosers, file_name=file_name, transpose=False
)
raise RuntimeError(
raise InvalidTravelError(
"Some trips could not be matched to probs based on join columns %s."
% probs_join_cols
)
Expand Down
5 changes: 3 additions & 2 deletions activitysim/abm/models/trip_scheduling.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from activitysim.core import chunk, config, estimation, expressions, tracing, workflow
from activitysim.core.configuration.base import PreprocessorSettings, PydanticReadable
from activitysim.core.util import reindex
from activitysim.core.exceptions import InvalidTravelError, PipelineError

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -615,7 +616,7 @@ def trip_scheduling(
logger.info("%s %s failed", trace_label_i, failed.sum())

if (failed.sum() > 0) & (model_settings.scheduling_mode == "relative"):
raise RuntimeError("failed trips with relative scheduling mode")
raise InvalidTravelError("failed trips with relative scheduling mode")

if not is_last_iteration:
# boolean series of trips whose leg scheduling failed
Expand Down Expand Up @@ -653,7 +654,7 @@ def trip_scheduling(
)

if failfix != FAILFIX_DROP_AND_CLEANUP:
raise RuntimeError(
raise PipelineError(
"%s setting '%s' not enabled in settings"
% (FAILFIX, FAILFIX_DROP_AND_CLEANUP)
)
Expand Down
7 changes: 4 additions & 3 deletions activitysim/abm/models/util/cdap.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

from activitysim.core import chunk, logit, simulate, tracing, workflow
from activitysim.core.configuration.base import ComputeSettings
from activitysim.core.exceptions import ModelConfigurationError

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -48,7 +49,7 @@ def add_pn(col, pnum):
elif isinstance(col, (list, tuple)):
return [c if c == _hh_id_ else "%s_p%s" % (c, pnum) for c in col]
else:
raise RuntimeError("add_pn col not list or str")
raise TypeError("add_pn col not list or str")


def assign_cdap_rank(
Expand Down Expand Up @@ -270,7 +271,7 @@ def preprocess_interaction_coefficients(interaction_coefficients):
"Error in cdap_interaction_coefficients at row %s. Expect only M, N, or H!"
% coefficients[~coefficients["activity"].isin(["M", "N", "H"])].index.values
)
raise RuntimeError(msg)
raise ModelConfigurationError(msg)

coefficients["cardinality"] = (
coefficients["interaction_ptypes"].astype(str).str.len()
Expand Down Expand Up @@ -470,7 +471,7 @@ def build_cdap_spec(
continue

if not (0 <= row.cardinality <= MAX_INTERACTION_CARDINALITY):
raise RuntimeError(
raise ModelConfigurationError(
"Bad row cardinality %d for %s" % (row.cardinality, row.slug)
)

Expand Down
3 changes: 2 additions & 1 deletion activitysim/abm/models/util/probabilistic_scheduling.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import pandas as pd

from activitysim.core import chunk, logit, tracing, workflow
from activitysim.core.exceptions import InvalidTravelError

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -210,7 +211,7 @@ def _postprocess_scheduling_choices(

if scheduling_mode == "relative":
if failed.any():
RuntimeError(
InvalidTravelError(
f"Failed trips in realtive mode for {failed.sum()} trips: {choosers[failed]}"
)

Expand Down
2 changes: 1 addition & 1 deletion activitysim/abm/models/util/vectorize_tour_scheduling.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def skims_for_logsums(
elif isinstance(destination_for_tour_purpose, dict):
dest_col_name = destination_for_tour_purpose.get(tour_purpose)
else:
raise RuntimeError(
raise TypeError(
f"expected string or dict DESTINATION_FOR_TOUR_PURPOSE model_setting for {tour_purpose}"
)

Expand Down
3 changes: 2 additions & 1 deletion activitysim/abm/tables/households.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from activitysim.abm.tables.util import simple_table_join
from activitysim.core import tracing, workflow
from activitysim.core.input import read_input_table
from activitysim.core.exceptions import MissingInputTableDefinition

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -45,7 +46,7 @@ def households(state: workflow.State) -> pd.DataFrame:
)

if df.shape[0] == 0:
raise RuntimeError("No override households found in store")
raise MissingInputTableDefinition("No override households found in store")

# if we are tracing hh exclusively
elif _trace_hh_id and households_sample_size == 1:
Expand Down
7 changes: 4 additions & 3 deletions activitysim/abm/tables/persons.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from activitysim.abm.tables.util import simple_table_join
from activitysim.core import workflow
from activitysim.core.input import read_input_table
from activitysim.core.exceptions import InputPopulationError

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -55,7 +56,7 @@ def persons(state: workflow.State) -> pd.DataFrame:
f"{persons_without_households.sum()} persons out of {len(df)} without households\n"
f"{pd.Series({'person_id': persons_without_households.index.values})}"
)
raise RuntimeError(
raise InputPopulationError(
f"{persons_without_households.sum()} persons with bad household_id"
)

Expand All @@ -67,7 +68,7 @@ def persons(state: workflow.State) -> pd.DataFrame:
f"{households_without_persons.sum()} households out of {len(households.index)} without persons\n"
f"{pd.Series({'household_id': households_without_persons.index.values})}"
)
raise RuntimeError(
raise InputPopulationError(
f"{households_without_persons.sum()} households with no persons"
)

Expand Down Expand Up @@ -107,5 +108,5 @@ def persons_merged(
left_on="person_id",
)
if n_persons != len(persons):
raise RuntimeError("number of persons changed")
raise InputPopulationError("number of persons changed")
return persons
21 changes: 11 additions & 10 deletions activitysim/abm/tables/shadow_pricing.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from activitysim.core.configuration import PydanticReadable
from activitysim.core.configuration.logit import TourLocationComponentSettings
from activitysim.core.input import read_input_table
from activitysim.core.exceptions import SystemConfigurationError, MissingNameError

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -181,7 +182,7 @@ def __init__(
logger.warning(
"deprecated combination of multiprocessing and not fail_fast"
)
raise RuntimeError(
raise SystemConfigurationError(
"Shadow pricing requires fail_fast setting in multiprocessing mode"
)

Expand Down Expand Up @@ -904,7 +905,7 @@ def update_shadow_prices(self, state):
self.sampled_persons = sampled_persons

else:
raise RuntimeError("unknown SHADOW_PRICE_METHOD %s" % shadow_price_method)
raise SystemConfigurationError("unknown SHADOW_PRICE_METHOD %s, method must be one of 'ctramp', 'daysim', or 'simulation'" % shadow_price_method)

def dest_size_terms(self, segment):
assert segment in self.segment_ids
Expand All @@ -922,8 +923,8 @@ def dest_size_terms(self, segment):
elif shadow_price_method == "simulation":
utility_adjustment = self.shadow_prices[segment]
else:
raise RuntimeError(
"unknown SHADOW_PRICE_METHOD %s" % shadow_price_method
raise SystemConfigurationError(
"unknown SHADOW_PRICE_METHOD %s, method must be one of 'ctramp', 'daysim', or 'simulation'" % shadow_price_method
)

size_terms = pd.DataFrame(
Expand Down Expand Up @@ -1036,7 +1037,7 @@ def buffers_for_shadow_pricing(shadow_pricing_info):
if np.issubdtype(dtype, np.int64):
typecode = ctypes.c_int64
else:
raise RuntimeError(
raise TypeError(
"buffer_for_shadow_pricing unrecognized dtype %s" % dtype
)

Expand Down Expand Up @@ -1085,7 +1086,7 @@ def buffers_for_shadow_pricing_choice(state, shadow_pricing_choice_info):
if np.issubdtype(dtype, np.int64):
typecode = ctypes.c_int64
else:
raise RuntimeError(
raise TypeError(
"buffer_for_shadow_pricing unrecognized dtype %s" % dtype
)

Expand Down Expand Up @@ -1145,12 +1146,12 @@ def shadow_price_data_from_buffers_choice(
block_shapes = shadow_pricing_info["block_shapes"]

if model_selector not in block_shapes:
raise RuntimeError(
raise MissingNameError(
"Model selector %s not in shadow_pricing_info" % model_selector
)

if block_name(model_selector + "_choice") not in data_buffers:
raise RuntimeError(
raise MissingNameError(
"Block %s not in data_buffers" % block_name(model_selector + "_choice")
)

Expand Down Expand Up @@ -1195,12 +1196,12 @@ def shadow_price_data_from_buffers(data_buffers, shadow_pricing_info, model_sele
block_shapes = shadow_pricing_info["block_shapes"]

if model_selector not in block_shapes:
raise RuntimeError(
raise MissingNameError(
"Model selector %s not in shadow_pricing_info" % model_selector
)

if block_name(model_selector) not in data_buffers:
raise RuntimeError("Block %s not in data_buffers" % block_name(model_selector))
raise MissingNameError("Block %s not in data_buffers" % block_name(model_selector))

shape = block_shapes[model_selector]
data = data_buffers[block_name(model_selector)]
Expand Down
5 changes: 3 additions & 2 deletions activitysim/core/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from activitysim.core import workflow
from activitysim.core.configuration.base import PydanticBase
from activitysim.core.configuration.logit import LogitComponentSettings
from activitysim.core.exceptions import ModelConfigurationError

# ActivitySim
# See full license in LICENSE.txt.
Expand Down Expand Up @@ -123,13 +124,13 @@ def get_logit_model_settings(

if logit_type not in ["NL", "MNL"]:
logger.error("Unrecognized logit type '%s'" % logit_type)
raise RuntimeError("Unrecognized logit type '%s'" % logit_type)
raise ModelConfigurationError("Unrecognized logit type '%s'. Logit type must be 'NL' for nested logit or 'MNL' for multinomial logit" % logit_type)

if logit_type == "NL":
nests = model_settings.get("NESTS", None)
if nests is None:
logger.error("No NEST found in model spec for NL model type")
raise RuntimeError("No NEST found in model spec for NL model type")
raise ModelConfigurationError("No NEST found in model spec for NL model type")

return nests

Expand Down
Loading
Loading