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

Enhance `Tensor` metadata with label `alias` mapping #51

Closed jofrevalles closed 1 year ago

jofrevalles commented 1 year ago

This PR addresses the issue "Incorporate labels representation for physical indices of each Tensor within a State" (fix #49). The implementation enhances the meta field of a Tensor within a State or Operator by including a dictionary that links the physical representation of each index (left, right, ...) with its respective label. This feature has been implemented for all the currently supported structs, MatrixProductState and MatrixProductOperator.

Implemented changes:

  1. Updated the code for MatrixProductState{Open}, MatrixProductState{Closed}, MatrixProductOperator{Open}, and MatrixProductOperator{Closed} to include the new alias dictionary within the meta field of a Tensor.
  2. Added test cases to ensure that the alias dictionaries in the tensors are correct.

Here's an example showcasing the new meta field with the alias dictionary:

julia> using Tenet

julia> ψ = rand(MatrixProductOperator{Open}, 4, 2, 8, 4)
TensorNetwork{MatrixProductOperator{Open}}(#tensors=4, #inds=11)

julia> one = tensors(ψ, 1); one.meta
Dict{Symbol, Any} with 2 entries:
  :tags  => Set{String}()
  :alias => Dict(:o=>Symbol("6a835717-eb51-403b-85e8-3ad4b439f4b0"), :r=>Symbol("95d79e6d-82b0-4c7d-bb0c-f55398890b4c"), :i=>Symbol("5d0684da-9155-4f61-a6b5-ea5b7702702f"))

julia> two = tensors(ψ, 2); two.meta
Dict{Symbol, Any} with 2 entries:
  :tags  => Set{String}()
  :alias => Dict(:l=>Symbol("95d79e6d-82b0-4c7d-bb0c-f55398890b4c"), :o=>Symbol("00e4f5f1-ba5e-4188-afaf-59c362a6373e"), :r=>Symbol("f39496ab-1d95-4075-8365-d3f343a5f2d3"), :i=>Symbol("3f03c23f-11ca-4b2f-9a5d-2dc10fd1b16f"))

julia> one.meta[:alias][:r] === two.meta[:alias][:l]
true
codecov[bot] commented 1 year ago

Codecov Report

Merging #51 (910a247) into master (cee74dc) will increase coverage by 0.83%. The diff coverage is 100.00%.

@@            Coverage Diff             @@
##           master      #51      +/-   ##
==========================================
+ Coverage   79.96%   80.80%   +0.83%     
==========================================
  Files          11       12       +1     
  Lines         594      625      +31     
==========================================
+ Hits          475      505      +30     
- Misses        119      120       +1     
Impacted Files Coverage Δ
src/Quantum/MatrixProductOperator.jl 94.79% <100.00%> (+0.28%) :arrow_up:
src/Quantum/MatrixProductState.jl 71.95% <100.00%> (+0.34%) :arrow_up:

... and 9 files with indirect coverage changes

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

jofrevalles commented 1 year ago

I think this is ready to merge.