Intrinsics

Intrinsics

AddressConflictError <: Exception

Address conflict error in Block Construction.

source
IterControl{N, C}

N is the size of hilber space, C is the number of shifts.

source
QubitMismatchError <: Exception

Qubit number mismatch error when applying a Block to a Register or concatenating Blocks.

source
ishermitian(op) -> Bool

check if this operator is hermitian.

source
basis(num_bit::Int) -> UnitRange{Int}
basis(state::AbstractArray) -> UnitRange{Int}

Returns the UnitRange for basis in Hilbert Space of num_bit qubits. If an array is supplied, it will return a basis having the same size with the first diemension of array.

source
batch_normalize

normalize a batch of vector.

source
batch_normalize!(matrix)

normalize a batch of vector.

source
bdistance(i::DInt, j::DInt) -> Int

Return number of different bits.

source
bit_length(x::Int) -> Int

Return the number of bits required to represent input integer x.

source
bitarray(v::Vector, [num_bit::Int]) -> BitArray
bitarray(v::Int, num_bit::Int) -> BitArray
bitarray(num_bit::Int) -> Function

Construct BitArray from an integer vector, if num_bit not supplied, it is 64. If an integer is supplied, it returns a function mapping a Vector/Int to bitarray.

source
Yao.Intrinsics.bmaskFunction.
bmask(ibit::Int...) -> Int
bmask(bits::UnitRange{Int}) ->Int

Return an integer with specific position masked, which is offten used as a mask for binary operations.

source
breflect(num_bit::Int, b::Int[, masks::Vector{Int}]) -> Int

Return left-right reflected integer.

source
bsizeof(x) -> Int

Return the size of object, in number of bit.

source
controller(cbits, cvals) -> Function

Return a function that test whether a basis at cbits takes specific value cvals.

source

control-unitary

source
fidelity_mix(m1::Matrix, m2::Matrix)

Fidelity for mixed states.

Reference: http://iopscience.iop.org/article/10.1088/1367-2630/aa6a4b/meta

source

fidelity for pure states.

source
flip(index::Int, mask::Int) -> Int

Return an Integer with bits at masked position flipped.

source
general_controlled_gates(num_bit::Int, projectors::Vector{Tp}, cbits::Vector{Int}, gates::Vector{AbstractMatrix}, locs::Vector{Int}) -> AbstractMatrix

Return general multi-controlled gates in hilbert space of num_bit qubits,

  • projectors are often chosen as P0 and P1 for inverse-Control and Control at specific position.

  • cbits should have the same length as projectors, specifing the controling positions.

  • gates are a list of controlled single qubit gates.

  • locs should have the same length as gates, specifing the gates positions.

source
hilbertkron(num_bit::Int, gates::Vector{AbstractMatrix}, locs::Vector{Int}) -> AbstractMatrix

Return general kronecher product form of gates in Hilbert space of num_bit qubits.

  • gates are a list of matrices.

  • start_locs should have the same length as gates, specifing the gates starting positions.

source
indices_with(num_bit::Int, poss::Vector{Int}, vals::Vector{Int}) -> Vector{Int}

Return indices with specific positions poss with value vals in a hilbert space of num_bit qubits.

source
isreflexive(op) -> Bool

check if this operator is reflexive.

source
isunitary(op) -> Bool

check if this operator is a unitary operator.

source
itercontrol(num_bit::Int, poss::Vector{Int}, vals::Vector{Int}) -> IterControl

Return the iterator for basis with poss controlled to values vals, with the total number of bits num_bit.

source
Yao.Intrinsics.log2iFunction.
log2i(x::Integer) -> Integer

Return log2(x), this integer version of log2 is fast but only valid for number equal to 2^n. Ref: https://stackoverflow.com/questions/21442088

source
Yao.Intrinsics.negMethod.
neg(index::Int, num_bit::Int) -> Int

Return an integer with all bits flipped (with total number of bit num_bit).

source
onehotvec(::Type{T}, num_bit::Int, x::DInt) -> Vector{T}

one-hot wave vector.

source
packbits(arr::AbstractArray) -> AbstractArray

pack bits to integers, usually take a BitArray as input.

source

Reordered Basis

source
setbit(index::Int, mask::Int) -> Int

set the bit at masked position to 1.

source
swapbits(num::Int, mask12::Int) -> Int

Return an integer with bits at i and j flipped.

source
takebit(index::Int, ibit::Int) -> Int

Return a bit at specific position.

source
testall(index::Int, mask::Int) -> Bool

Return true if all masked position of index is 1.

source
testany(index::Int, mask::Int) -> Bool

Return true if any masked position of index is 1.

source
testval(index::Int, mask::Int, onemask::Int) -> Bool

Return true if values at positions masked by mask with value 1 at positions masked by onemask and 0 otherwise.

source
Base.sortMethod.
sort(t::Tuple; lt=isless, by=identity, rev::Bool=false) -> ::Tuple

Sorts the tuple t.

source
Base.sortpermMethod.
sortperm(t::Tuple; lt=isless, by=identity, rev::Bool=false) -> ::Tuple

Computes a tuple that contains the permutation required to sort t.

source

turn a vector/matrix to static vector/matrix (only if its length <= 256).

source