Skip to content

[WIP] Tiny Profiler: default report to diags/performance.txt - #7077

Open
ax3l wants to merge 1 commit into
BLAST-WarpX:developmentfrom
ax3l:topic-tp-file-diags
Open

[WIP] Tiny Profiler: default report to diags/performance.txt#7077
ax3l wants to merge 1 commit into
BLAST-WarpX:developmentfrom
ax3l:topic-tp-file-diags

Conversation

@ax3l

@ax3l ax3l commented Jul 19, 2026

Copy link
Copy Markdown
Member

The tiny profiler output is nice but verbose for many workflows, and many of our Python users fully disable it by default because of the large "scrolling" it causes in many workflows. Change for both modes (exe + input) to keep consistent, so we can request from users their profile consistently when analyzing/helping.

Now, by default, write the AMReX tiny profiler report to diags/performance.txt instead of stdout, for both executable- and Python-steered runs. If no diagnostics are configured (no full/BTD diagnostics and no reduced diagnostics), the profiler is turned off (/dev/null) so that no diags/ folder is created. A user-set tiny_profiler.output_file always takes precedence.

The default is applied in WarpX::InitData() (after the diagnostics managers are constructed), which runs for both the executable and the Python paths.

Requires the matching AMReX change to re-read tiny_profiler.output_file per init/finalize cycle.

@ax3l ax3l added enhancement New feature or request changes input scripts / defaults Changes the syntax or meaning of input scripts and/or defaults labels Jul 19, 2026
@ax3l ax3l changed the title Tiny Profiler: default report to diags/performance.txt Tiny Profiler: default report to diags/performance.txt Jul 19, 2026
Comment thread Docs/source/usage/parameters.rst Outdated
:pp:param:`warpx.reduced_diags_names`, or :pp:param:`diagnostics.enable` ``= 0``), the profiler
is turned off (``/dev/null``) so that no ``diags/`` folder is created.

Set this to a path to choose a specific file, to an empty string to print the report on the

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be more explicit, how about instead of an empty string, use tiny_profiler.output_file = stdout to write it to stdout.

@ax3l ax3l Jul 31, 2026

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that will require an AMReX change. Let us also add stderr as a keyword, for completeness.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dpgrote

dpgrote commented Jul 20, 2026

Copy link
Copy Markdown
Member

I'll have to update PR #6848 since there the profiles during the simulation would need to be in the context of the output to be meaningful. Maybe always write the additional profiles to stdout and only the final one controlled by tiny_profiler.output_file?

WeiqunZhang pushed a commit to AMReX-Codes/amrex that referenced this pull request Jul 20, 2026
## Summary

`TinyProfiler::get_output_file()` cached `tiny_profiler.output_file`
behind a process-lifetime function-local guard, so a process that cycles
AMReX `initialize`/`finalize` more than once (e.g. a Jupyter notebook
running several simulations) kept writing to the first cycle's report
location and could fail to open it on a later cycle.

Move the read-once guard to a namespace-scope flag (`output_file_read`)
that `Initialize()` re-arms, and reset the cached output_file there. The
value is still read at most once per cycle, so the timer and memory
reports (both opened in append mode) continue to share one
freshly-truncated file.

## Additional background

Needed for BLAST codes that like to change defaults of the TP output
file in the same process (e.g., Jupyter session) for subsequent
simulation runs.

- BLAST-ImpactX/impactx#1566
- BLAST-WarpX/warpx#7077

## Checklist

The proposed changes:
- [x] fix a bug or incorrect behavior in AMReX
- [ ] add new capabilities to AMReX
- [ ] changes answers in the test suite to more than roundoff level
- [ ] are likely to significantly affect the results of downstream AMReX
users
- [ ] include documentation in the code and/or rst files, if appropriate

Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@EZoni EZoni changed the title Tiny Profiler: default report to diags/performance.txt [WIP] Tiny Profiler: default report to diags/performance.txt Jul 28, 2026
@EZoni

EZoni commented Jul 28, 2026

Copy link
Copy Markdown
Member

Flagging this as WIP until the to-do list in the PR description is finalized.

@EZoni
EZoni self-requested a review July 28, 2026 22:45
@EZoni EZoni self-assigned this Jul 31, 2026
Comment thread Source/Initialization/WarpXInitData.cpp Outdated
By default, write the AMReX tiny profiler report to diags/performance.txt
instead of stdout, for both executable- and Python-steered runs. If no
diagnostics are configured (no full/BTD diagnostics and no reduced
diagnostics), the profiler is turned off (/dev/null) so that no diags/ folder
is created. A user-set tiny_profiler.output_file always takes precedence.

The default is applied in WarpX::InitData() (after the diagnostics managers
are constructed), which runs for both the executable and the Python paths.

Requires the matching AMReX change to re-read tiny_profiler.output_file per
init/finalize cycle.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@ax3l
ax3l force-pushed the topic-tp-file-diags branch from f00b685 to 211a32d Compare July 31, 2026 21:49
@ax3l

ax3l commented Jul 31, 2026

Copy link
Copy Markdown
Member Author

I'll have to update PR #6848 since there the profiles during the simulation would need to be in the context of the output to be meaningful. Maybe always write the additional profiles to stdout and only the final one controlled by tiny_profiler.output_file?

I am not sure, I would refrain from defaulting even more to stdout by default, for sake of interactive usage. Let us finish this PR here and then mirror in #6848 the options people might need?

Comment on lines +841 to +846
// Determine the directory under which WarpX writes its diagnostics.
std::string diags_dir;
if (multi_diags->GetTotalDiags() > 0) {
// Full/back-transformed diagnostics: <diag>.file_prefix, e.g. "diags/diag1".
diags_dir = std::filesystem::path(multi_diags->GetDiag(0).GetFilePrefix())
.parent_path().generic_string();

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fun way to steal a custom diags path from the first available diags...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

changes input scripts / defaults Changes the syntax or meaning of input scripts and/or defaults enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants