-
Notifications
You must be signed in to change notification settings - Fork 20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support a list of observables for expect
#376
base: main
Are you sure you want to change the base?
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #376 +/- ##
==========================================
+ Coverage 93.18% 93.32% +0.13%
==========================================
Files 43 43
Lines 2790 2803 +13
==========================================
+ Hits 2600 2616 +16
+ Misses 190 187 -3 ☔ View full report in Codecov by Sentry. |
ρ::QuantumObject, | ||
) where {DimsType<:AbstractDimensions,TF<:Number,TR<:Real} = expect.(O, Ref(ρ)) | ||
function expect(O::AbstractVector{<:AbstractQuantumObject{OperatorQuantumObject}}, ρ::QuantumObject) | ||
result = Vector{ComplexF64}(undef, length(O)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need to preallocate a vector first? What if we directly use the broadcasting?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cause I want to keep the output structure similar to QuTiP (first dimension represents observable, second one represents state), and in that case, directly use the broadcasting will result in type instability
expect(
O::AbstractVector{AbstractQuantumObject{OperatorQuantumObject}},
ρ::AbstractVector{<:QuantumObject},
) = expect.(O, Ref(ρ))
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
at least this is what I've tried and observed
In this case, if O
contains Hermitian
and other general Matrix
, it will return AbstractVector
here after broadcasting.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I think this can be fixed somehow. For the moment let's keep it as it is.
Could you just change the method definition with
expect(
O::AbstractVector{<:AbstractQuantumObject{OperatorQuantumObject}},
ρ::AbstractVector{<:QuantumObject},
)
...
Instead of
expect(
O::AbstractVector{AbstractQuantumObject{OperatorQuantumObject}},
ρ::AbstractVector{<:QuantumObject},
)
...
The first one should be more correct I think
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
uhh, I think this is what I already did in the code @@ ?
Checklist
Thank you for contributing to
QuantumToolbox.jl
! Please make sure you have finished the following tasks before opening the PR.make test
.julia
formatted by running:make format
.docs/
folder) related to code changes were updated and able to build locally by running:make docs
.CHANGELOG.md
should be updated (regarding to the code changes) and built by running:make changelog
.Request for a review after you have completed all the tasks. If you have not finished them all, you can also open a Draft Pull Request to let the others know this on-going work.
Description
As title
Related issues or PRs
close #374