Skip to content

Commit 115089f

Browse files
authored
Fix LocalOperator constructor for indices of type Tuple{Int,Int} (#176)
* Remove unnecessary type restriction on _safe_pow * Fix optimizer verbosity in `fixedpoint` algorithm selector * Fix tuple indices in LocalOperator constructor
1 parent 31e28f7 commit 115089f

2 files changed

Lines changed: 9 additions & 3 deletions

File tree

src/algorithms/select_algorithm.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ function select_algorithm(
4343

4444
# adjust optimizer tol and verbosity
4545
if optimizer_alg isa NamedTuple
46-
defaults = (; tol, verbosity=verbosity 1 ? -1 : 3)
46+
defaults = (; tol, verbosity=verbosity < 1 ? -1 : 3)
4747
optimizer_alg = merge(defaults, optimizer_alg)
4848
end
4949

src/operators/localoperator.jl

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ and the terms are stored as a tuple of pairs of indices and operators.
1414
# Constructors
1515
1616
LocalOperator(lattice::Matrix{S}, terms::Pair...)
17-
LocalOperator{T,S}(lattice::Matrix{S}, terms::T) where {T,S} # expert mode
17+
LocalOperator{T,S}(lattice::Matrix{S}, terms::T) where {T,S}
1818
1919
# Examples
2020
@@ -31,6 +31,7 @@ struct LocalOperator{T<:Tuple,S}
3131
# Check if the indices of the operator are valid with themselves and the lattice
3232
for (inds, operator) in terms
3333
@assert operator isa AbstractTensorMap
34+
@assert eltype(inds) <: CartesianIndex
3435
@assert numout(operator) == numin(operator) == length(inds)
3536
@assert spacetype(operator) == S
3637

@@ -52,7 +53,12 @@ function LocalOperator(
5253
relevant_terms = []
5354
for inds in unique(allinds)
5455
operator = sum(alloperators[findall(==(inds), allinds)])
55-
norm(operator) > atol && push!(relevant_terms, inds => operator)
56+
cinds = if !(eltype(inds) <: CartesianIndex) # force indices to be CartesianIndices
57+
map(CartesianIndex, inds)
58+
else
59+
inds
60+
end
61+
norm(operator) > atol && push!(relevant_terms, cinds => operator)
5662
end
5763

5864
terms_tuple = Tuple(relevant_terms)

0 commit comments

Comments
 (0)