Skip to content

IPython Integration

The IPython integration layer under jumper_extension.ipython connects the core service to notebooks and IPython shells. For user‑facing usage of magic commands, see the Jupyter API; the sections below provide code‑level reference generated via mkdocstrings.

Extension entry points

DropCellTransformer

Drop the entire cell if it is being recorded.

Source code in jumper_extension/ipython/extension.py
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
class DropCellTransformer:
    """
    Drop the entire cell if it is being recorded.
    """
    def __init__(
        self,
        is_control_cell: Callable,
        is_recording_active: Callable
    ):
        self.is_control_cell = is_control_cell
        self.is_recording_active = is_recording_active

    def __call__(self, lines: list[str]) -> list[str]:
        """
        IPython cleanup_transforms expects a callable: (lines) -> lines.
        """
        cell = "".join(lines)
        new_cell = self.transform_cell(cell)

        # Keep IPython expectations: return list[str] with line endings preserved.
        if new_cell == "":
            return []
        return new_cell.splitlines(keepends=True)

    def transform_cell(self, cell: str) -> str:
        """
        Return an empty string to drop the whole cell.
        """
        if not self.is_recording_active():
            return cell

        called_line_magics = get_called_line_magics(cell)
        if self.is_control_cell(called_line_magics):
            return cell  # Allow control magics cell to execute

        return "print('[JUmPER]: Cell execution skipped during script recording')\n"

__call__(lines)

IPython cleanup_transforms expects a callable: (lines) -> lines.

Source code in jumper_extension/ipython/extension.py
28
29
30
31
32
33
34
35
36
37
38
def __call__(self, lines: list[str]) -> list[str]:
    """
    IPython cleanup_transforms expects a callable: (lines) -> lines.
    """
    cell = "".join(lines)
    new_cell = self.transform_cell(cell)

    # Keep IPython expectations: return list[str] with line endings preserved.
    if new_cell == "":
        return []
    return new_cell.splitlines(keepends=True)

transform_cell(cell)

Return an empty string to drop the whole cell.

Source code in jumper_extension/ipython/extension.py
40
41
42
43
44
45
46
47
48
49
50
51
def transform_cell(self, cell: str) -> str:
    """
    Return an empty string to drop the whole cell.
    """
    if not self.is_recording_active():
        return cell

    called_line_magics = get_called_line_magics(cell)
    if self.is_control_cell(called_line_magics):
        return cell  # Allow control magics cell to execute

    return "print('[JUmPER]: Cell execution skipped during script recording')\n"

Magic commands

Bases: Magics

IPython line magics for the JUmPER extension.

This class defines the %perfmonitor_* family of magics and a few helpers. Each magic forwards its work to a :class:PerfmonitorMagicAdapter instance, which in turn delegates to :class:PerfmonitorService.

Parameters:

Name Type Description Default
shell Any

The current IPython shell instance.

required
magic_adapter PerfmonitorMagicAdapter

Adapter that implements the string-based public API used by these magics.

required

Examples:

Load the extension in a notebook::

%load_ext jumper_extension
Source code in jumper_extension/ipython/magics.py
 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
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
@magics_class
class PerfmonitorMagics(Magics):
    """IPython line magics for the JUmPER extension.

    This class defines the ``%perfmonitor_*`` family of magics and a
    few helpers. Each magic forwards its work to a
    :class:`PerfmonitorMagicAdapter` instance, which in turn delegates
    to :class:`PerfmonitorService`.

    Args:
        shell: The current IPython shell instance.
        magic_adapter: Adapter that implements the string-based public
            API used by these magics.

    Examples:
        Load the extension in a notebook::

            %load_ext jumper_extension
    """

    def __init__(
        self,
        shell: Any,
        magic_adapter: PerfmonitorMagicAdapter,
    ) -> None:
        """Initialize the magics wrapper.

        Args:
            shell: IPython shell the magics are registered on.
            magic_adapter: Adapter used to execute the underlying
                commands.
        """
        super().__init__(shell)
        self.magic_adapter = magic_adapter

    def pre_run_cell(self, info: Any) -> None:
        """Hook executed before each cell.

        This inspects the raw cell source, extracts any magic commands,
        and informs the underlying adapter so that monitoring and
        reporting state can be updated.

        Args:
            info: IPython pre-run information object that contains
                ``raw_cell``.
        Returns:
            None
        """
        raw_cell = info.raw_cell
        called_line_magics = get_called_line_magics(raw_cell)
        should_skip_report = is_pure_line_magic_cell(raw_cell)
        self.magic_adapter.on_pre_run_cell(
            raw_cell,
            called_line_magics,
            should_skip_report,
        )

    def post_run_cell(self, result: Any) -> None:
        """Hook executed after each cell has run.

        Delegates to the magic adapter so that post-cell reporting and
        bookkeeping can be performed.

        Args:
            result: IPython execution result object.
        Returns:
            None
        """
        self.magic_adapter.on_post_run_cell(result.result)

    @line_magic
    def perfmonitor_resources(self, line: str) -> None:
        """Show hardware resources available to the current session.

        This magic prints CPUs, memory, and GPU information for either
        a live or imported monitoring session.

        Args:
            line: Unused argument string.
        Returns:
            None

        Examples:
            Show resources for the current session::

                %perfmonitor_resources
        """
        self.magic_adapter.perfmonitor_resources(line)

    @line_magic
    def perfmonitor_start(self, line: str) -> None:
        """Start performance monitoring.

        If an interval is provided as a single numeric argument, it is
        interpreted as the sampling interval in seconds; otherwise the
        default interval is used.

        Args:
            line: Optional interval argument, for example ``"1.0"``.
        Returns:
            None

        Examples:
            Start monitoring with the default interval::

                %perfmonitor_start

            Start monitoring with a 0.5 second interval::

                %perfmonitor_start 0.5
        """
        self.magic_adapter.perfmonitor_start(line)

    @line_magic
    def perfmonitor_stop(self, line: str) -> None:
        """Stop the active performance monitoring session.

        Args:
            line: Unused argument string.
        Returns:
            None

        Examples:
            %perfmonitor_stop
        """
        self.magic_adapter.perfmonitor_stop(line)

    @line_magic
    def perfmonitor_plot(self, line: str) -> None:
        """Open an interactive performance plot.

        This magic opens interactive widgets for exploring collected
        performance data.

        Args:
            line: Raw argument string forwarded to the adapter.
        Returns:
            None

        Examples:
            Open an interactive plot for the current session::

                %perfmonitor_plot
        """
        self.magic_adapter.perfmonitor_plot(line)

    @line_magic
    def perfmonitor_enable_perfreports(self, line: str) -> None:
        """Enable automatic performance reports after each cell.

        The line string is parsed for options such as monitoring level,
        interval, and whether to use text or HTML output.

        Args:
            line: Raw argument string, for example
                ``"--level process --interval 1.0"``.
        Returns:
            None

        Examples:
            Enable HTML reports at process level::

                %perfmonitor_enable_perfreports --level process

            Enable text reports for user level with custom interval::

                %perfmonitor_enable_perfreports --level user --interval 0.5 --text
        """
        self.magic_adapter.perfmonitor_enable_perfreports(line)


    @line_magic
    def perfmonitor_disable_perfreports(self, line: str) -> None:
        """Disable automatic performance reports.

        Args:
            line: Unused argument string.
        Returns:
            None

        Examples:
            %perfmonitor_disable_perfreports
        """
        self.magic_adapter.perfmonitor_disable_perfreports(line)

    @line_magic
    def perfmonitor_perfreport(self, line: str) -> None:
        """Show a performance report for the current session.

        The line string may include cell range and monitoring level
        options to restrict the report.

        Args:
            line: Raw argument string, for example
                ``"--cell 2:5 --level system"``.
        Returns:
            None

        Examples:
            Show a report for all cells::

                %perfmonitor_perfreport

            Show a report for cells 2–5 at system level::

                %perfmonitor_perfreport --cell 2:5 --level system
        """
        self.magic_adapter.perfmonitor_perfreport(line)

    @line_magic
    def perfmonitor_export_perfdata(self, line: str) -> None:
        """Export performance data or push it into the notebook.

        If ``--file`` is provided, data is written to disk. Otherwise,
        the resulting data frames are pushed into the user namespace.

        Args:
            line: Raw argument string, such as
                ``"--file perf.csv --level process"``.
        Returns:
            None

        Examples:
            Export process-level data to CSV::

                %perfmonitor_export_perfdata --file perf.csv --level process

            Push a DataFrame into the notebook::

                %perfmonitor_export_perfdata --level user
        """
        perfdata = self.magic_adapter.perfmonitor_export_perfdata(line)
        self.shell.push(perfdata)

    @line_magic
    def perfmonitor_export_cell_history(self, line: str) -> None:
        """Export cell history or push it into the notebook.

        If ``--file`` is provided, the cell history is written to disk.
        Otherwise, a data frame is pushed into the user namespace.

        Args:
            line: Raw argument string, for example
                ``"--file cells.csv"``.
        Returns:
            None

        Examples:
            Export cell history to CSV::

                %perfmonitor_export_cell_history --file cells.csv

            Push the cell history DataFrame::

                %perfmonitor_export_cell_history
        """
        cell_history_data = self.magic_adapter.perfmonitor_export_cell_history(line)
        self.shell.push(cell_history_data)

    @line_magic
    def perfmonitor_load_perfdata(self, line: str) -> None:
        """Load performance data from disk and push it to the notebook.

        Args:
            line: Raw argument string containing ``--file``.
        Returns:
            None

        Examples:
            %perfmonitor_load_perfdata --file perf.csv
        """
        perfdata = self.magic_adapter.perfmonitor_load_perfdata(line)
        self.shell.push(perfdata)

    @line_magic
    def perfmonitor_load_cell_history(self, line: str) -> None:
        """Load cell history from disk and push it to the notebook.

        Args:
            line: Raw argument string containing ``--file``.
        Returns:
            None

        Examples:
            %perfmonitor_load_cell_history --file cells.csv
        """
        cell_history_data = self.magic_adapter.perfmonitor_load_cell_history(line)
        self.shell.push(cell_history_data)

    @line_magic
    def export_session(self, line: str) -> None:
        """Export the full monitoring session to a directory or zip.

        When the target ends with ``.zip``, a temporary directory is
        created and compressed into that archive.

        Args:
            line: Raw argument string containing an optional target
                path.
        Returns:
            None

        Examples:
            Export into a directory::

                %export_session my_dir

            Export into a zip archive::

                %export_session my_session.zip
        """
        self.magic_adapter.export_session(line)

    @line_magic
    def import_session(self, line: str) -> None:
        """Import a monitoring session from a directory or zip.

        Args:
            line: Raw argument string with the source path.
        Returns:
            None

        Examples:
            %import_session my_session.zip
        """
        self.magic_adapter.import_session(line)

    @line_magic
    def perfmonitor_fast_setup(self, line: str) -> None:
        """Run a quick setup for interactive monitoring.

        This helper enables ``ipympl`` interactive plots (if available),
        starts monitoring, and turns on automatic performance reports.

        Args:
            line: Unused argument string.
        Returns:
            None

        Examples:
            Quickly prepare interactive monitoring in a notebook::

                %perfmonitor_fast_setup
        """
        # Enable ipympl interactive plots
        try:
            self.shell.run_line_magic('matplotlib', 'ipympl')
            print("[JUmPER]: Enabled ipympl interactive plots")
        except Exception as e:
            logger.warning(f"Failed to enable ipympl interactive plots: {e}")
        self.magic_adapter.perfmonitor_fast_setup(line)

    @line_magic
    def show_cell_history(self, line: str) -> None:
        """Show an interactive table of executed cells.

        Args:
            line: Unused argument string.
        Returns:
            None

        Examples:
            %show_cell_history
        """
        self.magic_adapter.show_cell_history(line)

    @line_magic
    def perfmonitor_help(self, line: str) -> None:
        """Show comprehensive help for all available magics.

        Args:
            line: Unused argument string.
        Returns:
            None

        Examples:
            %perfmonitor_help
        """
        self.magic_adapter.perfmonitor_help(line)

    @line_magic
    def start_write_script(self, line: str) -> None:
        """Start recording code from subsequent cells to a Python script.

        If no path is provided, the script writer chooses a default
        filename based on the current time.

        Args:
            line: Optional output path, for example
                ``\"my_script.py\"``.

        Examples:
            Start recording to a generated filename::

                %start_write_script

            Record to a specific file::

                %start_write_script my_script.py
        """
        self.magic_adapter.start_write_script(line)

    @line_magic
    def end_write_script(self, line: str) -> None:
        """Stop recording and save accumulated code to a script file.

        Args:
            line: Unused argument string.

        Examples:
            %end_write_script
        """
        self.magic_adapter.end_write_script(line)

