From 1ff4e3286554202bbcebff987dda25d3ddfe15ff Mon Sep 17 00:00:00 2001 From: Ali Date: Mon, 13 May 2024 15:10:20 +0100 Subject: [PATCH] Handle single basis in embed This commit addresses the issue where the `embed` function fails when it receives a single basis instead of a composite basis as input. --- src/operators.jl | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/operators.jl b/src/operators.jl index ea824445..70513100 100644 --- a/src/operators.jl +++ b/src/operators.jl @@ -102,6 +102,20 @@ function embed(basis_l::CompositeBasis, basis_r::CompositeBasis, return Operator(basis_l, basis_r, data) end +""" + embed(basis::Basis, indices, ops::AbstractOperator) + +Special case of the `embed` to handle embedding an operator `ops` into a single +basis. +""" +function embed(basis::Basis, indices, ops::AbstractOperator) + if indices == 1 || indices == (1,) || indices == [1] + return ops + else + throw(ArgumentError("Invalid indices for single basis.")) + end +end + """ expect(op, state)