-
Notifications
You must be signed in to change notification settings - Fork 34
Adding operator support to time evolution problem #606
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
base: main
Are you sure you want to change the base?
Adding operator support to time evolution problem #606
Conversation
…nsions for examples.
…th a few other changes.
… sort out an issue that came up in the tests. Now all core tests pass.
ytdHuang
left a comment
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.
Can you also add two simple tests for propagator features ?
You can create a new file test/core-test/propagator.jl, and I would expect to see something like:
@testitem "Propagator (by solvers)" begin
ϵ0 = 1.0 * 2π
Δ = 0.8 * 2π
H = (ϵ0/2) * sigmaz() + (Δ/2) * sigmax()
L = liouvillian(H)
ψ0 = basis(2, 0)
ρ0 = mat2vec(ket2dm(ψ0))
dt = π/5
tlist = 0:dt:(2π)
ψt = sesolve(H, ψ0, tlist; progress_bar = Val(false)).states[2:end] # ignore the initial state
ρt = mesolve(H, ρ0, tlist; progress_bar = Val(false)).states[2:end] # ignore the initial state
Prop_se = sesolve(H, qeye_like(H), [0, dt]; progress_bar = Val(false)).states[-1]
Prop_me = mesolve(L, qeye_like(L), [0, dt]; progress_bar = Val(false)).states[-1]
for n in 1:(length(tlist)-1)
@test isapprox(Prop_se^n * ψ0, ψt[n]; atol = 1e-5)
@test isapprox(Prop_me^n * ρ0, ρt[n]; atol = 1e-5)
end
endYou can also add other more complicated examples if you have some.
src/time_evolution/callback_helpers/mcsolve_callback_helpers.jl
Outdated
Show resolved
Hide resolved
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #606 +/- ##
==========================================
+ Coverage 92.28% 93.18% +0.90%
==========================================
Files 50 50
Lines 3615 3627 +12
==========================================
+ Hits 3336 3380 +44
+ Misses 279 247 -32 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Co-authored-by: Yi-Te Huang <[email protected]>
Co-authored-by: Yi-Te Huang <[email protected]>
Co-authored-by: Yi-Te Huang <[email protected]>
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.
Pull request overview
This PR extends time evolution solvers (sesolve and mesolve) to support Operator and SuperOperator types as initial states, enabling propagator calculations. The implementation adds a states_type field to TimeEvolutionProblem to track the quantum object type throughout evolution, and updates all affected solvers and helper functions accordingly.
Key changes:
- Modified
TimeEvolutionProblemstruct to includestates_typefield for tracking quantum object types - Extended
sesolveandmesolveto acceptOperatorandSuperOperatorinitial states respectively - Added test coverage for propagator calculations using the new functionality
Reviewed changes
Copilot reviewed 9 out of 10 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| src/time_evolution/time_evolution.jl | Added states_type field to TimeEvolutionProblem struct to track quantum object types |
| src/time_evolution/sesolve.jl | Extended sesolve functions to support Operator initial states and updated solution generation |
| src/time_evolution/mesolve.jl | Extended mesolve functions to support SuperOperator initial states and refactored state handling |
| src/time_evolution/mcsolve.jl | Updated mcsolveEnsembleProblem to pass states_type field |
| src/time_evolution/ssesolve.jl | Updated ssesolveProblem to track and pass states_type field |
| src/time_evolution/smesolve.jl | Updated smesolveProblem to track and pass states_type field |
| src/qobj/functions.jl | Added to_dense methods for Diagonal types to support conversion |
| test/core-test/propagator.jl | Added new test for propagator calculations using both sesolve and mesolve |
| CHANGELOG.md | Documented the new functionality for propagator calculations |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| if isoperket(ψ0) || issuper(ψ0) | ||
| ρ0 = to_dense(T, copy(ψ0.data)) | ||
| states_type = ψ0.type | ||
| else | ||
| to_dense(_complex_float_type(T), mat2vec(ket2dm(ψ0).data)) | ||
| ρ0 = to_dense(T, mat2vec(ket2dm(ψ0).data)) | ||
| states_type = Operator() | ||
| end |
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.
Could you change this into
| if isoperket(ψ0) || issuper(ψ0) | |
| ρ0 = to_dense(T, copy(ψ0.data)) | |
| states_type = ψ0.type | |
| else | |
| to_dense(_complex_float_type(T), mat2vec(ket2dm(ψ0).data)) | |
| ρ0 = to_dense(T, mat2vec(ket2dm(ψ0).data)) | |
| states_type = Operator() | |
| end | |
| ρ0, states_type = if isoperket(ψ0) || issuper(ψ0) | |
| to_dense(T, copy(ψ0.data)), ψ0.type | |
| else | |
| to_dense(T, mat2vec(ket2dm(ψ0).data)), Operator() | |
| end |
It might fix the issue of JET.jl
Checklist
Thank you for contributing to
QuantumToolbox.jl! Please make sure you have finished the following tasks before opening the PR.make test.juliaformatted by running:make format.docs/folder) related to code changes were updated and able to build locally by running:make docs.CHANGELOG.mdshould 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
Updated TimeEvolutionProblem be parametrically typed using the type of the starting state as well as expanded sesolve, mesolve and mcsolve to allow them to take in operators, superoperators and operators respectively (along with other changes to facilitate this). ssesolve and smesolve are still in progress.
Related issues or PRs
Working on #521