AutovisualizerMagic#

class penzai.treescope.treescope_ipython.AutovisualizerMagic[source]#

Bases: Magics

Magics class for enabling automatic visualization.

Inherited Attributes

config

A trait whose value must be an instance of a specified class.

cross_validation_lock

A contextmanager for running a block with our cross validation lock set to True.

options_table

parent

A trait whose value must be an instance of a specified class.

shell

Methods

autovisualize(line, cell)

%%autovisualize cell magic: enables autovisualization in a cell.

Attributes

config

A trait whose value must be an instance of a specified class.

cross_validation_lock

A contextmanager for running a block with our cross validation lock set to True.

magics

options_table

parent

A trait whose value must be an instance of a specified class.

registered

shell

Inherited Methods

(expand to view inherited methods)

__init__([shell])

add_traits(**traits)

Dynamically add trait attributes to the HasTraits instance.

arg_err(func)

Print docstring if incorrect arguments were passed

class_config_rst_doc()

Generate rST documentation for this class' config options.

class_config_section([classes])

Get the config section for this class.

class_get_help([inst])

Get the help string for this class in ReST format.

class_get_trait_help(trait[, inst, helptext])

Get the helptext string for a single trait.

class_own_trait_events(name)

Get a dict of all event handlers defined on this class, not a parent.

class_own_traits(**metadata)

Get a dict of all the traitlets defined on this class, not a parent.

class_print_help([inst])

Get the help string for a single trait and print it.

class_trait_names(**metadata)

Get a list of all the names of this class' traits.

class_traits(**metadata)

Get a dict of all the traits of this class.

default_option(fn, optstr)

Make an entry in the options_table for fn, with value optstr

format_latex(strng)

Format a string for latex inclusion.

has_trait(name)

Returns True if the object has a trait with the specified name.

hold_trait_notifications()

Context manager for bundling trait change notifications and cross validation.

notify_change(change)

Notify observers of a change event

observe(handler[, names, type])

Setup a handler to be called when a trait changes.

on_trait_change([handler, name, remove])

DEPRECATED: Setup a handler to be called when a trait changes.

parse_options(arg_str, opt_str, *long_opts, **kw)

Parse options passed to an argument string.

section_names()

return section names as a list

set_trait(name, value)

Forcibly sets trait attribute, including read-only attributes.

setup_instance(**kwargs)

trait_defaults(*names, **metadata)

Return a trait's default value or a dictionary of them

trait_events([name])

Get a dict of all the event handlers of this class.

trait_has_value(name)

Returns True if the specified trait has a value.

trait_metadata(traitname, key[, default])

Get metadata values for trait by key.

trait_names(**metadata)

Get a list of all the names of this class' traits.

trait_values(**metadata)

A dict of trait names and their values.

traits(**metadata)

Get a dict of all the traits of this class.

unobserve(handler[, names, type])

Remove a trait change handler.

unobserve_all([name])

Remove trait change handlers of any type for the specified name.

update_config(config)

Update config and load the new values

autovisualize(line, cell)[source]#

%%autovisualize cell magic: enables autovisualization in a cell.

The %%autovisualize magic is syntactic sugar for running a cell with automatic visualization turned on. To use the default autovisualizer, you can annotate your cell with

%%autovisualize

# ... contents of your cell ...
result = ...
result

which expands to something like

with treescope.autovisualize.active_autovisualizer.set_scoped(
    treescope_ipython.default_magic_autovisualizer.get()
):
  # ... contents of your cell ...
  result = ...
  IPython.display.display(result)

You can also pass an explicit autovisualizer function/object:

%%autovisualize my_autovisualizer

# ... contents of your cell ...
result = ...
result

which expands to something like

with treescope.autovisualize.active_autovisualizer.set_scoped(
    my_autovisualizer
):
  # ... contents of your cell ...
  result = ...
  IPython.display.display(result)
Parameters:
  • line – Contents of the line where %%autovisualize is. Should either be empty or should be (a Python expression for) an autovisualizer object to use.

  • cell – Contents of the rest of the cell. Will be run inside the autovisualization scope.