bsc-quantic / Qrochet.jl

Quantum Tensor Networks
https://bsc-quantic.github.io/Qrochet.jl/
Apache License 2.0
1 stars 0 forks source link

Extend `Tenet.contract` to contract `:between` two `Site`s #30

Closed jofrevalles closed 3 months ago

jofrevalles commented 3 months ago

Summary

This PR enhances the Tenet.contract function, enabling it to contract the singular values within a bond between two Sites. It introduces an optional direction argument, allowing users to specify whether the singular values should be contracted onto the :left or the :right tensor.

Additionally, we have added tests for this new functionality, and refactored the existing tests for the canonize! function, resulting in more compact and efficient test code.

Example:

Let's exemplify the function:

julia> qtn = MPS([rand(2, 2), rand(2, 2, 2), rand(2, 2, 2), rand(2, 2, 2), rand(2, 2)])
MPS (inputs=0, outputs=5)

julia> canonized = canonize(qtn)
MPS (inputs=0, outputs=5)

julia> length(tensors(canonized))
9

julia> contract!(canonized, :between, Site(1), Site(2))
MPS (inputs=0, outputs=5)

julia> length(tensors(canonized)) # We removed one singular value vector
8

julia> select(canonized, :between, Site(1), Site(2))
ERROR: ArgumentError: collection must be non-empty
Stacktrace: ...

julia> @test isapprox(contract(TensorNetwork(canonized)), contract(TensorNetwork(qtn)))
Test Passed
codecov[bot] commented 3 months ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 75.00%. Comparing base (11890f0) to head (dcfb136). Report is 12 commits behind head on master.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## master #30 +/- ## ======================================= Coverage 75.00% 75.00% ======================================= Files 8 8 Lines 436 460 +24 ======================================= + Hits 327 345 +18 - Misses 109 115 +6 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.