Code Monkey home page Code Monkey logo

Comments (3)

danieldjohnson avatar danieldjohnson commented on May 20, 2024

Thanks for the question!

I'm not sure I fully understand what you are trying to do? By design, Penzai's selector system uses the actual jax.tree_util flattening and unflattening operations, so if you have custom tree flattening and unflattening operations, the selectors should compose with them correctly. You can't overload selectors with the current design, because then it would potentially go out of sync with how JAX sees the data structures under the hood.

penzai.treescope, on the other hand, is primarily a pretty-printer, and is somewhat separate from the selector system. You can implement your own handler for custom objects, including changing what gets copied when you click the "copy path" button. Doing so is a bit complex right now, but you might be able to figure it out by looking at some of the handlers in the handlers directory of penzai/treescope. I'd also like to make extending treescope easier in the future, and having specific use cases might help me figure out the best way to do that!

That said, I'm curious what problems you're running into right now? Have you run into problems trying to use Penzai with your custom classes already? There's a chance things would "just work" out of the box.

from penzai.

femtomc avatar femtomc commented on May 20, 2024

Thanks for the answer!

Right, a bit tough to explain succinctly, but I'll give it a shot: the data structures which I'm letting users pretty print have a specified interface for accessors and setters. This is different than just the Pytree flattening / unflattening operators and what you can build on top of them -- I hide a lot of the complexity of changing the data, as well as gaining access to the "semantically relevant" pieces of data in these objects.

These objects can represent things like "these are the samples that a probabilistic program sampled when it was executed" -- they can also represent things like "the constraints that a probabilistic program should execute under". In both cases, how these objects are constructed is important, and I have something very similar to a "data DSL" for creating these objects, and mutating them.

Maybe an immediate question (and my attempt at a quick answer): why have a "data DSL" at all -- and not just have a system like the selector system which works on Pytree? Because in the programs written in my system, "the identity of a random variable and its sampled value" is specified using a type of addressing system which is different from where the data actually lives in the fields of the Pytree. That's the main problem -- and the thing I'm trying to resolve (by e.g. providing a custom handler so that -- when a user pretty prints with penzai, the "copy" buttons use our addressing system, which also shows them where that random variable lives in the code that they wrote).

From your answer, I think I should investigate:

You can implement your own handler for custom objects, including changing what gets copied when you click the "copy path" button.

Just to clarify -- penzai is working perfectly fine (according to its design principles!) with my objects! I'm just hoping to provide a bit more of a walled garden for some of my objects.

from penzai.

femtomc avatar femtomc commented on May 20, 2024

Closing, as I have several ideas to think about.

from penzai.

Related Issues (10)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.