Skip to content

Add embed_lazy: lazy embedding of operators into composite bases#234

Open
shreyasavadatti wants to merge 1 commit into
qojulia:masterfrom
shreyasavadatti:feature/embed-lazy
Open

Add embed_lazy: lazy embedding of operators into composite bases#234
shreyasavadatti wants to merge 1 commit into
qojulia:masterfrom
shreyasavadatti:feature/embed-lazy

Conversation

@shreyasavadatti

Copy link
Copy Markdown

Closes qojulia/QuantumOptics.jl#523

embed always 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. And TimeDependentSum has no embed dispatch at all, so there's no clean way to lazily build time-dependent Hamiltonians today.

embed_lazy fixes this - you get a LazyTensor or LazySum back, nothing materialises until you call dense or sparse.

What's added:

  • src/embed_lazy.jl - six dispatch paths: single-site AbstractOperator, multi-site vector, LazyTensor re-embedding (preserves factor), LazySum (returns LazySum of LazyTensors), and TimeDependentSum (threads through op.static_op and op.coefficients). All paths check basis compatibility before constructing anything. LazyProduct is explicitly unsupported - it breaks time evolution inside LazyTensor per 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, LazySum at all sites, error paths, and an allocation benchmark (<4 kB for N=12 vs >1 MB eager).

  • Two lines in src/QuantumOpticsBase.jl, one in test/runtests.jl, embed_lazy entry in docs/src/api.md.

One thing to flag: sx + 0.5*sz materialises to a sparse Operator in this library, not a LazySum. embed_lazy on that returns a LazyTensor (still lazy, still correct). To get a LazySum result, construct one explicitly: LazySum([1.0, 0.5], (sx, sz)). Tests are written accordingly.

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.

Add an efficient LazyEmbed / embed_lazy API

1 participant