bsc-quantic / Tenet.jl

Composable Tensor Network library in Julia
https://bsc-quantic.github.io/Tenet.jl/
Apache License 2.0
17 stars 1 forks source link

Refactor TN `Ansatz`es to traits #96

Closed mofeing closed 8 months ago

mofeing commented 9 months ago

Using type-parameters for encoding TN ansatz is not going to scale well.

  1. Composite incurs in a lot of compilation.
  2. Runtime dispatch is more costly than conditionals.

Proposal

The idea is to replace MatrixProduct, ProjectedEntangledPair, ... for Holy traits.

abstract type MatrixProduct{P,B} <: Quantum where {P<:Plug,B<:Boundary} end

would be rewritten as

abstract type Ansatz end
struct MatrixProduct{P<:Plug,B<:Boundary} <: Ansatz end

Also, the current Ansatz type would be renamed, because it would no longer express what we are meaning about it (i.e. the form of the graph). I suggest renaming it to Domain because that's what its fields are going to vary on.

Links

https://invenia.github.io/blog/2019/11/06/julialang-features-part-2/ https://www.ahsmart.com/pub/holy-traits-design-patterns-and-best-practice-book/

mofeing commented 8 months ago

Related code moved to Qrochet.jl.