__init__(shell, magic_adapter)

Initialize the magics wrapper.

Parameters:

Name Type Description Default
shell Any

IPython shell the magics are registered on.

required
magic_adapter PerfmonitorMagicAdapter

Adapter used to execute the underlying commands.

required
Source code in jumper_extension/ipython/magics.py
36
37
38
39
40
41
42
43
44
45
46
47
48
49
def __init__(
    self,
    shell: Any,
    magic_adapter: PerfmonitorMagicAdapter,
) -> None:
    """Initialize the magics wrapper.

    Args:
        shell: IPython shell the magics are registered on.
        magic_adapter: Adapter used to execute the underlying
            commands.
    """
    super().__init__(shell)
    self.magic_adapter = magic_adapter

end_write_script(line)

Stop recording and save accumulated code to a script file.

Parameters:

Name Type Description Default
line str

Unused argument string.

required

Examples:

%end_write_script

Source code in jumper_extension/ipython/magics.py
418
419
420
421
422
423
424
425
426
427
428
@line_magic
def end_write_script(self, line: str) -> None:
    """Stop recording and save accumulated code to a script file.

    Args:
        line: Unused argument string.

    Examples:
        %end_write_script
    """
    self.magic_adapter.end_write_script(line)

export_session(line)

Export the full monitoring session to a directory or zip.

