Open nonatomiclabs opened 7 years ago
@nonatomiclabs: I will definitely look into the what would make the above possible keeping the API contract as simple as it is now. In the meantime, you can use https://github.com/csurfer/pyheat as a command line and use it on an entire file that way all your variables and the methods which access them are in one single file and you get an approximate idea of the bottlenecks in code.
P.S https://github.com/csurfer/pyheat is a pet project of mine which powers pyheatmagic.
Great, thank you very much.
About PyHeat, I'm not sure it's a real solution here, as:
Are either of the solutions in this stackoverflow thread (@needs_local_scope
decorator & from IPython.core.magic import Magics
) useful?
I've noticed issues with trying to refer to variables that are used outside of the function (for examples, variables defined in previous cells that are then passed into the function).
Is one way round this to allow those variables to be passed into the magic?
eg using a pattern along the lines of:
%%heat -v $myvar
def myfun(v):
pass
myfun(myvar)
where the -v
switch lets you pass variables in to the block magic?
@csurfer Thanks for creating this extension. I am wondering if you ever found anything that might allow the variables in previous cells to be used?
The only way I see is to paste all you need to trace on the same cell.
You can also merge multiple cells just for doing "heat magic" selecting multiple cells and then shift+M
, but you cant undo (well if you hit ctrl+shift+p
you can search for undo
, but it is not as good as others undoes in other programms.
The other is in git, save your work before doing the merge if you want to restore the cells as they where.
This issue is a definitive no-go for me (and I suspect many others), since any significantly complex analysis pipeline will start involving writing functions that you want to reuse from cells to cells (DRY code) and you don't want to start wrapping hundreds of lines within a single cell anytime you want to profile some snippet of code involving functions. That would just be a messy way to work. Seems to me that the problem is that the heat magic does not have access to local variables and functions. Maybe using the @needs_local_scope
decorator may help? Example of usage: https://github.com/ipython/ipython/blob/23fb4ff6343e32b9d1921af4f9f1c58ffadd3376/IPython/core/magics/execution.py#L1063-L1084
Usually, one can access from the current notebook cell variables from previous cells (for instance, we define
a
in cell 2 and access it in 3). However, I can not get that to work when using heat (example in cell 4), which is sometimes annoying (especially when creating such variable can take up some time).Full traceback (click to expand)
``` --------------------------------------------------------------------------- NameError Traceback (most recent call last)Would it be possible to add that feature? I have never worked on iPython extensions, but I would be glad to contribute to that one, if I'm pointed to the right part of code to improve.
Anyway, thank you for the great extension 👏