adding an `nsubsystems` to QuantumInterface
Krastanov opened this issue · 2 comments
Krastanov commented
@david-pl , @amilsted , @ChristophHotter do you have anything against publicly introducing an nsubystems
function, shared with QuatnumClifford and others, by declaring it in QuantumInterface.
My last PR added such a function for internal consumption in apply!
, which makes it much easier to detect when embed
is needed. Here is the current implementation:
nsubsystems(s::Ket) = nsubsystems(s.basis)
function nsubsystems(s::Operator)
s.basis_l == s.basis_r || throw(ArgumentError("`nsubsystem(::Operator)` is well defined only if the left and right bases are the same"))
nsubsystems(s.basis_l)
end
nsubsystems(b::CompositeBasis) = length(b.bases)
nsubsystems(b::Basis) = 1
david-pl commented
@Krastanov do it!