Skip to content

Contract mpo mpo #45

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed

Contract mpo mpo #45

wants to merge 2 commits into from

Conversation

shinaoka
Copy link
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
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
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
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
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.

Copy link
Contributor Author

@shinaoka shinaoka Jan 11, 2023

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
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
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
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
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
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
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
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
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
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
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
Copy link
Contributor Author

shinaoka commented Jan 12, 2023

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
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