diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index 7edabdb31..119793312 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -56,11 +56,11 @@ jobs: include: # for core tests (intermediate versions) - # - version: '1.x' - # node: - # os: 'ubuntu-latest' - # arch: 'x64' - # group: 'Core' + - version: '1.11' + node: + os: 'ubuntu-latest' + arch: 'x64' + group: 'Core' # for extension tests - version: '1' diff --git a/CHANGELOG.md b/CHANGELOG.md index aeebc41cc..8a8eb735c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased](https://github.com/qutip/QuantumToolbox.jl/tree/main) - Fix `cite()` bibtex output. ([#552]) +- Add `qeye_like` and `qzero_like`, which are synonyms of `one` and `zero`. ([#555]) ## [v0.36.0] Release date: 2025-09-29 @@ -326,3 +327,4 @@ Release date: 2024-11-13 [#544]: https://github.com/qutip/QuantumToolbox.jl/issues/544 [#546]: https://github.com/qutip/QuantumToolbox.jl/issues/546 [#552]: https://github.com/qutip/QuantumToolbox.jl/issues/552 +[#555]: https://github.com/qutip/QuantumToolbox.jl/issues/555 diff --git a/docs/src/resources/api.md b/docs/src/resources/api.md index 38b6bb226..e4e5e901a 100644 --- a/docs/src/resources/api.md +++ b/docs/src/resources/api.md @@ -188,6 +188,8 @@ logm expm sinm cosm +qeye_like +qzero_like ``` ## [Time evolution](@id doc-API:Time-evolution) diff --git a/docs/src/users_guide/QuantumObject/QuantumObject_functions.md b/docs/src/users_guide/QuantumObject/QuantumObject_functions.md index be76b0c06..3a1b16da5 100644 --- a/docs/src/users_guide/QuantumObject/QuantumObject_functions.md +++ b/docs/src/users_guide/QuantumObject/QuantumObject_functions.md @@ -10,8 +10,8 @@ Here is a table that summarizes all the supported linear algebra functions and a | **Description** | **Function call** | **Synonyms** | |:----------------|:------------------|:-------------| -| zero-like array | [`zero(Q)`](@ref zero) | - | -| identity-like matrix | [`one(Q)`](@ref one) | - | +| zero-like array | [`zero(Q)`](@ref zero) | [`qzero_like(Q)`](@ref qzero_like) | +| identity-like matrix | [`one(Q)`](@ref one) | [`qeye_like(Q)`](@ref qeye_like) | | conjugate | [`conj(Q)`](@ref conj) | - | | transpose | [`transpose(Q)`](@ref transpose) | [`trans(Q)`](@ref trans) | | conjugate transposition | [`adjoint(Q)`](@ref adjoint) | [`Q'`](@ref adjoint), [`dag(Q)`](@ref dag) | diff --git a/src/qobj/synonyms.jl b/src/qobj/synonyms.jl index 278fafe94..224c73b59 100644 --- a/src/qobj/synonyms.jl +++ b/src/qobj/synonyms.jl @@ -5,7 +5,7 @@ Synonyms of the functions for QuantumObject export Qobj, QobjEvo, shape, isherm export trans, dag, matrix_element, unit export tensor, ⊗ -export qeye +export qeye, qeye_like, qzero_like export vector_to_operator, operator_to_vector export sqrtm, logm, expm, sinm, cosm @@ -104,3 +104,21 @@ Matrix cosine of [`QuantumObject`](@ref), defined as Note that this function is same as `cos(A)` and only supports for [`Operator`](@ref) and [`SuperOperator`](@ref). """ cosm(A::QuantumObject{ObjType}) where {ObjType<:Union{Operator,SuperOperator}} = cos(A) + +@doc raw""" + qeye_like(A::AbstractQuantumObject) + +Return a similar [`AbstractQuantumObject`](@ref) with `dims` and `type` are same as `A`, but `data` is an identity matrix. + +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) + +@doc raw""" + qzero_like(A::AbstractQuantumObject) + +Return a similar [`AbstractQuantumObject`](@ref) with `dims` and `type` are same as `A`, but `data` is a zero-array. + +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) diff --git a/test/core-test/quantum_objects.jl b/test/core-test/quantum_objects.jl index 920f26970..6e51b849e 100644 --- a/test/core-test/quantum_objects.jl +++ b/test/core-test/quantum_objects.jl @@ -202,8 +202,8 @@ @test (a2 + 2).data == a2.data + 2 * I @test a2 * 2 == 2 * a2 - zero_like = zero(a2) - iden_like = one(a3) + zero_like = qzero_like(a2) + iden_like = qeye_like(a3) zero_array = spzeros(ComplexF64, 100, 100) iden_array = sparse(1:100, 1:100, ones(ComplexF64, 100)) @test zero_like == Qobj(zero_array, type = a2.type, dims = a2.dims) diff --git a/test/core-test/quantum_objects_evo.jl b/test/core-test/quantum_objects_evo.jl index a417f52ac..cb86a74fe 100644 --- a/test/core-test/quantum_objects_evo.jl +++ b/test/core-test/quantum_objects_evo.jl @@ -80,8 +80,8 @@ @test (a2 + 2).data == a2.data + 2 * I @test a2 * 2 == 2 * a2 - zero_like = zero(a2) - iden_like = one(a3) + zero_like = qzero_like(a2) + iden_like = qeye_like(a3) zero_array = NullOperator(100) iden_array = IdentityOperator(100) @test zero_like == QobjEvo(zero_array, type = a2.type, dims = a2.dims)