Blocks System

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

Block-System

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.

Block-System

Blocks

AbstractBlock

abstract type that all block will subtype from. N is the number of qubits.

source
AbstractMeasure <: AbstractBlock

Abstract block supertype which measurement block will inherit from.

source
BlockTreeIterator{BT}

Iterate through the whole block tree with breadth first search.

source
CacheFragment{BT, K, MT}

A fragment that will be stored for each cached block (of type BT) on a cache server.

source
CachedBlock{ST, BT, N, T} <: MatrixBlock{N, T}

A label type that tags an instance of type BT. It forwards every methods of the block it contains, except mat and apply!, it will cache the matrix form whenever the program has.

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

source
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

source
Concentrator{N} <: AbstractBlock

concentrates serveral lines together in the circuit, and expose it to other blocks.

source
ConstantGate{N, T} <: PrimitiveBlock{N, T}

Abstract type for constant gates.

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

source
Daggered{N, T, BT} <: MatrixBlock{N, T}

Daggered(blk::BT)
Daggered{N, T, BT}(blk)

Daggered Block.

source
FunctionBlock <: AbstractBlock

This block contains a general function that perform an in-place operation over a register

source
KronBlock{N, T} <: CompositeBlock

composite block that combine blocks by kronecker product.

source
MatrixBlock{N, T} <: AbstractBlock

abstract type that all block with a matrix form will subtype from.

source
PhiGate

Global phase gate.

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

source
PutBlock{N, C, GT, T} <: CompositeBlock{N, T}

put a block on given addrs.

source
ReflectBlock{N, T} <: PrimitiveBlock{N, T}

Householder reflection with respect to some target state, $|\psi\rangle = 2|s\rangle\langle s|-1$.

source
RepeatedBlock{N, C, GT, T} <: CompositeBlock{N, T}

repeat the same block on given addrs.

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

source
RotationGate{N, T, GT <: MatrixBlock{N, Complex{T}}} <: MatrixBlock{N, Complex{T}}

RotationGate, with GT both hermitian and isreflexive.

source
Sequential <: AbstractBlock

sequencial structure that looser than a chain, it does not require qubit consistency and does not have mat method.

source
ShiftGate <: PrimitiveBlock

Phase shift gate.

source
Yao.Blocks.apply!Function.
apply!(reg, block, [signal])

apply a block to a register reg with or without a cache signal.

source
applymatrix(g::AbstractBlock) -> Matrix

Transform the apply! function of specific block to dense matrix.

source
blockfilter(func, blk::AbstractBlock) -> Vector{AbstractBlock}
blockfilter!(func, rgs::Vector, blk::AbstractBlock) -> Vector{AbstractBlock}

tree wise filtering for blocks.

source
Yao.Blocks.blocksFunction.
blocks(composite_block)

get an iterator that iterate through all sub-blocks.

source
datatype(x) -> DataType

Returns the data type of x.

source
Yao.Blocks.dispatch!Function.
dispatch!(block, params)
dispatch!(block, params...)

dispatch parameters to this block.

source
dispatch!(f, c, params) -> c

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

source
Yao.Blocks.expectFunction.
expect(op::AbstractBlock, reg::AbstractRegister{B}) -> Vector
expect(op::AbstractBlock, dm::DensityMatrix{B}) -> Vector

expectation value of an operator.

source
Yao.Blocks.matFunction.
mat(block) -> Matrix

Returns the matrix form of this block.

source
nparameters(x) -> Integer

Returns the number of parameters of x.

source
parameters(block) -> Type

the type of parameters.

source
Yao.Blocks.parametersFunction.
parameters(block) -> Vector

Returns a list of all parameters in block.

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

source
isreflexive(x) -> Bool

Test whether this operator is reflexive.

source
isunitary(x) -> Bool

Test whether this operator is unitary.

source

all blocks are matrix blocks

source

promote types of blocks

source
Yao.Blocks.cache_keyFunction.
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.

source
cache_type(::Type) -> DataType

A type trait that defines the element type that a CacheFragment will use.

source
print_block(io, block)

define the style to print this block

source
@const_gate NAME = MAT_EXPR
@const_gate NAME::Type = MAT_EXPR
@const_Gate NAME::Type

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