Introduce SuperOperatorMatrixForm and add matrix_form argument - #707
Conversation
| function LinearAlgebra.mul!(v::AbstractMatrix, op::SprePostSuperOperator, u::AbstractMatrix, α::Number, β::Number) | ||
| iscached(op) || throw(ArgumentError("The cache for the SprePostSuperOperator must be initialized before multiplication. Use `cache_operator` to initialize the cache.")) | ||
| mul!(op.cache, op.L, u) # cache = L * u | ||
| mul!(v, op.cache, op.R, α, β) # v = α * (L * u * R) + β * v |
There was a problem hiding this comment.
this is potentially dense * sparse, and hurt performance greatly
There was a problem hiding this comment.
Don't we have already have efficient methods for dense * sparse multiplication?
cae455a to
9997077
Compare
f35aeaa to
42a8f1d
Compare
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #707 +/- ##
==========================================
- Coverage 67.30% 66.47% -0.83%
==========================================
Files 66 67 +1
Lines 3997 4116 +119
==========================================
+ Hits 2690 2736 +46
- Misses 1307 1380 +73 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull request overview
This PR adds a matrix-form superoperator representation (SuperOperatorMatrixForm) backed by SciMLOperators, and threads a new matrix_form keyword through liouvillian, liouvillian_dressed_nonsecular, and mesolve so users can avoid density-matrix vectorization for improved memory/performance on large systems.
Changes:
- Introduces
SuperOperatorMatrixFormplus SciMLOperators-backed left/right action operators for matrix-form evolution. - Adds
matrix_formkeyword plumbing tomesolve*and Liouvillian builders, with updated handling of matrix-shaped states in solutions/callbacks. - Expands core + CUDA tests and bumps SciMLOperators dependency version.
Reviewed changes
Copilot reviewed 17 out of 18 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| test/ext-test/gpu/cuda_ext.jl | Adds CUDA test coverage for mesolve(...; matrix_form=Val(true)). |
| test/core-test/time_evolution.jl | Extends time-evolution tests/inference checks for matrix_form paths and tuple-based ops. |
| test/core-test/liouvillian_dressed_nonsecular.jl | Adds tests comparing matrix-form vs vectorized Liouvillian action (unfiltered case) and updates inputs to tuples. |
| src/time_evolution/time_evolution.jl | Adds init-state handling for matrix-form superoperators (operate on Operator density matrices). |
| src/time_evolution/mesolve.jl | Threads matrix_form through mesolveProblem/mesolve/mesolve_map and adapts solution reconstruction for matrix states. |
| src/time_evolution/liouvillian_dressed_nonsecular.jl | Adds matrix_form support and refactors construction to support tuple inputs; enforces unfiltered-only for matrix form. |
| src/time_evolution/callback_helpers/mesolve_callback_helpers.jl | Documents expectation-value computation behavior when u is matrix-shaped. |
| src/QuantumToolbox.jl | Includes new qobj/superoperators_scimloperators.jl file. |
| src/qobj/superoperators.jl | Adds matrix_form support to spre/spost/sprepost/lindblad_dissipator/liouvillian and introduces matrix-form Liouvillian assembly. |
| src/qobj/superoperators_scimloperators.jl | New SciMLOperator types implementing right and left-right action on matrix density operators. |
| src/qobj/quantum_object.jl | Extends caching and show/type constraints to accommodate SuperOperatorType and matrix-form caching rules. |
| src/qobj/quantum_object_evo.jl | Extends QobjEvo typing/promotions and accepted object types to include SuperOperatorMatrixForm. |
| src/qobj/quantum_object_base.jl | Introduces SuperOperatorMatrixForm type tag and dimension checks. |
| src/qobj/boolean_functions.jl | Adjusts issuper semantics and adds issupermatform. |
| src/qobj/arithmetic_and_attributes.jl | Adds multiplication behavior for matrix-form superoperators acting on Operator / OperatorKet. |
| Project.toml | Bumps SciMLOperators compat to 1.26. |
| ext/QuantumToolboxCUDAExt.jl | Adds a CUDA dot specialization to support expectation-value computation when state is a CuArray matrix. |
| CHANGELOG.md | Documents the new matrix-form support and adds an issue reference link. |
Suppressed comments (1)
src/qobj/quantum_object_evo.jl:486
QuantumObjectEvolutionapplication only treatsSuperOperatoras a superoperator (issuper(A)), so matrix-form superoperators (SuperOperatorMatrixForm) don't trigger the input-type validation branch. Applying a matrix-form superoperator to aKet/OperatorKetwill currently fall through and fail later (likely with a less clear dimension error), instead of raising a targeted argument error.
if isoper(A) && isoperket(ψin)
throw(ArgumentError("The input state must be a Ket if the QuantumObjectEvolution object is an Operator."))
elseif issuper(A) && isket(ψin)
throw(
ArgumentError(
|
should we merge PR #751 first? cause some of these updates should be moved to |
…ll superoperators functions
Co-authored-by: Copilot <copilot@github.com>
Co-authored-by: Copilot <copilot@github.com>
5f7953e to
3887399
Compare
… Liouvillian matrix form
|
Fixed |
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
This package currently supports the superoperator representation in the framework of vectorized density matrix. By doing so, every superoperator is represented as a matrix. However, this can be suboptimal in several cases, especially when the system size increases.
Thus, I implemented here the support for the matrix form representation. In this framework, the density matrix remains a matrix (
Operator()). The right and left-right action is obtained through the use of SciMLOperators.jl.The user just needs to set
matrix_form = Val(true)in order to use this framework. For examplemesolve(H, psi0, tlist, c_ops; matrix_form = Val(true))liouvillian(H, c_ops; matrix_form = Val(true))liouvillian_dressed_nonsecular(H, fields, T_list; matrix_form = Val(true))There is currently this PR (SciML/SciMLOperators.jl#370) in SciMLOperators.jl that improves the cache efficiency for such cases, reducing even more the memory usage. This PR cannot be merged before that PR.
Transverse Field Ising Model Benchmarks
I benchmark now both the memory and the computational efficiency of
mesolve. The benchmarks are performed on the GPU NVIDIA 4090.Liouvillian Dressed Nonsecular Benchmarks
I then test the
liouvillian_dressed_nonsecular, which is known to be poorly sparse.CPU case
GPU
Related Issues
This PR fixes #617