Add lazy field to QuantumOpticsRepr (qojulia/QuantumOptics.jl#521)#86
Open
mk0dz wants to merge 1 commit into
Open
Add lazy field to QuantumOpticsRepr (qojulia/QuantumOptics.jl#521)#86mk0dz wants to merge 1 commit into
mk0dz 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.
Part 1 of 2 for qojulia/QuantumOptics.jl#521 (lazy operator support).
The ask
Add a
lazy::Bool=falsekeyword toQuantumOpticsReprso thatexpress(x, QuantumOpticsRepr(lazy=true))produces structure-preserving lazyoperators: symbolic sum →
LazySum, product →LazyProduct,tensor →
LazyTensor, withdense(lazy) ≈ eagerand backward compatibilityfor
QuantumOpticsRepr()/QuantumOpticsRepr(cutoff).The key insights
QuantumSymbolics expresses a composite symbolic expression via
operation(s)(express.(arguments(s))...)— it applies the symbolic operation(
+,*,⊗) to the eagerly-expressed arguments. Making it lazy = swap theoperation for its lazy constructor.
operation()is+forSAdd,*forSMulOperator/SScaled,⊗forSTensor(verified in source), so a singledispatch on the operation suffices.
Changes (2 repos → 2 coordinated PRs)
1.
QuantumInterface.jl—src/express.jlThe explicit 1-arg constructor is required because
@kwdefwith two fields makesthe positional constructor need both args — without it,
QuantumOpticsRepr(2)(a documented usage) would break.
2.
QuantumSymbolics.jl—ext/QuantumOpticsExt/QuantumOpticsExt.jlQuantumSavory/QuantumSymbolics.jl#201A
express_nolookup(s, repr::QuantumOpticsRepr)method that, whenrepr.lazy,maps the operation to its lazy constructor (and otherwise reproduces the eager
behaviour exactly). Guards ensure ket/bra cases (which also carry
operation===*)fall through to eager, and that
LazyTensor(which needs densifiable factors)collapses any lazy factor while keeping the tensor product itself lazy.
Plus
test/general/express_lazy_tests.jl(auto-discovered) and a paragraph indocs/src/express.md.Validation (local, Julia 1.12.6, dev-linked QuantumInterface)
express_lazy_tests.jl(constructor, backcompat, sum/product/tensor, dense≈eager, scalar, nesting, eager-unchanged)express_opt_tests.jl(eager sums/products/tensors/mixed)basis_consistency_tests.jlFiles changed (PR contents)
AI Acknowledgment: i want to thank claude opus 4.6 for making me understand code base of both repos and helpin me running testing and validations