Skip to content

Commit

Permalink
ENH: add computation time to progress reports
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffgortmaker committed Dec 17, 2022
1 parent e97f82d commit 09600d7
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions pyblp/economies/problem.py
Original file line number Diff line number Diff line change
Expand Up @@ -641,14 +641,17 @@ def wrapper(new_theta: Array, iterations: int, evaluations: int) -> ObjectiveRes
"""Compute and output progress associated with a single objective evaluation."""
nonlocal iteration_stats, smallest_objective, progress, detect_micro_collinearity
assert optimization is not None and shares_bounds is not None and costs_bounds is not None
progress_start_time = time.time()
progress = compute_step_progress(
new_theta, progress, optimization._compute_gradient, compute_hessian=False,
compute_micro_covariances=False, detect_micro_collinearity=detect_micro_collinearity,
compute_simulation_covariances=False,
)
iteration_stats.append(progress.iteration_stats)
progress_time = time.time() - progress_start_time
formatted_progress = progress.format(
optimization, shares_bounds, costs_bounds, step, iterations, evaluations, smallest_objective
optimization, shares_bounds, costs_bounds, step, iterations, evaluations, progress_time,
smallest_objective
)
if formatted_progress:
output(formatted_progress)
Expand Down Expand Up @@ -1743,7 +1746,7 @@ def __init__(

def format(
self, optimization: Optimization, shares_bounds: Bounds, costs_bounds: Bounds, step: int, iterations: int,
evaluations: int, smallest_objective: Array) -> str:
evaluations: int, progress_time: float, smallest_objective: Array) -> str:
"""Format a universal display of optimization progress as a string. The first iteration will include the
progress table header. If there are any errors, information about them will be formatted as well, regardless of
whether or not a universal display is to be used. The smallest_objective is the smallest objective value
Expand All @@ -1767,11 +1770,12 @@ def format(

# construct the leftmost part of the table that always shows up
header = [
("GMM", "Step"), ("Optimization", "Iterations"), ("Objective", "Evaluations"),
("GMM", "Step"), ("Computation", "Time"), ("Optimization", "Iterations"), ("Objective", "Evaluations"),
("Fixed Point", "Iterations"), ("Contraction", "Evaluations")
]
values = [
str(step),
format_seconds(progress_time),
str(iterations),
str(evaluations),
str(sum(s.iterations for s in self.iteration_stats.values())),
Expand Down

0 comments on commit 09600d7

Please sign in to comment.