Skip to content

Commit 335111b

Browse files
JoeJimFloodjpn--
andauthored
Clean up command prompt logging (#1004)
* Downgraded logging of which expression is being evaluated from "info" level to "debug" level * Downgraded column list before and after dropping unused columns from "INFO" to "DEBUG" * Downgraded reporting of model component results from "INFO" to "DEBUG" * Downgraded a few log messages in settings checker from "INFO" to "DEBUG" * Changed default value of `level` argument in flow.TimeLogger.summary() from 20 to 10 so that it's a DEBUG message by default * Downgraded logging statements when merging the choosers and alternatives from "INFO" to "DEBUG" * Downgraded runtimes for flow evaluations from "INFO" to "DEBUG" * Downgraded "sharrow_enabled is True/False" from "INFO" to "DEBUG" as it's repetitive and will likely only be of concern during development/debugging * Downgraded utility data types reporting from "INFO" to "DEBUG" * Downgraded all instances of logger.info to logger.debug in activitysim.core.chunk * Downgraded line reporting how many rows are being run for eval_interaction_utilities * Downgraded several (primarily repetitive) statements in activitysim.abm.models.util * Downgraded messages reportng how long each of the sampling, logsums, and simulation in trip destination choice from "INFO" to "DEBUG" * Downgraded more detailed messages from "INFO" to "DEBUG" in trip destination * Reclassified some logging statements * Swapped logging statement classifications to get desired statement printed * Downgraded statement from "INFO" to "DEBUG" that wasn't providing much information * blacken * Added documentation on logging levels --------- Co-authored-by: Jeffrey Newman <jeff@driftless.xyz>
1 parent 34539d0 commit 335111b

16 files changed

+130
-62
lines changed

activitysim/abm/models/settings_checker.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ def try_load_model_settings(
322322
) -> tuple[PydanticBase | None, Exception | None]:
323323

324324
msg = f"Attempting to load model settings for {model_name} via {model_settings_class.__name__} and {model_settings_file}"
325-
logger.info(msg)
325+
logger.debug(msg)
326326
file_logger.info(msg)
327327

328328
try:
@@ -348,7 +348,7 @@ class InputCheckerSettings(PydanticBase):
348348
)
349349
result = model_settings, None
350350
msg = f"Successfully loaded model settings from {model_settings_file}"
351-
logger.info(msg)
351+
logger.debug(msg)
352352
except Exception as e:
353353
result = None, e
354354
return result
@@ -358,12 +358,12 @@ def try_load_spec(
358358
model_name: str, model_settings: PydanticBase, spec_file: str, state: State
359359
) -> tuple[DataFrame | None, Exception | None]:
360360
msg = f"Attempting to load SPEC for {model_name} via {model_settings.__class__.__name__}"
361-
logger.info(msg)
361+
logger.debug(msg)
362362
file_logger.info(msg)
363363
try:
364364
result = state.filesystem.read_model_spec(spec_file), None
365365
msg = f"Successfully loaded model SPEC from {spec_file}"
366-
logger.info(msg)
366+
logger.debug(msg)
367367
file_logger.info(msg)
368368
except Exception as e:
369369
# always return a dataframe
@@ -375,13 +375,13 @@ def try_load_coefs(
375375
model_name: str, model_settings: PydanticBase, coefs_file: str, state: State
376376
) -> tuple[DataFrame, Optional[Exception]]:
377377
msg = f"Attempting to load COEFFICIENTS for {model_name} via {model_settings.__class__.__name__}"
378-
logger.info(msg)
378+
logger.debug(msg)
379379
file_logger.info(msg)
380380

