Skip to content

Conversation

@Gavin-Rockwood
Copy link

@Gavin-Rockwood Gavin-Rockwood commented Dec 1, 2025

Checklist

Thank you for contributing to QuantumToolbox.jl! Please make sure you have finished the following tasks before opening the PR.

  • Please read Contributing to Quantum Toolbox in Julia.
  • Any code changes were done in a way that does not break public API.
  • Appropriate tests were added and tested locally by running: make test.
  • Any code changes should be julia formatted by running: make format.
  • All documents (in docs/ folder) related to code changes were updated and able to build locally by running: make docs.
  • (If necessary) the 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

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

Copy link
Member

@ytdHuang ytdHuang left a 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
end

You can also add other more complicated examples if you have some.

@ytdHuang ytdHuang marked this pull request as ready for review December 12, 2025 01:46
@codecov
Copy link

codecov bot commented Dec 12, 2025

Codecov Report

❌ Patch coverage is 96.87500% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 93.18%. Comparing base (0c77d51) to head (29f85dc).
⚠️ Report is 4 commits behind head on main.

Files with missing lines Patch % Lines
src/qobj/functions.jl 50.00% 1 Missing ⚠️
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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link

Copilot AI left a 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 TimeEvolutionProblem struct to include states_type field for tracking quantum object types
  • Extended sesolve and mesolve to accept Operator and SuperOperator initial 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.

@qutip qutip deleted a comment from Copilot AI Dec 16, 2025
Comment on lines +116 to 122
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
Copy link
Member

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

Suggested change
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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants