Zoo
Yao.Zoo.GroverIter
— Type.GroverIter{N, T}
GroverIter(oracle, ref::ReflectBlock{N, T}, psi::DefaultRegister, niter::Int)
an iterator that perform Grover operations step by step. An Grover operation consists of applying oracle and Reflection.
Yao.Zoo.RotBasis
— Type.RotBasis{T} <: PrimitiveBlock{1, Complex{T}}
A special rotation block that transform basis to angle θ and ϕ in bloch sphere.
Yao.Zoo.cnot_entangler
— Method.cnot_entangler([n::Int, ] pairs::Vector{Pair}) = ChainBlock
Arbitrary rotation unit, support lazy construction.
Yao.Zoo.collect_rotblocks
— Method.collect_rotblocks(blk::AbstractBlock) -> Vector{RotationGate}
filter out all rotation gates, which is differentiable.
Yao.Zoo.diff_circuit
— Method.diff_circuit(n, nlayer, pairs) -> ChainBlock
A kind of widely used differentiable quantum circuit, angles in the circuit is randomely initialized.
ref: 1. Kandala, A., Mezzacapo, A., Temme, K., Takita, M., Chow, J. M., & Gambetta, J. M. (2017). Hardware-efficient Quantum Optimizer for Small Molecules and Quantum Magnets. Nature Publishing Group, 549(7671), 242–246. https://doi.org/10.1038/nature23879.
Yao.Zoo.groverblock
— Method.groverblock(oracle, ref::ReflectBlock{N, T}, niter::Int=-1)
groverblock(oracle, psi::DefaultRegister, niter::Int=-1)
Return a ChainBlock/Sequential as Grover Iteration, the default niter
will stop at the first optimal step.
Yao.Zoo.inference_oracle
— Method.inference_oracle([nbit::Int,] locs::Vector{Int}) -> ControlBlock
A simple inference oracle, e.g. inference([-1, -8, 5]) is a control block that flip the bit if values of bits on position [1, 8, 5] match [0, 0, 1].
Yao.Zoo.num_gradient
— Function.num_gradient(lossfunc, rots::Vector{<:RotationGate}, δ::Float64=1e-2) -> Vector
Compute gradient numerically.
Yao.Zoo.num_grover_step
— Method.num_grover_step(psi::DefaultRegister, oracle) -> Int
Return number of grover steps needed to match the oracle.
Yao.Zoo.openbox
— Function.For a black box, like QFTBlock, you can get its white box (loyal simulation) using this function.
Yao.Zoo.opgrad
— Method.opgrad(op_expect, rots::Vector{<:RotationGate}) -> Vector
get the gradient of an operator expectation function.
References: Mitarai, K., Negoro, M., Kitagawa, M., & Fujii, K. (2018). Quantum Circuit Learning, 1–3. Retrieved from http://arxiv.org/abs/1803.00745
Yao.Zoo.perturb
— Method.perturb(func, gates::Vector{<:RotationGate}, diff::Real) -> Matrix
perturb every rotation gates, and evaluate losses. The i-th element of first column of resulting Matrix corresponds to Gi(θ+δ), and the second corresponds to Gi(θ-δ).
Yao.Zoo.polar2u
— Method.polar2u(vec::Array) -> Array
transform polar angle to su(2) state vector, apply to the first dimension of size 2.
Yao.Zoo.prob_match_oracle
— Method.prob_match_oracle(psi, oracle) -> Float64
Return the probability that psi
matches oracle.
Yao.Zoo.randpolar
— Method.randpolar(params::Int...) -> Array
random polar basis, number of basis
Yao.Zoo.rotter
— Function.rotter(noleading::Bool=false, notrailing::Bool=false) -> ChainBlock{1, ComplexF64}
Arbitrary rotation unit, set parameters notrailing, noleading true to remove trailing and leading Z gates.
Yao.Zoo.u2polar
— Method.u2polar(vec::Array) -> Array
transform su(2) state vector to polar angle, apply to the first dimension of size 2.
Yao.Zoo.target_space
— Method.target_space(oracle) -> Vector{Bool}
Return a mask, that disired subspace of an oracle are masked true.