Skip to content

Commit

Permalink
Merge branch 'main' into squeeze
Browse files Browse the repository at this point in the history
  • Loading branch information
apkille committed Sep 16, 2024
2 parents 57faf25 + f2cda40 commit d2cd291
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 19 deletions.
50 changes: 50 additions & 0 deletions docs/src/introduction.md
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,56 @@ Below, we state all of the supported linear algebra operations on quantum object
- exponential of an operator: [`exp`](@ref),
- vectorization of an operator: [`vec`](@ref).

## Predefined Quantum Objects

So far in this tutorial, we have considered arbitrary kets, bras, operators, and their corresponding operations. This package supports predefined quantum objects and operations in several formalisms, which are discussed in detail in other sections (see, for example, the [quantum harmonic oscillators](@ref Quantum-Harmonic-Oscillators) or [qubit basis](@ref Typical-Qubit-Bases) pages). To get a taste of what's available, let us consider a few symbolic examples. For a complete description, see the [full API page](@ref Full-API).

Quantum gates and their basis states can be represented symbolically:

```jldoctest
julia> CNOT # CNOT Gate
CNOT
julia> X, Y, Z, I # Pauli operators
(X, Y, Z, 𝕀)
julia> X1, X2 # Eigenstates of the Pauli X operator
(|X₁⟩, |X₂⟩)
julia> CPHASE * (Z1 ⊗ Z2) # Application of CPHASE gate on |01⟩
CPHASE|Z₁⟩|Z₂⟩
```

We also have symbolic representations of bosonic systems:

```jldoctest
julia> FockState(4) # Fock state with 4 excitation quanta
|4⟩
julia> Create, Destroy # creation and annihilation operators
(a†, a)
julia> DisplaceOp(im) # Displacement operator for single bosonic mode
D(im)
julia> N * vac # Application of number operator on vacuum state
n|0⟩
```

If we want to substitute a predefined quantum object into a general symbolic expression, we can use the [`substitute`](https://symbolics.juliasymbolics.org/v3.5/manual/expression_manipulation/#SymbolicUtils.substitute) command from [`Symbolics.jl`](https://github.com/JuliaSymbolics/Symbolics.jl):

```jldoctest
julia> using Symbolics
julia> @op A; @ket k;
julia> ex = 2*A + projector(k)
(2A+𝐏[|k⟩])
julia> substitute(ex, Dict([A => X, k => X1]))
(2X+𝐏[|X₁⟩])
```

## Simplifying Expressions

For predefined objects such as the Pauli operators [`X`](@ref), [`Y`](@ref), and [`Z`](@ref), additional simplification can be performed with the [`qsimplify`](@ref) function. Take the following example:
Expand Down
2 changes: 1 addition & 1 deletion test/test_express_opt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
express(state)
nocache = @timed express(state2)
withcache = @timed express(state2)
@test nocache.time > 50*withcache.time
@test nocache.time > 20*withcache.time
@test withcache.bytes == 0
@test nocache.value withcache.value express(state2)

Expand Down
19 changes: 1 addition & 18 deletions test/test_jet.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,9 @@
using JET
using QuantumOptics, QuantumClifford # to load the extensions

using JET: ReportPass, BasicPass, InferenceErrorReport, UncaughtExceptionReport

# Custom report pass that ignores `UncaughtExceptionReport`
# Too coarse currently, but it serves to ignore the various
# "may throw" messages for runtime errors we raise on purpose
# (mostly on malformed user input)
struct MayThrowIsOk <: ReportPass end

# ignores `UncaughtExceptionReport` analyzed by `JETAnalyzer`
(::MayThrowIsOk)(::Type{UncaughtExceptionReport}, @nospecialize(_...)) = return

# forward to `BasicPass` for everything else
function (::MayThrowIsOk)(report_type::Type{<:InferenceErrorReport}, @nospecialize(args...))
BasicPass()(report_type, args...)
end

using InteractiveUtils, Latexify, SymbolicUtils

rep = report_package("QuantumSymbolics";
report_pass=MayThrowIsOk(), # TODO have something more fine grained than a generic "do not care about thrown errors"
ignored_modules=(
AnyFrameModule(InteractiveUtils),
AnyFrameModule(Latexify),
Expand All @@ -30,5 +13,5 @@ rep = report_package("QuantumSymbolics";
)
@show rep
@test_broken length(JET.get_reports(rep)) == 0
@test length(JET.get_reports(rep)) <= 7
@test length(JET.get_reports(rep)) <= 6
end

0 comments on commit d2cd291

Please sign in to comment.