When the target ends with .zip, a temporary directory is created and compressed into that archive.

Parameters:

Name Type Description Default
line str

Raw argument string containing an optional target path.

required

Returns: None

Examples:

Export into a directory::

%export_session my_dir

Export into a zip archive::

%export_session my_session.zip
Source code in jumper_extension/ipython/magics.py
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
@line_magic
def export_session(self, line: str) -> None:
    """Export the full monitoring session to a directory or zip.

    When the target ends with ``.zip``, a temporary directory is
    created and compressed into that archive.

    Args:
        line: Raw argument string containing an optional target
            path.
    Returns:
        None

    Examples:
        Export into a directory::

            %export_session my_dir

        Export into a zip archive::

            %export_session my_session.zip
    """
    self.magic_adapter.export_session(line)

import_session(line)

Import a monitoring session from a directory or zip.

Parameters:

Name Type Description Default
line str

Raw argument string with the source path.

required

Returns: None

Examples:

%import_session my_session.zip

Source code in jumper_extension/ipython/magics.py
329
330
331
332
333
334
335
336
337
338
339
340
341
@line_magic
def import_session(self, line: str) -> None:
    """Import a monitoring session from a directory or zip.

    Args:
        line: Raw argument string with the source path.
    Returns:
        None

    Examples:
        %import_session my_session.zip
    """
    self.magic_adapter.import_session(line)

perfmonitor_disable_perfreports(line)

Disable automatic performance reports.

Parameters:

Name Type Description Default
line str

Unused argument string.

required

Returns: None

Examples:

%perfmonitor_disable_perfreports

