Skip to content

Commit

Permalink
consolidate chunk_tags for trip destination, tour destination, trip p…
Browse files Browse the repository at this point in the history
…urpose
  • Loading branch information
toliwaga committed May 15, 2021
1 parent 4d98042 commit 9c0a2ac
Show file tree
Hide file tree
Showing 10 changed files with 348 additions and 51 deletions.
53 changes: 34 additions & 19 deletions activitysim/abm/models/location_choice.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,8 @@ def _location_sample(
estimator,
model_settings,
alt_dest_col_name,
chunk_size, trace_label):
chunk_size, chunk_tag,
trace_label):
"""
select a sample of alternative locations.
Expand Down Expand Up @@ -155,6 +156,7 @@ def _location_sample(
skims=skims,
locals_d=locals_d,
chunk_size=chunk_size,
chunk_tag=chunk_tag,
trace_label=trace_label)

return choices
Expand All @@ -167,7 +169,8 @@ def location_sample(
dest_size_terms,
estimator,
model_settings,
chunk_size, trace_label):
chunk_size, chunk_tag,
trace_label):

# FIXME - MEMORY HACK - only include columns actually used in spec
chooser_columns = model_settings['SIMULATE_CHOOSER_COLUMNS']
Expand All @@ -190,7 +193,7 @@ def location_sample(
estimator,
model_settings,
alt_dest_col_name,
chunk_size,
chunk_size, chunk_tag,
trace_label)

return choices
Expand Down Expand Up @@ -256,7 +259,8 @@ def location_presample(
dest_size_terms,
estimator,
model_settings,
chunk_size, trace_label):
chunk_size, chunk_tag,
trace_label):

trace_label = tracing.extend_trace_label(trace_label, 'presample')

Expand Down Expand Up @@ -293,7 +297,7 @@ def location_presample(
estimator,
model_settings,
DEST_TAZ,
chunk_size,
chunk_size, chunk_tag,
trace_label)

# print(f"taz_sample\n{taz_sample}")
Expand All @@ -320,7 +324,8 @@ def run_location_sample(
dest_size_terms,
estimator,
model_settings,
chunk_size, trace_label):
chunk_size, chunk_tag,
trace_label):
"""
select a sample of alternative locations.
Expand Down Expand Up @@ -361,7 +366,9 @@ def run_location_sample(
dest_size_terms,
estimator,
model_settings,
chunk_size, trace_label)
chunk_size,
chunk_tag=f'{chunk_tag}.presample',
trace_label=trace_label)

else:

Expand All @@ -372,7 +379,9 @@ def run_location_sample(
dest_size_terms,
estimator,
model_settings,
chunk_size, trace_label)
chunk_size,
chunk_tag=f'{chunk_tag}.sample',
trace_label=trace_label)

return choices

