Base
The Base module of Yao is defined in YaoBase.jl, it provides:
- the basic abstract register and its interface
- quantum information related math functions
@interfacemacro for drier interface definition in Yao ecosystem- custom errors and assertion handling
- general properties, e.g
ishermitian,isunitary, etc. - common constants in quantum information
Math Functions
YaoBase.autostatic — Method.autostatic(A[; threshold=8])Staticize dynamic array A by a threshold.
YaoBase.batch_normalize — Function.batch_normalizenormalize a batch of vector.
YaoBase.batch_normalize! — Function.batch_normalize!(matrix)normalize a batch of vector.
YaoBase.density_fidelity — Method.density_fidelity(ρ1, ρ2)General fidelity (including mixed states) between two density matrix for qubits.
Definition
YaoBase.general_c1_gates — Method.general_c1_gates(num_bit::Int, projector::AbstractMatrix, cbit::Int, gates::Vector{AbstractMatrix}, locs::Vector{Int}) -> AbstractMatrixgeneral (low performance) construction method for control gate on different lines.
YaoBase.general_controlled_gates — Method.general_controlled_gates(num_bit::Int, projectors::Vector{Tp}, cbits::Vector{Int}, gates::Vector{AbstractMatrix}, locs::Vector{Int}) -> AbstractMatrixReturn general multi-controlled gates in hilbert space of num_bit qubits,
projectorsare often chosen asP0andP1for inverse-Control and Control at specific position.cbitsshould have the same length asprojectors, specifing the controling positions.gatesare a list of controlled single qubit gates.locsshould have the same length asgates, specifing the gates positions.
YaoBase.hilbertkron — Method.hilbertkron(num_bit::Int, gates::Vector{AbstractMatrix}, locs::Vector{Int}) -> AbstractMatrixReturn general kronecher product form of gates in Hilbert space of num_bit qubits.
gatesare a list of matrices.start_locsshould have the same length asgates, specifing the gates starting positions.
YaoBase.linop2dense — Method.linop2dense([T=ComplexF64], linear_map!::Function, n::Int) -> MatrixReturns the dense matrix representation given linear map function.
YaoBase.nucnorm — Method.nucnorm(m)
Computes the nuclear norm of a matrix m.
YaoBase.pure_state_fidelity — Method.pure_state_fidelity(v1::Vector, v2::Vector)fidelity for pure states.
YaoBase.purification_fidelity — Method.purification_fidelity(m1::Matrix, m2::Matrix)Fidelity for mixed states via purification.
Reference: http://iopscience.iop.org/article/10.1088/1367-2630/aa6a4b/meta
YaoBase.rand_hermitian — Method.rand_hermitian([T=ComplexF64], N::Int) -> MatrixCreate a random hermitian matrix.
YaoBase.rand_unitary — Method.rand_unitary([T=ComplexF64], N::Int) -> MatrixCreate a random unitary matrix.
YaoBase.rotmat — Method.rotmat(M::AbstractMatrix, θ::Real)Returns rotated M: $exp(-\frac{imθ}{2} M)$.
YaoBase.sprand_hermitian — Method.sprand_hermitian([T=ComplexF64], N, density)Create a sparse random hermitian matrix.
YaoBase.sprand_unitary — Method.sprand_unitary([T=ComplexF64], N::Int, density) -> SparseMatrixCSCCreate a random sparse unitary matrix.
YaoBase.trnorm — Method.trnorm(m)
Computes the trace norm of a matrix m.
General Properties
LinearAlgebra.ishermitian — Method.ishermitian(op) -> Boolcheck if this operator is hermitian.
YaoBase.iscommute — Method.iscommute(ops...) -> Boolcheck if operators are commute.
YaoBase.isreflexive — Method.isreflexive(op) -> Boolcheck if this operator is reflexive.
YaoBase.isunitary — Method.isunitary(op) -> Boolcheck if this operator is a unitary operator.
Error and Exceptions
YaoBase.QubitMismatchError — Type.QubitMismatchError <: ExceptionQubit number mismatch error when applying a Block to a Register or concatenating Blocks.
YaoBase.islocs_conflict — Method.islocs_conflict(locs) -> BoolCheck if the input locations has conflicts.
YaoBase.islocs_inbounds — Method.islocs_inbounds(n, locs) -> BoolCheck if the input locations are inside given bounds n.
YaoBase.@assert_locs_inbounds — Macro.@assert_locs_inbounds <number of total qubits> <locations list> [<msg>]Assert if all the locations are inbounds.
YaoBase.@assert_locs_safe — Macro.@assert_locs_safe <number of total qubits> <locations list> [<msg>]Assert if all the locations are: - inbounds. - do not have any conflict.
Constants
| defined constants |
|---|
| $CNOT$ |
| $CZ$ |
| $H$ |
| $I2$ |
| $P0$ |
| $P1$ |
| $Pd$ |
| $Pu$ |
| $S$ |
| $SWAP$ |
| $Sdag$ |
| $T$ |
| $Tdag$ |
| $Toffoli$ |
| $X$ |
| $Y$ |
| $Z$ |