Skip to content

Commit

Permalink
Updates according to latest SymbolicUtils and TermInterface versions (#…
Browse files Browse the repository at this point in the history
…42)


---------

Co-authored-by: CompatHelper Julia <[email protected]>
Co-authored-by: Stefan Krastanov <[email protected]>
  • Loading branch information
3 people authored Jun 13, 2024
1 parent bfaf2b9 commit 0be23ed
Show file tree
Hide file tree
Showing 16 changed files with 79 additions and 54 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/benchmark.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
- uses: actions/checkout@v4
- uses: julia-actions/setup-julia@latest
with:
version: 'nightly'
version: '1'
- uses: julia-actions/julia-buildpkg@latest
- name: install dependencies
run: julia -e 'using Pkg; pkg"add PkgBenchmark [email protected]"'
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
matrix:
version:
- '1'
- '1.9'
- '1.10'
os:
- ubuntu-latest
- windows-latest
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/downgrade.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
version: ['1.9']
version: ['1.10']
steps:
- uses: actions/checkout@v4
- uses: julia-actions/setup-julia@v1
Expand Down
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# News

## v0.3.0 - 2024-06-12

- Bump compat for symbolics-related foundational packages.
- Bump lowest julia requirement to 1.10.

## v0.2.7 - 2024-03-22

- Bump QuantumClifford compat.
Expand Down
14 changes: 7 additions & 7 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.2.7"
version = "0.3.0"

[deps]
Graphs = "86223c79-3864-5bf0-83f7-82e725a168b6"
Expand All @@ -24,13 +24,13 @@ QuantumOpticsExt = "QuantumOpticsBase"

[compat]
Graphs = "1.9"
Latexify = "0.15, 0.16"
Latexify = "0.16"
LinearAlgebra = "1.9"
PrecompileTools = "1.2"
QuantumClifford = "0.8.19, 0.9"
QuantumInterface = "0.3.3"
QuantumOpticsBase = "0.4.19"
SymbolicUtils = "1.5"
Symbolics = "5.13"
TermInterface = "0.3"
julia = "1.9"
QuantumOpticsBase = "0.4.22"
SymbolicUtils = "2.0.2"
Symbolics = "5.30.3"
TermInterface = "0.4, 0.5, 1"
julia = "1.10"
4 changes: 2 additions & 2 deletions ext/QuantumCliffordExt/QuantumCliffordExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ using QuantumSymbolics: HGate, XGate, YGate, ZGate, CPHASEGate, CNOTGate,
Symbolic
import QuantumSymbolics: express, express_nolookup, express_from_cache
using TermInterface
using TermInterface: istree, exprhead, operation, arguments, similarterm, metadata
using TermInterface: isexpr, head, operation, arguments, metadata

using QuantumClifford

Expand All @@ -24,7 +24,7 @@ express_nolookup(s::XBasisState, ::CliffordRepr) = (_qc_s₊,_qc_s₋)[s.idx]
express_nolookup(s::YBasisState, ::CliffordRepr) = (_qc_i₊,_qc_i₋)[s.idx]
express_nolookup(s::ZBasisState, ::CliffordRepr) = (_qc_l,_qc_h)[s.idx]
function express_nolookup(s::Symbolic{T}, repr::CliffordRepr) where {T<:Union{AbstractKet,AbstractOperator}}
if istree(s) && operation(s)==
if isexpr(s) && operation(s)==
#operation(s)(express.(arguments(s), (repr,))...) # TODO this does not work because QuantumClifford.⊗ is different from ⊗
QuantumClifford.tensor(express.(arguments(s), (repr,))...)
else
Expand Down
2 changes: 1 addition & 1 deletion ext/QuantumOpticsExt/QuantumOpticsExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ using QuantumSymbolics:
qubit_basis, inf_fock_basis
import QuantumSymbolics: express, express_nolookup
using TermInterface
using TermInterface: istree, exprhead, operation, arguments, similarterm, metadata
using TermInterface: isexpr, head, operation, arguments, metadata

