Skip to content
This repository has been archived by the owner on Jul 7, 2024. It is now read-only.

Extend Tenet.contract to contract :between two Sites #30

Merged
merged 15 commits into from
Mar 14, 2024

Conversation

jofrevalles
Copy link
Member

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

@jofrevalles jofrevalles requested a review from mofeing March 13, 2024 12:00
src/Ansatz/Chain.jl Outdated Show resolved Hide resolved
src/Ansatz/Chain.jl Outdated Show resolved Hide resolved
@jofrevalles jofrevalles requested a review from mofeing March 13, 2024 16:04
src/Ansatz/Chain.jl Outdated Show resolved Hide resolved
@jofrevalles jofrevalles requested a review from mofeing March 14, 2024 08:04
src/Ansatz/Chain.jl Outdated Show resolved Hide resolved
test/Ansatz/Chain_test.jl Outdated Show resolved Hide resolved
test/Ansatz/Chain_test.jl Show resolved Hide resolved
test/Ansatz/Chain_test.jl Outdated Show resolved Hide resolved
test/Ansatz/Chain_test.jl Outdated Show resolved Hide resolved
Copy link

codecov bot commented Mar 14, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

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

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

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

jofrevalles and others added 2 commits March 14, 2024 17:53
@jofrevalles jofrevalles merged commit b505360 into master Mar 14, 2024
5 checks passed
@jofrevalles jofrevalles deleted the feature/contract-between branch March 14, 2024 17:01
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants