Skip to content
Draft
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
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ repos:
args: ["--profile", "black", "--filter-files"]

- repo: https://github.com/psf/black
rev: 22.6.0
rev: 22.12.0
hooks:
- id: black
language_version: python3.13
Expand Down
15 changes: 15 additions & 0 deletions activitysim/abm/models/location_choice.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
)
from activitysim.core.interaction_sample import interaction_sample
from activitysim.core.interaction_sample_simulate import interaction_sample_simulate
from activitysim.core.logit import AltsContext
from activitysim.core.util import reindex
from activitysim.core.exceptions import DuplicateWorkflowTableError

Expand Down Expand Up @@ -603,6 +604,7 @@ def run_location_simulate(
chunk_tag,
trace_label,
skip_choice=False,
alts_context: AltsContext | None = None,
):
"""
run location model on location_sample annotated with mode_choice logsum
Expand Down Expand Up @@ -712,6 +714,7 @@ def run_location_simulate(
compute_settings=model_settings.compute_settings.subcomponent_settings(
"simulate"
),
alts_context=alts_context,
)

if not want_logsums:
Expand Down Expand Up @@ -788,6 +791,13 @@ def run_location_choice(
if choosers.shape[0] == 0:
logger.info(f"{trace_label} skipping segment {segment_name}: no choosers")
continue
# using land use rather than size terms in case something goes 0 base -> nonzero project, double
# check if that would be in dest_size_terms as a zero
alts_context = AltsContext.from_series(
dest_size_terms.index
) # index zone_id, not ALT_DEST_COL_NAME
# assumes that dest_size_terms will always contain zeros for non-attractive zones, i.e. it will have the
# same length as land_use

# - location_sample
location_sample_df = run_location_sample(
Expand Down Expand Up @@ -841,6 +851,7 @@ def run_location_choice(
trace_label, "simulate.%s" % segment_name
),
skip_choice=skip_choice,
alts_context=alts_context,
)

if estimator:
Expand Down Expand Up @@ -1019,6 +1030,10 @@ def iterate_location_choice(
) = None # initialize to None, will be populated in first iteration

for iteration in range(1, max_iterations + 1):
# Force reset the setting at the start of each shadow price iteration for consistency
logger.info("Resetting random number seeds for iteration {}".format(iteration))
state.get_rn_generator().end_step(trace_label)
state.get_rn_generator().begin_step(trace_label)
persons_merged_df_ = persons_merged_df.copy()

if spc.use_shadow_pricing and iteration > 1:
Expand Down
7 changes: 7 additions & 0 deletions activitysim/abm/models/parking_location_choice.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
from activitysim.core.configuration.base import PreprocessorSettings
from activitysim.core.configuration.logit import LogitComponentSettings
from activitysim.core.interaction_sample_simulate import interaction_sample_simulate
from activitysim.core.logit import AltsContext
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
Expand Down Expand Up @@ -112,6 +113,7 @@ def parking_destination_simulate(
chunk_size,
trace_hh_id,
trace_label,
alts_context: AltsContext | None = None,
):
"""
Chose destination from destination_sample (with od_logsum and dp_logsum columns added)
Expand Down Expand Up @@ -150,6 +152,7 @@ def parking_destination_simulate(
trace_label=trace_label,
trace_choice_name="parking_loc",
explicit_chunk_size=model_settings.explicit_chunk,
alts_context=alts_context,
)

# drop any failed zero_prob destinations
Expand Down Expand Up @@ -211,6 +214,9 @@ def choose_parking_location(
)
destination_sample.index = np.repeat(trips.index.values, len(alternatives))
destination_sample.index.name = trips.index.name
# using destination_sample would also be right because destination_sample isn't a sample here,
# but that could change
alts_context = AltsContext.from_series(alternatives[alt_dest_col_name])

destinations = parking_destination_simulate(
state,
Expand All @@ -223,6 +229,7 @@ def choose_parking_location(
chunk_size=chunk_size,
trace_hh_id=trace_hh_id,
trace_label=trace_label,
alts_context=alts_context,
)

if want_sample_table:
Expand Down
9 changes: 8 additions & 1 deletion activitysim/abm/models/trip_destination.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
from activitysim.core.configuration.logit import LocationComponentSettings
from activitysim.core.interaction_sample import interaction_sample
from activitysim.core.interaction_sample_simulate import interaction_sample_simulate
from activitysim.core.logit import AltsContext
from activitysim.core.skim_dictionary import DataFrameMatrix
from activitysim.core.tracing import print_elapsed_time
from activitysim.core.util import assign_in_place, reindex
Expand Down Expand Up @@ -950,6 +951,7 @@ def trip_destination_simulate(
skim_hotel,
estimator,
trace_label,
alts_context: AltsContext | None = None,
):
"""
Chose destination from destination_sample (with od_logsum and dp_logsum columns added)
Expand Down Expand Up @@ -1036,6 +1038,7 @@ def trip_destination_simulate(
trace_choice_name="trip_dest",
estimator=estimator,
explicit_chunk_size=model_settings.explicit_chunk,
alts_context=alts_context,
)

if not want_logsums:
Expand Down Expand Up @@ -1126,7 +1129,10 @@ def choose_trip_destination(
destination_sample["dp_logsum"] = 0.0

t0 = print_elapsed_time("%s.compute_logsums" % trace_label, t0, debug=True)

alt_dest_col_name = model_settings.ALT_DEST_COL_NAME
alts = alternatives.index
assert alts.name == alt_dest_col_name
alts_context = AltsContext.from_series(alts)
destinations = trip_destination_simulate(
state,
primary_purpose=primary_purpose,
Expand All @@ -1138,6 +1144,7 @@ def choose_trip_destination(
skim_hotel=skim_hotel,
estimator=estimator,
trace_label=trace_label,
alts_context=alts_context,
)

dropped_trips = ~trips.index.isin(destinations.index)
Expand Down
4 changes: 4 additions & 0 deletions activitysim/abm/models/trip_scheduling_choice.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
)
from activitysim.core.configuration.logit import LogitComponentSettings
from activitysim.core.interaction_sample_simulate import _interaction_sample_simulate
from activitysim.core.logit import AltsContext
from activitysim.core.skim_dataset import SkimDataset
from activitysim.core.skim_dictionary import SkimDict

Expand Down Expand Up @@ -314,6 +315,9 @@ def run_trip_scheduling_choice(
estimator=None,
chunk_sizer=chunk_sizer,
compute_settings=model_settings.compute_settings,
alts_context=AltsContext(
schedules[SCHEDULE_ID].min(), schedules[SCHEDULE_ID].max()
),
)

assert len(choices.index) == len(choosers.index)
Expand Down
1 change: 1 addition & 0 deletions activitysim/abm/tables/shadow_pricing.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ def __init__(

self.num_processes = num_processes
self.use_shadow_pricing = bool(state.settings.use_shadow_pricing)
logger.info("Use shadow pricing: %s", self.use_shadow_pricing)
self.saved_shadow_price_file_path = (
None # set by read_saved_shadow_prices if loaded
)
Expand Down
1 change: 1 addition & 0 deletions activitysim/core/chunk.py
Original file line number Diff line number Diff line change
Expand Up @@ -1244,6 +1244,7 @@ def adaptive_chunked_choosers(
chunk_size = math.ceil(num_choosers * explicit_chunk_size)
else:
chunk_size = math.ceil(explicit_chunk_size / num_processes)
logger.info(f"Running {trace_label} with {chunk_size} choosers")
elif chunk_size is None:
chunk_size = state.settings.chunk_size

Expand Down
Loading
Loading