YaoExtensions.jl
YaoExtensions.AbstractBag
YaoExtensions.Bag
YaoExtensions.Diff
YaoExtensions.KMod
YaoExtensions.MMD
YaoExtensions.Mod
YaoExtensions.NDWeights
YaoExtensions.PauliString
YaoExtensions.PauliString
YaoExtensions.ReflectGate
YaoExtensions.ReflectGate
YaoExtensions.ReflectGate
YaoExtensions.RotBasis
YaoExtensions.StatFunctional
YaoExtensions.Wait
YaoBlocks.expect
YaoExtensions.basis_rotor
YaoExtensions.cz_entangler
YaoExtensions.eyeblock
YaoExtensions.faithful_grad
YaoExtensions.general_U4
YaoExtensions.heisenberg
YaoExtensions.inverselines
YaoExtensions.invorder_firstdim
YaoExtensions.markdiff
YaoExtensions.mathgate
YaoExtensions.merged_rotor
YaoExtensions.mod_inverse
YaoExtensions.numdiff
YaoExtensions.openbox
YaoExtensions.pair_ring
YaoExtensions.pair_square
YaoExtensions.pair_supremacy
YaoExtensions.polar2u
YaoExtensions.rand_gate
YaoExtensions.rand_google53
YaoExtensions.rand_supremacy2d
YaoExtensions.randpolar
YaoExtensions.reflect
YaoExtensions.reflect
YaoExtensions.rotor
YaoExtensions.transverse_ising
YaoExtensions.u2polar
YaoExtensions.variational_circuit
YaoExtensions.AbstractBag
— Type.AbstractBag{BT, N}<:TagBlock{BT, N}
Abstract Bag
is a wrapper of a block that conserves all properties. Including mat
, apply!
, ishermitian
, isreflexive
, isunitary
, occupied_locs
, apply_back!
and mat_back!
.
YaoExtensions.Bag
— Type.Bag{N}<:TagBlock{AbstractBlock, N}
A bag is a trivil container, but can * setcontent!(bag, content)
* disable_block!(bag)
* enable_block!(bag)
YaoExtensions.Diff
— Type.Diff{GT, N} <: TagBlock{GT, N}
Diff(block) -> Diff
Mark a block as quantum differentiable.
YaoExtensions.KMod
— Type.KMod{N, K} <: PrimitiveBlock{N}
The first K
qubits are exponent k
, and the rest N-K
are base a
, it calculates mod(a^k*x, L)
, notice gcd(a, L)
should be 1.
YaoExtensions.MMD
— Type.MMD{T,FT,VT<:AbstractVector{T}}
MMD(f, probs) -> MMD
MMD loss, VT
is the typeof probability vector, FT
is the type of kernel function.
YaoExtensions.Mod
— Type.Mod{N} <: PrimitiveBlock{N}
calculates mod(a*x, L)
, notice gcd(a, L)
should be 1.
YaoExtensions.PauliString
— Method.PauliString(list::Vector)
Create a PauliString
from a list of Pauli gates.
Example
julia> PauliString([X, Y, Z])
┌ Warning: `PauliString` will be moved to `YaoExtensions.jl` in the next release.
└ @ YaoBlocks ~/.julia/packages/YaoBlocks/XXC9Y/src/composite/pauli_strings.jl:8
nqubits: 3
PauliString
├─ X gate
├─ Y gate
└─ Z gate
YaoExtensions.PauliString
— Method.PauliString(xs::PauliGate...)
Create a PauliString
from some Pauli gates.
Example
julia> PauliString(X, Y, Z)
┌ Warning: `PauliString` will be moved to `YaoExtensions.jl` in the next release.
└ @ YaoBlocks ~/.julia/packages/YaoBlocks/XXC9Y/src/composite/pauli_strings.jl:8
nqubits: 3
PauliString
├─ X gate
├─ Y gate
└─ Z gate
YaoExtensions.ReflectGate
— Type.ReflectGate{N, T, Tr} <: PrimitiveBlock{N}
Reflection operator to target state psi
.
Definition
YaoExtensions.ReflectGate
— Method.ReflectGate(r::AbstractVector)
Create a ReflectGate
with a quantum state vector v
.
YaoExtensions.ReflectGate
— Method.ReflectGate(r::ArrayReg{1})
Create a ReflectGate
with a quantum register r
.
YaoExtensions.RotBasis
— Type.RotBasis{T} <: PrimitiveBlock{1, Complex{T}}
A special rotation block that transform basis to angle θ and ϕ in bloch sphere.
YaoExtensions.StatFunctional
— Type.StatFunctional{N, F}
StatFunctional{N}(f::F) -> StatFunctional{N}
f
is a function, f(xᵢ,xⱼ,xₖ...)
, this functional is 1/C(r,n)... ∑ᵢⱼₖ...f(xᵢ,xⱼ,xₖ...)
, see U-statistics for detail.
References: U-statistics, http://personal.psu.edu/drh20/asymp/fall2006/lectures/ANGELchpt10.pdf
YaoExtensions.Wait
— Type.Wait{N, T} <: TrivilGate{N}
Wait{N}(t)
Wait the experimental signals for time t
(empty run).
YaoExtensions.basis_rotor
— Method.basis_rotor(::ZGate) -> AbstractBlock
basis_rotor(basis::PauliGate, nbit, locs) -> AbstractBlock
Return a block to rotate the basis to pauli basis for measurements.
YaoExtensions.cz_entangler
— Method.control-Z entangler.
YaoExtensions.faithful_grad
— Method.faithful_grad(x, pair::Pair{<:ArrayReg, <:AbstractBlock}) -> Vector
Differentiate x
over all parameters. x
can be an AbstractBlock
, StatFunctional
or MMD
.
YaoExtensions.general_U4
— Method.general_U4([params...]) -> AbstractBlock
A general two qubits gate decomposed to (CNOT, Ry, Rz), parameters default to 0.
YaoExtensions.heisenberg
— Method.heisenberg(nbit::Int; periodic::Bool=true)
1D heisenberg hamiltonian, for its ground state, refer PRB 48, 6141
.
YaoExtensions.inverselines
— Method.inverselines(nbit::Int; n_reg::Int=nbit) -> ChainBlock
inverse first n_reg
lines
TODO: deprecate this function, it is not used.
YaoExtensions.invorder_firstdim
— Method.invorder_firstdim(v::VecOrMat) -> VecOrMat
inverse the bit order of first dimension.
YaoExtensions.markdiff
— Function.markdiff(mode::Symbol, block::AbstractBlock) -> AbstractBlock
markdiff(mode::Symbol) -> Function
automatically mark differentiable items in a block tree as differentiable.
YaoExtensions.mathgate
— Method.mathgate(nbits, f)
Create a MathGate
with a math function f
and number of bits.
mathgate(f) -> f(n)
Lazy curried version of mathgate
.
Example
We can make a classical toffoli gate on quantum register.
julia> r = ArrayReg(bit"110")
ArrayReg{1, Complex{Float64}, Array...}
active qubits: 3/3
julia> function toffli(b::BitStr)
t = @inbounds b[1] ⊻ (b[3] & b[2])
return @inbounds bit_literal(t, b[2], b[3])
end
toffli (generic function with 1 method)
julia> g = mathgate(3, toffli)
┌ Warning: `MathGate` will be moved to `YaoExtensions.jl` in the next release.
└ @ YaoBlocks ~/.julia/packages/YaoBlocks/XXC9Y/src/primitive/math_gate.jl:8
mathgate(toffli; nbits=3)
julia> apply!(r, g) == ArrayReg(bit"111")
true
YaoExtensions.merged_rotor
— Function.merged_rotor(noleading::Bool=false, notrailing::Bool=false) -> ChainBlock{1, ComplexF64}
Single qubit arbitrary rotation unit, set parameters notrailing, noleading true to remove trailing and leading Z gates.
Here, merged
means Rz(η)⋅Rx(θ)⋅Rz(ξ)
are multiplied first, this kind of operation if now allowed in differentiable circuit with back-propagation (:BP
) mode (just because we are lazy to implement it!). But is a welcoming component in quantum differentiation.
YaoExtensions.numdiff
— Function.numdiff(loss, circuit::AbstractBlock, δ::Real=1e-2) => Vector
Numeric differentiation a loss over a circuit, the loss take the circuit as input.
YaoExtensions.openbox
— Method.openbox(block::AbstractBlock) -> AbstractBlock
For a black box, like QFTBlock, you can get its white box (faithful simulation) using this function.
YaoExtensions.pair_ring
— Method.pair_ring(n::Int) -> Vector
Pair ring.
YaoExtensions.pair_square
— Method.pair_square(m::Int, n::Int) -> Vector
Pair square.
YaoExtensions.pair_supremacy
— Method.obtain supremacy pairing patterns
YaoExtensions.polar2u
— Method.polar2u(vec::Array) -> Array
transform polar angle to su(2) state vector, apply to the first dimension of size 2.
YaoExtensions.rand_gate
— Method.rand_gate(nbit::Int, mbit::Int, [ngate::Int]) -> AbstractBlock
random nbit gate.
YaoExtensions.rand_google53
— Method.rand_google53(depth::Int; seed=1, nbits=53) -> AbstactBlock
random google supremacy circuit with 53 qubits.
YaoExtensions.rand_supremacy2d
— Method.rand_supremacy2d(nx::Int, ny::Int, depth::Int; seed=1) -> AbstactBlock
random supremacy circuit.
NOTE: the restriction to T
gate is removed.
YaoExtensions.randpolar
— Method.randpolar(params::Int...) -> Array
random polar basis, number of basis
YaoExtensions.reflect
— Method.reflect(v::AbstractVector{<:Complex})
Create a ReflectGate
with an quantum state vector v
.
Example
julia> reflect(rand_state(3))
┌ Warning: `ReflectGate` will be moved to `YaoExtensions.jl` in the next release.
└ @ YaoBlocks ~/.julia/packages/YaoBlocks/XXC9Y/src/primitive/reflect_gate.jl:19
reflect(ArrayReg{1, Complex{Float64}, Array...})
YaoExtensions.reflect
— Method.reflect(r::ArrayReg)
Create a ReflectGate
with an ArrayReg
.
YaoExtensions.rotor
— Function.rotor(nbit::Int, ibit::Int, noleading::Bool=false, notrailing::Bool=false) -> ChainBlock{nbit, ComplexF64}
Arbitrary rotation unit (put in nbit
space), set parameters notrailing, noleading true to remove trailing and leading Z gates.
YaoExtensions.transverse_ising
— Method.transverse_ising(nbit::Int; periodic::Bool=true)
1D transverse ising hamiltonian.
YaoExtensions.u2polar
— Method.u2polar(vec::Array) -> Array
transform su(2) state vector to polar angle, apply to the first dimension of size 2.
YaoExtensions.variational_circuit
— Method.variational_circuit(nbit[, nlayer][, pairs]; mode=:Split, do_cache=false, entangler=cnot)
A kind of widely used differentiable quantum circuit, angles in the circuit is randomely initialized.
* pairs: list of `Pair`s for entanglers in a layer, default to `pair_ring` structure,
* mode: :Split or :Merged,
* do_cache: cache the entangler matrix,
* entangler: a constructor returns a two qubit gate, `f(n,i,j) -> gate`.
The default value is `cnot(n,i,j)`.
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.
YaoExtensions.NDWeights
— Type.NDWeights{N, AT<:AbstractArray{T,N} where T}
Weights not limited to 1 dimension.
YaoBlocks.expect
— Method.U-statistics of order 2.
YaoExtensions.eyeblock
— Method.Identity block
YaoExtensions.mod_inverse
— Method.mod_inverse(x::Int, N::Int) -> Int
Return y
that (x*y)%N == 1
, notice the (x*y)%N
operations in Z* forms a group and this is the definition of inverse.