Skip to content

Fuse charges into MPO and tensor product terms in a LocalOperator - #476

Open
Yue-Zhengyuan wants to merge 1 commit into
QuantumKitHub:mainfrom
Yue-Zhengyuan:fuse-charge-mpo
Open

Yue-Zhengyuan wants to merge 1 commit into
QuantumKitHub:mainfrom
Yue-Zhengyuan:fuse-charge-mpo

Conversation

@Yue-Zhengyuan

Copy link
Copy Markdown
Member

This PR extends add_physical_charge to work with MPOTerm and TensorProductTerm of a LocalOperator introduced in #425.

@codecov

codecov Bot commented Oct 27, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

Files with missing lines Coverage Δ
src/operators/localoperator.jl 84.76% <ø> (ø)
src/operators/localoperator/mpo.jl 100.00% <100.00%> (ø)
src/operators/localoperator/tensorproduct.jl 95.65% <100.00%> (-4.35%) ⬇️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@leburgel

Copy link
Copy Markdown
Member

This seems great, I'll have a closer look later today. I did have one question right away.

The MPOTerm _fuse_charge implementation now has a very big overlap with what MPSKit.add_physical_charge does within MPSKit itself. Do you think there's any opportunity to reuse shared functionality from there? We don't have to forcibly fit this into the MPSKit implementation if it doesn't make sense, but since they really do the same thing it might make sense to share core routines.

This can also be done afterwards with some changes on both sides if it's not natural with the current state.

"""
Fuse an auxiliary charge into an MPO factor's physical legs while preserving its virtual bond spaces.
"""
function _fuse_mpo_charge(tensor::AbstractTensorMap, charge::Sector)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To reuse MPSKit, the result looks like this:

function _fuse_mpo_charge(tensor::AbstractTensorMap, charge::Sector)
    nout, nin = numout(tensor), numin(tensor)
    # MPSKit expects both virtual legs, including trivial legs at MPO endpoints.
    nout == 1 && (tensor = insertleftunit(tensor, 1))
    nin == 1 && (tensor = insertrightunit(tensor, numind(tensor)))
    # MPSKit dualizes its charge argument; LocalOperator has already done so.
    tensor = MPSKit.add_physical_charge(tensor, dual(charge))
    nin == 1 && (tensor = removeunit(tensor, 4))
    nout == 1 && (tensor = removeunit(tensor, 1))
    return tensor
end

The extra handling does not cost much, but this does remind me if we want to support PBC-MPOTerms.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants