Skip to content

Commit 2529e60

Browse files
dhenslealetzdy
andauthored
Minor Fixes: optional logsums, duplicate data in parking lot choice, activitysim version to logfile (#963)
* adding activitysim version to log file * fix duplicate columns in parking location choice as described in #633 * making tour mode choice logsum optional in destionation choice models #847 * logsum settings in location choice, trip dest, tour_od * optional logsums in trip destination * blacken --------- Co-authored-by: Ali Etezady <[email protected]>
1 parent 6a553fc commit 2529e60

File tree

7 files changed

+87
-55
lines changed

7 files changed

+87
-55
lines changed

activitysim/abm/models/location_choice.py

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -838,19 +838,23 @@ def run_location_choice(
838838
)
839839

840840
# - location_logsums
841-
location_sample_df = run_location_logsums(
842-
state,
843-
segment_name,
844-
choosers,
845-
network_los,
846-
location_sample_df,
847-
model_settings,
848-
chunk_size,
849-
chunk_tag=f"{chunk_tag}.logsums",
850-
trace_label=tracing.extend_trace_label(
851-
trace_label, "logsums.%s" % segment_name
852-
),
853-
)
841+
# skip logsum calculations if LOGSUM_SETTINGS is None
842+
if model_settings.LOGSUM_SETTINGS:
843+
location_sample_df = run_location_logsums(
844+
state,
845+
segment_name,
846+
choosers,
847+
network_los,
848+
location_sample_df,
849+
model_settings,
850+
chunk_size,
851+
chunk_tag=f"{chunk_tag}.logsums",
852+
trace_label=tracing.extend_trace_label(
853+
trace_label, "logsums.%s" % segment_name
854+
),
855+
)
856+
else:
857+
location_sample_df[ALT_LOGSUM] = 0.0
854858

855859
# - location_simulate
856860
choices_df = run_location_simulate(

activitysim/abm/models/parking_location_choice.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,8 +203,10 @@ def choose_parking_location(
203203
additional_columns=model_settings.compute_settings.protect_columns,
204204
)
205205

206+
# Passing only the index of the trips table to the interaction_dataset
207+
# See ActivitySim issue #633
206208
destination_sample = logit.interaction_dataset(
207-
state, trips, alternatives, alt_index_id=alt_dest_col_name
209+
state, trips[[]], alternatives, alt_index_id=alt_dest_col_name
208210
)
209211
destination_sample.index = np.repeat(trips.index.values, len(alternatives))
210212
destination_sample.index.name = trips.index.name

activitysim/abm/models/trip_destination.py

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1053,16 +1053,21 @@ def choose_trip_destination(
10531053
return pd.Series(index=trips.index).to_frame("choice"), None
10541054

10551055
# - compute logsums
1056-
destination_sample = compute_logsums(
1057-
state,
1058-
primary_purpose=primary_purpose,
1059-
trips=trips,
1060-
destination_sample=destination_sample,
1061-
tours_merged=tours_merged,
1062-
model_settings=model_settings,
1063-
skim_hotel=skim_hotel,
1064-
trace_label=trace_label,
1065-
)
1056+
# If LOGSUM_SETTINGS is set to None, we don't want to compute logsums
1057+
if model_settings.LOGSUM_SETTINGS:
1058+
destination_sample = compute_logsums(
1059+
state,
1060+
primary_purpose=primary_purpose,
1061+
trips=trips,
1062+
destination_sample=destination_sample,
1063+
tours_merged=tours_merged,
1064+
model_settings=model_settings,
1065+
skim_hotel=skim_hotel,
1066+
trace_label=trace_label,
1067+
)
1068+
else:
1069+
destination_sample["od_logsum"] = 0.0
1070+
destination_sample["dp_logsum"] = 0.0
10661071

10671072
t0 = print_elapsed_time("%s.compute_logsums" % trace_label, t0)
10681073

@@ -1272,9 +1277,14 @@ def run_trip_destination(
12721277
state.filesystem, model_settings_file_name
12731278
)
12741279
preprocessor_settings = model_settings.preprocessor
1275-
logsum_settings = state.filesystem.read_model_settings(
1276-
model_settings.LOGSUM_SETTINGS
1277-
)
1280+
1281+
# read in logsum settings if they exist, otherwise logsum calculations are skipped
1282+
if model_settings.LOGSUM_SETTINGS:
1283+
logsum_settings = state.filesystem.read_model_settings(
1284+
model_settings.LOGSUM_SETTINGS
1285+
)
1286+
else:
1287+
logsum_settings = None
12781288

12791289
logsum_column_name = model_settings.DEST_CHOICE_LOGSUM_COLUMN_NAME
12801290
want_logsums = logsum_column_name is not None
@@ -1342,7 +1352,9 @@ def run_trip_destination(
13421352

13431353
# - filter tours_merged (AFTER copying destination and origin columns to trips)
13441354
# tours_merged is used for logsums, we filter it here upfront to save space and time
1345-
tours_merged_cols = logsum_settings["TOURS_MERGED_CHOOSER_COLUMNS"]
1355+
tours_merged_cols = (
1356+
logsum_settings["TOURS_MERGED_CHOOSER_COLUMNS"] if logsum_settings else []
1357+
)
13461358
redundant_cols = model_settings.REDUNDANT_TOURS_MERGED_CHOOSER_COLUMNS or []
13471359
if redundant_cols:
13481360
tours_merged_cols = [c for c in tours_merged_cols if c not in redundant_cols]

activitysim/abm/models/util/tour_destination.py

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -894,17 +894,21 @@ def run_tour_destination(
894894
)
895895

896896
# - destination_logsums
897-
tour_purpose = segment_name # tour_purpose is segment_name
898-
location_sample_df = run_destination_logsums(
899-
state,
900-
tour_purpose,
901-
persons_merged,
902-
location_sample_df,
903-
model_settings,
904-
network_los,
905-
chunk_size=state.settings.chunk_size,
906-
trace_label=tracing.extend_trace_label(segment_trace_label, "logsums"),
907-
)
897+
# if LOGSUM_SETTINGS is set to 'None', we skip this step
898+
if model_settings.LOGSUM_SETTINGS:
899+
tour_purpose = segment_name # tour_purpose is segment_name
900+
location_sample_df = run_destination_logsums(
901+
state,
902+
tour_purpose,
903+
persons_merged,
904+
location_sample_df,
905+
model_settings,
906+
network_los,
907+
chunk_size=state.settings.chunk_size,
908+
trace_label=tracing.extend_trace_label(segment_trace_label, "logsums"),
909+
)
910+
else:
911+
location_sample_df["mode_choice_logsum"] = 0
908912

909913
# - destination_simulate
910914
spec_segment_name = segment_name # spec_segment_name is segment_name

activitysim/abm/models/util/tour_od.py

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1132,20 +1132,24 @@ def run_tour_od(
11321132
)
11331133

11341134
# - destination_logsums
1135-
od_sample_df = run_od_logsums(
1136-
state,
1137-
spec_segment_name,
1138-
choosers,
1139-
od_sample_df,
1140-
model_settings,
1141-
network_los,
1142-
estimator,
1143-
chunk_size=chunk_size,
1144-
trace_hh_id=trace_hh_id,
1145-
trace_label=tracing.extend_trace_label(
1146-
trace_label, f"logsums.{segment_name}"
1147-
),
1148-
)
1135+
# Skip logsum calculation step if LOGSUM_SETTINGS is None
1136+
if model_settings.LOGSUM_SETTINGS:
1137+
od_sample_df = run_od_logsums(
1138+
state,
1139+
spec_segment_name,
1140+
choosers,
1141+
od_sample_df,
1142+
model_settings,
1143+
network_los,
1144+
estimator,
1145+
chunk_size=chunk_size,
1146+
trace_hh_id=trace_hh_id,
1147+
trace_label=tracing.extend_trace_label(
1148+
trace_label, f"logsums.{segment_name}"
1149+
),
1150+
)
1151+
else:
1152+
od_sample_df["tour_mode_choice_logsum"] = 0.0
11491153

11501154
# - od_simulate
11511155
choices = run_od_simulate(

activitysim/cli/run.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,9 @@ def run(args):
328328
config.filter_warnings(state)
329329
logging.captureWarnings(capture=True)
330330

331+
activitysim_version = importlib.metadata.version("activitysim")
332+
logger.info(f"ActivitySim Version: {activitysim_version}")
333+
331334
# directories
332335
for k in ["configs_dir", "settings_file_name", "data_dir", "output_dir"]:
333336
logger.info("SETTING %s: %s" % (k, getattr(state.filesystem, k, None)))

activitysim/core/configuration/logit.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,8 +212,11 @@ class LocationComponentSettings(BaseLogitComponentSettings):
212212
SAMPLE_SIZE: int
213213
"""This many candidate alternatives will be sampled for each choice."""
214214

215-
LOGSUM_SETTINGS: Path
216-
"""Settings for the logsum computation."""
215+
LOGSUM_SETTINGS: Path | None = None
216+
"""
217+
Settings for the logsum computation.
218+
If None, no logsum is computed and logsum field is populated with zeros.
219+
"""
217220

218221
explicit_chunk: float = 0
219222
"""

0 commit comments

Comments
 (0)