Source code in jumper_extension/ipython/magics.py
187
188
189
190
191
192
193
194
195
196
197
198
199
@line_magic
def perfmonitor_disable_perfreports(self, line: str) -> None:
    """Disable automatic performance reports.

    Args:
        line: Unused argument string.
    Returns:
        None

    Examples:
        %perfmonitor_disable_perfreports
    """
    self.magic_adapter.perfmonitor_disable_perfreports(line)

perfmonitor_enable_perfreports(line)

Enable automatic performance reports after each cell.

The line string is parsed for options such as monitoring level, interval, and whether to use text or HTML output.

Parameters:

Name Type Description Default
line str

Raw argument string, for example "--level process --interval 1.0".

required

Returns: None

Examples:

Enable HTML reports at process level::

%perfmonitor_enable_perfreports --level process

Enable text reports for user level with custom interval::

%perfmonitor_enable_perfreports --level user --interval 0.5 --text
Source code in jumper_extension/ipython/magics.py
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
@line_magic
def perfmonitor_enable_perfreports(self, line: str) -> None:
    """Enable automatic performance reports after each cell.

    The line string is parsed for options such as monitoring level,
    interval, and whether to use text or HTML output.

    Args:
        line: Raw argument string, for example
            ``"--level process --interval 1.0"``.
    Returns:
        None

    Examples:
        Enable HTML reports at process level::

            %perfmonitor_enable_perfreports --level process

        Enable text reports for user level with custom interval::

            %perfmonitor_enable_perfreports --level user --interval 0.5 --text
    """
    self.magic_adapter.perfmonitor_enable_perfreports(line)

perfmonitor_export_cell_history(line)

Export cell history or push it into the notebook.

If --file is provided, the cell history is written to disk. Otherwise, a data frame is pushed into the user namespace.

Parameters:

Name Type Description Default
line str

Raw argument string, for example "--file cells.csv".

required

Returns: None

Examples:

Export cell history to CSV::

%perfmonitor_export_cell_history --file cells.csv

Push the cell history DataFrame::

%perfmonitor_export_cell_history
Source code in jumper_extension/ipython/magics.py
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
@line_magic
def perfmonitor_export_cell_history(self, line: str) -> None:
    """Export cell history or push it into the notebook.

    If ``--file`` is provided, the cell history is written to disk.
    Otherwise, a data frame is pushed into the user namespace.

    Args:
        line: Raw argument string, for example
            ``"--file cells.csv"``.
    Returns:
        None

    Examples:
        Export cell history to CSV::

            %perfmonitor_export_cell_history --file cells.csv

        Push the cell history DataFrame::

            %perfmonitor_export_cell_history
    """
    cell_history_data = self.magic_adapter.perfmonitor_export_cell_history(line)
    self.shell.push(cell_history_data)

perfmonitor_export_perfdata(line)

Export performance data or push it into the notebook.

If --file is provided, data is written to disk. Otherwise, the resulting data frames are pushed into the user namespace.

Parameters:

Name Type Description Default
line str

Raw argument string, such as "--file perf.csv --level process".

required

Returns: None

Examples:

Export process-level data to CSV::

%perfmonitor_export_perfdata --file perf.csv --level process

Push a DataFrame into the notebook::

%perfmonitor_export_perfdata --level user
Source code in jumper_extension/ipython/magics.py
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
@line_magic
def perfmonitor_export_perfdata(self, line: str) -> None:
    """Export performance data or push it into the notebook.

    If ``--file`` is provided, data is written to disk. Otherwise,
    the resulting data frames are pushed into the user namespace.

    Args:
        line: Raw argument string, such as
            ``"--file perf.csv --level process"``.
    Returns:
        None

    Examples:
        Export process-level data to CSV::

            %perfmonitor_export_perfdata --file perf.csv --level process

        Push a DataFrame into the notebook::

            %perfmonitor_export_perfdata --level user
    """
    perfdata = self.magic_adapter.perfmonitor_export_perfdata(line)
    self.shell.push(perfdata)

perfmonitor_fast_setup(line)

Run a quick setup for interactive monitoring.

