|
| 1 | +@doc raw""" |
| 2 | + function evaluate( |
| 3 | + mps::Union{ITensorMPS.MPS,ITensorMPS.MPO}, |
| 4 | + indexspecs::Vararg{AbstractVector{<:Tuple{ITensorMPS.Index,Int}}} |
| 5 | + ) |
| 6 | +
|
| 7 | +Evaluates an MPS or MPO for a given set of index values. |
| 8 | +
|
| 9 | +- `indexspec` is a list of tuples, where each tuple contains an `ITensorMPS.Index` object specifying an index, and an `Int` corresponding to the value of the specified index. |
| 10 | +
|
| 11 | +If many evaluations are necessary, it may be advantageous to convert your MPS to a [`TensorCrossInterpolation.TTCache`](@ref) object first. |
| 12 | +""" |
| 13 | +function evaluate( |
| 14 | + mps::Union{ITensorMPS.MPS,ITensorMPS.MPO}, |
| 15 | + indexspecs::Vararg{AbstractVector{<:Tuple{ITensors.Index,Int}}} |
| 16 | +) |
| 17 | + if isempty(indexspecs) |
| 18 | + error("Please specify at which indices you wish to evaluate the MPS.") |
| 19 | + elseif any(length.(indexspecs) .!= length(mps)) |
| 20 | + error("Need one index per MPS leg") |
| 21 | + end |
| 22 | + |
| 23 | + V = ITensor(1.0) |
| 24 | + for j in eachindex(indexspecs[1]) |
| 25 | + states = prod(ITensorMPS.state(spec[j]...) for spec in indexspecs) |
| 26 | + V *= mps[j] * states |
| 27 | + end |
| 28 | + return scalar(V) |
| 29 | +end |
| 30 | +@doc raw""" |
| 31 | + function evaluate( |
| 32 | + mps::Union{ITensorMPS.MPS,ITensorMPS.MPO}, |
| 33 | + indices::AbstractVector{<:ITensors.Index}, |
| 34 | + indexvalues::AbstractVector{Int} |
| 35 | + ) |
| 36 | +
|
| 37 | +Evaluates an MPS or MPO for a given set of index values. |
| 38 | +
|
| 39 | +- `indices` is a list of `ITensors.Index` objects that specifies the order in which indices are given. |
| 40 | +- `indexvalues` is a list of integer values in the same order as `indices`. |
| 41 | +
|
| 42 | +If many evaluations are necessary, it may be advantageous to convert your MPS to a [`TensorCrossInterpolation.TTCache`](@ref) object first. |
| 43 | +""" |
| 44 | +function evaluate( |
| 45 | + mps::Union{ITensorMPS.MPS,ITensorMPS.MPO}, |
| 46 | + indices::AbstractVector{<:ITensors.Index}, |
| 47 | + indexvalues::AbstractVector{Int} |
| 48 | +) |
| 49 | + return evaluate(mps, collect(zip(indices, indexvalues))) |
| 50 | +end |
0 commit comments