|
450 | 450 | # TODO: rename `sqnorm` to match https://github.com/JuliaStats/Distances.jl?
|
451 | 451 | norm2(ψ::AbstractITensorNetwork; sequence) = contract_inner(ψ, ψ; sequence)
|
452 | 452 |
|
| 453 | +#Run over all edges of an ITENSORNETWORK and combine any duplicated indices into one |
| 454 | +#Can take pre-existing combiners as an argument |
| 455 | +function combine_link_indices(psi::AbstractITensorNetwork; combiners=nothing) |
| 456 | + if (combiners == nothing) |
| 457 | + outcombiners = Dict{NamedDimEdge{Tuple},ITensor}() |
| 458 | + end |
| 459 | + es = edges(psi) |
| 460 | + new_psi = deepcopy(psi) |
| 461 | + |
| 462 | + for e in es |
| 463 | + v1, v2 = src(e), dst(e) |
| 464 | + if (combiners == nothing) |
| 465 | + is = commoninds(psi, e) |
| 466 | + C = combiner(is; tags=tags(is[1])) |
| 467 | + else |
| 468 | + C = combiners[e] |
| 469 | + end |
| 470 | + new_psi[v1] = new_psi[v1] * C |
| 471 | + new_psi[v2] = new_psi[v2] * C |
| 472 | + if (combiners == nothing) |
| 473 | + outcombiners[e] = C |
| 474 | + end |
| 475 | + end |
| 476 | + |
| 477 | + if (combiners == nothing) |
| 478 | + return new_psi, outcombiners |
| 479 | + else |
| 480 | + return new_psi |
| 481 | + end |
| 482 | +end |
| 483 | + |
| 484 | +#Run over all edges of an ITENSORNETWORK and uncombine any indices which were previously combined |
| 485 | +#Can take pre-existing combiners as an argument |
| 486 | +function uncombine_link_indices( |
| 487 | + psi::AbstractITensorNetwork, combiners=Dict{NamedDimEdge{Tuple},ITensor}() |
| 488 | +) |
| 489 | + es = edges(psi) |
| 490 | + new_psi = deepcopy(psi) |
| 491 | + |
| 492 | + for e in es |
| 493 | + v1, v2 = src(e), dst(e) |
| 494 | + if (haskey(combiners, e)) |
| 495 | + C = combiners[e] |
| 496 | + new_psi[v1] = new_psi[v1] * C |
| 497 | + new_psi[v2] = new_psi[v2] * C |
| 498 | + end |
| 499 | + end |
| 500 | + |
| 501 | + return new_psi |
| 502 | +end |
| 503 | + |
| 504 | +#GIVEN AN ITENSOR NETWORK WITH DANGLING (PHYSICAL) BONDS, CONTRACT IT ONTO ITS CONJUGATE AND COMBINE ALL |
| 505 | +#DOUBLE INDICES. RETURN THE COMBINERS USED ON THE LINK INDICES |
| 506 | +#CAN APPLY LOCAL OPS ALONG THE PHYSICAL INDICES OF THE ITENSORNETWORK BEFORE CONTRACTION (ops is a list of strings, vops is a list of vertices, s is the indsnetwork) |
| 507 | +#CAN ALSO PASS COMBINERS FROM BEFORE TO ENSURE THE INDICES ARE CONSISTENT BETWEEN DIFFERENT APPLICATIONS OF THIS FUNCTION |
| 508 | +function flatten_thicken_bonds( |
| 509 | + psi::AbstractITensorNetwork; ops=nothing, vops=nothing, s=nothing, combiners=nothing |
| 510 | +) |
| 511 | + psiin = deepcopy(psi) |
| 512 | + outcombiners = Dict{NamedDimEdge{Tuple},ITensor}() |
| 513 | + |
| 514 | + if (ops != nothing) |
| 515 | + for (op, v) in zip(ops, vops) |
| 516 | + O = ITensor(Op(op, v), s) |
| 517 | + psiin[v] = noprime!(O * psiin[v]) |
| 518 | + end |
| 519 | + end |
| 520 | + |
| 521 | + flatpsi = flattened_inner_network(psiin, psi) |
| 522 | + flatpsi = rename_vertices_itn(flatpsi, Dictionary(vertices(flatpsi), vertices(psi))) |
| 523 | + |
| 524 | + return combine_link_indices(flatpsi; combiners=combiners) |
| 525 | +end |
| 526 | + |
453 | 527 | #
|
454 | 528 | # Printing
|
455 | 529 | #
|
|
0 commit comments