Old API for Developers¶
This API still exists, but I don’t think they were used publicly anywhere. The new API should be preferred.
Entry point¶
Main file for perprof.
Classes¶
perprof.main.ParserOptions
¶
Bases: TypedDict
Type definition for parser options dictionary.
Source code in perprof/main.py
70 71 72 73 74 75 76 77 78 79 80 81 | |
perprof.main.ProfilerOptions
¶
Bases: TypedDict
Type definition for profiler options dictionary.
Source code in perprof/main.py
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 | |
Functions¶
perprof.main.main()
¶
Run the perprof command-line tool.
Orchestrates the performance profile generation workflow: 1. Parse command-line arguments and configure logging 2. Process arguments into option dictionaries 3. Select backend and generate profile output
Handles errors gracefully with user-friendly messages.
Example usage
$ perprof –bokeh data1.txt data2.txt -o comparison.html $ perprof –matplotlib –pdf solver1.csv solver2.csv $ perprof –tikz –tex algorithm1.yaml algorithm2.yaml
Raises:
-
SystemExit–On argument parsing errors or critical failures.
Source code in perprof/main.py
503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 | |
perprof.main.process_arguments(args)
¶
Convert command-line arguments into parser and profiler option dictionaries.
Separates data processing options from visualization options and validates backend/format compatibility.
Parameters:
-
args(Namespace) –Parsed command-line arguments from argparse.
Returns:
-
tuple[ParserOptions, ProfilerOptions]–tuple[ParserOptions, ProfilerOptions]: A tuple containing: - ParserOptions: Configuration for data parsing and processing - ProfilerOptions: Configuration for profile visualization
Raises:
-
NotImplementedError–If an unsupported output format is specified for a backend.
-
AssertionError–If RGB color values are invalid.
Example
import argparse
Create a minimal mock args object - full args object would be much larger¶
This demonstrates the function’s purpose rather than testing all attributes¶
pass # Simplified example due to extensive argument requirements
Source code in perprof/main.py
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 | |
perprof.main.set_arguments(args)
¶
Parse and validate command-line arguments for perprof.
Defines the CLI argument parser with backend options, output formats, and data processing parameters.
Parameters:
Returns:
-
Namespace–argparse.Namespace: Parsed and validated arguments ready for processing.
Example
Parse arguments for Bokeh output¶
args = set_arguments([“–bokeh”, “data1.txt”, “data2.txt”, “-o”, “out.html”]) args.bokeh True args.file_name [‘data1.txt’, ‘data2.txt’] args.output ‘out.html’
Source code in perprof/main.py
242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 | |
perprof.main.setup_logging(verbose=False, debug=False, log_file=None)
¶
Configure logging for the application.
Parameters:
-
verbose(bool, default:False) –Enable INFO level logging
-
debug(bool, default:False) –Enable DEBUG level logging (overrides verbose)
-
log_file(str | None, default:None) –Optional file path for logging output
Source code in perprof/main.py
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 | |
File parse¶
Functions to parse the files.
The files must be in the following format::
---
<Metadata 01>: <Value 01>
<Metadata 02>: <Value 02>
---
<Problem Name 01> <Exit Flag 01> <Cost 01>
<Problem Name 02> <Exit Flag 02> <Cost 02>
<Problem Name 03> <Exit Flag 03> <Cost 03>
...
Functions¶
perprof.parse.parse_file(filename, parser_options)
¶
Parse one file.
Parameters:
-
filename(str) –name of the file to be parser
-
parser_options(dict) –dictionary with the following keys:
- subset (list): list with the name of the problems to use
- success (list): list with strings to mark sucess
- mintime (float): minimum time running the solver
- maxtime (float): maximum time running the solver
-
bool(free_format) –if False request that fail be mark with
d
Returns:
Source code in perprof/parse.py
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 | |
Profile interface¶
The functions related with the perform (not the output).
Classes¶
perprof.prof.Pdata
¶
Store data for performance profile.
Source code in perprof/prof.py
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 | |
Functions¶
__init__(parser_options, profiler_options)
¶
Parameters:
Source code in perprof/prof.py
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 | |
__repr__()
¶
Return a representation of the Pdata object.
Source code in perprof/prof.py
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 | |
get_set_problems()
¶
get_set_solvers()
¶
plot()
¶
Generate the plot.
Source code in perprof/prof.py
168 169 170 | |
pre_plot()
¶
Run plot-related checks and processing.
Source code in perprof/prof.py
153 154 155 156 157 158 159 160 161 162 163 164 165 166 | |
print_rob_eff_table()
¶
Print table of robustness and efficiency.
Source code in perprof/prof.py
172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 | |
scale()
¶
Scale time.
Source code in perprof/prof.py
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 | |
set_percent_problems_solved_by_time()
¶
Set the percent of problems solved by time.
Source code in perprof/prof.py
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 | |
Functions¶
perprof.prof.load_data(parser_options)
¶
Load the data.
Parameters:
-
parser_options(dict) –the configuration dicionary
Source code in perprof/prof.py
14 15 16 17 18 19 20 21 22 23 24 | |
Profiler using TikZ¶
Plot using tikz.
Classes¶
perprof.tikz.Profiler
¶
Bases: Pdata
Performance profile generator using TikZ/PGFPlots for LaTeX integration.
Creates LaTeX-based performance profile plots using TikZ and PGFPlots. Suitable for academic publications and technical reports.
Features: - Vector graphics with scalability - LaTeX document font consistency - Mathematical notation support - Standalone and embedded figure support
The profiler generates either standalone LaTeX documents or TikZ code that can be embedded into larger documents. It supports both color and black-and-white output with extensive line style and color customization.
Attributes:
-
output(str | TextIO) –Output filename or file handle (stdout for None).
-
standalone(bool) –Whether to generate standalone LaTeX document.
-
output_format(str) –Target format (“tex” or “pdf”).
-
plot_lang(function) –Localization function for plot text.
Example
Creating a TikZ profiler for publication-quality output:
from perprof.tikz import Profiler
parser_opts = {
"files": ["solver1.txt", "solver2.txt"],
"success": ["converged"],
"free_format": True
}
profiler_opts = {
"output": "publication_figure",
"output_format": "pdf",
"standalone": True,
"black_and_white": False,
"title": "Performance Profile Comparison",
"lang": "en"
}
profiler = Profiler(parser_opts, profiler_opts)
profiler.plot() # Creates publication_figure.tex and compiles to PDF
Source code in perprof/tikz.py
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 | |
Functions¶
__init__(parser_options, profiler_options)
¶
Parameters:
-
parser_options(dict) –Data parsing configuration including: - files: List of solver data files to process - success: Success criteria for solver convergence - maxtime/mintime: Time filtering bounds - compare: Performance metric to compare (default: “time”) - subset: Optional problem subset restriction
-
profiler_options(dict) –Visualization configuration including: - output: Output filename prefix (None for stdout) - output_format: Target format (“tex” or “pdf”) - standalone: Generate standalone LaTeX document - black_and_white: Use monochrome line styles - semilog: Use logarithmic x-axis scaling - lang: Language for plot labels - title/xlabel/ylabel: Plot text customization - pgfplot_version: PGFPlots compatibility version - background/page_background: Color customization
Note
TikZ backend has solver limits: 13 for black-and-white plots, 30 for color plots. This is due to the finite number of predefined line styles and colors in the TikZ implementation.
Example
parser_opts = {"files": ["data1.txt"], "success": ["converged"]}
profiler_opts = {"output": "plot", "output_format": "pdf",
"standalone": True, "lang": "en"}
profiler = Profiler(parser_opts, profiler_opts)
Source code in perprof/tikz.py
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 | |
plot()
¶
Generate and save the TikZ/PGFPlots performance profile.
Creates LaTeX code for performance profiles using TikZ and PGFPlots. Output can be standalone LaTeX document or TikZ code for embedding.
Process: 1. Document structure (if standalone) 2. Color and line style definitions 3. PGFPlots axis environment with scaling and labels 4. Data plots using step functions 5. Legend and finalization 6. Optional PDF compilation
Features: - Step plots using PGFPlots \addplot commands - Logarithmic x-axis scaling (if semilog=True) - Color and line style combinations - Automatic PDF compilation for PDF output - Background color support
Validates solver count limits (13 for B&W, 30 for color).
Raises:
-
ValueError–If too many solvers for the chosen style (B&W vs color).
-
subprocess-related exceptions–If PDF compilation fails.
Example
# After creating profiler instance (see __init__ example)
profiler.plot() # Creates .tex file and optionally compiles to PDF
Source code in perprof/tikz.py
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 | |
Profiler using matplotlib¶
Plot using matplotlib.
Classes¶
perprof.matplotlib.Profiler
¶
Bases: Pdata
Performance profile generator using matplotlib backend.
Creates performance profile plots using matplotlib with support for multiple output formats (PNG, PDF, SVG, EPS, PS) and customization options.
Generates step plots showing cumulative distribution of solver performance ratios.
Attributes:
-
output(str) –Output filename including format extension.
-
output_format(str) –File format for the output (png, pdf, svg, etc.).
-
plot_lang(function) –Localization function for plot text.
Example
Creating a matplotlib profiler for performance analysis:
from perprof.matplotlib import Profiler
# Configure data parsing
parser_opts = {
"files": ["solver1.txt", "solver2.txt"],
"success": ["converged", "solved"],
"maxtime": 300.0,
"compare": "time"
}
# Configure plot appearance
profiler_opts = {
"output": "comparison",
"output_format": "png",
"semilog": True,
"lang": "en",
"title": "Performance Comparison"
}
# Generate plot
profiler = Profiler(parser_opts, profiler_opts)
profiler.plot() # Creates comparison.png
Source code in perprof/matplotlib.py
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 | |
Functions¶
__init__(parser_options, profiler_options)
¶
Parameters:
-
parser_options(dict) –Data parsing configuration including: - files: List of solver data files to process - success: Success criteria for solver convergence - maxtime/mintime: Time filtering bounds - compare: Performance metric to compare (default: “time”) - subset: Optional problem subset restriction
-
profiler_options(dict) –Visualization configuration including: - output: Output filename prefix (extension auto-added) - output_format: File format (png, pdf, svg, eps, ps) - semilog: Use logarithmic x-axis scaling - black_and_white: Use monochrome line styles - lang: Language for plot labels - title/xlabel/ylabel: Plot text customization - background/page_background: Color customization
Example
parser_opts = {"files": ["data1.txt"], "success": ["converged"]}
profiler_opts = {"output": "plot", "output_format": "png", "lang": "en"}
profiler = Profiler(parser_opts, profiler_opts)
Source code in perprof/matplotlib.py
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 | |
plot()
¶
Generate and save the performance profile plot.
Creates a step plot showing cumulative distribution of performance ratios for each solver.
Features: - Step plot with solver-specific line styles and colors - Logarithmic x-axis scaling (if semilog=True) - Customizable background colors and transparency - Legend and grid lines - Automatic axis scaling
Saves plot to filename specified during initialization.
Raises:
-
matplotlib-related exceptions–If plot generation or saving fails.
Example
# After creating profiler instance (see __init__ example)
profiler.plot() # Creates the performance profile plot file
Source code in perprof/matplotlib.py
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 | |