This helper enables ipympl interactive plots (if available), starts monitoring, and turns on automatic performance reports.

Parameters:

Name Type Description Default
line str

Unused argument string.

required

Returns: None

Examples:

Quickly prepare interactive monitoring in a notebook::

%perfmonitor_fast_setup
Source code in jumper_extension/ipython/magics.py
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
@line_magic
def perfmonitor_fast_setup(self, line: str) -> None:
    """Run a quick setup for interactive monitoring.

    This helper enables ``ipympl`` interactive plots (if available),
    starts monitoring, and turns on automatic performance reports.

    Args:
        line: Unused argument string.
    Returns:
        None

    Examples:
        Quickly prepare interactive monitoring in a notebook::

            %perfmonitor_fast_setup
    """
    # Enable ipympl interactive plots
    try:
        self.shell.run_line_magic('matplotlib', 'ipympl')
        print("[JUmPER]: Enabled ipympl interactive plots")
    except Exception as e:
        logger.warning(f"Failed to enable ipympl interactive plots: {e}")
    self.magic_adapter.perfmonitor_fast_setup(line)

perfmonitor_help(line)

Show comprehensive help for all available magics.

Parameters:

Name Type Description Default
line str

Unused argument string.

required

Returns: None

Examples:

%perfmonitor_help

Source code in jumper_extension/ipython/magics.py
382
383
384
385
386
387
388
389
390
391
392
393
394
@line_magic
def perfmonitor_help(self, line: str) -> None:
    """Show comprehensive help for all available magics.

    Args:
        line: Unused argument string.
    Returns:
        None

    Examples:
        %perfmonitor_help
    """
    self.magic_adapter.perfmonitor_help(line)

perfmonitor_load_cell_history(line)

Load cell history from disk and push it to the notebook.

Parameters:

Name Type Description Default
line str

Raw argument string containing --file.

required

Returns: None

Examples:

%perfmonitor_load_cell_history --file cells.csv

Source code in jumper_extension/ipython/magics.py
290
291
292
293
294
295
296
297
298
299
300
301
302
303
@line_magic
def perfmonitor_load_cell_history(self, line: str) -> None:
    """Load cell history from disk and push it to the notebook.

    Args:
        line: Raw argument string containing ``--file``.
    Returns:
        None

    Examples:
        %perfmonitor_load_cell_history --file cells.csv
    """
    cell_history_data = self.magic_adapter.perfmonitor_load_cell_history(line)
    self.shell.push(cell_history_data)

perfmonitor_load_perfdata(line)

Load performance data from disk and push it to the notebook.

Parameters:

Name Type Description Default
line str

Raw argument string containing --file.

required

Returns: None

Examples:

%perfmonitor_load_perfdata --file perf.csv

Source code in jumper_extension/ipython/magics.py
275
276
277
278
279
280
281
282
283
284
285
286
287
288
@line_magic
def perfmonitor_load_perfdata(self, line: str) -> None:
    """Load performance data from disk and push it to the notebook.

    Args:
        line: Raw argument string containing ``--file``.
    Returns:
        None

    Examples:
        %perfmonitor_load_perfdata --file perf.csv
    """
    perfdata = self.magic_adapter.perfmonitor_load_perfdata(line)
    self.shell.push(perfdata)

perfmonitor_perfreport(line)

Show a performance report for the current session.

The line string may include cell range and monitoring level options to restrict the report.

Parameters:

Name Type Description Default
line str

Raw argument string, for example "--cell 2:5 --level system".

required

Returns: None

Examples:

Show a report for all cells::

%perfmonitor_perfreport

Show a report for cells 2–5 at system level::

%perfmonitor_perfreport --cell 2:5 --level system
Source code in jumper_extension/ipython/magics.py
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
@line_magic
def perfmonitor_perfreport(self, line: str) -> None:
    """Show a performance report for the current session.

    The line string may include cell range and monitoring level
    options to restrict the report.

    Args:
        line: Raw argument string, for example
            ``"--cell 2:5 --level system"``.
    Returns:
        None

    Examples:
        Show a report for all cells::

            %perfmonitor_perfreport

        Show a report for cells 2–5 at system level::

            %perfmonitor_perfreport --cell 2:5 --level system
    """
    self.magic_adapter.perfmonitor_perfreport(line)

perfmonitor_plot(line)

Open an interactive performance plot.

This magic opens interactive widgets for exploring collected performance data.

Parameters:

Name Type Description Default
line str

Raw argument string forwarded to the adapter.

required

Returns: None

Examples:

Open an interactive plot for the current session::

%perfmonitor_plot
Source code in jumper_extension/ipython/magics.py
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
@line_magic
def perfmonitor_plot(self, line: str) -> None:
    """Open an interactive performance plot.

    This magic opens interactive widgets for exploring collected
    performance data.

    Args:
        line: Raw argument string forwarded to the adapter.
    Returns:
        None

    Examples:
        Open an interactive plot for the current session::

            %perfmonitor_plot
    """
    self.magic_adapter.perfmonitor_plot(line)

perfmonitor_resources(line)

Show hardware resources available to the current session.

This magic prints CPUs, memory, and GPU information for either a live or imported monitoring session.

Parameters:

Name Type Description Default
line str

Unused argument string.

required

Returns: None

Examples:

Show resources for the current session::

%perfmonitor_resources
Source code in jumper_extension/ipython/magics.py
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
@line_magic
def perfmonitor_resources(self, line: str) -> None:
    """Show hardware resources available to the current session.

    This magic prints CPUs, memory, and GPU information for either
    a live or imported monitoring session.

    Args:
        line: Unused argument string.
    Returns:
        None

    Examples:
        Show resources for the current session::

            %perfmonitor_resources
    """
    self.magic_adapter.perfmonitor_resources(line)

perfmonitor_start(line)

Start performance monitoring.

If an interval is provided as a single numeric argument, it is interpreted as the sampling interval in seconds; otherwise the default interval is used.

Parameters:

Name Type Description Default
line str

Optional interval argument, for example "1.0".

required

Returns: None

Examples:

Start monitoring with the default interval::

%perfmonitor_start

Start monitoring with a 0.5 second interval::

%perfmonitor_start 0.5
Source code in jumper_extension/ipython/magics.py
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
@line_magic
def perfmonitor_start(self, line: str) -> None:
    """Start performance monitoring.

    If an interval is provided as a single numeric argument, it is
    interpreted as the sampling interval in seconds; otherwise the
    default interval is used.

    Args:
        line: Optional interval argument, for example ``"1.0"``.
    Returns:
        None

    Examples:
        Start monitoring with the default interval::

            %perfmonitor_start

        Start monitoring with a 0.5 second interval::

            %perfmonitor_start 0.5
    """
    self.magic_adapter.perfmonitor_start(line)

perfmonitor_stop(line)

Stop the active performance monitoring session.

Parameters:

Name Type Description Default
line str

Unused argument string.

required

Returns: None

Examples:

%perfmonitor_stop

Source code in jumper_extension/ipython/magics.py
129
130
131
132
133
134
135
136
137
138
139
140
141
@line_magic
def perfmonitor_stop(self, line: str) -> None:
    """Stop the active performance monitoring session.

    Args:
        line: Unused argument string.
    Returns:
        None

    Examples:
        %perfmonitor_stop
    """
    self.magic_adapter.perfmonitor_stop(line)

post_run_cell(result)

Hook executed after each cell has run.

Delegates to the magic adapter so that post-cell reporting and bookkeeping can be performed.

Parameters:

Name Type Description Default
result Any

IPython execution result object.

required

Returns: None

Source code in jumper_extension/ipython/magics.py
73
74
75
76
77
78
79
80
81
82
83
84
def post_run_cell(self, result: Any) -> None:
    """Hook executed after each cell has run.

    Delegates to the magic adapter so that post-cell reporting and
    bookkeeping can be performed.

    Args:
        result: IPython execution result object.
    Returns:
        None
    """
    self.magic_adapter.on_post_run_cell(result.result)

