Skip to content

Worth acknowledging in README: works natively with Pluto #32

Closed

Description

@mmikhasenko

I'm just amazed that my visualization of the computation graph worked natively with Symbolics+D3Trees+AbstractTrees in Pluto.jl

Image
Code of the notebook
# ╔═╡ 25bd6e29-136f-4b9e-8691-2e8ea2695bbe
using D3Trees

# ╔═╡ 2c93ba8b-4ec6-49cd-b4e6-1a1053254deb
using AbstractTrees

# ╔═╡ bdbeb3f0-7e71-4fed-bd6b-716e25108804
using Symbolics

# ╔═╡ f2e1e0c0-614a-11f0-2ae8-ed45f17f9f2b
f(x) = x^2 + 3x - log(x^5 / (1 + x^5))

# ╔═╡ db6f56a9-f484-4807-ab59-f5ede781c947
@variables x

# ╔═╡ 2c8b9fd0-8064-4bca-970e-bc40f6b414d6
expr = f(x)

# ╔═╡ f0d8407a-ab41-4983-a56c-78a55c3e46a9
begin
	# AbstractTrees interface for symbolic expressions
	AbstractTrees.children(x::Symbolics.Num) = AbstractTrees.children(Symbolics.unwrap(x))
	AbstractTrees.children(x::SymbolicUtils.BasicSymbolic) = SymbolicUtils.iscall(x) ? SymbolicUtils.arguments(x) : []
	
	function get_label(x)
	    if x isa Symbolics.Num
	        return get_label(Symbolics.unwrap(x))
	    elseif x isa SymbolicUtils.BasicSymbolic
	        if SymbolicUtils.iscall(x)
	            string(SymbolicUtils.operation(x))
	        else
	            string(x)
	        end
	    else
	        string(x)
	    end
	end
	
	function AbstractTrees.printnode(io::IO, x)
	    print(io, get_label(x))
	end
	
end

# ╔═╡ ece18b3c-b9f5-4c97-8a36-1dde5fdbc033
t = let
	nodes = collect(AbstractTrees.PreOrderDFS(expr))
	D3Tree(expr, init_expand = 10,
	style = fill("stroke:blue; stroke-width:1px; font-size:22px", length(nodes)))
end

Activity

  1. BoZenKhaa commented on Jul 15, 2025

    @BoZenKhaa
    Contributor

    Well I am amazed as well, looks neat!

  2. zsunberg commented on Jul 16, 2025

    @zsunberg
    Member

    Wow! That is neat! Thanks for sharing!

  3. zsunberg commented on Jul 16, 2025

    @zsunberg
    Member

    Added to the readme!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions