-
Notifications
You must be signed in to change notification settings - Fork 17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add profile decorator to simpa utils #241
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks sensible! :)
If we are starting the simulations from an editor, though, it's not that easy to set the environment variables, no? I took a brief look and setting them with os.environ["VARIABLE"] = x
didn't work for me.
Do I miss something?
Which editor are you using? I think in vscode you can add an |
I'm using PyCharm and adding environment variables to the run configuration worked but since we'll call everything else in simpa in a script, I wanted to set them there. |
So I haven't really found a clean way of passing settings to the
Would that be ok, or are there situations where you can't set the env var before importing simpa? |
The only thing that would come to my mind would be that according to PEP8, imports should be at the top without constant declarations or else. Other than that, I don't see a problem |
While it technically violates PEP8, as it's only modifying the environment it doesn't really seem against the spirit of PEP8 to me, and as this code is not going into the simpa library but would only be in a user script I think it's fine. (Also checking at run-time which profiler to use with every call to the |
- Allows `@profile` decorator to be added to functions - By default this decorator does nothing - But if the SIMPA_PROFILE` environment variable is set to: - `TIME`: `line_profiler` is used for line-by-line run-time profiling - `MEMORY`: `memory_profiler` is used for line-by-line RAM use profiling - `GPU_MEMORY`: `pytorch_memlab` is used for line-by-line GPU RAM profiling - Profiling output is written to the console when the script finishes - For GPU_MEMORY, a summary of gpu memory use (torch.cuda.memory_summary()) is also written to the console - Add these profiling dependencies to tool.poetry.group.profile.dependencies
- avoids `SIMPA_PROFILE` env var being checked at first import of simpa - @Profile decorator is now imported using `from simpa.utils.profiling import profile` - allows env var to be set later in script
c7f01c0
to
cec9d9e
Compare
This is just a convenience wrapper around using different profilers - making a PR in case you also find it useful
@profile
decorator to be added to functionsTIME
:line_profiler
is used for line-by-line run-time profilingMEMORY
:memory_profiler
is used for line-by-line RAM use profilingGPU_MEMORY
:pytorch_memlab
is used for line-by-line GPU RAM profilingPlease check the following before creating the pull request (PR):
List any specific code review questions
List any special testing requirements
Additional context (e.g. papers, documentation, blog posts, ...)
Provide issue / feature request fixed by this PR
Example of output after adding
@profile
decorator toget_enclosed_indices
in utils/libraries/structure_library/EllipticalTubularStructure.py:With
SIMPA_PROFILE=TIME
:With
SIMPA_PROFILE=MEMORY
:With
SIMPA_PROFILE=GPU_MEMORY
: