Comments (3)
Sounds good, if that works for you then that's the approach I'd recommend. I'll go ahead and close this issue then.
To register treescope as the default pretty printer and also change the handler, you could run something like this:
# Install things in IPython
pz.ts.register_as_default()
pz.ts.register_autovisualize_magic()
# Enable global overrides
pz.enable_interactive_context()
# Configure the custom handler
my_custom_renderer = pz.ts.active_renderer.get().extended_with(<stuff here>)
pz.ts.active_renderer.set_interactive(my_custom_renderer)
# Optional: enable automatic array visualization
pz.ts.active_autovisualizer.set_interactive(pz.ts.ArrayAutovisualizer())
You could alternatively set my_custom_renderer
to a custom instance of penzai.treescope.renderer.TreescopeRenderer
if you want to fully control its configuration.
from penzai.
Ah, that's an interesting interaction. Right now Treescope assumes things that define _repr_html_
are "figure-like", so render_to_html
computes and adds the rich visualization as an annotation. This is useful for stuff like showing lists of plotly figures. I didn't anticipate that someone would call render_to_html
inside _repr_html_
.
This behavior is enabled by the repr_html_postprocessor.append_repr_html_when_present
wrapper hook (here). You can disable this behavior by removing that wrapper hook from the wrapper_hooks
list.
In this case, you might also want to avoid using pz.ts.render_to_html
directly, because that uses the default global renderer which you might not always have control over. Instead, you could construct a new renderer specific to your types, and call renderer.to_html
instead. That would let you fully control the set of handlers that are enabled for the renderer you're using inside _repr_html_
.
(For context, are you doing this so that you can render your objects with treescope even if treescope isn't enabled by default? If treescope is enabled, you shouldn't have to define _repr_html_
at all.)
from penzai.
@danieldjohnson Got it -- I think I'll just install treescope by default in my notebooks, and not futz around with _repr_html_
at all.
In that case, is there a pithy few line incantation for me to install treescope and push my own custom handler onto the default?
from penzai.
Related Issues (10)
- Customized `selector` functions for user-defined `Pytree` classes HOT 3
- Default `pytree_dataclass` for inheritors of a common baseclass HOT 2
- Synchronize sliders across array data in Pytree HOT 3
- Penzai as a training framework HOT 1
- importing model from other jax-based libraries for weight visualization HOT 1
- A few HTML feature requests... HOT 3
- Keep axes in nmap HOT 5
- Auto unwrap for full reductions. HOT 2
- Feature request: Animate button
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from penzai.