Blocks System
Blocks are the basic component of a quantum circuit in Yao.
Block System
The whole framework is consist of a block system. The whole system characterize a quantum circuit into serveral kinds of blocks. The uppermost abstract type for the whole system is AbstractBlock
Composite Blocks
Roller
Roller is a special pattern of quantum circuits. Usually is equivalent to a KronBlock, but we can optimize the computation by rotate the tensor form of a quantum state and apply each small block on it each time.
Blocks
Yao.Blocks.AbstractBlock — Type.AbstractBlockabstract type that all block will subtype from. N is the number of qubits.
Yao.Blocks.AbstractMeasure — Type.AbstractMeasure <: AbstractBlockAbstract block supertype which measurement block will inherit from.
Yao.Blocks.BlockTreeIterator — Type.BlockTreeIterator{BT}Iterate through the whole block tree with breadth first search.
Yao.Blocks.CacheFragment — Type.CacheFragment{BT, K, MT}A fragment that will be stored for each cached block (of type BT) on a cache server.
Yao.Blocks.CachedBlock — Type.Yao.Blocks.ChainBlock — Type.ChainBlock{N, T} <: CompositeBlock{N, T}ChainBlock is a basic construct tool to create user defined blocks horizontically. It is a Vector like composite type.
Yao.Blocks.CompositeBlock — Type.CompositeBlock{N, T} <: MatrixBlock{N, T}abstract supertype which composite blocks will inherit from.
extended APIs
blocks: get an iteratable of all blocks contained by this CompositeBlock
Yao.Blocks.Concentrator — Type.Concentrator{N} <: AbstractBlockconcentrates serveral lines together in the circuit, and expose it to other blocks.
Yao.Blocks.ConstantGate — Type.ConstantGate{N, T} <: PrimitiveBlock{N, T}Abstract type for constant gates.
Yao.Blocks.ControlBlock — Type.ControlBlock{BT, N, C, B, T} <: CompositeBlock{N, T}N: number of qubits, BT: controlled block type, C: number of control bits, T: type of matrix.
Yao.Blocks.Daggered — Type.Daggered{N, T, BT} <: MatrixBlock{N, T}
Daggered(blk::BT)
Daggered{N, T, BT}(blk)Daggered Block.
Yao.Blocks.FunctionBlock — Type.FunctionBlock <: AbstractBlockThis block contains a general function that perform an in-place operation over a register
Yao.Blocks.KronBlock — Type.KronBlock{N, T} <: CompositeBlockcomposite block that combine blocks by kronecker product.
Yao.Blocks.MatrixBlock — Type.MatrixBlock{N, T} <: AbstractBlockabstract type that all block with a matrix form will subtype from.
Yao.Blocks.PhaseGate — Type.PhiGateGlobal phase gate.
Yao.Blocks.PrimitiveBlock — Type.PrimitiveBlock{N, T} <: MatrixBlock{N, T}abstract type that all primitive block will subtype from. A primitive block is a concrete block who can not be decomposed into other blocks. All composite block can be decomposed into several primitive blocks.
NOTE: subtype for primitive block with parameter should implement hash and == method to enable key value cache.
Yao.Blocks.PutBlock — Type.PutBlock{N, C, GT, T} <: CompositeBlock{N, T}put a block on given addrs.
Yao.Blocks.ReflectBlock — Type.ReflectBlock{N, T} <: PrimitiveBlock{N, T}Householder reflection with respect to some target state, $|\psi\rangle = 2|s\rangle\langle s|-1$.
Yao.Blocks.RepeatedBlock — Type.RepeatedBlock{N, C, GT, T} <: CompositeBlock{N, T}repeat the same block on given addrs.
Yao.Blocks.Roller — Type.Roller{N, T, BT} <: CompositeBlock{N, T}map a block type to all lines and use a rolling method to evaluate them.
TODO
fill identity like KronBlock -> To interface.
Yao.Blocks.RotationGate — Type.RotationGate{N, T, GT <: MatrixBlock{N, Complex{T}}} <: MatrixBlock{N, Complex{T}}RotationGate, with GT both hermitian and isreflexive.
Yao.Blocks.Sequential — Type.Sequential <: AbstractBlocksequencial structure that looser than a chain, it does not require qubit consistency and does not have mat method.
Yao.Blocks.ShiftGate — Type.ShiftGate <: PrimitiveBlockPhase shift gate.
Yao.Blocks.apply! — Function.apply!(reg, block, [signal])apply a block to a register reg with or without a cache signal.
Yao.Blocks.applymatrix — Method.applymatrix(g::AbstractBlock) -> MatrixTransform the apply! function of specific block to dense matrix.
Yao.Blocks.blockfilter — Method.blockfilter(func, blk::AbstractBlock) -> Vector{AbstractBlock}
blockfilter!(func, rgs::Vector, blk::AbstractBlock) -> Vector{AbstractBlock}tree wise filtering for blocks.
Yao.Blocks.blocks — Function.blocks(composite_block)get an iterator that iterate through all sub-blocks.
Yao.Blocks.datatype — Method.datatype(x) -> DataTypeReturns the data type of x.
Yao.Blocks.dispatch! — Function.dispatch!(block, params)
dispatch!(block, params...)dispatch parameters to this block.
Yao.Blocks.dispatch! — Method.dispatch!(f, c, params) -> cdispatch parameters and tweak it according to callback function f(original, parameter)->new
dispatch a vector of parameters to this composite block according to each sub-block's number of parameters.
Yao.Blocks.expect — Function.expect(op::AbstractBlock, reg::AbstractRegister{B}) -> Vector
expect(op::AbstractBlock, dm::DensityMatrix{B}) -> Vectorexpectation value of an operator.
Yao.Blocks.mat — Function.mat(block) -> MatrixReturns the matrix form of this block.
Yao.Blocks.nparameters — Function.nparameters(x) -> IntegerReturns the number of parameters of x.
Yao.Blocks.parameter_type — Function.parameters(block) -> Typethe type of parameters.
Yao.Blocks.parameters — Function.parameters(block) -> VectorReturns a list of all parameters in block.
Yao.Blocks.usedbits — Method.addrs(block::AbstractBlock) -> Vector{Int}Occupied addresses (include control bits and bits occupied by blocks), fall back to all bits if this method is not provided.
Yao.Intrinsics.isreflexive — Function.isreflexive(x) -> BoolTest whether this operator is reflexive.
Yao.Intrinsics.isunitary — Function.isunitary(x) -> BoolTest whether this operator is unitary.
Yao.Blocks._allmatblock — Method.all blocks are matrix blocks
Yao.Blocks._blockpromote — Method.promote types of blocks
Yao.Blocks.cache_key — Function.cache_key(block)Returns the key that identify the matrix cache of this block. By default, we use the returns of parameters as its key.
Yao.Blocks.cache_type — Method.cache_type(::Type) -> DataTypeA type trait that defines the element type that a CacheFragment will use.
Yao.Blocks.print_block — Method.print_block(io, block)define the style to print this block
@const_gate NAME = MAT_EXPR
@const_gate NAME::Type = MAT_EXPR
@const_Gate NAME::TypeThis macro simplify the definition of a constant gate. It will automatically bind the matrix form to a constant which will reduce memory allocation in the runtime.
@const_gate X = ComplexF64[0 1;1 0]or
@const_gate X::ComplexF64 = [0 1;1 0]You can bind new element types by simply re-declare with a type annotation.
@const_gate X::ComplexF32