Expand All @@ -383,7 +392,8 @@ def run_location_logsums(
network_los,
location_sample_df,
model_settings,
chunk_size, trace_hh_id, trace_label):
chunk_size, chunk_tag,
trace_label):
"""
add logsum column to existing location_sample table
Expand Down Expand Up @@ -427,6 +437,7 @@ def run_location_logsums(
logsum_settings, model_settings,
network_los,
chunk_size,
chunk_tag,
trace_label)

# "add_column series should have an index matching the table to which it is being added"
Expand All @@ -447,7 +458,8 @@ def run_location_simulate(
want_logsums,
estimator,
model_settings,
chunk_size, trace_label):
chunk_size, chunk_tag,
trace_label):
"""
run location model on location_sample annotated with mode_choice logsum
to select a dest zone from sample alternatives
Expand Down Expand Up @@ -506,7 +518,7 @@ def run_location_simulate(
want_logsums=want_logsums,
skims=skims,
locals_d=locals_d,
chunk_size=chunk_size,
chunk_size=chunk_size, chunk_tag=chunk_tag,
trace_label=trace_label,
trace_choice_name=model_settings['DEST_CHOICE_COLUMN_NAME'],
estimator=estimator)
Expand All @@ -529,7 +541,8 @@ def run_location_choice(
want_sample_table,
estimator,
model_settings,
chunk_size, trace_hh_id, trace_label
chunk_size, chunk_tag,
trace_hh_id, trace_label
):
"""
Run the three-part location choice algorithm to generate a location choice for each chooser
Expand Down Expand Up @@ -591,7 +604,8 @@ def run_location_choice(
estimator,
model_settings,
chunk_size,
tracing.extend_trace_label(trace_label, 'sample.%s' % segment_name))
chunk_tag, # run_location_sample will add appropriate suffix for sample or presample
trace_label=tracing.extend_trace_label(trace_label, 'sample.%s' % segment_name))

# - location_logsums
location_sample_df = \
Expand All @@ -601,9 +615,8 @@ def run_location_choice(
network_los,
location_sample_df,
model_settings,
chunk_size,
trace_hh_id,
tracing.extend_trace_label(trace_label, 'logsums.%s' % segment_name))
chunk_size, chunk_tag=f'{chunk_tag}.logsums',
trace_label=tracing.extend_trace_label(trace_label, 'logsums.%s' % segment_name))

# - location_simulate
choices_df = \
Expand All @@ -616,8 +629,8 @@ def run_location_choice(
want_logsums,
estimator,
model_settings,
chunk_size,
tracing.extend_trace_label(trace_label, 'simulate.%s' % segment_name))
chunk_size, chunk_tag=f'{chunk_tag}.simulate',
trace_label=tracing.extend_trace_label(trace_label, 'simulate.%s' % segment_name))

if estimator:
if trace_hh_id:
Expand Down Expand Up @@ -717,6 +730,8 @@ def iterate_location_choice(
adds annotations to persons table
"""

chunk_tag = trace_label

# boolean to filter out persons not needing location modeling (e.g. is_worker, is_student)
chooser_filter_column = model_settings['CHOOSER_FILTER_COLUMN_NAME']

Expand Down Expand Up @@ -757,7 +772,7 @@ def iterate_location_choice(
want_sample_table=want_sample_table,
estimator=estimator,
model_settings=model_settings,
chunk_size=chunk_size,
chunk_size=chunk_size, chunk_tag=chunk_tag,
trace_hh_id=trace_hh_id,
trace_label=tracing.extend_trace_label(trace_label, 'i%s' % iteration))

Expand Down
37 changes: 25 additions & 12 deletions activitysim/abm/models/trip_destination.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ def _destination_sample(
alt_dest_col_name,
estimator,
chunk_size,
chunk_tag,
trace_label):
"""
Expand Down Expand Up @@ -103,8 +104,9 @@ def _destination_sample(
spec=spec,
skims=skims,
locals_d=locals_dict,
chunk_size=chunk_size,
trace_label=trace_label)
chunk_size=chunk_size, chunk_tag=chunk_tag,
trace_label=trace_label
)

return choices

Expand All @@ -120,6 +122,8 @@ def destination_sample(
chunk_size,
trace_label):

chunk_tag = 'trip_destination.sample'

skims = skim_hotel.sample_skims(presample=False)
alt_dest_col_name = model_settings['ALT_DEST_COL_NAME']

Expand All @@ -133,7 +137,8 @@ def destination_sample(
alt_dest_col_name,
estimator,
chunk_size,
trace_label)
chunk_tag=chunk_tag,
trace_label=trace_label)

return choices

Expand Down Expand Up @@ -356,8 +361,7 @@ def destination_presample(
trace_label):

trace_label = tracing.extend_trace_label(trace_label, 'presample')

logger.info(f"{trace_label} destination_presample")
chunk_tag = 'trip_destination.presample' # distinguish from trip_destination.sample

alt_dest_col_name = model_settings['ALT_DEST_COL_NAME']
maz_taz = network_los.maz_taz_df[['MAZ', 'TAZ']].set_index('MAZ').TAZ
Expand Down Expand Up @@ -387,7 +391,8 @@ def destination_presample(
alt_dest_col_name,
estimator,
chunk_size,
trace_label)
chunk_tag=chunk_tag,
trace_label=trace_label)

# choose a MAZ for each DEST_TAZ choice, choice probability based on MAZ size_term fraction of TAZ total
maz_sample = choose_MAZ_for_TAZ(taz_sample, size_term_matrix, trips, network_los, alt_dest_col_name, trace_label)
Expand Down Expand Up @@ -423,7 +428,7 @@ def trip_destination_sample(
pick_count : int
number of duplicate picks for chooser, alt
"""
trace_label = tracing.extend_trace_label(trace_label, 'trip_destination_sample')
trace_label = tracing.extend_trace_label(trace_label, 'sample')

