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@ket_strCreate 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⟩YaoSym.@bra_str — Macro@bra_strCreate 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")
1YaoSym.szero_state — Functionszero_state(n; nbatch=1)Create a symbolic zero state, same as ket"000", but allows you use an integer.