Skip to content

Commit

Permalink
Merge branch 'master' into BayDAG_contribution_playground
Browse files Browse the repository at this point in the history
  • Loading branch information
dhensle committed Dec 15, 2023
2 parents 0950b80 + a8e755f commit 808e04e
Show file tree
Hide file tree
Showing 12 changed files with 194 additions and 90 deletions.
27 changes: 27 additions & 0 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
---
name: Bug report
about: Create a report to help us improve
title: ''
labels: Bug
assignees: ''

---

**Describe the bug**
A clear and concise description of what the bug is.

**To Reproduce**
Steps to reproduce the behavior:
1. Go to '...'
2. Click on '....'
3. Scroll down to '....'
4. See error

**Expected behavior**
A clear and concise description of what you expected to happen.

**Screenshots**
If applicable, add screenshots to help explain your problem.

**Additional context**
Add any other context about the problem here.
20 changes: 20 additions & 0 deletions .github/ISSUE_TEMPLATE/feature_request.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
name: Feature request
about: Suggest an idea for this project
title: ''
labels: Feature
assignees: ''

---

**Is your feature request related to a problem? Please describe.**
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]

**Describe the solution you'd like**
A clear and concise description of what you want to happen.

**Describe alternatives you've considered**
A clear and concise description of any alternative solutions or features you've considered.

**Additional context**
Add any other context or screenshots about the feature request here.
63 changes: 47 additions & 16 deletions activitysim/abm/models/trip_scheduling.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
# ActivitySim
# See full license in LICENSE.txt.
import logging
import warnings
from builtins import range

import numpy as np
import pandas as pd

from activitysim.abm.models.util import estimation
from activitysim.abm.models.util.trip import cleanup_failed_trips, failed_trip_cohorts
from activitysim.core import chunk, config, inject, pipeline, tracing, expressions
from activitysim.core import chunk, config, expressions, inject, pipeline, tracing
from activitysim.core.util import reindex

from .util.school_escort_tours_trips import split_out_school_escorting_trips
from .util import probabilistic_scheduling as ps
from .util.school_escort_tours_trips import split_out_school_escorting_trips

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -47,6 +48,22 @@
PROBS_JOIN_COLUMNS_RELATIVE_BASED = ["outbound", "periods_left"]


def _logic_version(model_settings):
logic_version = model_settings.get("logic_version", None)
if logic_version is None:
warnings.warn(
"The trip_scheduling component now has a logic_version setting "
"to control how the scheduling rules are applied. The default "
"logic_version is currently set at `1` but may be moved up in "
"the future. Explicitly set `logic_version` to 2 in the model "
"settings to upgrade your model logic now, or set it to 1 to "
"suppress this message.",
FutureWarning,
)
logic_version = 1
return logic_version


def set_tour_hour(trips, tours):
"""
add columns 'tour_hour', 'earliest', 'latest' to trips
Expand Down Expand Up @@ -108,7 +125,7 @@ def set_stop_num(trips):
trips["stop_num"] = trips.stop_num.where(trips["outbound"], trips["trip_num"])


def update_tour_earliest(trips, outbound_choices):
def update_tour_earliest(trips, outbound_choices, logic_version: int):
"""
Updates "earliest" column for inbound trips based on
the maximum outbound trip departure time of the tour.
Expand All @@ -121,6 +138,14 @@ def update_tour_earliest(trips, outbound_choices):
outbound_choices: pd.Series
time periods depart choices, one per trip (except for trips with
zero probs)
logic_version : int
Logic version 1 is the original ActivitySim implementation, which
sets the "earliest" value to the max outbound departure for all
inbound trips, regardless of what that max outbound departure value
is (even if it is NA). Logic version 2 introduces a change whereby
that assignment is only made if the max outbound departure value is
not NA.
Returns
-------
modifies trips in place
Expand All @@ -145,11 +170,18 @@ def update_tour_earliest(trips, outbound_choices):
# set the trips "earliest" column equal to the max outbound departure
# time for all inbound trips. preserve values that were used for outbound trips
# FIXME - extra logic added because max_outbound_departure can be NA if previous failed trip was removed
tmp_trips["earliest"] = np.where(
~tmp_trips["outbound"] & ~tmp_trips["max_outbound_departure"].isna(),
tmp_trips["max_outbound_departure"],
tmp_trips["earliest"],
)
if logic_version == 1:
tmp_trips["earliest"] = tmp_trips["earliest"].where(
tmp_trips["outbound"], tmp_trips["max_outbound_departure"]
)
elif logic_version > 1:
tmp_trips["earliest"] = np.where(
~tmp_trips["outbound"] & ~tmp_trips["max_outbound_departure"].isna(),
tmp_trips["max_outbound_departure"],
tmp_trips["earliest"],
)
else:
raise ValueError(f"bad logic_version: {logic_version}")

