Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 36 additions & 17 deletions activitysim/abm/models/trip_destination.py
Original file line number Diff line number Diff line change
Expand Up @@ -1496,23 +1496,42 @@ def run_trip_destination(
for primary_purpose, trips_segment in nth_trips.groupby(
"primary_purpose", observed=True
):
choices, destination_sample = choose_trip_destination(
state,
primary_purpose,
trips_segment,
alternatives,
tours_merged,
model_settings,
want_logsums,
want_sample_table,
size_term_matrix,
skim_hotel,
estimator,
chunk_size,
trace_label=tracing.extend_trace_label(
nth_trace_label, primary_purpose
),
)
try:
choices, destination_sample = choose_trip_destination(
state,
primary_purpose,
trips_segment,
alternatives,
tours_merged,
model_settings,
want_logsums,
want_sample_table,
size_term_matrix,
skim_hotel,
estimator,
chunk_size,
trace_label=tracing.extend_trace_label(
nth_trace_label, primary_purpose
),
)
except KeyError as err:
if err.args[0] == "purpose_index_num":
logger.error(
"""

When using the trip destination model with sharrow, it is necessary
to set a value for `purpose_index_num` in the trip destination
annotate trips preprocessor. This allows for an optimized compiled
lookup of the size term from the array of size terms. The value of
`purpose_index_num` should be the integer column position in the size
matrix, with usual zero-based numpy indexing semantics (i.e. the first
column is zero). The preprocessor expression most likely needs to be
"size_terms.get_cols(df.purpose)" unless some unusual transform of
size terms has been employed.

"""
)
raise

choices_list.append(choices)
if want_sample_table:
Expand Down
25 changes: 24 additions & 1 deletion activitysim/core/simulate.py
Original file line number Diff line number Diff line change
Expand Up @@ -989,7 +989,7 @@ def to_array(x):
# return utilities


def set_skim_wrapper_targets(df, skims):
def set_skim_wrapper_targets(df, skims, allow_partial_success: bool = True):
"""
Add the dataframe to the SkimWrapper object so that it can be dereferenced
using the parameters of the skims object.
Expand All @@ -1007,6 +1007,11 @@ def set_skim_wrapper_targets(df, skims):
dataframe that comes back from interacting choosers with
alternatives. See the skims module for more documentation on how
the skims object is intended to be used.
allow_partial_success : bool, optional
If True (default), failures to set skim targets for some skim objects
(for example due to missing required columns in `df`) will be collected
and logged as warnings but will not raise an exception. If False, any
such failure will be raised immediately, preventing partial success.
"""

skims = (
Expand All @@ -1016,13 +1021,31 @@ def set_skim_wrapper_targets(df, skims):
if isinstance(skims, dict)
else [skims]
)
problems = []

# assume any object in skims can be treated as a skim
for skim in skims:
try:
skim.set_df(df)
except AttributeError:
# sometimes when passed as a dict, the skims have a few keys given as
# settings or constants, which are not actually "skim" objects and have
# no `set_df` attribute. This is fine and we just let them pass.
pass
except AssertionError as e:
# An assertion error will get triggered if the columns of `df` are
# missing one of the required keys needed to look up values in the
# skims. This may not be a problem, if this particular set of skims
# is not actually used in this model component. So we'll warn about
# it but usually not raise a showstopping error.
problems.append(e)
if not allow_partial_success:
raise

if problems:
# if problems were discovered, log them as warnings
for problem in problems:
logger.warning(str(problem))


#
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ dependencies = [
"requests >= 2.7",
"scikit-learn >= 1.2",
"setuptools>=80.9.0",
"sharrow >= 2.9.1",
"sharrow>=2.15",
"sparse",
"tables >= 3.9", # pytables is tables in pypi
"xarray >= 2024.05",
Expand Down
10 changes: 5 additions & 5 deletions uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.