Can someone help me figure out how to arrange a package with the structure as in ITensors.jl?

I want to split plotting functionality (which depends on Plots or Makie) from my main package to reduce loading time. I notice that ITensors.jl does the exact thing I want to do. But I have difficulty on how it works. For example,

  • as the subpacakges are in the same github repo, how can I register each of them?
  • Why there is an ITensorVisualizationCore module within the main package ITensor?

Thanks!

TLDR: @JuliaRegistrator register subdir=path/to/my/package

Btw, instead of using subpackages or Requires.jl there might be better support for optional/weak dependencies in the (soon?) future, see e.g. Support in code loading and precompilation for weak dependencies by KristofferC · Pull Request #47040 · JuliaLang/julia · GitHub

2 Likes

As for ITensorsVisualizationBase, I would think that it just hold common code that is shared among the different plotting backend packages.

I am not confused with ITensorsVisualizationBase, but ITensorVisualizationCore, which resides in ITensors/src/ITensorVisualizationCore. Note that ITensorsVisualizationBase is a subpackage instead of a sub module inside ITensors (it locates at ITensors/ITensorsVisualizationBase)

My bad. Don’t what this module is for exactly. Someone else should be able to comment on that.

The reason for the ITensorVisualizationCore submodule within the ITensors module is to define the interface function visualize and macro @visualize, which I want to be able to use inside ITensors to help debug code by visualizing tensor contractions. However, I didn’t want all of ITensorsVisualizationBase (the common infrastructure of the various visualization backends like UnicodePlots and Makie) defined inside ITensors, so I defined ITensorVisualizationCore just to define the minimal interface that then gets extended by ITensorsVisualizationBase and the backend packages.

Perhaps there is a better way to achieve this. Ultimately it might make sense to have a separate VisualizationCore interface package that just defines visualize and @visualize which can then be loaded inside ITensors (analogous to packages like GitHub - JuliaArrays/StaticArraysCore.jl: Interface package for StaticArrays.jl) which then get overloaded by ITensorsVisualizationBase and extended by the various visualization backend packages.

Also I should probably re-implement some of this using the new Pkg extensions system coming to Julia 1.9 (5. Creating Packages · Pkg.jl).

Great! Thanks for such a detailed explanation.