Skip to content

Commit ea8c323

Browse files
JoeJimFloodjpn--
andauthored
RuntimeError consolidation (#1000)
* Added new exceptions based on RuntimeError inventory results * Changed RuntimeErrors in abm\models * Corrected name of SystemConfigurationError * Updated RuntimeErrors in abm\tables * Added SubprocessError * Updated RuntimeErrors in core directory * Renamed `TableSliceError` to `TableSlicingError` * Classified RuntimeErrors in input and settings checkers as ModelConfigurationErrors * Created `SegmentedSpecificationError` for when there's an issue with a spec table that's created for a specific segment * Added TableIndexError * Classified RuntimeError in initialize_tours as InputPopulationError * Created EstimationDataError * Improved clarity of a couple error messages * Blacken code * Updated code to reflect older version of Black (22.12.0) * Updated error messages to look for in activitysim.core tests * Updated error to look for in abm.text * Changed SystemConfigurationError to TableSlicingError in test * Reclasified error when a step is run more than once from TableSlicingError to DuplicateWorkflowNameError * Renamed InputPopulationError to InputTableError for clarity as it can be raised if tours are being input --------- Co-authored-by: Jeffrey Newman <[email protected]>
1 parent 335111b commit ea8c323

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+322
-174
lines changed

activitysim/abm/models/disaggregate_accessibility.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -622,9 +622,11 @@ def create_proto_pop(self):
622622

623623
# Create ID columns, defaults to "%tablename%_id"
624624
hhid, perid, tourid = (
625-
self.params[x]["index_col"]
626-
if len(self.params[x]["index_col"]) > 0
627-
else x + "_id"
625+
(
626+
self.params[x]["index_col"]
627+
if len(self.params[x]["index_col"]) > 0
628+
else x + "_id"
629+
)
628630
for x in klist
629631
)
630632

activitysim/abm/models/initialize_tours.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from activitysim.core import expressions, tracing, workflow
1111
from activitysim.core.configuration import PydanticReadable
1212
from activitysim.core.configuration.base import PreprocessorSettings
13+
from activitysim.core.exceptions import InputTableError
1314
from activitysim.core.input import read_input_table
1415

1516
logger = logging.getLogger(__name__)
@@ -140,7 +141,7 @@ def initialize_tours(
140141
f"{tours_without_persons.sum()} tours out of {len(persons)} without persons\n"
141142
f"{pd.Series({'person_id': tours_without_persons.index.values})}"
142143
)
143-
raise RuntimeError(f"{tours_without_persons.sum()} tours with bad person_id")
144+
raise InputTableError(f"{tours_without_persons.sum()} tours with bad person_id")
144145

145146
if trace_hh_id:
146147
state.tracing.trace_df(tours, label="initialize_tours", warn_if_empty=True)

activitysim/abm/models/input_checker.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
from activitysim.core import workflow
1515
from activitysim.core.input import read_input_table
16+
from activitysim.core.exceptions import ModelConfigurationError
1617

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

469470
if input_check_failure:
470471
logger.error("Run is killed due to input checker failure!!")
471-
raise RuntimeError(
472+
raise ModelConfigurationError(
472473
"Encountered error in input checker, see input_checker.log for details"
473474
)

activitysim/abm/models/joint_tour_participation.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
from activitysim.core.configuration.base import ComputeSettings, PreprocessorSettings
2222
from activitysim.core.configuration.logit import LogitComponentSettings
2323
from activitysim.core.util import assign_in_place, reindex
24+
from activitysim.core.exceptions import InvalidTravelError
2425

2526
logger = logging.getLogger(__name__)
2627

@@ -218,11 +219,11 @@ def participants_chooser(
218219
non_choice_col = [col for col in probs.columns if col != choice_col][0]
219220
probs[non_choice_col] = 1 - probs[choice_col]
220221
if iter > MAX_ITERATIONS + 1:
221-
raise RuntimeError(
222+
raise InvalidTravelError(
222223
f"{num_tours_remaining} tours could not be satisfied even with forcing participation"
223224
)
224225
else:
225-
raise RuntimeError(
226+
raise InvalidTravelError(
226227
f"{num_tours_remaining} tours could not be satisfied after {iter} iterations"
227228
)
228229

activitysim/abm/models/location_choice.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
from activitysim.core.interaction_sample import interaction_sample
1919
from activitysim.core.interaction_sample_simulate import interaction_sample_simulate
2020
from activitysim.core.util import reindex
21+
from activitysim.core.exceptions import DuplicateWorkflowTableError
2122

2223
"""
2324
The school/workplace location model predicts the zones in which various people will
@@ -1125,7 +1126,7 @@ def iterate_location_choice(
11251126
assert len(save_sample_df.index.get_level_values(0).unique()) == len(choices_df)
11261127
# lest they try to put school and workplace samples into the same table
11271128
if state.is_table(sample_table_name):
1128-
raise RuntimeError(
1129+
raise DuplicateWorkflowTableError(
11291130
"dest choice sample table %s already exists" % sample_table_name
11301131
)
11311132
state.extend_table(sample_table_name, save_sample_df)

activitysim/abm/models/parking_location_choice.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
from activitysim.core.interaction_sample_simulate import interaction_sample_simulate
2424
from activitysim.core.tracing import print_elapsed_time
2525
from activitysim.core.util import assign_in_place, drop_unused_columns
26+
from activitysim.core.exceptions import DuplicateWorkflowTableError
2627

2728
logger = logging.getLogger(__name__)
2829

@@ -500,7 +501,9 @@ def parking_location(
500501

501502
# lest they try to put tour samples into the same table
502503
if state.is_table(sample_table_name):
503-
raise RuntimeError("sample table %s already exists" % sample_table_name)
504+
raise DuplicateWorkflowTableError(
505+
"sample table %s already exists" % sample_table_name
506+
)
504507
state.extend_table(sample_table_name, save_sample_df)
505508

506509
expressions.annotate_tables(

activitysim/abm/models/settings_checker.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
eval_nest_coefficients,
2222
read_model_coefficient_template,
2323
)
24+
from activitysim.core.exceptions import ModelConfigurationError
2425

2526
# import model settings
2627
from activitysim.abm.models.accessibility import AccessibilitySettings
@@ -760,7 +761,7 @@ def check_model_settings(
760761
for e in all_errors:
761762
logger.error(f"\t{str(e)}")
762763
file_logger.error(f"\t{str(e)}")
763-
raise RuntimeError(
764+
raise ModelConfigurationError(
764765
f"Encountered one or more errors in settings checker. See f{log_file} for details."
765766
)
766767
msg = f"Setting Checker Complete. No runtime errors were raised. Check f{log_file} for warnings. These *may* prevent model from successfully running."

activitysim/abm/models/trip_departure_choice.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
from activitysim.core.skim_dataset import SkimDataset
2828
from activitysim.core.skim_dictionary import SkimDict
2929
from activitysim.core.util import reindex
30+
from activitysim.core.exceptions import SegmentedSpecificationError
3031

3132
logger = logging.getLogger(__name__)
3233

@@ -219,7 +220,7 @@ def choose_tour_leg_pattern(
219220
)
220221

221222
if len(spec.columns) > 1:
222-
raise RuntimeError("spec must have only one column")
223+
raise SegmentedSpecificationError("spec must have only one column")
223224

224225
# - join choosers and alts
225226
# in vanilla interaction_simulate interaction_df is cross join of choosers and alternatives

activitysim/abm/models/trip_destination.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
from activitysim.core.skim_dictionary import DataFrameMatrix
3636
from activitysim.core.tracing import print_elapsed_time
3737
from activitysim.core.util import assign_in_place, reindex
38+
from activitysim.core.exceptions import InvalidTravelError, DuplicateWorkflowTableError
3839

3940
logger = logging.getLogger(__name__)
4041

@@ -1668,7 +1669,7 @@ def trip_destination(
16681669
# testing feature t0 make sure at least one trip fails so trip_purpose_and_destination model is run
16691670
if state.settings.testing_fail_trip_destination and not trips_df.failed.any():
16701671
if (trips_df.trip_num < trips_df.trip_count).sum() == 0:
1671-
raise RuntimeError(
1672+
raise InvalidTravelError(
16721673
"can't honor 'testing_fail_trip_destination' setting because no intermediate trips"
16731674
)
16741675

@@ -1749,7 +1750,9 @@ def trip_destination(
17491750

17501751
# lest they try to put tour samples into the same table
17511752
if state.is_table(sample_table_name):
1752-
raise RuntimeError("sample table %s already exists" % sample_table_name)
1753+
raise DuplicateWorkflowTableError(
1754+
"sample table %s already exists" % sample_table_name
1755+
)
17531756
state.extend_table(sample_table_name, save_sample_df)
17541757

17551758
expressions.annotate_tables(

activitysim/abm/models/trip_purpose.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
)
2323
from activitysim.core.configuration.base import PreprocessorSettings, PydanticReadable
2424
from activitysim.core.util import reindex
25+
from activitysim.core.exceptions import InvalidTravelError
2526

2627
logger = logging.getLogger(__name__)
2728

@@ -134,7 +135,7 @@ def choose_intermediate_trip_purpose(
134135
state.tracing.write_csv(
135136
unmatched_choosers, file_name=file_name, transpose=False
136137
)
137-
raise RuntimeError(
138+
raise InvalidTravelError(
138139
"Some trips could not be matched to probs based on join columns %s."
139140
% probs_join_cols
140141
)

0 commit comments

Comments
 (0)