381381
try:
382382
result = state.filesystem.read_model_coefficients(file_name=coefs_file), None
383383
msg = f"Successfully loaded model Coefficients from {coefs_file}"
384-
logger.info(msg)
384+
logger.debug(msg)
385385
file_logger.info(msg)
386386
except Exception as e:
387387
result = None, e
@@ -423,7 +423,7 @@ def try_eval_spec_coefs(
423423
else:
424424
result = eval_coefficients(state, spec, coefs, estimator=None), None
425425
msg = f"Successfully evaluated coefficients for {model_name}"
426-
logger.info(msg)
426+
logger.debug(msg)
427427
file_logger.info(msg)
428428
except Exception as e:
429429
result = None, e

activitysim/abm/models/trip_destination.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -820,7 +820,7 @@ def compute_logsums(
820820
adds od_logsum and dp_logsum columns to trips (in place)
821821
"""
822822
trace_label = tracing.extend_trace_label(trace_label, "compute_logsums")
823-
logger.info("Running %s with %d samples", trace_label, destination_sample.shape[0])
823+
logger.debug("Running %s with %d samples", trace_label, destination_sample.shape[0])
824824

825825
# chunk usage is uniform so better to combine
826826
chunk_tag = "trip_destination.compute_logsums"
@@ -977,7 +977,7 @@ def trip_destination_simulate(
977977

978978
alt_dest_col_name = model_settings.ALT_DEST_COL_NAME
979979

980-
logger.info("Running trip_destination_simulate with %d trips", len(trips))
980+
logger.debug("Running trip_destination_simulate with %d trips", len(trips))
981981

982982
skims = skim_hotel.sample_skims(presample=False)
983983

@@ -1102,7 +1102,7 @@ def choose_trip_destination(
11021102
)
11031103
trips = trips[~dropped_trips]
11041104

1105-
t0 = print_elapsed_time("%s.trip_destination_sample" % trace_label, t0)
1105+
t0 = print_elapsed_time("%s.trip_destination_sample" % trace_label, t0, debug=True)
11061106

11071107
if trips.empty:
11081108
return pd.Series(index=trips.index).to_frame("choice"), None
@@ -1124,7 +1124,7 @@ def choose_trip_destination(
11241124
destination_sample["od_logsum"] = 0.0
11251125
destination_sample["dp_logsum"] = 0.0
11261126

1127-
t0 = print_elapsed_time("%s.compute_logsums" % trace_label, t0)
1127+
t0 = print_elapsed_time("%s.compute_logsums" % trace_label, t0, debug=True)
11281128

11291129
destinations = trip_destination_simulate(
11301130
state,
@@ -1155,7 +1155,9 @@ def choose_trip_destination(
11551155
else:
11561156
destination_sample = None
11571157

1158-
t0 = print_elapsed_time("%s.trip_destination_simulate" % trace_label, t0)
1158+
t0 = print_elapsed_time(
1159+
"%s.trip_destination_simulate" % trace_label, t0, debug=True
1160+
)
11591161

11601162
return destinations, destination_sample
11611163

@@ -1484,7 +1486,9 @@ def run_trip_destination(
14841486
else:
14851487
None
14861488

1487-
logger.info("Running %s with %d trips", nth_trace_label, nth_trips.shape[0])
1489+
logger.debug(
1490+
"Running %s with %d trips", nth_trace_label, nth_trips.shape[0]
1491+
)
14881492

14891493
# - choose destination for nth_trips, segmented by primary_purpose
14901494
choices_list = []
@@ -1649,7 +1653,7 @@ def trip_destination(
16491653
estimator.write_table(state.get_dataframe("land_use"), "landuse", append=False)
16501654
estimator.write_model_settings(model_settings, model_settings_file_name)
16511655

1652-
logger.info("Running %s with %d trips", trace_label, trips_df.shape[0])
1656+
logger.debug("Running %s with %d trips", trace_label, trips_df.shape[0])
16531657

16541658
trips_df, save_sample_df = run_trip_destination(
16551659
state,

activitysim/abm/models/util/canonical_ids.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ def canonical_tours(state: workflow.State):
255255
)
256256
non_mandatory_channels = enumerate_tour_types(non_mandatory_tour_flavors)
257257

258-
logger.info(f"Non-Mandatory tour flavors used are {non_mandatory_tour_flavors}")
258+
logger.debug(f"Non-Mandatory tour flavors used are {non_mandatory_tour_flavors}")
259259

260260
# ---- mandatory_channels
261261
mtf_model_settings_file_name = "mandatory_tour_frequency.yaml"
@@ -271,7 +271,7 @@ def canonical_tours(state: workflow.State):
271271
)
272272
mandatory_channels = enumerate_tour_types(mandatory_tour_flavors)
273273

274-
logger.info(f"Mandatory tour flavors used are {mandatory_tour_flavors}")
274+
logger.debug(f"Mandatory tour flavors used are {mandatory_tour_flavors}")
275275

276276
# ---- atwork_subtour_channels
277277
atwork_model_settings_file_name = "atwork_subtour_frequency.yaml"
@@ -288,7 +288,7 @@ def canonical_tours(state: workflow.State):
288288
)
289289
atwork_subtour_channels = enumerate_tour_types(atwork_subtour_flavors)
290290

291-
logger.info(f"Atwork subtour flavors used are {atwork_subtour_flavors}")
291+
logger.debug(f"Atwork subtour flavors used are {atwork_subtour_flavors}")
292292

293293
# we need to distinguish between subtours of different work tours
294294
# (e.g. eat1_1 is eat subtour for parent work tour 1 and eat1_2 is for work tour 2)
@@ -317,7 +317,7 @@ def canonical_tours(state: workflow.State):
317317
joint_tour_flavors = determine_flavors_from_alts_file(
318318
jtf_alts, provided_joint_flavors, default_joint_flavors
319319
)
320-
logger.info(f"Joint tour flavors used are {joint_tour_flavors}")
320+
logger.debug(f"Joint tour flavors used are {joint_tour_flavors}")
321321

322322
joint_tour_channels = enumerate_tour_types(joint_tour_flavors)
323323
joint_tour_channels = ["j_%s" % c for c in joint_tour_channels]
@@ -343,7 +343,7 @@ def canonical_tours(state: workflow.State):
343343
school_escort_flavors = {"escort": 2 * num_escortees}
344344
school_escort_channels = enumerate_tour_types(school_escort_flavors)
345345
school_escort_channels = ["se_%s" % c for c in school_escort_channels]
346-
logger.info(f"School escort tour flavors used are {school_escort_flavors}")
346+
logger.debug(f"School escort tour flavors used are {school_escort_flavors}")
347347

348348
sub_channels = sub_channels + school_escort_channels
349349

activitysim/abm/models/util/tour_destination.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -92,18 +92,18 @@ def _destination_sample(
9292
coefficients_file_name=model_settings.COEFFICIENTS,
9393
)
9494

95-
logger.info("running %s with %d tours", trace_label, len(choosers))
95+
logger.debug("running %s with %d tours", trace_label, len(choosers))
9696

9797
sample_size = model_settings.SAMPLE_SIZE
9898
if estimator and model_settings.ESTIMATION_SAMPLE_SIZE >= 0:
9999
sample_size = model_settings.ESTIMATION_SAMPLE_SIZE
100-
logger.info(
100+
logger.debug(
101101
f"Estimation mode for {trace_label} using sample size of {sample_size}"
102102
)
103103

104104
if state.settings.disable_destination_sampling:
105105
sample_size = 0
106-
logger.info(
106+
logger.debug(
107107
f"SAMPLE_SIZE set to 0 for {trace_label} because disable_destination_sampling is set"
108108
)
109109

@@ -562,7 +562,7 @@ def destination_presample(
562562
trace_label = tracing.extend_trace_label(trace_label, "presample")
563563
chunk_tag = "tour_destination.presample"
564564

565-
logger.info(f"{trace_label} location_presample")
565+
logger.debug(f"{trace_label} location_presample")
566566

567567
alt_dest_col_name = model_settings.ALT_DEST_COL_NAME
568568
assert DEST_TAZ != alt_dest_col_name
@@ -652,7 +652,7 @@ def run_destination_sample(
652652
)
653653

654654
if pre_sample_taz:
655-
logger.info(
655+
logger.debug(
656656
"Running %s destination_presample with %d tours" % (trace_label, len(tours))
657657
)
658658

@@ -740,7 +740,7 @@ def run_destination_logsums(
740740
how="left",
741741
)
742742

743-
logger.info("Running %s with %s rows", trace_label, len(choosers))
743+
logger.debug("Running %s with %s rows", trace_label, len(choosers))
744744

745745
state.tracing.dump_df(DUMP, persons_merged, trace_label, "persons_merged")
746746
state.tracing.dump_df(DUMP, choosers, trace_label, "choosers")
@@ -832,7 +832,7 @@ def run_destination_simulate(
832832

833833
constants = model_settings.CONSTANTS
834834

835-
logger.info("Running tour_destination_simulate with %d persons", len(choosers))
835+
logger.debug("Running tour_destination_simulate with %d persons", len(choosers))
836836

837837
# create wrapper with keys for this lookup - in this case there is a home_zone_id in the choosers
838838
# and a zone_id in the alternatives which get merged during interaction

activitysim/abm/models/util/tour_od.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -155,15 +155,15 @@ def _od_sample(
155155
else:
156156
alt_col_name = alt_od_col_name
157157

158-
logger.info("running %s with %d tours", trace_label, len(choosers))
158+
logger.debug("running %s with %d tours", trace_label, len(choosers))
159159

160160
sample_size = model_settings.SAMPLE_SIZE
161161
if state.settings.disable_destination_sampling or (
162162
estimator and estimator.want_unsampled_alternatives
163163
):
164164
# FIXME interaction_sample will return unsampled complete alternatives
165165
# with probs and pick_count
166-
logger.info(
166+
logger.debug(
167167
(
168168
"Estimation mode for %s using unsampled alternatives "
169169
"short_circuit_choices"
@@ -607,7 +607,7 @@ def od_presample(
607607
trace_label = tracing.extend_trace_label(trace_label, "presample")
608608
chunk_tag = "tour_od.presample"
609609

610-
logger.info(f"{trace_label} od_presample")
610+
logger.debug(f"{trace_label} od_presample")
611611

612612
alt_od_col_name = get_od_id_col(ORIG_MAZ, DEST_TAZ)
613613

@@ -711,7 +711,7 @@ def run_od_sample(
711711
)
712712

713713
if pre_sample_taz:
714-
logger.info(
714+
logger.debug(
715715
"Running %s destination_presample with %d tours" % (trace_label, len(tours))
716716
)
717717

@@ -780,7 +780,7 @@ def run_od_logsums(
780780
choosers[origin_id_col].astype(str) + "_" + choosers[dest_id_col].astype(str)
781781
)
782782

783-
logger.info("Running %s with %s rows", trace_label, len(choosers))
783+
logger.debug("Running %s with %s rows", trace_label, len(choosers))
784784

785785
state.tracing.dump_df(DUMP, choosers, trace_label, "choosers")
786786

@@ -989,7 +989,7 @@ def run_od_simulate(
989989

990990
constants = model_settings.CONSTANTS
991991

992-
logger.info("Running tour_destination_simulate with %d persons", len(choosers))
992+
logger.debug("Running tour_destination_simulate with %d persons", len(choosers))
993993

994994
# create wrapper with keys for this lookup - in this case there is an origin ID
995995
# column and a destination ID columns in the alternatives table.

activitysim/abm/models/util/tour_scheduling.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ def run_tour_scheduling(
140140
if estimators:
141141
timetable.begin_transaction(list(estimators.values()))
142142

143-
logger.info(f"Running {trace_label} with %d tours", len(chooser_tours))
143+
logger.debug(f"Running {trace_label} with %d tours", len(chooser_tours))
144144
choices = vts.vectorize_tour_scheduling(
145145
state,
146146
chooser_tours,

activitysim/abm/models/util/vectorize_tour_scheduling.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ def _compute_logsums(
161161
mandatory=False,
162162
)
163163
choosers = alt_tdd.join(tours_merged, how="left", rsuffix="_chooser")
164-
logger.info(
164+
logger.debug(
165165
f"{trace_label} compute_logsums for {choosers.shape[0]} choosers {alt_tdd.shape[0]} alts"
166166
)
167167

@@ -194,7 +194,7 @@ def _compute_logsums(
194194

195195
if preprocessor_settings:
196196
simulate.set_skim_wrapper_targets(choosers, skims)
197-
logger.info(
197+
logger.debug(
198198
f"{trace_label} start preprocessing prior to compute_logsums for {choosers.shape[0]} choosers {alt_tdd.shape[0]} alts"
199199
)
200200
expressions.assign_columns(
@@ -204,7 +204,7 @@ def _compute_logsums(
204204
locals_dict=locals_dict,
205205
trace_label=trace_label,
206206
)
207-
logger.info(
207+
logger.debug(
208208
f"{trace_label} end preprocessing prior to compute_logsums for {choosers.shape[0]} choosers {alt_tdd.shape[0]} alts"
209209
)
210210

@@ -426,7 +426,7 @@ def compute_tour_scheduling_logsums(
426426
)
427427
chunk_sizer.log_df(trace_label, "deduped_alt_tdds", deduped_alt_tdds)
428428

429-
logger.info(
429+
logger.debug(
430430
f"{trace_label} compute_logsums "
431431
f"deduped_alt_tdds reduced number of rows by "
432432
f"{round(100 * (len(alt_tdd) - len(deduped_alt_tdds)) / len(alt_tdd), 2)}% "
@@ -758,7 +758,7 @@ def _schedule_tours(
758758
759759
"""
760760

761-
logger.info(
761+
logger.debug(
762762
"%s schedule_tours running %d tour choices" % (tour_trace_label, len(tours))
763763
)
764764

@@ -908,7 +908,7 @@ def schedule_tours(
908908
logger.info("schedule_tours %s tours not monotonic_increasing - sorting df")
909909
tours = tours.sort_index()
910910

911-
logger.info(
911+
logger.debug(
912912
"%s schedule_tours running %d tour choices" % (tour_trace_label, len(tours))
913913
)
914914

activitysim/core/assign.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,7 @@ def rng_lognormal(random_draws, mu, sigma, broadcast=True, scale=False):
360360
)
361361

362362
if trace_label:
363-
logger.info(f"{trace_label}.assign_variables {target} = {expression}")
363+
logger.debug(f"{trace_label}.assign_variables {target} = {expression}")
364364

365365
if is_temp_singular(target) or is_throwaway(target):
366366
try:

0 commit comments

Comments
 (0)