Skip to content

Commit

Permalink
Merge 99d7833 into 2bf32ca
Browse files Browse the repository at this point in the history
  • Loading branch information
mofeing authored Sep 25, 2024
2 parents 2bf32ca + 99d7833 commit 49d8b0d
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 0 deletions.
2 changes: 2 additions & 0 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ version = "0.8.0-DEV"
AbstractTrees = "1520ce14-60c1-5f80-bbc7-55ef81b5835c"
Combinatorics = "861a8166-3701-5b0c-9a16-15d98fcdc6aa"
DeltaArrays = "10b0fc19-5ccc-4427-889b-d75dd6306188"
ECharts_jll = "ffd69456-1935-58d2-abba-ba12e8909167"
EinExprs = "b1794770-133b-4de1-afb4-526377e9f4c5"
KeywordDispatch = "5888135b-5456-5c80-a1b6-c91ef8180460"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
Expand Down Expand Up @@ -60,6 +61,7 @@ ChainRulesTestUtils = "1"
Combinatorics = "1.0"
Dagger = "0.18"
DeltaArrays = "0.1.1"
ECharts_jll = "5"
EinExprs = "0.5, 0.6"
FiniteDifferences = "0.12"
GraphMakie = "0.4,0.5"
Expand Down
2 changes: 2 additions & 0 deletions src/Tenet.jl
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ export PEPS, pPEPS, PEPO, pPEPO

export evolve!, expect, overlap

include("Visualization.jl")

# reexports from EinExprs
export einexpr, inds

Expand Down
66 changes: 66 additions & 0 deletions src/Visualization.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
using ECharts_jll

function Base.show(io::IO, ::MIME"juliavscode/html", @nospecialize(tn::AbstractTensorNetwork))
tn = transform(tn, Tenet.HyperFlatten)
appid = gensym("tenet-graph")
tensormap = IdDict([tensor => i for (i, tensor) in enumerate(tensors(tn))])

nodes = collect(values(tensormap))

return print(
io,
"""
<script type="text/javascript">$(
read(joinpath(dirname(ECharts_jll.echarts), "echarts.min.js"), String)
)</script>
<div id="$appid" style="width: 600px; height: 600px;"></div>
<script>
var chart = echarts.init(document.getElementById('$appid'));
option = {
series: [
{
type: 'graph',
layout: 'force',
animation: false,
left: '0%',
top: '0%',
width: '100%',
height: '100%',
draggable: true,
force: {
// initLayout: 'circular'
gravity: 0.1,
repulsion: 100,
edgeLength: 3
},
data: $nodes,
edges: [$(join(
map(inds(tn; set=:inner)) do i
a,b = tensors(tn; intersects=i)
return "{ source: $(tensormap[a]), target: $(tensormap[b]), name: '$i' }"
end
, ','))],
edgeLabel: {
show: false,
formatter: function (params) {
return params.data.name;
}
},
emphasis: {
edgeLabel: {
show: true
},
lineStyle: {
width: 3
},
},
}
]
};
option && chart.setOption(option);
</script>
""",
)
end

0 comments on commit 49d8b0d

Please sign in to comment.