Skip to content

Contract mpo mpo - #45

Closed
shinaoka wants to merge 2 commits into
ITensor:mainfrom
shinaoka:contract_mpo_mpo
Closed

Contract mpo mpo#45
shinaoka wants to merge 2 commits into
ITensor:mainfrom
shinaoka:contract_mpo_mpo

Conversation

@shinaoka

Copy link
Copy Markdown
Contributor

Moved from ITensor/ITensorTDVP.jl#48

We may need to polish the interface a bit.
Does it make sense to introduce a specialization of apply(MPO, MPO, ...)?

Comment on lines +33 to 46
init_mpsi = siteinds(init_mps)
for j in 1:n
ti = nothing
for i in Ai[j]
if !hasind(psi0[j], i)
ti[j] = i
ti = i
break
end
end
if ti !== nothing
ci = commoninds(init_mpsi[j], A[j])[1]
replaceind!(init_mps[j], ci=>ti)
end
end

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Could you explain what this is doing?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This ensures that phi0 and init_mps have the same site indices. This originates from the old code, but I feel this is hard to understand. Why not throwing an error if the two MPSs do not have the site indices?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

In general, I prefer to write the code where it is as flexible as possible about the indices, so it should be ok if there are missing site indices (for example I have hit examples like that in ITensorQTT.jl).

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Along those lines, in general I would avoid doing index replacements/forcing indices to match, if that is what this code is doing.

@shinaoka shinaoka Jan 11, 2023

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Oh, there was a typo. This code ensures that A phi0 and init_mps have the same site indices.
What example do you have in ITensorQTT.jl? A acts only on a subset of site indices (subset of tensors) of phi0?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I would vote for just not checking or fixing anything at first to allow the most flexibility, and if issues come up from that we can add checks for particular issues.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

For context, I think in general in the past we have over-specialized code too much in functions like this, and the goal of ITensorNetworks.jl is to be as agnostic as possible about particular tensor network structures.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Along those lines, as of #44 the underlying generic tdvp function now works for tree tensor networks, so with some minor modifications it should be easy to make this function work for that case as well!

Comment on lines +54 to +60
function asMPS(M::MPO, sites)
M_ = MPS(length(sites))
for n in eachindex(sites)
M_[n] = M[n]
end
return M_
end

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I would remove this and just use MPS([A for A in M]) directly in the test.

M2_ = asMPS(M2, sites)

M12_ref = asMPS(contract(M1, M2; alg="naive"), sites)
M12 = contract(M1, M2_; alg="fit")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Isn't this only testing MPO-MPS contraction?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Ah, I got your point. We are testing MPO-(MPS with two site indices) here. I'll rename it correctly.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I guess I'm unclear about what the new functionality is. Is it MPO-MPO contraction, or a more general MPO-MPS contraction where the MPS can have dangling (uncontracted) indices?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Originally, I intended to support MPO-MPO contraction. But, the latter case should work. I will add a test on the latter case.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

One goal of ITensorNetworks.jl is to make code "just work" whether it involves MPO or MPS, and in fact we may just not have separate types (that is still being debated). But it would be best if this kind of code didn't care much if the inputs are MPO or MPS (and as of #44, TTNO/TTNS types as well).

@mtfishman

Copy link
Copy Markdown
Member

We may need to polish the interface a bit. Does it make sense to introduce a specialization of apply(MPO, MPO, ...)?

apply(::MPO, ::MPO) is already defined in ITensors.jl.

@shinaoka

shinaoka commented Jan 12, 2023

Copy link
Copy Markdown
Contributor Author

OK, once #44 has been merged, which I was not aware of, this PR does not make sense. I will close it and work on the current main branch.

@shinaoka

Copy link
Copy Markdown
Contributor Author

This has been addressed in #46 .

@shinaoka shinaoka closed this Jan 25, 2023
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