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:
@varsfor defining symbolic variablessubsfor substituting symbolic variables with concrete values
julia> using Yaojulia> @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_str — Macro
YaoSym.@bra_str — Macro
YaoSym.szero_state — Function
szero_state(n; nbatch=1)Create a symbolic zero state, same as ket"000", but allows you use an integer.