AddressConflictError <: Exception

Address conflict error in Block Construction.

IterControl{N, C}

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

QubitMismatchError <: Exception

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

ishermitian(op) -> Bool

check if this operator is hermitian.

baddrs(b::Integer) -> Vector

get the locations of nonzeros bits, i.e. the inverse operation of bmask.

basis([IntType], num_bit::Int) -> UnitRange{IntType}
basis([IntType], state::AbstractArray) -> UnitRange{IntType}

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.


normalize a batch of vector.


normalize a batch of vector.

bdistance(i::Integer, j::Integer) -> Int

Return number of different bits.

bfloat(b::Integer; nbit::Int=bit_length(b)) -> Float64

float view, with big end qubit 1.

bfloat_r(b::Integer; nbit::Int) -> Float64

float view, with bits read in inverse order.

bint(b; nbit=nothing) -> Int

integer view, with little end qubit 1.

bint_r(b; nbit::Int) -> Integer

integer read in inverse order.

bit_length(x::Integer) -> Int

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

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.

bmask([IntType], ibit::Int...) -> IntType
bmask([IntType], bits::UnitRange{Int}) ->IntType

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

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

Return left-right reflected integer.

bsizeof(x) -> Int

Return the size of object, in number of bit.

controldo(func::Function, ic::IterControl{N, C})

Faster than for i in ic ... end.

controller(cbits, cvals) -> Function

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


cunmat(nbit::Int, cbits::NTuple{C, Int}, cvals::NTuple{C, Int}, U0::AbstractMatrix, locs::NTuple{M, Int}) where {C, M} -> AbstractMatrix

control-unitary matrix

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

Fidelity for mixed states.


fidelity for pure states.

flip(index::Integer, mask::Integer) -> Integer

Return an Integer with bits at masked position flipped.

general_c1_gates(num_bit::Int, projector::AbstractMatrix, cbit::Int, gates::Vector{AbstractMatrix}, locs::Vector{Int}) -> AbstractMatrix

general (low performance) construction method for control gate on different lines.

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.
getcol(csc::SDparseMatrixCSC, icol::Int) -> (View, View)

get specific col of a CSC matrix, returns a slice of (rowval, nzval)

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.
hypercubic(A::Union{Array, DefaultRegister}) -> Array

get the hypercubic representation for an array or a regiseter.

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.

iscommute(ops...) -> Bool

check if operators are commute.

isreflexive(op) -> Bool

check if this operator is reflexive.

isunitary(op) -> Bool

check if this operator is a unitary operator.

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.

linop2dense(applyfunc!::Function, num_bit::Int) -> Matrix

get the dense matrix representation given matrix*matrix function.

log2i(x::Integer) -> Integer

Return log2(x), this integer version of log2 is fast but only valid for number equal to 2^n.

matvec(x::VecOrMat) -> MatOrVec

Return vector if a matrix is a column vector, else untouched.

mulcol!(v::AbstractVector, i::Int, f) -> VecOrMat

multiply col i of v by f inplace.

mulrow!(v::AbstractVector, i::Int, f) -> VecOrMat

multiply row i of v by f inplace.

neg(index::Integer, num_bit::Int) -> Integer

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

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

one-hot wave vector.

packbits(arr::AbstractArray) -> AbstractArray

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

rand_hermitian(N::Int) -> Matrix

Random hermitian matrix.

rand_unitary(N::Int) -> Matrix

Random unitary matrix.

Reordered Basis

setbit(index::Integer, mask::Integer) -> Integer

set the bit at masked position to 1.

setcol!(csc::SparseMatrixCSC, icol::Int, rowval::AbstractVector, nzval) -> SparseMatrixCSC

set specific col of a CSC matrix

swapbits(num::Integer, mask12::Integer) -> Integer

Return an integer with bits at i and j flipped.

swapcols!(v::VecOrMat, i::Int, j::Int[, f1, f2]) -> VecOrMat

swap col i and col j of v inplace, with f1, f2 factors applied on i and j (before swap).

swaprows!(v::VecOrMat, i::Int, j::Int[, f1, f2]) -> VecOrMat

swap row i and row j of v inplace, with f1, f2 factors applied on i and j (before swap).

takebit(index::Integer, bits::Int...) -> Int

Return a bit(s) at specific position.

testall(index::Integer, mask::Integer) -> Bool

Return true if all masked position of index is 1.

testany(index::Integer, mask::Integer) -> Bool

Return true if any masked position of index is 1.

testval(index::Integer, mask::Integer, onemask::Integer) -> Bool

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

u1rows!(state::VecOrMat, i::Int, j::Int, a, b, c, d) -> VecOrMat

apply u1 on row i and row j of state inplace.

unmat(nbit::Int, U::AbstractMatrix, locs::NTuple) -> AbstractMatrix

Returns the matrix representation of putting matrix at locs.

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

Sorts the tuple t.

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

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

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

u1ij!(target, i, j, a, b, c, d)

single u1 matrix into a target matrix.

Note: For coo, we take a additional parameter * ptr: starting position to store new data.

nactive(m::AbstractArray) -> Int

Returns the log-size of its first dimension.