Skip to content

Commit

Permalink
Migrate express functionality and AbstractRepresentation type to …
Browse files Browse the repository at this point in the history
…QuantumInterface (#93)

* migrate express functionality to QuantumInterface

* rm default repr from QuantumSymbolics

* make second round changes

* add `AbsRepr` and `AbsUse` types to `own_types`

* update project.toml and changelog
  • Loading branch information
apkille authored Jan 18, 2025
1 parent be8cb24 commit e697f48
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 36 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# News

## v0.4.6 - 2025-01-18

- Migrate `express` functionality and representation types to QuantumInterface.

## v0.4.5 - 2024-11-14

- Updated compat lower bounds for Symbolics to v6 (and for SymbolicUtils and TermInterface)
Expand Down
4 changes: 2 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "QuantumSymbolics"
uuid = "efa7fd63-0460-4890-beb7-be1bbdfbaeae"
authors = ["QuantumSymbolics.jl contributors"]
version = "0.4.5"
version = "0.4.6"

[deps]
Latexify = "23fbe1c1-3f47-55db-b15f-69d7ec21a316"
Expand All @@ -28,7 +28,7 @@ LinearAlgebra = "1.9"
MacroTools = "0.5.13"
PrecompileTools = "1.2"
QuantumClifford = "0.8.19, 0.9"
QuantumInterface = "0.3.3"
QuantumInterface = "0.3.7"
QuantumOpticsBase = "0.4.22, 0.5"
SymbolicUtils = "3.7"
Symbolics = "6"
Expand Down
11 changes: 3 additions & 8 deletions src/QSymbolicsBase/QSymbolicsBase.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ import QuantumInterface:
basis,Basis,samebases,IncompatibleBases,SpinBasis,FockBasis,CompositeBasis,
nqubits,
projector,dagger,tr,ptrace,
AbstractBra,AbstractKet,AbstractOperator,AbstractSuperOperator
AbstractBra,AbstractKet,AbstractOperator,AbstractSuperOperator,
express,AbstractRepresentation,AbstractUse,UseAsState,UseAsObservable,UseAsOperation,
QuantumOpticsRepr,QuantumMCRepr,CliffordRepr

export SymQObj,QObj,
AbstractRepresentation,AbstractUse,
Expand Down Expand Up @@ -53,13 +55,6 @@ export SymQObj,QObj,
# Metadata cache helpers
##

"""An abstract type for the supported representation of quantum objects."""
abstract type AbstractRepresentation end
abstract type AbstractUse end
struct UseAsState <: AbstractUse end
struct UseAsOperation <: AbstractUse end
struct UseAsObservable <: AbstractUse end

const CacheType = Dict{Tuple{<:AbstractRepresentation,<:AbstractUse},Any}
mutable struct Metadata
express_cache::CacheType # TODO use more efficient mapping
Expand Down
26 changes: 2 additions & 24 deletions src/QSymbolicsBase/express.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import SymbolicUtils: Symbolic
"""
express(s, repr::AbstractRepresentation=QuantumOpticsRepr()[, use::AbstractUse])
The main interface for expressing quantum objects in various representations.
The main interface for expressing symbolic quantum objects in various representations.
```jldoctest
julia> express(X1)
Expand All @@ -37,8 +37,6 @@ julia> express(QuantumSymbolics.X, CliffordRepr(), UseAsObservable())
+ X
```
"""
function express end

function express(state::Symbolic, repr::AbstractRepresentation, use::AbstractUse)
md = metadata(state)
isnothing(md) && return express_from_cache(express_nolookup(state, repr, use))
Expand All @@ -51,10 +49,6 @@ function express(state::Symbolic, repr::AbstractRepresentation, use::AbstractUse
end
end

express(s::Number, repr::AbstractRepresentation, use::AbstractUse) = s

express(s, repr::AbstractRepresentation) = express(s, repr, UseAsState())

express_nolookup(x, repr::AbstractRepresentation, ::AbstractUse) = express_nolookup(x, repr)

express_nolookup(x, repr::AbstractRepresentation, ::UseAsState) = express_nolookup(x, repr)
Expand All @@ -72,28 +66,12 @@ function consistent_representation(reprs,state)
end
first(reprs)
end

##
# Commonly used representations -- interfaces for each one defined in separate packages
##

"""Representation using kets, bras, density matrices, and superoperators governed by `QuantumOptics.jl`."""
@kwdef struct QuantumOpticsRepr <: AbstractRepresentation
cutoff::Int = 2
end
"""Similar to `QuantumOpticsRepr`, but using trajectories instead of superoperators."""
struct QuantumMCRepr <: AbstractRepresentation end
"""Representation using tableaux governed by `QuantumClifford.jl`"""
struct CliffordRepr <: AbstractRepresentation end

express(state::Symbolic) = express(state, QuantumOpticsRepr()) # The default representation
express_nolookup(state, ::QuantumMCRepr) = express_nolookup(state, QuantumOpticsRepr())
express(state) = state

function express_nolookup(s, repr::AbstractRepresentation)
if isexpr(s)
operation(s)(express.(arguments(s), (repr,))...)
else
error("Encountered an object $(s) of type $(typeof(s)) that can not be converted to $(repr) representation") # TODO make a nice error type
end
end
end
4 changes: 2 additions & 2 deletions test/test_aqua.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

# Add any new types needed to QObj, or here if QObj if not appropriate.
# Add types from elsewhere in the ecosystem here or preferably to QObj
own_types = [Base.uniontypes(QObj)...,]
own_types_union = Union{SymQObj,}
own_types = [Base.uniontypes(QObj)...,AbstractRepresentation,AbstractUse,]
own_types_union = Union{SymQObj,AbstractRepresentation,AbstractUse,}

Aqua.test_all(QuantumSymbolics, piracies=(;treat_as_own=own_types))

Expand Down

2 comments on commit e697f48

@apkille
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/123264

Tip: Release Notes

Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

To add them here just re-invoke and the PR will be updated.

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.4.6 -m "<description of version>" e697f480982570ea69e3f92d697c97dfbbbd585b
git push origin v0.4.6

Please sign in to comment.