Symbolic Computation

The symbolic engine of Yao is based on SymEngine.jl. It allows one to define quantum circuits with symbolic parameters and perform symbolic computation on them. Two macro/functions play a key role in the symbolic computation:

  • @vars for defining symbolic variables
  • subs for substituting symbolic variables with concrete values
julia> using Yao
julia> @vars θ(θ,)
julia> circuit = chain(2, put(1=>H), put(2=>Ry(θ)))nqubits: 2 chain ├─ put on (1) │ └─ H └─ put on (2) └─ rot(Y, θ)
julia> mat(circuit)4×4 SparseMatrixCSC{Basic, Int64} with 16 stored entries: (1/2)*sqrt(2)*cos((1/2)*θ) … (-1/2)*sqrt(2)*sin((1/2)*θ) (1/2)*sqrt(2)*cos((1/2)*θ) (1/2)*sqrt(2)*sin((1/2)*θ) (1/2)*sqrt(2)*sin((1/2)*θ) (1/2)*sqrt(2)*cos((1/2)*θ) (1/2)*sqrt(2)*sin((1/2)*θ) (-1/2)*sqrt(2)*cos((1/2)*θ)
julia> new_circuit = subs(circuit, θ=>π/2)nqubits: 2 chain ├─ put on (1) │ └─ H └─ put on (2) └─ rot(Y, 1.5707963267949)
julia> mat(new_circuit)4×4 SparseMatrixCSC{Basic, Int64} with 16 stored entries: 0.353553390593274*sqrt(2) … (-0.353553390593274 + -0.0*im)*sqrt(2) 0.353553390593274*sqrt(2) (0.353553390593274 + 0.0*im)*sqrt(2) (0.353553390593274 + -0.0*im)*sqrt(2) 0.353553390593274*sqrt(2) (0.353553390593274 + -0.0*im)*sqrt(2) -0.353553390593274*sqrt(2)

API

The following functions are for working with symbolic states.

YaoSym.@ket_strMacro
@ket_str

Create a ket register. See also @bra_str.

Examples

a symbolic quantum state can be created simply by

julia> ket"110" + 2ket"111"
|110⟩ + 2.0|111⟩

qubits can be partially actived by focus!

julia> ket"100" + ket"111" |> focus!(1:2)
|100⟩ + |111⟩
source
YaoSym.@bra_strMacro
@bra_str

Create a bra register. See also @ket_str.

Examples

Similar to @ket_str literal, a symbolic quantum state can be created by

julia> bra"111" + 2bra"101"
2.0⟨101| + ⟨111|

julia> bra"111" * (ket"101" + ket"111")
1
source
YaoSym.szero_stateFunction
szero_state(n; nbatch=1)

Create a symbolic zero state, same as ket"000", but allows you use an integer.

source