Skip to content

Commit

Permalink
Merge branch 'main' into parking_loc_mem_savings
Browse files Browse the repository at this point in the history
  • Loading branch information
dhensle authored Apr 22, 2024
2 parents 1808704 + 652883a commit b760303
Show file tree
Hide file tree
Showing 53 changed files with 786 additions and 281 deletions.
1 change: 0 additions & 1 deletion .github/workflows/core_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,6 @@ jobs:
matrix:
region:
- prototype_mtc
- prototype_arc
- placeholder_psrc
- prototype_marin
- prototype_mtc_extended
Expand Down
1 change: 1 addition & 0 deletions activitysim/abm/models/atwork_subtour_frequency.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ def atwork_subtour_frequency(
trace_label=trace_label,
trace_choice_name="atwork_subtour_frequency",
estimator=estimator,
compute_settings=model_settings.compute_settings,
)

# convert indexes to alternative names
Expand Down
3 changes: 1 addition & 2 deletions activitysim/abm/models/atwork_subtour_scheduling.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ def atwork_subtour_scheduling(
estimator = estimation.manager.begin_estimation(state, "atwork_subtour_scheduling")

model_spec = state.filesystem.read_model_spec(file_name=model_settings.SPEC)
sharrow_skip = model_settings.sharrow_skip
coefficients_df = state.filesystem.read_model_coefficients(model_settings)
model_spec = simulate.eval_coefficients(
state, model_spec, coefficients_df, estimator
Expand Down Expand Up @@ -96,7 +95,7 @@ def atwork_subtour_scheduling(
estimator=estimator,
chunk_size=state.settings.chunk_size,
trace_label=trace_label,
sharrow_skip=sharrow_skip,
compute_settings=model_settings.compute_settings,
)

if estimator:
Expand Down
11 changes: 8 additions & 3 deletions activitysim/abm/models/auto_ownership.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,21 @@

from activitysim.core import (
config,
expressions,
estimation,
expressions,
simulate,
tracing,
workflow,
)
from activitysim.core.configuration.base import PreprocessorSettings, PydanticReadable
from activitysim.core.configuration.logit import LogitComponentSettings

from .util import annotate

logger = logging.getLogger(__name__)


class AutoOwnershipSettings(LogitComponentSettings):
class AutoOwnershipSettings(LogitComponentSettings, extra="forbid"):
"""
Settings for the `auto_ownership` component.
"""
Expand All @@ -36,6 +37,8 @@ def auto_ownership_simulate(
state: workflow.State,
households: pd.DataFrame,
households_merged: pd.DataFrame,
# FIXME: persons_merged not used but included, see #853
persons_merged: pd.DataFrame,
model_settings: AutoOwnershipSettings | None = None,
model_settings_file_name: str = "auto_ownership.yaml",
trace_label: str = "auto_ownership_simulate",
Expand Down Expand Up @@ -75,6 +78,7 @@ def auto_ownership_simulate(
locals_d.update(constants)

expressions.assign_columns(
state,
df=choosers,
model_settings=preprocessor_settings,
locals_dict=locals_d,
Expand All @@ -99,6 +103,7 @@ def auto_ownership_simulate(
trace_choice_name="auto_ownership",
log_alt_losers=log_alt_losers,
estimator=estimator,
compute_settings=model_settings.compute_settings,
)

if estimator:
Expand All @@ -117,7 +122,7 @@ def auto_ownership_simulate(
)

if model_settings.annotate_households:
annotate.annotate_households(model_settings, trace_label)
annotate.annotate_households(state, model_settings, trace_label)

if trace_hh_id:
state.tracing.trace_df(households, label="auto_ownership", warn_if_empty=True)
11 changes: 10 additions & 1 deletion activitysim/abm/models/cdap.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@
tracing,
workflow,
)
from activitysim.core.configuration.base import PreprocessorSettings, PydanticReadable
from activitysim.core.configuration.base import (
ComputeSettings,
PreprocessorSettings,
PydanticReadable,
)
from activitysim.core.util import reindex

logger = logging.getLogger(__name__)
Expand All @@ -30,10 +34,13 @@ class CdapSettings(PydanticReadable, extra="forbid"):
FIXED_RELATIVE_PROPORTIONS_SPEC: str = "cdap_fixed_relative_proportions.csv"
ADD_JOINT_TOUR_UTILITY: bool = False
JOINT_TOUR_COEFFICIENTS: str = "cdap_joint_tour_coefficients.csv"
JOINT_TOUR_USEFUL_COLUMNS: list[str] | None = None
"""Columns to include from the persons table that will be need to calculate household joint tour utility."""
annotate_persons: PreprocessorSettings | None = None
annotate_households: PreprocessorSettings | None = None
COEFFICIENTS: Path
CONSTANTS: dict[str, Any] = {}
compute_settings: ComputeSettings | None = None


@workflow.step
Expand Down Expand Up @@ -202,6 +209,7 @@ def cdap_simulate(
trace_hh_id=trace_hh_id,
trace_label=trace_label,
add_joint_tour_utility=add_joint_tour_utility,
compute_settings=model_settings.compute_settings,
)
else:
choices = cdap.run_cdap(
Expand All @@ -215,6 +223,7 @@ def cdap_simulate(
chunk_size=state.settings.chunk_size,
trace_hh_id=trace_hh_id,
trace_label=trace_label,
compute_settings=model_settings.compute_settings,
)

if estimator:
Expand Down
1 change: 1 addition & 0 deletions activitysim/abm/models/free_parking.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ def free_parking(
trace_label=trace_label,
trace_choice_name="free_parking_at_work",
estimator=estimator,
compute_settings=model_settings.compute_settings,
)

free_parking_alt = model_settings.FREE_PARKING_ALT
Expand Down
4 changes: 4 additions & 0 deletions activitysim/abm/models/initialize.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,10 @@ def initialize_households(
suffixes = disaggregate_accessibility.disaggregate_suffixes(state)
shadow_pricing.add_size_tables(state, suffixes)

# create disaggregate_accessibility table if not model was run
if state.is_table("proto_disaggregate_accessibility"):
disaggregate_accessibility.disaggregate_accessibility(state)

# - preload person_windows
person_windows = state.get_dataframe("person_windows")
chunk_sizer.log_df(trace_label, "person_windows", person_windows)
Expand Down
1 change: 1 addition & 0 deletions activitysim/abm/models/joint_tour_composition.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ def joint_tour_composition(
trace_label=trace_label,
trace_choice_name="composition",
estimator=estimator,
compute_settings=model_settings.compute_settings,
)

# convert indexes to alternative names
Expand Down
1 change: 1 addition & 0 deletions activitysim/abm/models/joint_tour_frequency.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ def joint_tour_frequency(
trace_label=trace_label,
trace_choice_name="joint_tour_frequency",
estimator=estimator,
compute_settings=model_settings.compute_settings,
)

# convert indexes to alternative names
Expand Down
3 changes: 2 additions & 1 deletion activitysim/abm/models/joint_tour_frequency_composition.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
logger = logging.getLogger(__name__)


class JointTourFrequencyCompositionSettings(LogitComponentSettings):
class JointTourFrequencyCompositionSettings(LogitComponentSettings, extra="forbid"):
"""
Settings for the `joint_tour_frequency_composition` component.
"""
Expand Down Expand Up @@ -140,6 +140,7 @@ def joint_tour_frequency_composition(
trace_choice_name=trace_label,
estimator=estimator,
explicit_chunk_size=0,
compute_settings=model_settings.compute_settings,
)

if estimator:
Expand Down
12 changes: 11 additions & 1 deletion activitysim/abm/models/joint_tour_participation.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
tracing,
workflow,
)
from activitysim.core.configuration.base import PreprocessorSettings
from activitysim.core.configuration.base import ComputeSettings, PreprocessorSettings
from activitysim.core.configuration.logit import LogitComponentSettings
from activitysim.core.util import assign_in_place, reindex

Expand Down Expand Up @@ -408,6 +408,15 @@ def joint_tour_participation(
)
candidates["chunk_id"] = reindex(household_chunk_ids, candidates.household_id)

# these hardcoded columns need to be protected from being dropped
assert model_settings is not None
if model_settings.compute_settings is None:
model_settings.compute_settings = ComputeSettings()
assert model_settings.compute_settings is not None
for i in ["person_is_preschool", "composition", "adult"]:
if i not in model_settings.compute_settings.protect_columns:
model_settings.compute_settings.protect_columns.append(i)

choices = simulate.simple_simulate_by_chunk_id(
state,
choosers=candidates,
Expand All @@ -418,6 +427,7 @@ def joint_tour_participation(
trace_choice_name="participation",
custom_chooser=participants_chooser,
estimator=estimator,
compute_settings=model_settings.compute_settings,
)

# choice is boolean (participate or not)
Expand Down
3 changes: 1 addition & 2 deletions activitysim/abm/models/joint_tour_scheduling.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@ def joint_tour_scheduling(
estimator = estimation.manager.begin_estimation(state, "joint_tour_scheduling")

model_spec = state.filesystem.read_model_spec(file_name=model_settings.SPEC)
sharrow_skip = model_settings.sharrow_skip
coefficients_df = state.filesystem.read_model_coefficients(model_settings)
model_spec = simulate.eval_coefficients(
state, model_spec, coefficients_df, estimator
Expand All @@ -128,7 +127,7 @@ def joint_tour_scheduling(
estimator=estimator,
chunk_size=state.settings.chunk_size,
trace_label=trace_label,
sharrow_skip=sharrow_skip,
compute_settings=model_settings.compute_settings,
)

if estimator:
Expand Down
6 changes: 6 additions & 0 deletions activitysim/abm/models/location_choice.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,9 @@ def _location_sample(
chunk_tag=chunk_tag,
trace_label=trace_label,
zone_layer=zone_layer,
compute_settings=model_settings.compute_settings.subcomponent_settings(
"sample"
),
)

return choices
Expand Down Expand Up @@ -696,6 +699,9 @@ def run_location_simulate(
trace_choice_name=model_settings.DEST_CHOICE_COLUMN_NAME,
estimator=estimator,
skip_choice=skip_choice,
compute_settings=model_settings.compute_settings.subcomponent_settings(
"simulate"
),
)

if not want_logsums:
Expand Down
3 changes: 2 additions & 1 deletion activitysim/abm/models/mandatory_tour_frequency.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def add_null_results(state, trace_label, mandatory_tour_frequency_settings):
state.add_table("persons", persons)


class MandatoryTourFrequencySettings(LogitComponentSettings):
class MandatoryTourFrequencySettings(LogitComponentSettings, extra="forbid"):
"""
Settings for the `mandatory_tour_frequency` component.
"""
Expand Down Expand Up @@ -134,6 +134,7 @@ def mandatory_tour_frequency(
trace_label=trace_label,
trace_choice_name="mandatory_tour_frequency",
estimator=estimator,
compute_settings=model_settings.compute_settings,
)

# convert indexes to alternative names
Expand Down
8 changes: 6 additions & 2 deletions activitysim/abm/models/non_mandatory_tour_frequency.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@

from activitysim.abm.models.util import annotate
from activitysim.abm.models.util.overlap import (
person_max_window,
person_available_periods,
person_max_window,
)
from activitysim.abm.models.util.school_escort_tours_trips import (
recompute_tour_count_statistics,
Expand Down Expand Up @@ -161,7 +161,7 @@ class NonMandatoryTourSpecSegment(PydanticReadable):
COEFFICIENTS: Path


class NonMandatoryTourFrequencySettings(LogitComponentSettings):
class NonMandatoryTourFrequencySettings(LogitComponentSettings, extra="forbid"):
"""
Settings for the `non_mandatory_tour_frequency` component.
"""
Expand Down Expand Up @@ -321,6 +321,7 @@ def non_mandatory_tour_frequency(
trace_choice_name="non_mandatory_tour_frequency",
estimator=estimator,
explicit_chunk_size=model_settings.explicit_chunk,
compute_settings=model_settings.compute_settings,
)

if estimator:
Expand All @@ -333,6 +334,9 @@ def non_mandatory_tour_frequency(

choices_list.append(choices)

# FIXME only want to keep actual purposes, adding cols in alts will mess this up
# this is complicated by canonical_ids calculated based on alts if not specified explicitly
# thus, adding column to input alts will change IDs and break estimation mode....
del alternatives["tot_tours"] # del tot_tours column we added above

# The choice value 'non_mandatory_tour_frequency' assigned by interaction_simulate
Expand Down
10 changes: 7 additions & 3 deletions activitysim/abm/models/parking_location_choice.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
from activitysim.core.configuration.logit import LogitComponentSettings
from activitysim.core.interaction_sample_simulate import interaction_sample_simulate
from activitysim.core.tracing import print_elapsed_time
from activitysim.core.util import assign_in_place, drop_unused_chooser_columns
from activitysim.core.util import assign_in_place, drop_unused_columns

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -185,8 +185,8 @@ def choose_parking_location(
locals_dict["PARKING"] = skims["op_skims"].dest_key

spec = get_spec_for_segment(state, model_settings, segment_name)
trips = drop_unused_chooser_columns(trips, spec, locals_dict, custom_chooser=None)
alternatives = drop_unused_chooser_columns(
trips = drop_unused_columns(trips, spec, locals_dict, custom_chooser=None)
alternatives = drop_unused_columns(
alternatives, spec, locals_dict, custom_chooser=None
)

Expand Down Expand Up @@ -340,6 +340,10 @@ class ParkingLocationSettings(LogitComponentSettings, extra="forbid"):

SEGMENTS: list[str] | None = None

AUTO_MODES: list[str]
"""List of auto modes that use parking. AUTO_MODES are used in write_trip_matrices to make sure
parking locations are accurately represented in the output trip matrices."""


@workflow.step
def parking_location(
Expand Down
Loading

0 comments on commit b760303

Please sign in to comment.