-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathipython_config.py
More file actions
53 lines (47 loc) · 1.79 KB
/
ipython_config.py
File metadata and controls
53 lines (47 loc) · 1.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
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
c = get_config()
c.InteractiveShellApp.exec_lines.append('%reload_ext autoreload')
c.InteractiveShellApp.exec_lines.append('%autoreload 2')
c.TerminalInteractiveShell.editing_mode = 'vi'
c.TerminalInteractiveShell.emacs_bindings_in_vi_insert_mode = False
c.TerminalInteractiveShell.timeoutlen = 0.5
c.TerminalInteractiveShell.prompt_includes_vi_mode = False
c.TerminalInteractiveShell.ttimeoutlen = 0.01
c.InteractiveShellApp.exec_lines = [
"""
def pb_cmd(self, arg):
'''pb <variable>: Probe any variable with enhanced type inspection.
Examples:
pb tensor # Probe a PyTorch tensor
pb my_dict # Probe a dictionary
pb model # Probe a model object
pb arr # Probe a NumPy array
'''
try:
# Import locally to avoid circular imports
import torch
import numpy as np
from explorer import get_type
# Try to get the variable
obj = self.curframe_locals.get(arg)
if obj is None:
try:
obj = eval(arg, self.curframe.f_globals, self.curframe_locals)
except:
print(f"Error: '{arg}' not found in current scope.")
return
# Use our enhanced get_type function
get_type(obj)
except Exception as e:
print(f"Error probing '{arg}': {e}")
import traceback
traceback.print_exc()
# Install the pb command into IPdb
try:
import IPython.terminal.debugger
IPython.terminal.debugger.TerminalPdb.do_pb = pb_cmd
# Also add help for the command
IPython.terminal.debugger.TerminalPdb.help_pb = lambda self: print(pb_cmd.__doc__)
except ImportError:
pass
"""
]