pre_run_cell(info)

Hook executed before each cell.

This inspects the raw cell source, extracts any magic commands, and informs the underlying adapter so that monitoring and reporting state can be updated.

Parameters:

Name Type Description Default
info Any

IPython pre-run information object that contains raw_cell.

required

Returns: None

Source code in jumper_extension/ipython/magics.py
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
def pre_run_cell(self, info: Any) -> None:
    """Hook executed before each cell.

    This inspects the raw cell source, extracts any magic commands,
    and informs the underlying adapter so that monitoring and
    reporting state can be updated.

    Args:
        info: IPython pre-run information object that contains
            ``raw_cell``.
    Returns:
        None
    """
    raw_cell = info.raw_cell
    called_line_magics = get_called_line_magics(raw_cell)
    should_skip_report = is_pure_line_magic_cell(raw_cell)
    self.magic_adapter.on_pre_run_cell(
        raw_cell,
        called_line_magics,
        should_skip_report,
    )

show_cell_history(line)

Show an interactive table of executed cells.

Parameters:

Name Type Description Default
line str

Unused argument string.

required

Returns: None

Examples:

%show_cell_history

Source code in jumper_extension/ipython/magics.py
368
369
370
371
372
373
374
375
376
377
378
379
380
@line_magic
def show_cell_history(self, line: str) -> None:
    """Show an interactive table of executed cells.

    Args:
        line: Unused argument string.
    Returns:
        None

    Examples:
        %show_cell_history
    """
    self.magic_adapter.show_cell_history(line)

start_write_script(line)

Start recording code from subsequent cells to a Python script.

If no path is provided, the script writer chooses a default filename based on the current time.

Parameters:

Name Type Description Default
line str

Optional output path, for example "my_script.py".

required

Examples:

Start recording to a generated filename::

%start_write_script

Record to a specific file::

%start_write_script my_script.py
Source code in jumper_extension/ipython/magics.py
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
@line_magic
def start_write_script(self, line: str) -> None:
    """Start recording code from subsequent cells to a Python script.

    If no path is provided, the script writer chooses a default
    filename based on the current time.

    Args:
        line: Optional output path, for example
            ``\"my_script.py\"``.

    Examples:
        Start recording to a generated filename::

            %start_write_script

        Record to a specific file::

            %start_write_script my_script.py
    """
    self.magic_adapter.start_write_script(line)

IPython utilities

get_called_line_magics(raw_cell)

Get the list of line magics called in a cell

Source code in jumper_extension/ipython/utilities.py
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
def get_called_line_magics(raw_cell: str) -> list:
    """
    Get the list of line magics called in a cell
    """
    line_magics = get_line_magics_cached()
    called_line_magics = []
    # Get the list of available line magics, names without '%'
    lines = raw_cell.splitlines()
    for line in lines:
        stripped = line.strip()
        if not stripped:
            # skip empty lines
            continue
        if stripped.startswith("#"):
            # skip comments
            continue
        if is_known_line_magic(line, line_magics):
            called_line_magics.append(stripped[1:])
    return called_line_magics

is_pure_line_magic_cell(raw_cell)

A pure line-magic cell = each non-empty line is either: - starts with % (optionally with arguments), - or is a comment (#...).

Source code in jumper_extension/ipython/utilities.py
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
def is_pure_line_magic_cell(raw_cell: str) -> bool:
    """
    A pure line-magic cell = each non-empty line is either:
      - starts with %<known_magic> (optionally with arguments),
      - or is a comment (#...).
    """
    line_magics = get_line_magics_cached()
    # Get the list of available line magics, names without '%'
    lines = raw_cell.splitlines()
    for line in lines:
        stripped = line.strip()
        if not stripped:
            # skip empty lines
            continue
        if stripped.startswith("#"):
            # skip comments
            continue
        if is_known_line_magic(line, line_magics):
            # skip line magic
            continue
        # any other non-empty line is considered code -> not "pure"
        return False
    return True