Skip to content
Merged

Dev #222

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: 2 additions & 0 deletions activitysim/abm/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,7 @@
import atwork_subtour_destination
import atwork_subtour_scheduling

import utility_steps

# parameterized models
import annotate_table
1 change: 0 additions & 1 deletion activitysim/abm/models/annotate_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
from activitysim.core.util import assign_in_place

logger = logging.getLogger(__name__)
DUMP = True


@inject.step()
Expand Down
2 changes: 2 additions & 0 deletions activitysim/abm/models/atwork_subtour_destination.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,8 @@ def atwork_subtour_destination_simulate(tours,

pipeline.replace_table("tours", tours)

pipeline.drop_table('atwork_subtour_destination_sample')

if trace_hh_id:
tracing.trace_df(tours,
label=trace_label,
Expand Down
13 changes: 7 additions & 6 deletions activitysim/abm/models/atwork_subtour_frequency.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ def atwork_subtour_frequency(tours,
spec=atwork_subtour_frequency_spec,
nest_spec=nest_spec,
locals_d=constants,
chunk_size=chunk_size,
trace_label=trace_label,
trace_choice_name='atwork_subtour_frequency')

Expand All @@ -97,13 +98,13 @@ def atwork_subtour_frequency(tours,

subtours = process_atwork_subtours(work_tours, atwork_subtour_frequency_alternatives)

pipeline.extend_table("tours", subtours)
tracing.register_traceable_table('tours', subtours)
print subtours

tours = pipeline.extend_table("tours", subtours)
tracing.register_traceable_table('tours', tours)
pipeline.get_rn_generator().add_channel(subtours, 'tours')

if trace_hh_id:
trace_columns = ['atwork_subtour_frequency']
tracing.trace_df(inject.get_table('tours').to_frame(),
label=trace_label,
columns=trace_columns,
tracing.trace_df(tours,
label='atwork_subtour_frequency.tours',
warn_if_empty=True)
2 changes: 1 addition & 1 deletion activitysim/abm/models/atwork_subtour_scheduling.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

logger = logging.getLogger(__name__)

DUMP = True
DUMP = False


@inject.injectable()
Expand Down
11 changes: 7 additions & 4 deletions activitysim/abm/models/auto_ownership.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import logging

from activitysim.core import simulate as asim
from activitysim.core import simulate
from activitysim.core import tracing
from activitysim.core import pipeline
from activitysim.core import config
Expand All @@ -14,7 +14,7 @@

@inject.injectable()
def auto_ownership_spec(configs_dir):
return asim.read_model_spec(configs_dir, 'auto_ownership.csv')
return simulate.read_model_spec(configs_dir, 'auto_ownership.csv')


@inject.injectable()
Expand All @@ -26,23 +26,26 @@ def auto_ownership_settings(configs_dir):
def auto_ownership_simulate(households_merged,
auto_ownership_spec,
auto_ownership_settings,
chunk_size,
trace_hh_id):
"""
Auto ownership is a standard model which predicts how many cars a household
with given characteristics owns
"""
trace_label = 'auto_ownership_simulate'

logger.info("Running auto_ownership_simulate with %d households" % len(households_merged))

nest_spec = config.get_logit_model_settings(auto_ownership_settings)
constants = config.get_model_constants(auto_ownership_settings)

choices = asim.simple_simulate(
choices = simulate.simple_simulate(
choosers=households_merged.to_frame(),
spec=auto_ownership_spec,
nest_spec=nest_spec,
locals_d=constants,
trace_label=trace_hh_id and 'auto_ownership',
chunk_size=chunk_size,
trace_label=trace_label,
trace_choice_name='auto_ownership')

tracing.print_summary('auto_ownership', choices, value_counts=True)
Expand Down
24 changes: 9 additions & 15 deletions activitysim/abm/models/initialize.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,43 +19,37 @@
@inject.step()
def initialize():
"""

Because random seed is set differently for each step, the sampling of households depends
on which step they are initially loaded in.

We load them explicitly up front, so that
on which step they are initially loaded in so we force them to load here and they get
stored to the pipeline,
"""

t0 = tracing.print_elapsed_time()
inject.get_table('land_use').to_frame()
t0 = tracing.print_elapsed_time("preload land_use")
t0 = tracing.print_elapsed_time("preload land_use", t0, debug=True)

inject.get_table('households').to_frame()
t0 = tracing.print_elapsed_time("preload households")
t0 = tracing.print_elapsed_time("preload households", t0, debug=True)

inject.get_table('persons').to_frame()
t0 = tracing.print_elapsed_time("preload persons")
t0 = tracing.print_elapsed_time("preload persons", t0, debug=True)

inject.get_table('person_windows').to_frame()
t0 = tracing.print_elapsed_time("preload person_windows")

pass
t0 = tracing.print_elapsed_time("preload person_windows", t0, debug=True)


@inject.injectable(cache=True)
def preload_injectables():
"""
called after pipeline is
preload bulky injectables up front - stuff that isn't inserted into eh pipeline
"""

# could simply list injectables as arguments, but this way we can report timing...

logger.info("preload_injectables")

t0 = tracing.print_elapsed_time()

if inject.get_injectable('skim_dict', None) is not None:
t0 = tracing.print_elapsed_time("preload skim_dict")
t0 = tracing.print_elapsed_time("preload skim_dict", t0, debug=True)

if inject.get_injectable('skim_stack', None) is not None:
t0 = tracing.print_elapsed_time("preload skim_stack")
t0 = tracing.print_elapsed_time("preload skim_stack", t0, debug=True)
2 changes: 1 addition & 1 deletion activitysim/abm/models/mandatory_scheduling.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

logger = logging.getLogger(__name__)

DUMP = True
DUMP = False


@inject.injectable()
Expand Down
35 changes: 22 additions & 13 deletions activitysim/abm/models/mandatory_tour_frequency.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import pandas as pd

from activitysim.core import simulate as asim
from activitysim.core import simulate
from activitysim.core import tracing
from activitysim.core import pipeline
from activitysim.core import config
Expand All @@ -20,7 +20,7 @@

@inject.injectable()
def mandatory_tour_frequency_spec(configs_dir):
return asim.read_model_spec(configs_dir, 'mandatory_tour_frequency.csv')
return simulate.read_model_spec(configs_dir, 'mandatory_tour_frequency.csv')


@inject.injectable()
Expand All @@ -41,12 +41,15 @@ def mandatory_tour_frequency_alternatives(configs_dir):
def mandatory_tour_frequency(persons_merged,
mandatory_tour_frequency_spec,
mandatory_tour_frequency_settings,
chunk_size,
trace_hh_id):
"""
This model predicts the frequency of making mandatory trips (see the
alternatives above) - these trips include work and school in some combination.
"""

trace_label = 'mandatory_tour_frequency'

choosers = persons_merged.to_frame()
# filter based on results of CDAP
choosers = choosers[choosers.cdap_activity == 'M']
Expand All @@ -55,12 +58,13 @@ def mandatory_tour_frequency(persons_merged,
nest_spec = config.get_logit_model_settings(mandatory_tour_frequency_settings)
constants = config.get_model_constants(mandatory_tour_frequency_settings)

choices = asim.simple_simulate(
choices = simulate.simple_simulate(
choosers,
spec=mandatory_tour_frequency_spec,
nest_spec=nest_spec,
locals_d=constants,
trace_label=trace_hh_id and 'mandatory_tour_frequency',
chunk_size=chunk_size,
trace_label=trace_label,
trace_choice_name='mandatory_tour_frequency')

# convert indexes to alternative names
Expand All @@ -72,16 +76,16 @@ def mandatory_tour_frequency(persons_merged,

inject.add_column("persons", "mandatory_tour_frequency", choices)

create_mandatory_tours()
create_mandatory_tours(trace_hh_id)

# add mandatory_tour-dependent columns (e.g. tour counts) to persons
pipeline.add_dependent_columns("persons", "persons_mtf")

if trace_hh_id:
trace_columns = ['mandatory_tour_frequency']
tracing.trace_df(inject.get_table('persons_merged').to_frame(),
label="mandatory_tour_frequency",
columns=trace_columns,
tracing.trace_df(inject.get_table('persons').to_frame(),
label="mandatory_tour_frequency.persons",
# columns=trace_columns,
warn_if_empty=True)


Expand All @@ -92,7 +96,7 @@ def mandatory_tour_frequency(persons_merged,
"""


def create_mandatory_tours():
def create_mandatory_tours(trace_hh_id):

# FIXME - move this to body?

Expand All @@ -105,14 +109,19 @@ def create_mandatory_tours():

tour_frequency_alternatives = inject.get_injectable('mandatory_tour_frequency_alternatives')

tours = process_mandatory_tours(persons, tour_frequency_alternatives)
mandatory_tours = process_mandatory_tours(persons, tour_frequency_alternatives)

expressions.assign_columns(
df=tours,
df=mandatory_tours,
model_settings='annotate_tours_with_dest',
configs_dir=configs_dir,
trace_label='create_mandatory_tours')

pipeline.extend_table("tours", tours)
tours = pipeline.extend_table("tours", mandatory_tours)
tracing.register_traceable_table('tours', tours)
pipeline.get_rn_generator().add_channel(tours, 'tours')
pipeline.get_rn_generator().add_channel(mandatory_tours, 'tours')

if trace_hh_id:
tracing.trace_df(mandatory_tours,
label="mandatory_tour_frequency.mandatory_tours",
warn_if_empty=True)
Loading