Repository navigation
Conversation
prob.stats (and fn.stats for a compiled expression) returns a snapshot with one row per phase: build, setup, objective, gradient, constraints, jacobian and hessian. Each row has the seconds spent inside the engine's own routines, the seconds spent around them (Python and the bindings), and the number of real evaluations. Printing it gives a table. The engine's timers are read through a new binding, problem_stats, and subtracted from wall times measured in Python. A method is not charged for the stages it needs from another method. The time to build the expressions is measured in the operators and functions users call and stored on the node they return; a problem adds it up over its own nodes. This makes building expressions about 8% slower. verbose=True now prints the build and setup rows from Python when the problem is set up. The engine's banner at garbage collection is no longer triggered from Python. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012aJMgsjHjvvLLFNbMGuvAL
It printed the first two rows of the table that print(prob.stats) gives in full, compile() never had it, and it was not documented. Problem(..., verbose=True) now raises a TypeError. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012aJMgsjHjvvLLFNbMGuvAL
With seconds chosen from the grand total, a problem whose time is almost all in the engine printed 0.000 in every row of the python column. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012aJMgsjHjvvLLFNbMGuvAL
main added the PerformanceWarning for problems written entry by entry (#46). _collect_leaves now returns both the entry count for the warning and the build time for stats. The stats test that builds a loop uses 400 entries, below the warning's threshold. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012aJMgsjHjvvLLFNbMGuvAL
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
prob.stats(andfn.statsfor a compiled expression) reports where the time went, split into the Python interface and the C engine.Rows:
build,setup,objective,gradient,constraints,jacobian,hessian. Every row is aTiming(calls, python, engine).What a log looks like
All output below is copied unedited from one run (Apple M-series, Release build).
The model is written entry by entry, with 20,000 terms in the objective (since #46 this also raises a
PerformanceWarning, on stderr):It is evaluated at 20 points, as a solver would:
1. The command
print(prob.stats)prints this:2. The command
print(prob.stats.hessian)prints this:A small compiled expression with its own variable, evaluated once:
3. The command
print(fn.stats)prints this:Benchmark problems
Two models from diffengine-paper-benchmarks, with the data from each problem's
data.py(make_data,sample_point), single-threaded BLAS as inbench.py, and 100 evaluation points each.NMF,
m, n, k = 200, 200, 5(2,000 variables, nearly dense Hessian):4. The command
print(prob.stats)prints this:Optimal pricing,
n = 20000products (40,000 variables, 20,000 constraints):5. The command
print(prob.stats)prints this:Notes on the tables:
hessianstill asks the engine for the (empty) constraint values and Jacobian, so those rows appear with almost no time.compile, theconstraintsrow is labelledforward.What the columns mean
Diff_engine_stats).setupthis includes the engine's node constructors called through the bindings, which the engine does not time.Problem(...)is called.hessianrow does not include the Jacobian or the forward passes._refresh) is not timed.How
problem_stats(prob)returns the engine's six timers as a dict. No engine change.Problemmeasures wall time withperf_counteron each method's cache-miss path and subtracts the engine's number._timed, which stores the elapsed time on the node they return.Problemadds it up in the walk it already does over its nodes, so shared subexpressions count once and each problem only sees its own expressions. Timed functions call untimed helpers internally (_neg,_pow,_broadcast,_index_flat) so nothing is counted twice; a test checks this for 31 operators and functions.Behaviour changes
verboseargument ofProblemis removed:sp.Problem(..., verbose=True)raises aTypeError. It was undocumented and only made the engine print its own banner when the problem was garbage-collected; nothing is printed unless the user printsprob.stats.Tests
tests/test_stats.py(10 tests). Full suite: 131 passed locally (after merging main, which added thePerformanceWarningof #46) against a Release build of this branch. Not run on a free-threaded build.🤖 Generated with Claude Code
https://claude.ai/code/session_012aJMgsjHjvvLLFNbMGuvAL