Skip to content

Commit 7a2a5fc

Browse files
TendonFFFcailixun
andauthored
add qeye_like and qzero_like (#555)
Co-authored-by: cailixun <[email protected]>
1 parent 849ffcb commit 7a2a5fc

File tree

7 files changed

+34
-12
lines changed

7 files changed

+34
-12
lines changed

.github/workflows/CI.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,11 @@ jobs:
5656

5757
include:
5858
# for core tests (intermediate versions)
59-
# - version: '1.x'
60-
# node:
61-
# os: 'ubuntu-latest'
62-
# arch: 'x64'
63-
# group: 'Core'
59+
- version: '1.11'
60+
node:
61+
os: 'ubuntu-latest'
62+
arch: 'x64'
63+
group: 'Core'
6464

6565
# for extension tests
6666
- version: '1'

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
88
## [Unreleased](https://github.com/qutip/QuantumToolbox.jl/tree/main)
99

1010
- Fix `cite()` bibtex output. ([#552])
11+
- Add `qeye_like` and `qzero_like`, which are synonyms of `one` and `zero`. ([#555])
1112

1213
## [v0.36.0]
1314
Release date: 2025-09-29
@@ -326,3 +327,4 @@ Release date: 2024-11-13
326327
[#544]: https://github.com/qutip/QuantumToolbox.jl/issues/544
327328
[#546]: https://github.com/qutip/QuantumToolbox.jl/issues/546
328329
[#552]: https://github.com/qutip/QuantumToolbox.jl/issues/552
330+
[#555]: https://github.com/qutip/QuantumToolbox.jl/issues/555

docs/src/resources/api.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,8 @@ logm
188188
expm
189189
sinm
190190
cosm
191+
qeye_like
192+
qzero_like
191193
```
192194

193195
## [Time evolution](@id doc-API:Time-evolution)

docs/src/users_guide/QuantumObject/QuantumObject_functions.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ Here is a table that summarizes all the supported linear algebra functions and a
1010

1111
| **Description** | **Function call** | **Synonyms** |
1212
|:----------------|:------------------|:-------------|
13-
| zero-like array | [`zero(Q)`](@ref zero) | - |
14-
| identity-like matrix | [`one(Q)`](@ref one) | - |
13+
| zero-like array | [`zero(Q)`](@ref zero) | [`qzero_like(Q)`](@ref qzero_like) |
14+
| identity-like matrix | [`one(Q)`](@ref one) | [`qeye_like(Q)`](@ref qeye_like) |
1515
| conjugate | [`conj(Q)`](@ref conj) | - |
1616
| transpose | [`transpose(Q)`](@ref transpose) | [`trans(Q)`](@ref trans) |
1717
| conjugate transposition | [`adjoint(Q)`](@ref adjoint) | [`Q'`](@ref adjoint), [`dag(Q)`](@ref dag) |

src/qobj/synonyms.jl

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Synonyms of the functions for QuantumObject
55
export Qobj, QobjEvo, shape, isherm
66
export trans, dag, matrix_element, unit
77
export tensor,
8-
export qeye
8+
export qeye, qeye_like, qzero_like
99
export vector_to_operator, operator_to_vector
1010
export sqrtm, logm, expm, sinm, cosm
1111

@@ -104,3 +104,21 @@ Matrix cosine of [`QuantumObject`](@ref), defined as
104104
Note that this function is same as `cos(A)` and only supports for [`Operator`](@ref) and [`SuperOperator`](@ref).
105105
"""
106106
cosm(A::QuantumObject{ObjType}) where {ObjType<:Union{Operator,SuperOperator}} = cos(A)
107+
108+
@doc raw"""
109+
qeye_like(A::AbstractQuantumObject)
110+
111+
Return a similar [`AbstractQuantumObject`](@ref) with `dims` and `type` are same as `A`, but `data` is an identity matrix.
112+
113+
Note that this function is same as `one(A)` and only supports for [`Operator`](@ref) and [`SuperOperator`](@ref).
114+
"""
115+
qeye_like(A::AbstractQuantumObject{OpType}) where {OpType<:Union{Operator,SuperOperator}} = one(A)
116+
117+
@doc raw"""
118+
qzero_like(A::AbstractQuantumObject)
119+
120+
Return a similar [`AbstractQuantumObject`](@ref) with `dims` and `type` are same as `A`, but `data` is a zero-array.
121+
122+
Note that this function is same as `zero(A)` and only supports for [`Operator`](@ref) and [`SuperOperator`](@ref).
123+
"""
124+
qzero_like(A::AbstractQuantumObject{OpType}) where {OpType<:Union{Operator,SuperOperator}} = zero(A)

test/core-test/quantum_objects.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,8 +202,8 @@
202202
@test (a2 + 2).data == a2.data + 2 * I
203203
@test a2 * 2 == 2 * a2
204204

205-
zero_like = zero(a2)
206-
iden_like = one(a3)
205+
zero_like = qzero_like(a2)
206+
iden_like = qeye_like(a3)
207207
zero_array = spzeros(ComplexF64, 100, 100)
208208
iden_array = sparse(1:100, 1:100, ones(ComplexF64, 100))
209209
@test zero_like == Qobj(zero_array, type = a2.type, dims = a2.dims)

test/core-test/quantum_objects_evo.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,8 @@
8080
@test (a2 + 2).data == a2.data + 2 * I
8181
@test a2 * 2 == 2 * a2
8282

83-
zero_like = zero(a2)
84-
iden_like = one(a3)
83+
zero_like = qzero_like(a2)
84+
iden_like = qeye_like(a3)
8585
zero_array = NullOperator(100)
8686
iden_array = IdentityOperator(100)
8787
@test zero_like == QobjEvo(zero_array, type = a2.type, dims = a2.dims)

0 commit comments

Comments
 (0)