Add embed_lazy: lazy embedding of operators into composite bases#234
Open
shreyasavadatti wants to merge 1 commit into
Open
Add embed_lazy: lazy embedding of operators into composite bases#234shreyasavadatti wants to merge 1 commit into
shreyasavadatti wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes qojulia/QuantumOptics.jl#523
embedalways builds the full matrix immediately. For a 12-site chain that's ~1.6 MB per term just to construct the Hamiltonian, before anything gets applied to a state. AndTimeDependentSumhas noembeddispatch at all, so there's no clean way to lazily build time-dependent Hamiltonians today.embed_lazyfixes this - you get aLazyTensororLazySumback, nothing materialises until you calldenseorsparse.What's added:
src/embed_lazy.jl- six dispatch paths: single-siteAbstractOperator, multi-site vector,LazyTensorre-embedding (preserves factor),LazySum(returnsLazySumofLazyTensors), andTimeDependentSum(threads throughop.static_opandop.coefficients). All paths check basis compatibility before constructing anything.LazyProductis explicitly unsupported - it breaks time evolution insideLazyTensorper the existing docs.test/test_embed_lazy.jl- 13 testsets, 101/101 passing. Covers dense/sparse ops, multi-site, re-embedding with scaled factors, asymmetric bases,LazySumat all sites, error paths, and an allocation benchmark (<4 kB for N=12 vs >1 MB eager).Two lines in
src/QuantumOpticsBase.jl, one intest/runtests.jl,embed_lazyentry indocs/src/api.md.One thing to flag:
sx + 0.5*szmaterialises to a sparseOperatorin this library, not aLazySum.embed_lazyon that returns aLazyTensor(still lazy, still correct). To get aLazySumresult, construct one explicitly:LazySum([1.0, 0.5], (sx, sz)). Tests are written accordingly.