Add lazy option to QuantumOpticsRepr#85
Open
GrovyleX wants to merge 1 commit into
Open
Conversation
Add a `lazy::Bool=false` field to `QuantumOpticsRepr` so downstream `express` conversions can opt into the lazy operator types of QuantumOpticsBase. An explicit `QuantumOpticsRepr(cutoff::Int)` constructor keeps the existing positional calling convention working, and the default representation is unchanged. Part of qojulia/QuantumOptics.jl#521
12 tasks
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.
What this does
Adds an opt-in
lazy::Bool=falsefield toQuantumOpticsRepr. On its own this does nothingvisible — it's the switch the companion QuantumSymbolics PR (QuantumSavory/QuantumSymbolics.jl#203) reads to decide whether
expressbuilds eager matrices or QuantumOpticsBase's lazy operators (LazySum,LazyProduct,LazyTensor). Together they implement qojulia/QuantumOptics.jl#521. The default is unchanged:QuantumOpticsRepr()is still eager.Keeping the existing constructors working
QuantumOpticsRepris aBase.@kwdefstruct, so naively adding a second field breaks thepositional call
QuantumOpticsRepr(4)— it would start expecting two positional arguments. Oneouter constructor restores it:
So nothing existing breaks and the option is purely additive:
Why a field, and not a flag passed some other way
express caches its conversions in a Dict keyed on the representation value, and
QuantumOpticsRepr relies on the default structural ==/hash. Making lazy a real field means
an eager and a lazy representation of the same object compare unequal, so they get separate cache
slots and the cache can't hand back the wrong type. test/test_express.jl checks that invariant
plus all the constructor forms above.
Pkg.test() is green locally on Julia 1.12.6, including Aqua. CHANGELOG bumped to v0.4.3.
Part of qojulia/QuantumOptics.jl#521
AI disclosure
I used AI to help analyze the codebase understand different and help in implementation, but I worked out the @kwdef/constructor and caching details myself, verified them against how express actually keys its cache, and wrote
and ran the tests. I went through the whole diff and understand every line - happy to walk through
any of it.