const _b2 = SpinBasis(1//2)
const _l0 = spinup(_b2)
Expand Down
6 changes: 3 additions & 3 deletions src/QSymbolicsBase/QSymbolicsBase.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import Symbolics: simplify
using SymbolicUtils
import SymbolicUtils: Symbolic, _isone, flatten_term, isnotflat, Chain, Fixpoint
using TermInterface
import TermInterface: istree, exprhead, operation, arguments, similarterm, metadata
import TermInterface: isexpr, head, iscall, children, operation, arguments, metadata

using LinearAlgebra
import LinearAlgebra: eigvecs
Expand Down Expand Up @@ -47,7 +47,7 @@ end
function countmap_flatten(samples, flattenhead)
counts = Dict{Any,Any}()
for s in samples
if istree(s) && s isa flattenhead # TODO Could you use the TermInterface `operation` here instead of `flattenhead`?
if isexpr(s) && s isa flattenhead # TODO Could you use the TermInterface `operation` here instead of `flattenhead`?
coef, term = arguments(s)
counts[term] = get(counts, term, 0)+coef
else
Expand Down Expand Up @@ -134,7 +134,7 @@ Base.:(-)(x::SymQObj,y::SymQObj) = x + (-y)

function Base.isequal(x::X,y::Y) where {X<:SymQObj, Y<:SymQObj}
if X==Y
if istree(x)
if isexpr(x)
if operation(x)==operation(y)
ax,ay = arguments(x),arguments(y)
(length(ax) == length(ay)) && all(zip(ax,ay)) do xy isequal(xy...) end
Expand Down
22 changes: 14 additions & 8 deletions src/QSymbolicsBase/basic_ops_homogeneous.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ struct SOperator <: Symbolic{AbstractKet}
basis::Basis
end
const SymQ = Union{SKet, SOperator}
istree(::SymQ) = false
isexpr(::SymQ) = false
metadata(::SymQ) = nothing
basis(x::SymQ) = x.basis

Expand All @@ -24,10 +24,12 @@ Base.show(io::IO, x::SymQObj) = print(io, symbollabel(x)) # fallback that probab
obj
SScaled{S}(c,k) where S = _isone(c) ? k : new{S}(c,k)
end
istree(::SScaled) = true
arguments(x::SScaled) = [x.coeff, x.obj]
isexpr(::SScaled) = true
iscall(::SScaled) = true
arguments(x::SScaled) = [x.coeff,x.obj]
operation(x::SScaled) = *
exprhead(x::SScaled) = :*
head(x::SScaled) = :*
children(x::SScaled) = [:*,x.coeff,x.obj]
Base.:(*)(c, x::Symbolic{T}) where {T<:QObj} = SScaled{T}(c,x)
Base.:(*)(x::Symbolic{T}, c) where {T<:QObj} = SScaled{T}(c,x)
Base.:(/)(x::Symbolic{T}, c) where {T<:QObj} = SScaled{T}(1/c,x)
Expand Down Expand Up @@ -63,10 +65,12 @@ end
dict
SAdd{S}(d) where S = length(d)==1 ? SScaled{S}(reverse(first(d))...) : new{S}(d)
end
istree(::SAdd) = true
isexpr(::SAdd) = true
iscall(::SAdd) = true
arguments(x::SAdd) = [SScaledKet(v,k) for (k,v) in pairs(x.dict)]
operation(x::SAdd) = +
exprhead(x::SAdd) = :+
head(x::SAdd) = :+
children(x::SAdd) = [:+,SScaledKet(v,k) for (k,v) in pairs(x.dict)]
Base.:(+)(xs::Vararg{Symbolic{T},N}) where {T<:QObj,N} = SAdd{T}(countmap_flatten(xs, SScaled{T}))
Base.:(+)(xs::Vararg{Symbolic{<:QObj},0}) = 0 # to avoid undefined type parameters issue in the above method
basis(x::SAdd) = basis(first(x.dict).first)
Expand All @@ -86,10 +90,12 @@ Base.show(io::IO, x::SAddBra) = print(io, "("*join(map(string, arguments(x)),"+"
coeff * new{S}(cleanterms)
end
end
istree(::STensor) = true
isexpr(::STensor) = true
iscall(::STensor) = true
arguments(x::STensor) = x.terms
operation(x::STensor) =
exprhead(x::STensor) = :
head(x::STensor) = :
children(x::STensor) = pushfirst!(x.terms,:)
(xs::Symbolic{T}...) where {T<:QObj} = STensor{T}(collect(xs))
basis(x::STensor) = tensor(basis.(x.terms)...)

Expand Down
30 changes: 20 additions & 10 deletions src/QSymbolicsBase/basic_ops_inhomogeneous.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@
op
ket
end
istree(::SApplyKet) = true
isexpr(::SApplyKet) = true
iscall(::SApplyKet) = true
arguments(x::SApplyKet) = [x.op,x.ket]
operation(x::SApplyKet) = *
exprhead(x::SApplyKet) = :*
head(x::SApplyKet) = :*
children(x::SApplyKet) = [:*,x.op,x.ket]
Base.:(*)(op::Symbolic{AbstractOperator}, k::Symbolic{AbstractKet}) = SApplyKet(op,k)
Base.show(io::IO, x::SApplyKet) = begin print(io, x.op); print(io, x.ket) end
basis(x::SApplyKet) = basis(x.ket)
Expand All @@ -18,10 +20,12 @@ basis(x::SApplyKet) = basis(x.ket)
bra
op
end
istree(::SApplyBra) = true
isexpr(::SApplyBra) = true
iscall(::SApplyBra) = true
arguments(x::SApplyBra) = [x.bra,x.op]
operation(x::SApplyBra) = *
exprhead(x::SApplyBra) = :*
head(x::SApplyBra) = :*
children(x::SApplyBra) = [:*,x.bra,x.op]
Base.:(*)(b::Symbolic{AbstractBra}, op::Symbolic{AbstractOperator}) = SApplyBra(b,op)
Base.show(io::IO, x::SApplyBra) = begin print(io, x.bra); print(io, x.op) end
basis(x::SApplyBra) = basis(x.bra)
Expand All @@ -31,10 +35,12 @@ basis(x::SApplyBra) = basis(x.bra)
bra
ket
end
istree(::SBraKet) = true
isexpr(::SBraKet) = true
iscall(::SBraKet) = true
arguments(x::SBraKet) = [x.bra,x.ket]
operation(x::SBraKet) = *
exprhead(x::SBraKet) = :*
head(x::SBraKet) = :*
children(x::SBraKet) = [:*,x.bra,x.ket]
Base.:(*)(b::Symbolic{AbstractBra}, k::Symbolic{AbstractKet}) = SBraKet(b,k)
function Base.show(io::IO, x::SBraKet)
print(io,x.bra)
Expand All @@ -46,10 +52,12 @@ end
sop
op
end
istree(::SApplyOp) = true
isexpr(::SApplyOp) = true
iscall(::SApplyOp) = true
arguments(x::SApplyOp) = [x.sop,x.op]
operation(x::SApplyOp) = *
exprhead(x::SApplyOp) = :*
head(x::SApplyOp) = :*
children(x::SApplyOp) = [:*,x.sop,x.op]
Base.:(*)(sop::Symbolic{AbstractSuperOperator}, op::Symbolic{AbstractOperator}) = SApplyOp(sop,op)
Base.:(*)(sop::Symbolic{AbstractSuperOperator}, k::Symbolic{AbstractKet}) = SApplyOp(sop,SProjector(k))
Base.show(io::IO, x::SApplyOp) = begin print(io, x.sop); print(io, x.op) end
Expand All @@ -60,10 +68,12 @@ basis(x::SApplyOp) = basis(x.op)
ket
bra
end
istree(::SOuterKetBra) = true
isexpr(::SOuterKetBra) = true
iscall(::SOuterKetBra) = true
arguments(x::SOuterKetBra) = [x.ket,x.bra]
operation(x::SOuterKetBra) = *
exprhead(x::SOuterKetBra) = :*
head(x::SOuterKetBra) = :*
children(x::SOuterKetBra) = [:*,x.ket,x.bra]
Base.:(*)(k::Symbolic{AbstractKet}, b::Symbolic{AbstractBra}) = SOuterKetBra(k,b)
Base.:(*)(k::SScaledKet, b::Symbolic{AbstractBra}) = k.coeff*SOuterKetBra(k.obj,b)
Base.:(*)(k::Symbolic{AbstractKet}, b::SScaledBra) = b.coeff*SOuterKetBra(k,b.obj)
Expand Down
2 changes: 1 addition & 1 deletion src/QSymbolicsBase/express.jl
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ express_nolookup(state, ::QuantumMCRepr) = express_nolookup(state, QuantumOptics
express(state) = state

function express_nolookup(s, repr::AbstractRepresentation)
if istree(s)
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
Expand Down
8 changes: 4 additions & 4 deletions src/QSymbolicsBase/latexify.jl
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ end
return LaTeXString("\\hat $(symbollabel(x))")
end
@latexrecipe function f(x::SDagger)
if istree(x.ket)
if isexpr(x.ket)
return Expr(:latexifymerge, "\\left( ", x.ket, "\\right)^\\dagger")
else
return Expr(:latexifymerge, "\\left\\langle ", symbollabel(x), "\\right|")
Expand All @@ -48,14 +48,14 @@ end
end

function _toexpr(x)
if istree(x)
return Expr(:call, exprhead(x), arguments(x)...)
if isexpr(x)
return Expr(:call, head(x), arguments(x)...)
else
x
end
end
function _addparen(x)
if istree(x)
if isexpr(x)
return Expr(:latexifymerge, "\\left(", x, "\\right)")
else
return x
Expand Down
26 changes: 15 additions & 11 deletions src/QSymbolicsBase/predefined.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
##

abstract type SpecialKet <: Symbolic{AbstractKet} end
istree(::SpecialKet) = false
isexpr(::SpecialKet) = false
basis(x::SpecialKet) = x.basis
Base.show(io::IO, x::SpecialKet) = print(io, "|$(symbollabel(x))")

Expand Down Expand Up @@ -84,8 +84,8 @@ abstract type AbstractSingleQubitOp <: Symbolic{AbstractOperator} end
abstract type AbstractTwoQubitOp <: Symbolic{AbstractOperator} end
abstract type AbstractSingleQubitGate <: AbstractSingleQubitOp end # TODO maybe an IsUnitaryTrait is a better choice
abstract type AbstractTwoQubitGate <: AbstractTwoQubitOp end
istree(::AbstractSingleQubitGate) = false
istree(::AbstractTwoQubitGate) = false
isexpr(::AbstractSingleQubitGate) = false
isexpr(::AbstractTwoQubitGate) = false
basis(::AbstractSingleQubitGate) = qubit_basis
basis(::AbstractTwoQubitGate) = qubit_basisqubit_basis
Base.show(io::IO, x::AbstractSingleQubitOp) = print(io, "$(symbollabel(x))")
Expand All @@ -97,7 +97,7 @@ Base.show(io::IO, x::AbstractTwoQubitOp) = print(io, "$(symbollabel(x))")
indices::Vector{Int}
basis::Basis
end
istree(::OperatorEmbedding) = true
isexpr(::OperatorEmbedding) = true

@withmetadata struct XGate <: AbstractSingleQubitGate end
eigvecs(g::XGate) = [X1,X2]
Expand Down Expand Up @@ -157,7 +157,7 @@ const CPHASE = CPHASEGate()

abstract type AbstractSingleBosonOp <: Symbolic{AbstractOperator} end
abstract type AbstractSingleBosonGate <: AbstractSingleBosonOp end # TODO maybe an IsUnitaryTrait is a better choice
istree(::AbstractSingleBosonGate) = false
isexpr(::AbstractSingleBosonGate) = false
basis(::AbstractSingleBosonGate) = inf_fock_basis

@withmetadata struct NumberOp <: AbstractSingleBosonOp end
Expand Down Expand Up @@ -193,10 +193,12 @@ Operator(dim=2x2)
@withmetadata struct SProjector <: Symbolic{AbstractOperator}
ket::Symbolic{AbstractKet} # TODO parameterize
end
istree(::SProjector) = true
isexpr(::SProjector) = true
iscall(::SProjector) = true
arguments(x::SProjector) = [x.ket]
operation(x::SProjector) = projector
exprhead(x::SProjector) = :projector
head(x::SProjector) = :projector
children(x::SProjector) = [:projector,x.ket]
projector(x::Symbolic{AbstractKet}) = SProjector(x)
basis(x::SProjector) = basis(x.ket)
function Base.show(io::IO, x::SProjector)
Expand All @@ -209,10 +211,12 @@ end
@withmetadata struct SDagger <: Symbolic{AbstractBra}
ket::Symbolic{AbstractKet}
end
istree(::SDagger) = true
isexpr(::SDagger) = true
iscall(::SDagger) = true
arguments(x::SDagger) = [x.ket]
operation(x::SDagger) = dagger
exprhead(x::SDagger) = :dagger
head(x::SDagger) = :dagger
children(x::SDagger) = [:dagger, x.ket]
dagger(x::Symbolic{AbstractKet}) = SDagger(x)
dagger(x::SScaledKet) = SScaledBra(x.coeff, dagger(x.obj))
dagger(x::SAddKet) = SAddBra(Dict(dagger(k)=>v for (k,v) in pairs(x.dict)))
Expand Down Expand Up @@ -250,7 +254,7 @@ julia> express(MixedState(X1⊗X2), CliffordRepr())
end
MixedState(x::Symbolic{AbstractKet}) = MixedState(basis(x))
MixedState(x::Symbolic{AbstractOperator}) = MixedState(basis(x))
istree(::MixedState) = false
isexpr(::MixedState) = false
basis(x::MixedState) = x.basis
symbollabel(x::MixedState) = "𝕄"

Expand All @@ -269,6 +273,6 @@ Operator(dim=2x2)
end
IdentityOp(x::Symbolic{AbstractKet}) = IdentityOp(basis(x))
IdentityOp(x::Symbolic{AbstractOperator}) = IdentityOp(basis(x))
istree(::IdentityOp) = false
isexpr(::IdentityOp) = false
basis(x::IdentityOp) = x.basis
symbollabel(x::IdentityOp) = "𝕀"
2 changes: 1 addition & 1 deletion src/QSymbolicsBase/predefined_CPTP.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export PauliNoiseCPTP, DephasingCPTP, DephasingCPTP, GateCPTP

abstract type NoiseCPTP <: Symbolic{AbstractSuperOperator} end
istree(::NoiseCPTP) = false
isexpr(::NoiseCPTP) = false
basis(x::NoiseCPTP) = x.basis

"""Single-qubit Pauli noise CPTP map
Expand Down
4 changes: 2 additions & 2 deletions src/QSymbolicsBase/rules.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ function prefactorscalings(xs)
terms = []
coeff = 1::Any
for x in xs
if istree(x) && operation(x) == *
if isexpr(x) && operation(x) == *
c,t = arguments(x)
coeff *= c
push!(terms,t)
Expand All @@ -30,7 +30,7 @@ function isnotflat_precheck(*)
operation(x) === (*) || return false
args = arguments(x)
for t in args
if istree(t) && operation(t) === (*)
if isexpr(t) && operation(t) === (*)
return true
end
end
Expand Down
Loading

2 comments on commit 0be23ed

@Krastanov
Copy link
Member

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/108885

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.3.0 -m "<description of version>" 0be23ed9081c551fc3ec38c855cc5ec7f7b63cc2
git push origin v0.3.0

Please sign in to comment.