trips["earliest"] = tmp_trips["earliest"].reindex(trips.index)

Expand Down Expand Up @@ -248,7 +280,6 @@ def schedule_trips_in_leg(

first_trip_in_leg = True
for i in range(trips.trip_num.min(), trips.trip_num.max() + 1):

nth_trace_label = tracing.extend_trace_label(trace_label, "num_%s" % i)

# - annotate trips
Expand Down Expand Up @@ -296,7 +327,12 @@ def schedule_trips_in_leg(
# choices are relative to the previous departure time
choices = nth_trips.earliest + choices
# need to update the departure time based on the choice
update_tour_earliest(trips, choices)
logic_version = _logic_version(model_settings)
if logic_version == 1:
raise ValueError(
"cannot use logic version 1 with 'relative' scheduling mode"
)
update_tour_earliest(trips, choices, logic_version)

# adjust allowed depart range of next trip
has_next_trip = nth_trips.next_trip_id != NO_TRIP_ID
Expand Down Expand Up @@ -332,7 +368,6 @@ def run_trip_scheduling(
trace_hh_id,
trace_label,
):

set_tour_hour(trips_chunk, tours)
set_stop_num(trips_chunk)

Expand Down Expand Up @@ -361,7 +396,7 @@ def run_trip_scheduling(

# departure time of last outbound trips must constrain
# departure times for initial inbound trips
update_tour_earliest(trips_chunk, choices)
update_tour_earliest(trips_chunk, choices, _logic_version(model_settings))

if (~trips_chunk.outbound).any():
leg_chunk = trips_chunk[~trips_chunk.outbound]
Expand All @@ -386,7 +421,6 @@ def run_trip_scheduling(

@inject.step()
def trip_scheduling(trips, tours, chunk_size, trace_hh_id):

"""
Trip scheduling assigns depart times for trips within the start, end limits of the tour.
Expand Down Expand Up @@ -498,13 +532,10 @@ def trip_scheduling(trips, tours, chunk_size, trace_hh_id):
) in chunk.adaptive_chunked_choosers_by_chunk_id(
trips_df, chunk_size, trace_label, trace_label
):

i = 0
while (i < max_iterations) and not trips_chunk.empty:

# only chunk log first iteration since memory use declines with each iteration
with chunk.chunk_log(trace_label) if i == 0 else chunk.chunk_log_skip():

i += 1
is_last_iteration = i == max_iterations

Expand Down
1 change: 0 additions & 1 deletion activitysim/abm/models/util/estimation.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,6 @@ def write_omnibus_table(self):
1 if omnibus_table in self.omnibus_tables_append_columns else 0
)

# df = pd.concat([self.tables[t] for t in table_names], axis=concat_axis)
if len(table_names) == 0:
# empty tables
df = pd.DataFrame()
Expand Down
6 changes: 3 additions & 3 deletions activitysim/cli/create.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ def get_example(
Files downloaded via http pointers will be cached in
this location. If a path is not given but just a truthy
value, then a cache directory is created using in a location
selected by the appdirs library (or, if not installed,
selected by the platformdirs library (or, if not installed,
linking is skipped.)
"""
if example_name not in EXAMPLES:
Expand Down Expand Up @@ -200,11 +200,11 @@ def download_asset(url, target_path, sha256=None, link=True):
if link:
if not isinstance(link, (str, Path)):
try:
import appdirs
import platformdirs
except ImportError:
link = False
else:
link = appdirs.user_data_dir("ActivitySim")
link = platformdirs.user_data_dir("ActivitySim")
original_target_path = target_path
target_path = os.path.join(link, target_path)
os.makedirs(os.path.dirname(target_path), exist_ok=True)
Expand Down
10 changes: 9 additions & 1 deletion activitysim/core/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -708,7 +708,7 @@ def filter_warnings():
# These warning are left as warnings as an invitation for future enhancement.
from pandas.errors import PerformanceWarning

warnings.filterwarnings("ignore", category=PerformanceWarning)
warnings.filterwarnings("default", category=PerformanceWarning)

# pandas 1.5
# beginning in pandas version 1.5, a new warning is emitted when a column is set via iloc
Expand Down Expand Up @@ -750,6 +750,14 @@ def filter_warnings():
else:
warnings.filterwarnings("default", category=CacheMissWarning)

# beginning from PR #660 (after 1.2.0), a FutureWarning is emitted when the trip
# scheduling component lacks a logic_version setting
warnings.filterwarnings(
"ignore",
category=FutureWarning,
message="The trip_scheduling component now has a logic_version setting.*",
)


def handle_standard_args(parser=None):

Expand Down
47 changes: 24 additions & 23 deletions conda-environments/activitysim-dev-base.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ dependencies:
- black >= 22.0,<23
- bump2version # for making a release
- coveralls
- cytoolz >= 0.8.1
- dask
- cytoolz = 0.12.*
- dask = 2023.3.*
- descartes
- filelock
- fsspec
Expand All @@ -30,44 +30,45 @@ dependencies:
- ipykernel # so this env will appear in jupyter as a selection
- isort
- jupyterlab
- larch >= 5.5.8
- larch = 5.7.*
- matplotlib
- myst-parser # allows markdown in sphinx
- nbconvert
- nbformat
- numba >= 0.55.2
- numba = 0.56.*
- numexpr
- numpy >= 1.16.1,<=1.21
- numpy = 1.23.*
- numpydoc
- openmatrix >= 0.3.4.1
- orca >= 1.6
- pandas >= 1.1.0,<2.0
- openmatrix = 0.3.*
- orca = 1.8
- pandas = 1.4.*
- platformdirs = 3.2.*
- pre-commit
- psutil >= 4.1
- pyarrow >= 2.0
- psutil = 5.9.*
- pyarrow = 11.*
- pycodestyle
- pydantic
- pydantic = 1.10.*
- pydata-sphinx-theme
- pyinstrument
- pypyr
- pyinstrument = 4.4
- pypyr = 5.8.*
- pytables >=3.5.1,<3.7
- pytest
- pytest = 7.2.*
- pytest-cov
- pytest-regressions
- pyyaml >= 5.1
- requests >= 2.7
- rich
- pyyaml = 6.*
- requests = 2.28.*
- rich = 13.3.*
- ruby # required for benchmarking pre-commit hooks
- setuptools_scm
- scikit-learn >= 1.1
- scikit-learn = 1.2.*
- simwrapper > 1.7
- snakeviz # for profiling
- sphinx
- sphinx_rtd_theme
- sphinx-argparse
- xarray >= 0.21
- sphinx = 6.1.*
- sphinx_rtd_theme = 1.2.*
- sphinx-argparse = 0.4.*
- xarray = 2023.2.*
- xmle
- zarr
- zarr = 2.14.*

- pip:
- autodoc_pydantic
Loading

0 comments on commit 808e04e

Please sign in to comment.