bsc-quantic / Tenet.jl

Composable Tensor Network library in Julia
https://bsc-quantic.github.io/Tenet.jl/
Apache License 2.0
17 stars 1 forks source link

`TensorNetwork(circ::Quac.Circuit)` fails for `circ` with some empty lanes #112

Closed jofrevalles closed 8 months ago

jofrevalles commented 8 months ago

The function TensorNetwork fails when is called for a given Quac.Circuit and there are some lanes that do not contain any gate.

Example:

julia> circ = Circuit(4)

julia> push!(circ, X(1)); push!(circ, X(2)); push!(circ, X(3)) # Lane 4 is empty

julia> tn = TensorNetwork(circ)
ERROR: "Quantum" metadata is not valid
Stacktrace:
 [1] checkansatz(tn::TensorNetwork{Quantum, NamedTuple{(:plug, :interlayer), Tuple{Type{<:Plug}, Vector{Bijections.Bijection{Int64, Symbol}}}}})
   @ Tenet ~/.julia/packages/Tenet/LSZRg/src/TensorNetwork.jl:69
 [2] (TensorNetwork{Quantum})(tensors::Vector{Tensor}; metadata::Base.Pairs{Symbol, Any, Tuple{Symbol, Symbol}, NamedTuple{(:plug, :interlayer), Tuple{DataType, Vector{Bijections.Bijection{Int64, Symbol}}}}})
   @ Tenet ~/.julia/packages/Tenet/LSZRg/src/TensorNetwork.jl:52
 [3] TensorNetwork
   @ ~/.julia/packages/Tenet/LSZRg/src/TensorNetwork.jl:36 [inlined]
 [4] TensorNetwork(circuit::Circuit)
   @ TenetQuacExt ~/.julia/packages/Tenet/LSZRg/ext/TenetQuacExt.jl:40
 [5] top-level scope
   @ REPL[36]:1

julia> push!(circ, X(4))

julia> tn = TensorNetwork(circ)
TensorNetwork{Quantum, NamedTuple{(:plug, :interlayer), Tuple{Type{<:Plug}, Vector{Bijections.Bijection{Int64, Symbol}}}}}(#tensors=4, #inds=8)
mofeing commented 8 months ago

This is expected, as no tensor is ever created for that lane and calling TensorNetwork(circuit) will create a operator (no tensor, no index for that lane).

jofrevalles commented 8 months ago

But this could be solved by simply adding an identity in that lane, right?

mofeing commented 8 months ago

yes, but does it make sense? wouldn't a circuit where a lane has no gate be a smaller circuit?

mofeing commented 8 months ago

Related code moved to Qrochet.jl.