Skip to content
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

Implement inds method for physical and virtual indices #186

Merged
merged 2 commits into from
Aug 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/Quantum.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using KeywordDispatch

"""
AbstractQuantum

Expand Down Expand Up @@ -174,6 +176,15 @@ function Base.show(io::IO, q::Quantum)
end

@kwmethod inds(tn::AbstractQuantum; at) = Quantum(tn).sites[at]
@kwmethod function inds(tn::AbstractQuantum; set)
if set === :physical
return values(Quantum(tn).sites)
elseif set === :virtual
return setdiff(inds(tn), values(Quantum(tn).sites))
else
return inds(TensorNetwork(tn); set)
end
end

"""
adjoint(q::Quantum)
Expand Down
12 changes: 12 additions & 0 deletions test/Quantum_test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
@test nsites(qtn; set=:outputs) == 1
@test issetequal(sites(qtn), [site"1"])
@test socket(qtn) == State(; dual=false)
@test inds(qtn; at=site"1") == :i
@test issetequal(inds(qtn; set=:physical), [:i])
@test isempty(inds(qtn; set=:virtual))

# forwarded methods to `TensorNetwork`
@test TensorNetwork(qtn) == tn
Expand All @@ -20,6 +23,9 @@
@test nsites(qtn; set=:outputs) == 0
@test issetequal(sites(qtn), [site"1'"])
@test socket(qtn) == State(; dual=true)
@test inds(qtn; at=site"1'") == :i
@test issetequal(inds(qtn; set=:physical), [:i])
@test isempty(inds(qtn; set=:virtual))

_tensors = Tensor[Tensor(zeros(2, 2), [:i, :j])]
tn = TensorNetwork(_tensors)
Expand All @@ -28,6 +34,10 @@
@test nsites(qtn; set=:outputs) == 1
@test issetequal(sites(qtn), [site"1", site"1'"])
@test socket(qtn) == Operator()
@test inds(qtn; at=site"1") == :i
@test inds(qtn; at=site"1'") == :j
@test issetequal(inds(qtn; set=:physical), [:i, :j])
@test isempty(inds(qtn; set=:virtual))

_tensors = Tensor[Tensor(fill(0))]
tn = TensorNetwork(_tensors)
Expand All @@ -36,6 +46,8 @@
@test nsites(qtn; set=:outputs) == 0
@test isempty(sites(qtn))
@test socket(qtn) == Scalar()
@test isempty(inds(qtn; set=:physical))
@test isempty(inds(qtn; set=:virtual))

# detect errors
_tensors = Tensor[Tensor(zeros(2), [:i]), Tensor(zeros(2), [:i])]
Expand Down
Loading