From 88ce1c009c4f007e5ef70d56635aaf1f9e1aecb8 Mon Sep 17 00:00:00 2001 From: Gavin Date: Sun, 11 Jan 2026 00:55:14 +0000 Subject: [PATCH] updating qeye_like and qzero_like. --- CHANGELOG.md | 1 + src/qobj/arithmetic_and_attributes.jl | 9 +++++++++ src/qobj/synonyms.jl | 4 ++-- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e6e86d043..05ec6caa9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Optimize `liouvillian_dressed_nonsecular`: avoid O(N⁴) dense filter matrices. ([#627]) - Restrict `CUDA.jl` version compatibility to < 5.9.6 due to breaking changes in that release. ([#630]) - Move from `JuliaFormatter.jl` to `Runic.jl` for code formatting. ([#633]) +- Updated `qeye_like` to properly handle `QobjEvo` types. ## [v0.40.0] Release date: 2025-12-21 diff --git a/src/qobj/arithmetic_and_attributes.jl b/src/qobj/arithmetic_and_attributes.jl index 3ceed9de3..291eba3b0 100644 --- a/src/qobj/arithmetic_and_attributes.jl +++ b/src/qobj/arithmetic_and_attributes.jl @@ -751,3 +751,12 @@ _dims_and_perm(::Operator, dims::SVector{2, SVector{N, Int}}, order::AbstractVec _order_dimensions(dimensions::Dimensions, order::AbstractVector{Int}) = Dimensions(dimensions.to[order]) _order_dimensions(dimensions::GeneralDimensions, order::AbstractVector{Int}) = GeneralDimensions(dimensions.to[order], dimensions.from[order]) + + +_find_matrix(A::AbstractArray) = A +_find_matrix(A::MatrixOperator) = A.A +_find_matrix(A::ScaledOperator) = _find_matrix(A.L) +function _find_matrix(A::Union{AddedOperator, ComposedOperator}) + idx = findfirst(x -> _find_matrix(x) isa AbstractMatrix, A.ops) + return _find_matrix(A.ops[idx]) +end diff --git a/src/qobj/synonyms.jl b/src/qobj/synonyms.jl index c27d1d7e1..05362c91a 100644 --- a/src/qobj/synonyms.jl +++ b/src/qobj/synonyms.jl @@ -115,7 +115,7 @@ Return a similar [`AbstractQuantumObject`](@ref) with `dims` and `type` are same Note that this function is same as `one(A)` and only supports for [`Operator`](@ref) and [`SuperOperator`](@ref). """ -qeye_like(A::AbstractQuantumObject{OpType}) where {OpType <: Union{Operator, SuperOperator}} = one(A) +qeye_like(A::AbstractQuantumObject{OpType}) where {OpType <: Union{Operator, SuperOperator}} = QuantumObject(one(_find_matrix(A.data)), A.type, A.dimensions) @doc raw""" qzero_like(A::AbstractQuantumObject) @@ -124,4 +124,4 @@ Return a similar [`AbstractQuantumObject`](@ref) with `dims` and `type` are same Note that this function is same as `zero(A)` and only supports for [`Operator`](@ref) and [`SuperOperator`](@ref). """ -qzero_like(A::AbstractQuantumObject{OpType}) where {OpType <: Union{Operator, SuperOperator}} = zero(A) +qzero_like(A::AbstractQuantumObject{OpType}) where {OpType <: Union{Operator, SuperOperator}} = QuantumObject(zero(_find_matrix(A.data)), A.type, A.dimensions)