assert len(trips) > 0
assert len(alternatives) > 0
Expand Down Expand Up @@ -474,7 +479,8 @@ def compute_ood_logsums(
od_skims,
locals_dict,
chunk_size,
trace_label):
trace_label,
chunk_tag):
"""
Compute one (of two) out-of-direction logsums for destination alternatives
Expand All @@ -495,7 +501,8 @@ def compute_ood_logsums(
skims=od_skims,
locals_d=locals_dict,
chunk_size=chunk_size,
trace_label=trace_label)
trace_label=trace_label,
chunk_tag=chunk_tag)

assert logsums.index.equals(choosers.index)

Expand Down Expand Up @@ -526,6 +533,9 @@ def compute_logsums(
trace_label = tracing.extend_trace_label(trace_label, 'compute_logsums')
logger.info("Running %s with %d samples", trace_label, destination_sample.shape[0])

# chunk usage is uniform so better to combine
chunk_tag = 'trip_destination.compute_logsums'

# FIXME should pass this in?
network_los = inject.get_injectable('network_los')

Expand Down Expand Up @@ -588,7 +598,8 @@ def compute_logsums(
od_skims,
locals_dict,
chunk_size,
trace_label=tracing.extend_trace_label(trace_label, 'od'))
trace_label=tracing.extend_trace_label(trace_label, 'od'),
chunk_tag=chunk_tag)

# - dp_logsums
dp_skims = {
Expand All @@ -611,7 +622,8 @@ def compute_logsums(
dp_skims,
locals_dict,
chunk_size,
trace_label=tracing.extend_trace_label(trace_label, 'dp'))
trace_label=tracing.extend_trace_label(trace_label, 'dp'),
chunk_tag=chunk_tag)

return destination_sample

Expand All @@ -637,6 +649,7 @@ def trip_destination_simulate(
destination alt chosen
"""
trace_label = tracing.extend_trace_label(trace_label, 'trip_dest_simulate')
chunk_tag = 'trip_destination.simulate'

spec = simulate.spec_for_segment(model_settings, spec_id='DESTINATION_SPEC',
segment_name=primary_purpose, estimator=estimator)
Expand Down Expand Up @@ -665,7 +678,7 @@ def trip_destination_simulate(
allow_zero_probs=True, zero_prob_choice_val=NO_DESTINATION,
skims=skims,
locals_d=locals_dict,
chunk_size=chunk_size,
chunk_size=chunk_size, chunk_tag=chunk_tag,
trace_label=trace_label,
trace_choice_name='trip_dest',
estimator=estimator)
Expand Down
5 changes: 4 additions & 1 deletion activitysim/abm/models/trip_purpose.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,9 @@ def run_trip_purpose(
purpose: pandas.Series of purpose (str) indexed by trip_id
"""

# uniform across trip_purpose
chunk_tag = 'trip_purpose'

model_settings_file_name = 'trip_purpose.yaml'
model_settings = config.read_model_settings(model_settings_file_name)

Expand Down Expand Up @@ -176,7 +179,7 @@ def run_trip_purpose(
trace_label=trace_label)

for i, trips_chunk, chunk_trace_label in \
chunk.adaptive_chunked_choosers(trips_df, chunk_size, trace_label):
chunk.adaptive_chunked_choosers(trips_df, chunk_size, chunk_tag, trace_label):

choices = choose_intermediate_trip_purpose(
trips_chunk,
Expand Down
5 changes: 4 additions & 1 deletion activitysim/abm/models/util/logsums.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ def compute_logsums(choosers,
tour_purpose,
logsum_settings, model_settings,
network_los,
chunk_size, trace_label):
chunk_size,
chunk_tag,
trace_label):
"""
Parameters
Expand Down Expand Up @@ -150,6 +152,7 @@ def compute_logsums(choosers,
skims=skims,
locals_d=locals_dict,
chunk_size=chunk_size,
chunk_tag=chunk_tag,
trace_label=trace_label)

return logsums

0 comments on commit 9c0a2ac

Please sign in to comment.