Home

YaoExtensions.jl

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!.

source
Bag{N}<:TagBlock{AbstractBlock, N}

A bag is a trivil container, but can * setcontent!(bag, content) * disable_block!(bag) * enable_block!(bag)

source
Diff{GT, N} <: TagBlock{GT, N}
Diff(block) -> Diff

Mark a block as quantum differentiable.

source
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.

source
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.

source
Mod{N} <: PrimitiveBlock{N}

calculates mod(a*x, L), notice gcd(a, L) should be 1.

source
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
source
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
source
ReflectGate{N, T, Tr} <: PrimitiveBlock{N}

Reflection operator to target state psi.

Definition

\[|ψ⟩ → 2 |s⟩⟨s| - 1\]
source
ReflectGate(r::AbstractVector)

Create a ReflectGate with a quantum state vector v.

source
ReflectGate(r::ArrayReg{1})

Create a ReflectGate with a quantum register r.

source
RotBasis{T} <: PrimitiveBlock{1, Complex{T}}

A special rotation block that transform basis to angle θ and ϕ in bloch sphere.

source
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

source
Wait{N, T} <: TrivilGate{N}
Wait{N}(t)

Wait the experimental signals for time t (empty run).

source
basis_rotor(::ZGate) -> AbstractBlock
basis_rotor(basis::PauliGate, nbit, locs) -> AbstractBlock

Return a block to rotate the basis to pauli basis for measurements.

source

control-Z entangler.

source
faithful_grad(x, pair::Pair{<:ArrayReg, <:AbstractBlock}) -> Vector

Differentiate x over all parameters. x can be an AbstractBlock, StatFunctional or MMD.

source
general_U4([params...]) -> AbstractBlock

A general two qubits gate decomposed to (CNOT, Ry, Rz), parameters default to 0.

source
heisenberg(nbit::Int; periodic::Bool=true)

1D heisenberg hamiltonian, for its ground state, refer PRB 48, 6141.

source
inverselines(nbit::Int; n_reg::Int=nbit) -> ChainBlock

inverse first n_reg lines

TODO: deprecate this function, it is not used.

source
invorder_firstdim(v::VecOrMat) -> VecOrMat

inverse the bit order of first dimension.

source
markdiff(mode::Symbol, block::AbstractBlock) -> AbstractBlock
markdiff(mode::Symbol) -> Function

automatically mark differentiable items in a block tree as differentiable.

source
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
source
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.

Note

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.

source
YaoExtensions.numdiffFunction.
numdiff(loss, circuit::AbstractBlock, δ::Real=1e-2) => Vector

Numeric differentiation a loss over a circuit, the loss take the circuit as input.

source
openbox(block::AbstractBlock) -> AbstractBlock

For a black box, like QFTBlock, you can get its white box (faithful simulation) using this function.

source
pair_ring(n::Int) -> Vector

Pair ring.

source
pair_square(m::Int, n::Int) -> Vector

Pair square.

source

obtain supremacy pairing patterns

source
polar2u(vec::Array) -> Array

transform polar angle to su(2) state vector, apply to the first dimension of size 2.

source
rand_gate(nbit::Int, mbit::Int, [ngate::Int]) -> AbstractBlock

random nbit gate.

source
rand_google53(depth::Int; seed=1, nbits=53) -> AbstactBlock

random google supremacy circuit with 53 qubits.

source
rand_supremacy2d(nx::Int, ny::Int, depth::Int; seed=1) -> AbstactBlock

random supremacy circuit.

NOTE: the restriction to T gate is removed.

source
randpolar(params::Int...) -> Array

random polar basis, number of basis

source
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...})
source
reflect(r::ArrayReg)

Create a ReflectGate with an ArrayReg.

source
YaoExtensions.rotorFunction.
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.

source
transverse_ising(nbit::Int; periodic::Bool=true)

1D transverse ising hamiltonian.

source
u2polar(vec::Array) -> Array

transform su(2) state vector to polar angle, apply to the first dimension of size 2.

source
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.

source
NDWeights{N, AT<:AbstractArray{T,N} where T}

Weights not limited to 1 dimension.

source
YaoBlocks.expectMethod.

U-statistics of order 2.

source

Identity block

source
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.

source