From 484b15eaa065921c38cf192a60ea89b36297c00c Mon Sep 17 00:00:00 2001 From: apkille Date: Sun, 22 Dec 2024 04:06:11 -0500 Subject: [PATCH 1/5] migrate express functionality to QuantumInterface --- src/QSymbolicsBase/QSymbolicsBase.jl | 5 ++--- src/QSymbolicsBase/express.jl | 19 +------------------ 2 files changed, 3 insertions(+), 21 deletions(-) diff --git a/src/QSymbolicsBase/QSymbolicsBase.jl b/src/QSymbolicsBase/QSymbolicsBase.jl index 8825cfe..ab89f7d 100644 --- a/src/QSymbolicsBase/QSymbolicsBase.jl +++ b/src/QSymbolicsBase/QSymbolicsBase.jl @@ -16,7 +16,8 @@ import QuantumInterface: basis,Basis,samebases,IncompatibleBases,SpinBasis,FockBasis,CompositeBasis, nqubits, projector,dagger,tr,ptrace, - AbstractBra,AbstractKet,AbstractOperator,AbstractSuperOperator + AbstractBra,AbstractKet,AbstractOperator,AbstractSuperOperator, + express,AbstractRepresentation,QuantumOpticsRepr,QuantumMCRepr,CliffordRepr export SymQObj,QObj, AbstractRepresentation,AbstractUse, @@ -53,8 +54,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 diff --git a/src/QSymbolicsBase/express.jl b/src/QSymbolicsBase/express.jl index e40b2f0..f2be89a 100644 --- a/src/QSymbolicsBase/express.jl +++ b/src/QSymbolicsBase/express.jl @@ -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)) @@ -72,23 +70,8 @@ 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) @@ -96,4 +79,4 @@ function express_nolookup(s, repr::AbstractRepresentation) 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 \ No newline at end of file From ac7e2058b6b6ced859d1bc5b38ef8a173db73f73 Mon Sep 17 00:00:00 2001 From: apkille Date: Sun, 22 Dec 2024 04:23:37 -0500 Subject: [PATCH 2/5] rm default repr from QuantumSymbolics --- src/QSymbolicsBase/express.jl | 1 - 1 file changed, 1 deletion(-) diff --git a/src/QSymbolicsBase/express.jl b/src/QSymbolicsBase/express.jl index f2be89a..19ce8bd 100644 --- a/src/QSymbolicsBase/express.jl +++ b/src/QSymbolicsBase/express.jl @@ -70,7 +70,6 @@ function consistent_representation(reprs,state) end first(reprs) end -express(state::Symbolic) = express(state, QuantumOpticsRepr()) # The default representation express_nolookup(state, ::QuantumMCRepr) = express_nolookup(state, QuantumOpticsRepr()) function express_nolookup(s, repr::AbstractRepresentation) From d86cfc52c6a624a49e3d1b8dec96163d5d065dc8 Mon Sep 17 00:00:00 2001 From: apkille Date: Thu, 16 Jan 2025 14:19:51 -0500 Subject: [PATCH 3/5] make second round changes --- Project.toml | 2 +- src/QSymbolicsBase/QSymbolicsBase.jl | 8 ++------ src/QSymbolicsBase/express.jl | 6 +----- 3 files changed, 4 insertions(+), 12 deletions(-) diff --git a/Project.toml b/Project.toml index 76f73a4..d4e520a 100644 --- a/Project.toml +++ b/Project.toml @@ -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 = "2.0.2, 3" Symbolics = "5.30.3" diff --git a/src/QSymbolicsBase/QSymbolicsBase.jl b/src/QSymbolicsBase/QSymbolicsBase.jl index ab89f7d..231b51c 100644 --- a/src/QSymbolicsBase/QSymbolicsBase.jl +++ b/src/QSymbolicsBase/QSymbolicsBase.jl @@ -17,7 +17,8 @@ import QuantumInterface: nqubits, projector,dagger,tr,ptrace, AbstractBra,AbstractKet,AbstractOperator,AbstractSuperOperator, - express,AbstractRepresentation,QuantumOpticsRepr,QuantumMCRepr,CliffordRepr + express,AbstractRepresentation,AbstractUse,UseAsState,UseAsObservable,UseAsOperation, + QuantumOpticsRepr,QuantumMCRepr,CliffordRepr export SymQObj,QObj, AbstractRepresentation,AbstractUse, @@ -54,11 +55,6 @@ export SymQObj,QObj, # Metadata cache helpers ## -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 diff --git a/src/QSymbolicsBase/express.jl b/src/QSymbolicsBase/express.jl index 19ce8bd..156d497 100644 --- a/src/QSymbolicsBase/express.jl +++ b/src/QSymbolicsBase/express.jl @@ -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) @@ -49,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) From 37aaffc6ac0a16d64940efdaa0364fb87e85c3d7 Mon Sep 17 00:00:00 2001 From: apkille Date: Sat, 18 Jan 2025 11:17:56 -0500 Subject: [PATCH 4/5] add `AbsRepr` and `AbsUse` types to `own_types` --- test/test_aqua.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/test_aqua.jl b/test/test_aqua.jl index df8fec6..886371a 100644 --- a/test/test_aqua.jl +++ b/test/test_aqua.jl @@ -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)) From 36f3903baf0574e066db40b23d8ee99c68a9e5e4 Mon Sep 17 00:00:00 2001 From: apkille Date: Sat, 18 Jan 2025 11:36:07 -0500 Subject: [PATCH 5/5] update project.toml and changelog --- CHANGELOG.md | 4 ++++ Project.toml | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0f5b30c..81540ca 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) diff --git a/Project.toml b/Project.toml index 23582b0..d54149f 100644 --- a/Project.toml +++ b/Project.toml @@ -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"