-
Notifications
You must be signed in to change notification settings - Fork 19
Add StateVectorRepr backend with tests and documentation #120
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 14 commits
ff40438
4fa4eba
3cb77e2
72622a9
e9ec426
1188360
fac7b79
119d511
952b77e
77f30db
125b52e
ff4475b
c0e0cb9
e1d79c8
eed6db7
594d0bc
e60a229
372a768
d21161f
a388036
e5263b7
9b9f248
e7365f3
d63df5c
175d5c3
c524dde
cc78eb5
808a8eb
3d2d507
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,8 @@ import QuantumSymbolics: express, express_nolookup | |
using TermInterface | ||
using TermInterface: isexpr, head, operation, arguments, metadata | ||
|
||
using SymbolicUtils | ||
|
||
const _b2 = SpinBasis(1//2) | ||
const _l0 = spinup(_b2) | ||
const _l1 = spindown(_b2) | ||
|
@@ -100,4 +102,28 @@ express_nolookup(s::SOuterKetBra, r::QuantumOpticsRepr) = projector(express(s.ke | |
|
||
include("should_upstream.jl") | ||
|
||
""" | ||
StateVectorRepr(config=nothing) | ||
|
||
A custom backend for `QuantumSymbolics.express`. Converts symbolic quantum | ||
objects into Julia's `Vector{ComplexF64}` (kets) or `Matrix{ComplexF64}` (operators). | ||
|
||
Internally uses `QuantumOptics.QuantumOpticsRepr` and extracts `.data`. | ||
An optional `config` (e.g., `(cutoff=4,)`) is forwarded to `QuantumOptics.QuantumOpticsRepr`. | ||
""" | ||
struct StateVectorRepr{C} | ||
config::C | ||
StateVectorRepr(config=nothing) = new{typeof(config)}(config) | ||
end | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The type parameterization here is a bit overly complicated. Any reason to set it up like this? Check out the |
||
|
||
function QuantumSymbolics.express(sym_obj::SymbolicUtils.Symbolic, backend::StateVectorRepr) | ||
qo_repr = if backend.config isa Nothing | ||
QuantumOptics.QuantumOpticsRepr() | ||
else | ||
QuantumOptics.QuantumOpticsRepr(backend.config...) | ||
end | ||
qo_obj = QuantumSymbolics.express(sym_obj, qo_repr) | ||
return qo_obj.data | ||
end | ||
|
||
end |
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The changes to this file seem a bit weird. Was this done by an LLM? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Indeed, an LLM provided some initial support on these changes, especially with deciphering a few errors and code patterns There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. check the Pkg.jl documentation and look at how QuantumSymbolics.jl and QuantumClifford.jl have things done as a reference, so that you can detect whether the LLM is suggesting silly things |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
using QuantumSymbolics | ||
using QuantumOptics | ||
using QuantumSavory | ||
|
||
@testitem "StateVectorRepr Conversion Tests" begin | ||
# Test: Symbolic Ket (X1) conversion | ||
sym_X1_test = QuantumSavory.X1 | ||
qo_X1_data = QuantumOptics.express(sym_X1_test, QuantumOptics.QuantumOpticsRepr()).data | ||
sv_X1_data = express(sym_X1_test, StateVectorRepr()) | ||
@test sv_X1_data isa Vector{ComplexF64} | ||
@test isapprox(sv_X1_data, qo_X1_data) | ||
@test length(sv_X1_data) == 2 | ||
|
||
# Test: Symbolic Operator (Z1) conversion | ||
sym_Z1_test = QuantumSavory.Z1 | ||
qo_Z1_data = QuantumOptics.express(sym_Z1_test, QuantumOptics.QuantumOpticsRepr()).data | ||
sv_Z1_data = express(sym_Z1_test, StateVectorRepr()) | ||
@test sv_Z1_data isa Matrix{ComplexF64} | ||
@test isapprox(sv_Z1_data, qo_Z1_data) | ||
@test size(sv_Z1_data) == (2, 2) | ||
|
||
# Test: Product operator (X1 * Y2) conversion | ||
sym_XY_test = QuantumSavory.X1 * QuantumSavory.Y2 | ||
qo_XY_data = QuantumOptics.express(sym_XY_test, QuantumOptics.QuantumOpticsRepr()).data | ||
sv_XY_data = express(sym_XY_test, StateVectorRepr()) | ||
@test sv_XY_data isa Matrix{ComplexF64} | ||
@test isapprox(sv_XY_data, qo_XY_data) | ||
@test size(sv_XY_data) == (4, 4) | ||
|
||
# Test: Bosonic operator (N) with custom cutoff | ||
sym_N_test = QuantumSavory.N | ||
qo_N_cutoff4_data = QuantumOptics.express(sym_N_test, QuantumOptics.QuantumOpticsRepr(cutoff=4)).data | ||
sv_N_cutoff4_data = express(sym_N_test, StateVectorRepr(cutoff=4)) | ||
@test sv_N_cutoff4_data isa Matrix{ComplexF64} | ||
@test isapprox(sv_N_cutoff4_data, qo_N_cutoff4_data) | ||
@test size(sv_N_cutoff4_data) == (5, 5) | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
QuantumOpticsBase should be sufficient. I do not think you need QuantumOptics.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks i have removed that line now