Documentation for TensorQEC.
TensorQEC.AbstractDecoderTensorQEC.AbstractDecodingProblemTensorQEC.AbstractPauliTensorQEC.AbstractSyndromeTensorQEC.AbstractTannerGraphTensorQEC.BPDecoderTensorQEC.CSSBimatrixTensorQEC.CSSErrorPatternTensorQEC.CSSTannerGraphTensorQEC.ClassicalDecodingProblemTensorQEC.CliffordGateTensorQEC.CliffordGateTensorQEC.CliffordSimulateResultTensorQEC.Code1573TensorQEC.Code422TensorQEC.Code513TensorQEC.Code832TensorQEC.CompiledDecoderTensorQEC.DecodingResultTensorQEC.FWSWeightedGraphTensorQEC.FlatDecodingProblemTensorQEC.GeneralDecodingProblemTensorQEC.IPDecoderTensorQEC.IndependentDepolarizingDecodingProblemTensorQEC.IndependentDepolarizingErrorTensorQEC.IndependentFlipErrorTensorQEC.MatchingDecoderTensorQEC.MatchingWithBoundaryTensorQEC.Mod2TensorQEC.NoOptimizerTensorQEC.PauliTensorQEC.PauliGroupElementTensorQEC.PauliStringTensorQEC.QCInfoTensorQEC.ShorCodeTensorQEC.SimpleTannerGraphTensorQEC.SimpleTannerGraphTensorQEC.SimpleTensorNetworkTensorQEC.SteaneCodeTensorQEC.SumOfPaulisTensorQEC.SurfaceCodeTensorQEC.TNMAPTensorQEC.TNMMAPTensorQEC.TableDecoderTensorQEC.TruthTableOMEinsumContractionOrders.contraction_complexityOMEinsumContractionOrders.optimize_codeTensorQEC.SimpleMultiprocessing.multiprocess_runTensorQEC.ToricCodeTensorQEC.annotate_historyTensorQEC.check_logical_errorTensorQEC.check_logical_errorTensorQEC.clifford_groupTensorQEC.clifford_networkTensorQEC.clifford_simulateTensorQEC.code_distanceTensorQEC.coherent_error_unitaryTensorQEC.compileTensorQEC.correction_circuitTensorQEC.correction_dictTensorQEC.correction_pauli_stringTensorQEC.decodeTensorQEC.encode_stabilizersTensorQEC.error_pairsTensorQEC.error_quantum_circuitTensorQEC.error_quantum_circuit_pair_replaceTensorQEC.fidelity_tensornetworkTensorQEC.gaussian_elimination!TensorQEC.get_graphTensorQEC.iid_errorTensorQEC.iid_errorTensorQEC.inferenceTensorQEC.isanticommuteTensorQEC.isanticommuteTensorQEC.load_tableTensorQEC.logical_operatorTensorQEC.make_tableTensorQEC.measure_circuit_fault_tolTensorQEC.measure_circuit_steaneTensorQEC.measure_syndrome!TensorQEC.parse_stim_fileTensorQEC.pauli_basisTensorQEC.pauli_decompositionTensorQEC.pauli_reprTensorQEC.pauli_string_map_iterTensorQEC.place_qubitsTensorQEC.product_graphTensorQEC.random_error_patternTensorQEC.random_ldpcTensorQEC.reduce2generalTensorQEC.save_tableTensorQEC.simulation_tensornetworkTensorQEC.stabilizersTensorQEC.stg2uaimodelTensorQEC.sumofpaulisTensorQEC.syndrome_extractionTensorQEC.syndrome_inferenceTensorQEC.to_perm_matrixTensorQEC.transformed_syndrome_dictTensorQEC.yaoblockYaoToEinsum.contractTensorQEC.@P_str
TensorQEC.AbstractDecoder — TypeAbstractDecoderThe abstract type for a decoder.
TensorQEC.AbstractDecodingProblem — TypeAbstractDecodingProblemThe abstract type for a decoding problem.
TensorQEC.AbstractPauli — TypeAbstractPauli{N}An abstract type for Pauli operators, where N is the number of qubits.
TensorQEC.AbstractSyndrome — TypeAbstractSyndromeAbstract type for syndrome, which is basically a vector of bits.
TensorQEC.AbstractTannerGraph — TypeAbstractTannerGraphAbstract type for Tanner graphs, which is a bipartite graph that represents a classical linear code.
TensorQEC.BPDecoder — TypeBPDecoder(bp_max_iter::Int = 100, osd::Bool = true)Belief propagation decoder.
Fields:
bp_max_iter::Int: the maximum number of iterations.osd::Bool: whether to use osd.
TensorQEC.CSSBimatrix — TypeCSSBimatrixSince the encding process may alter the generators of stabilizer group, we introduce the CSSBimatrix structure to store the information of encoding process. The CSSBimatrix structure contains the following fields
matrix: The bimatrix representation of the stabilizers.Q: The matrix records the Gaussian elimination process, which is used to recover the original stabilizers.ordering: The ordering of qubits.xcodenum: The number of X stabilizers.
TensorQEC.CSSErrorPattern — TypeCSSErrorPattern(xerror::Vector{Mod2}, zerror::Vector{Mod2})A CSS error pattern with X and Z errors. Fields:
xerror::Vector{Mod2}: the X errorszerror::Vector{Mod2}: the Z errors
TensorQEC.CSSTannerGraph — TypeCSSTannerGraph(stgx::SimpleTannerGraph, stgz::SimpleTannerGraph)
CSSTannerGraph(nq::Int, stxs::Vector{Vector{Int}}, stzs::Vector{Vector{Int}})
CSSTannerGraph(sts::Vector{PauliString{N}}) where N
CSSTannerGraph(cqc::CSSQuantumCode)Two tanner graph for a CSS code, one for X stabilizers and one for Z stabilizers.
Fields
- stgx: Tanner graph for X stabilizers
- stgz: Tanner graph for Z stabilizers
TensorQEC.ClassicalDecodingProblem — TypeClassicalDecodingProblem(tanner::SimpleTannerGraph, pvec::IndependentFlipErrorA classical decoding problem. Fields:
tanner::SimpleTannerGraph: the Tanner graphpvec::IndependentFlipError: the independent probability distributions on each bit
TensorQEC.CliffordGate — TypeCliffordGate{PM<:PermMatrixCSC{Int, Int}}CliffordGate represented as a permutation matrix in the Pauli basis. It is a callable object that can be applied to a PauliString or a PauliGroupElement.
Fields
mat::PM: The permutation matrix.
Examples
julia> using TensorQEC.Yao
julia> hgate = CliffordGate(H)
CliffordGate(nqubits = 1)
I → I
X → Z
Y → -Y
Z → X
julia> hgate(P"IX", (2,))
+1 * IZ
julia> hgate(PauliGroupElement(1, P"IX"), (2,))
+i * IZTensorQEC.CliffordGate — Method(gate::CliffordGate)(ps::PauliString, pos::NTuple{M, Int}) where {M}Map the Pauli string ps by a Clifford gate gate. Return the mapped Pauli group element.
Arguments
ps: The Pauli string.pos: The positions to apply the permutation.
Returns
pg: The mapped Pauli group element.
TensorQEC.CliffordSimulateResult — TypeCliffordSimulateResult{N}The result of simulating a Pauli string by a Clifford circuit.
Fields
pg::PauliGroupElement{N}: A mapped Pauli group element as the output.error_pattern::Dict{Int, ErrorInstance}: The error pattern. The key is the index of the operation, the value is the error instance.history::Vector{PauliGroupElement{N}}: The history of Pauli group elements, its length islength(circuit)+1.
TensorQEC.Code1573 — TypeCode1573Construct a [[15,7,3]] CSS code instance.
TensorQEC.Code422 — TypeCode422Construct a [[4,2,2]] CSS code instance.
TensorQEC.Code513 — TypeCode513Construct a [[5,1,3]] code instance.
TensorQEC.Code832 — TypeCode832Construct a [[8,3,2]] CSS code instance.
TensorQEC.CompiledDecoder — TypeCompiledDecoderCompile the decoder to specific tanner graph and prior probability distributions.
TensorQEC.DecodingResult — TypeDecodingResult(success_tag::Bool, error_pattern::ET)The result of decoding.
Fields:
success_tag::Bool: whether the decoding is successful.error_pattern::ET: the error pattern.
TensorQEC.FWSWeightedGraph — TypeFWSWeightedGraph{T}A weighted graph that uses the Floyd-Warshall algorithm to find the shortest path. The last vertex stands for the boundary.
Fields:
edges::Vector{SimpleWeightedEdge{Int,T}}: the edges of the graph.v2e::Vector{Vector{Int}}: the vertex to edge mapping.dists::Matrix{T}: the distance matrix.error_path::Matrix{Vector{Int}}: the path matrix that stores the shortest path between each pair of vertices.
TensorQEC.FlatDecodingProblem — TypeFlatDecodingProblemInteger programming decoder can not directly apply to a tensor network probability distribution. We need to use auxiliary variables to represent each non-zero element of every tensor. The FlatDecodingProblem is a representation of the probability distribution in a flat form.
Fields
tanner::SimpleTannerGraph: The Tanner graphcode::Vector{Vector{Int}}: The tensor code of the probability distributionpvec::Vector{Vector{Float64}}: The probability vector
TensorQEC.GeneralDecodingProblem — TypeGeneralDecodingProblem(tanner::SimpleTannerGraph, ptn::SimpleTensorNetwork)A general decoding problem. Fields:
tanner::SimpleTannerGraph: the Tanner graphptn::TensorNetwork: the probability distributions, qubits are labeled as 1:qubit_num
TensorQEC.IPDecoder — TypeIPDecoder <: AbstractGeneralDecoderAn integer programming based decoder.
Keyword Arguments
optimizer = SCIP.Optimizer: The optimizer to use for solving the integer programming problemverbose::Bool = false: Whether to print the verbose output
TensorQEC.IndependentDepolarizingDecodingProblem — TypeIndependentDepolarizingDecodingProblem(tanner::CSSTannerGraph, pvec::IndependentDepolarizingError)A decoding problem with independent depolarizing error model. Fields:
tanner::CSSTannerGraph: the Tanner graphpvec::IndependentDepolarizingError: the independent probability distributions on each qubit
TensorQEC.IndependentDepolarizingError — TypeIndependentDepolarizingError(px::Vector{T}, py::Vector{T}, pz::Vector{T})Independent depolarizing error model.
Fields:
px::Vector{T}: the probability of each qubit depolarizing in X direction.py::Vector{T}: the probability of each qubit depolarizing in Y direction.pz::Vector{T}: the probability of each qubit depolarizing in Z direction.
TensorQEC.IndependentFlipError — TypeIndependentFlipError(p::Vector{T})Independent flip error model.
Fields:
p::Vector{T}: the probability of each qubit flipping.
TensorQEC.MatchingDecoder — TypeMatchingDecoder{T<:MatchingSolver} <: AbstractDecoderA decoder that uses matching algorithm.
Fields:
solver::T: the solver to solve the matching problem.
TensorQEC.MatchingWithBoundary — TypeMatchingWithBoundary{MT <: AbstractMatrix}A matching problem with a boundary. Only -1 stabilizers are considered as vertices. +1 stabilizers are removed.
Fields:
adj_mat::MT: the adjacency matrix of the graph.
TensorQEC.Mod2 — TypeMod2 <: Number
Mod2(x::Bool)A type representing a binary number in the field of integers modulo 2 (GF(2)). In this package, Mod2 algebra is used to represent the parity check matrix, and perform Gaussian elimination.
Fields
x::Bool: the binary number.
Examples
julia> Mod2(true) + Mod2(false)
1₂
julia> Mod2(true) + Mod2(true)
0₂TensorQEC.NoOptimizer — TypeNoOptimizer() <: CodeOptimizerA dummy optimizer that does not optimize the tensor network contraction order.
TensorQEC.Pauli — TypePauli <: AbstractPauli{1}A Pauli operator, i.e. $I$, $X$, $Y$, or $Z$.
Fields
id::Int: the id of the Pauli operator, which is 0 for $I$, 1 for $X$, 2 for $Y$, or 3 for $Z$.
TensorQEC.PauliGroupElement — TypePauliGroupElement{N} <: AbstractPauli{N}A Pauli group element is a Pauli string with a phase factor of im^k where k is in range 0-3.
Fields
phase::Int: the phase factor of the Pauli string, i.e.im^{phase}. It should be in range 0-3.ps::PauliString{N}: the Pauli string.
TensorQEC.PauliString — TypePauliString{N} <: AbstractPauli{N}
PauliString(operators::NTuple{N, Pauli}) where N
PauliString(pairs::Pair...)A Pauli string is a tensor product of Pauli operators, e.g. XYZ. The matrix representation of a Pauli string is evaluated as
\[A = \bigotimes_{i=1}^N \sigma_{operators[N-i+1]}\]
where operators is the array of Pauli operators. Note the order of operators is following the little-endian convention, i.e. the first qubit is the least significant qubit. For example, the Pauli string XYZ has matrix representation Z ⊗ Y ⊗ X.
Fields
operators::NTuple{N, Pauli}: the array of Pauli operators.
Arguments
pairs::Pair...: the pairs of locations and Pauli operators.
TensorQEC.QCInfo — TypeQCInfo(data_qubits::Vector{Int},ancilla_qubits::Vector{Int},nq::Int)
QCInfo(data_qubits::Vector{Int},nq::Int)A struct to store the qubit information of a quantum circuit.
Fields
data_qubits: The data qubit indices.ancilla_qubits: The ancilla qubit indices. If not specified, it is set to the complement ofdata_qubitsin1:nqnq: The total number of qubits.
TensorQEC.ShorCode — TypeShorCodeConstruct a Shor code instance.
TensorQEC.SimpleTannerGraph — TypeSimpleTannerGraph(nq::Int, ns::Int, q2s::Vector{Vector{Int}}, s2q::Vector{Vector{Int}}, H::Matrix{Mod2})Tanner graph for a classical linear code.
Fields
- nq: number of qubits
- ns: number of stabilizers
- q2s: a list of lists, q2s[i] is the list of stabilizers that contain qubit i
- s2q: a list of lists, s2q[i] is the list of qubits that stabilizer i contains
- H: the parity check matrix, H[i,j] = 1 means that the i-th stabilizer contains the j-th qubit
TensorQEC.SimpleTannerGraph — MethodSimpleTannerGraph(nq::Int, sts::Vector{Vector{Int}})Construct a Tanner graph from a list of stabilizers.
Arguments
- nq: number of qubits
- sts: a list of parity checks, each parity check is a list of bits.
TensorQEC.SimpleTensorNetwork — TypeSimpleTensorNetworkA (generalized) tensor network representation of a quantum circuit.
Fields
code::AbstractEinsum: The einsum code.tensors::Vector: The tensors in the network.
TensorQEC.SteaneCode — TypeSteaneCodeConstruct a Steane code instance.
TensorQEC.SumOfPaulis — TypeSumOfPaulis{T<:Number, N} <: AbstractPauli{N}A sum of Pauli strings is a linear combination of Pauli strings, e.g. $c_1 P_1 + c_2 P_2 + \cdots + c_n P_n$.
Fields
items::Vector{Pair{T, PauliString{N}}}: the vector of pairs of coefficients and Pauli strings.
Examples
julia> p1 = 0.5 * P"IXY" + 0.6 * P"XZI"
0.6 * XZI + 0.5 * IXY
julia> p2 = 0.7 * P"YZI" + 0.8 * P"XZI"
0.8 * XZI + 0.7 * YZI
julia> 0.2 * p1 + p2
0.92 * XZI + 0.7 * YZI + 0.1 * IXY
julia> p1 * p2
0.48 + 0.0im * III + 0.0 + 0.42im * ZII + 0.0 - 0.4im * XYY + 0.0 - 0.35im * YYYTensorQEC.SurfaceCode — TypeSurfaceCode(m::Int, n::Int)Construct a rotated surface code with m rows and n columns.
TensorQEC.TNMAP — TypeTNMAP(;optimizer::CodeOptimizer=default_optimizer()) <: AbstractGeneralDecoderA tensor network based maximum a posteriori (MAP) decoder, which finds the most probable configuration of the error pattern.
Keyword Arguments
optimizer::CodeOptimizer = TreeSA(): The optimizer to use for optimizing the tensor network contraction order.
TensorQEC.TNMMAP — TypeTNMMAP(;optimizer::CodeOptimizer=TreeSA(), factorize::Bool=false) <: AbstractGeneralDecoderA tensor network based marginal maximum a posteriori (MMAP) decoder, which finds the most probable logical sector after marginalizing out the error pattern on qubits.
Keyword Arguments
optimizer::CodeOptimizer = TreeSA(): The optimizer to use for optimizing the tensor network contraction order.factorize::Bool = true: Whether to factorize the tensors to rank-3 tensors.
TensorQEC.TableDecoder — TypeTableDecoder(d::Int)A decoder that uses a truth table to decode.
Arguments
d: The maximum number of errors to consider
TensorQEC.TruthTable — TypeTruthTableThe truth table for error correction.
Fields
table::Dict{Int,Int}: The truth table for error correction.num_qubits::Int: The number of qubits.num_st::Int: The number of stabilizers.d::Int64: The maximum number of errors.
OMEinsumContractionOrders.contraction_complexity — Methodcontraction_complexity(c::SimpleTensorNetwork)Return the contraction complexity of the tensor network.
OMEinsumContractionOrders.optimize_code — Methodoptimize_code(c::SimpleTensorNetwork, optimizer=TreeSA(); slicer=nothing)Optimize the code of the tensor network.
Arguments
c::SimpleTensorNetwork: The tensor network.optimizer::Optimizer: The optimizer to use, default isOMEinsum.TreeSA().
Keyword Arguments
slicer: The slicer to use, default isnothing. It can be e.g.OMEinsum.TreeSASlicer(score=OMEinsum.ScoreFunction(sc_target=30)).
For more, please check OMEinsumContractionOrders documentation.
TensorQEC.ToricCode — MethodToricCode(m::Int, n::Int)Construct a Toric code with m rows and n columns.
TensorQEC.annotate_history — Methodannotate_history(res::CliffordSimulateResult{N},qc::ChainBlock)Annotate the history of Pauli strings in the result of clifford_simulate with the quantum circuit.
Arguments
res: The result ofclifford_simulate.qc: The quantum circuit.
Returns
draw: The visualization of the history.
TensorQEC.check_logical_error — Methodcheck_logical_error(errored_qubits1::CSSErrorPattern, errored_qubits2::CSSErrorPattern, lx::Matrix{Mod2}, lz::Matrix{Mod2})Check if there is a logical error between two error patterns for a CSS code.
Input:
errored_qubits1: the first error pattern.errored_qubits2: the second error pattern.lx: the logical operator for X stabilizers.lz: the logical operator for Z stabilizers.
Output:
logical_error: true if there is a logical error, false otherwise.
TensorQEC.check_logical_error — Methodcheck_logical_error(errored_qubits1::Vector{Mod2}, errored_qubits2::Vector{Mod2}, lz::Matrix{Mod2})Check if there is a logical error between two error patterns by checking whether the difference of the two error patterns is a logical operator.
Input:
errored_qubits1: the first error pattern.errored_qubits2: the second error pattern.lz: the logical operator for Z stabilizers.
Output:
logical_error: true if there is a logical error, false otherwise.
TensorQEC.clifford_group — Methodclifford_group(n::Int)Generate the n-qubit Clifford group.
TensorQEC.clifford_network — Methodclifford_network(qc::ChainBlock)Generate a Clifford network from a quantum circuit.
TensorQEC.clifford_simulate — Methodclifford_simulate(paulistring, qc::ChainBlock)Perform Clifford simulation with a Pauli string paulistring as the input.
Arguments
paulistring: The input Pauli string, which can be aPauliStringor aPauliGroupElement.qc: The quantum circuit represented as a Yao'sChainBlock, its elements should be Clifford gates.
Returns
result: ACliffordSimulateResultrecords the output Pauli string, the phase factor, the simplified circuit, and the history of Pauli strings.
TensorQEC.code_distance — Methodcode_distance(tanner::CSSTannerGraph)Calculate the code distance of a CSS code.
Input:
tanner: the tanner graph of the CSS code.
Output:
d: the distance of the code.
TensorQEC.coherent_error_unitary — Methodcoherent_error_unitary(u::AbstractMatrix{T}, error_rate::Real; cache::Union{Vector, Nothing} = nothing) where TGenerate the error unitary near the given error rate.
Arguments
u: The original unitary.error_rate: The error rate.cache: The vector to store the error rate.
Returns
q: The errored unitary.
TensorQEC.compile — Methodcompile(decoder::AbstractDecoder, tanner::AbstractTannerGraph)Compile the decoder to specific tanner graph and prior probability distributions.
TensorQEC.correction_circuit — Methodcorrection_circuit(table::Dict{Int,Int}, num_qubits::Int, num_st::Int, st_pos::AbstractVector{Int}, total_qubits::Int)Generate the error correction circuit by embedding the truth table into the quantum circuit.
Arguments
table: The truth table for error correction.num_qubits: The number of qubits in the circuit.num_st: The number of stabilizers.st_pos: The indices of ancilla qubits that measure stabilizers.total_qubits: The total number of qubits in the circuit.
Returns
qc: The error correction circuit.
TensorQEC.correction_dict — Methodcorrection_dict(st::Vector{PauliString{N}}, d::Int64; et="XZ")Generate the correction dictionary for the given stabilizers.
Arguments
st: The vector of pauli strings, composing the generator of stabilizer group.d: The maximum number of errors.et: The type of error to be corrected. It can be "X", "Z", or "XZ". Default is "XZ".
Returns
table: The correction dictionary, mapping the syndrome to the corresponding error pattern.
TensorQEC.correction_pauli_string — Methodcorrection_pauli_string(qubit_num::Int, syn::Dict{Int, Bool}, prob::Dict{Int, Vector{Float64}})Generate the error Pauli string in the coding space. To correct the error, we still need to transform it to the physical space.
Arguments
qubit_num: The number of qubits.syn: The syndrome dictionary.prob: The inferred error probability of each physical qubit in coding space.
Returns
ps: The error Pauli string in the coding space.
TensorQEC.decode — Methoddecode(decoder::AbstractDecoder, problem::AbstractDecodingProblem, syndrome::AbstractSyndrome)
decode(compiled_decoder::CompiledDecoder, syndrome::AbstractSyndrome)Decode the syndrome using the decoder.
Input:
decoder::AbstractDecoder: the decoder.problem::AbstractDecodingProblem: the decoding problem.syndrome::AbstractSyndrome: the syndrome.compiled_decoder::CompiledDecoder: the compiled decoder.
Output:
decoding_result::DecodingResult: the decoding result.
TensorQEC.encode_stabilizers — Methodencode_stabilizers(stabilizers::AbstractVector{PauliString{N}}) where NGenerate the encoding circuit for the given stabilizers.
Arguments
stabilizers: The vector of pauli strings, composing the generator of stabilizer group.
Returns
qc: The encoding circuit.data_qubits: The indices of data qubits.bimat: The structure storing the encoding information.
TensorQEC.error_pairs — Methoderror_pairs(error_rate::T; gates = nothing) where {T <: Real}Generate the error pairs for the given error rate.
Arguments
error_rate: The error rate.gates: The gates to be errored. If not specified, it is set to[X,Y,Z,H,CCZ,ConstGate.Toffoli,ConstGate.CNOT,ConstGate.CZ]
Returns
pairs: The error pairs.vec: The vector to store the error rate to each gate.
TensorQEC.error_quantum_circuit — Methoderror_quantum_circuit(qc::ChainBlock, error_rate::T ) where {T <: Real}Generate the error quantum circuit for the given error rate.
Arguments
qc: The quantum circuit.error_rate: The error rate.
Returns
eqc: The error quantum circuit.
TensorQEC.error_quantum_circuit_pair_replace — Methoderror_quantum_circuit_pair_replace(qc::ChainBlock, error_rate::T ) where {T <: Real}
error_quantum_circuit_pair_replace(qc::ChainBlock, pairs)Generate the error quantum circuit for the given error rate. The errored gate to the same type of gate is the same.
Arguments
qc: The quantum circuit.error_rate: The error rate.pairs: The error gates used to replace the original gates.
Returns
qcf: The error quantum circuit.vec: The vector to store the error rate to each gate.
TensorQEC.fidelity_tensornetwork — Methodfidelity_tensornetwork(qc::ChainBlock,qc_info::QCInfo)Generate the tensor network representation of the quantum circuit fidelity with the given QCInfo, where ancilla qubits are initilized at zero state and partial traced after the circuit. The data qubits are traced out.
Arguments
qc: The quantum circuit.qc_info: The qubit information of the quantum circuit
Returns
tn: The tensor network representation of the quantum circuit.
TensorQEC.gaussian_elimination! — Methodgaussian_elimination!(bimat::Bimatrix, rows::UnitRange, col_offset::Int, qubit_offset::Int;allow_col_operation = true)Perform Gaussian elimination on a binary matrix.
Arguments
bimat: The binary matrix to perform Gaussian elimination on.rows: The range of rows to consider in the elimination process.col_offset: The offset for columns in the matrix.qubit_offset: The offset for qubits in the ordering.allow_col_operation: Whether column operations (qubit swapping) are allowed. Default is true.
Returns
bimat: The modified binary matrix after Gaussian elimination.
TensorQEC.get_graph — Methodget_graph(tanner::SimpleTannerGraph)
get_graph(ctg::CSSTannerGraph)Get the simple graph of a simple tanner graph or a CSS tanner graph.
TensorQEC.iid_error — Method" iid_error(p::T,n::Int) where T <: Real
Generate an independent and identically distributed flip error model.
Input:
p::T: the probability of each qubit flipping.n::Int: the number of qubits.
Output:
em::IndependentFlipError: the independent flip error model.
TensorQEC.iid_error — Methodiid_error(px::T,py::T,pz::T,n::Int) where T <: RealGenerate an independent and identically distributed depolarizing error model.
Input:
px::T: the probability of each qubit depolarizing in X direction.py::T: the probability of each qubit depolarizing in Y direction.pz::T: the probability of each qubit depolarizing in Z direction.n::Int: the number of qubits.
Output:
em::IndependentDepolarizingError: the independent depolarizing error model.
TensorQEC.inference — Methodinference(measure_outcome::Vector{Int}, code::CSSBimatrix, qc::ChainBlock, p::Vector{Vector{Float64}})Infer the error probability of each qubit from the measurement outcome of the stabilizers.
Arguments
measure_outcome: The measurement outcome of the stabilizers, which is either 1 or -1.code: The structure storing the encoding information.qc: The encoding circuit.p: The prior error probability of each physical qubit.
Returns
ps_ec_phy: The error Pauli string for error correction.
TensorQEC.isanticommute — Methodisanticommute(a::PauliGroupElement, b::PauliGroupElement)Returns true if two Pauli group elements anticommute, i.e. $a b + b a = 0$.
TensorQEC.isanticommute — Methodisanticommute(a::PauliString, b::PauliString)Returns true if two Pauli strings anticommute, i.e. $a b + b a = 0$.
TensorQEC.load_table — Methodload_table(filename::String, num_qubits::Int, num_st::Int)Load a truth table from a file.
Arguments
filename: The name of the file to load fromnum_qubits: The number of qubits in the codenum_st: The number of stabilizers in the code
Returns
A TruthTable loaded from the file.
TensorQEC.logical_operator — Methodlogical_operator(tanner::CSSTannerGraph)Calculate the logical operators of a CSS code.
Input:
tanner: the tanner graph of the CSS code.
Output:
lx: the logical operator for X stabilizers.lz: the logical operator for Z stabilizers.
TensorQEC.make_table — Methodmake_table(tanner::CSSTannerGraph, d::Int, sc::AbstractSyndromeConflict)Generate a truth table for error correction from a CSS Tanner graph.
Arguments
tanner: The CSS Tanner graph representing the stabilizer coded: The maximum number of errors to considersc: The syndrome conflict resolution strategy
Returns
A TruthTable containing the mapping from syndromes to error patterns.
TensorQEC.measure_circuit_fault_tol — Methodmeasure_circuit_fault_tol(sts::Vector{PauliString{N}}) where NGenerate the Shor type measurement circuit for fault tolerant measurement.
Arguments
sts: The vector of Pauli strings, composing the generator of stabilizer group.
Returns
qc: The measurement circuit.st_pos: The ancilla qubit indices that measrue corresponding stabilizers.num_qubits: The total number of qubits in the circuit.
TensorQEC.measure_circuit_steane — Methodmeasure_circuit_steane(data_qubit::Int, sts::Vector{PauliString{N}};qcen = nothing) where NGenerate the Steane type measurement circuit.
Arguments
data_qubit: The index of the data qubit.sts: The vector of Pauli strings, composing the generator of stabilizer group.qcen: The encoding circuit. Ifnothing, the measurement circuit will not contain the encoder for ancilla qubits.
Returns
qc: The measurement circuit.st_pos: The ancilla qubit indices that measrue corresponding stabilizers.
TensorQEC.measure_syndrome! — Methodmeasure_syndrome!(reg::AbstractRegister, stabilizers::AbstractVector{PauliString{N}}) where NMeasure the given stabilizers.
Arguments
reg: The quantum register.stabilizers: The vector of pauli strings, composing the generator of stabilizer group.
Returns
measure_outcome: The measurement outcome of the stabilizers, which is either 1 or -1.
TensorQEC.parse_stim_file — Methodparse_stim_file(file_path::String, qubit_number::Int)Parse a Stim file and return a Yao circuit.
Arguments
file_path::String: The path to the Stim file.qubit_number::Int: The number of qubits in the circuit.
TensorQEC.pauli_basis — Methodpauli_basis(nqubits::Int)
pauli_basis(::Val{N}) where NGenerate the n-qubit Pauli basis, which is a vector of PauliStrings. The size of the vector is 4^N.
Examples
julia> pauli_basis(1)
4-element Vector{PauliString{1}}:
I
X
Y
ZThe single qubit Pauli basis has 4 elements.
TensorQEC.pauli_decomposition — Methodpauli_decomposition(m::AbstractArray; atol=0)
pauli_decomposition(dm::DensityMatrix; atol=0)
pauli_decomposition(reg::ArrayReg; atol=0)Decompose a matrix of size 2^N x 2^N (or density matrix or array register) into the Pauli basis:
\[m = \sum_{i=1}^{4^N} c_i \cdot \sigma_i\]
where c_i is the coefficient of the i-th Pauli string, and \sigma_i is the i-th Pauli string.
Keyword Arguments
atol::Float64: the absolute tolerance for the coefficients. If the coefficient is less thanatol, it will be ignored.
Examples
julia> pauli_decomposition(mat(P"X" + 0.5 * P"Z"))
1.0 - 0.0im * X + 0.5 - 0.0im * ZThe return value is a SumOfPaulis object, which is recovered from the matrix representation of the Pauli expression.
TensorQEC.pauli_repr — Methodpauli_repr(m::AbstractMatrix) -> Matrix
pauli_repr(m::AbstractBlock) -> MatrixReturns the representation of a matrix in the Pauli basis. It should not be confused with pauli_decomposition, this function returns a matrix that represents how a Pauli string is mapped to others by this matrix. If a matrix has size 2^N x 2^N, its Pauli basis representation will be a 4^N x 4^N real matrix.
Examples
The Pauli operator flips the sign of Y and Z in the Pauli basis.
julia> using TensorQEC.Yao
julia> pauli_repr(ConstGate.S)
4×4 Matrix{Float64}:
1.0 0.0 0.0 0.0
0.0 0.0 -1.0 0.0
0.0 1.0 0.0 0.0
0.0 0.0 0.0 1.0Here, the [2,3] element of the matrix corresponds to tr(XSYS')/2 = -1, the [3,2] element of the matrix corresponds to tr(YSXS')/2 = 1, and the [4,4] element of the matrix corresponds to tr(ZSZS')/2 = 1.
TensorQEC.pauli_string_map_iter — Methodpauli_string_map_iter(ps::PauliString{N}, qc::ChainBlock) where NMap the Pauli string ps by a quantum circuit qc. Return the mapped Pauli string.
TensorQEC.place_qubits — Methodplace_qubits(reg0::AbstractRegister, data_qubits::Vector{Int}, num_qubits::Int)Place the data qubits to the specified position. The other qubits are filled with zero state.
Arguments
reg0: The data register.data_qubits: The indices of data qubits.num_qubits: The total number of qubits.
Returns
reg: The register with data qubits placed at the specified position.
TensorQEC.product_graph — Methodproduct_graph(tanner1::SimpleTannerGraph, tanner2::SimpleTannerGraph)Construct the hyper-graph product code of two simple tanner graphs.
TensorQEC.random_error_pattern — Methodrandom_error_pattern(qubit_number::Int, em::AbstractErrorModel)Generate a random error pattern for a given number of qubits and an error model.
TensorQEC.random_ldpc — Methodrandom_ldpc(n1::Int,n2::Int,nq::Int)Construct a random LDPC code with given connectivity numbers.
Input:
n1: the number of stabilizers that each qubit is checked by.n2: the number of qubits that each stabilizer contains.nq: the number of qubits in the code.
Output:
tanner: the tanner graph of the LDPC code.
TensorQEC.reduce2general — Methodreduce2general(tanner::CSSTannerGraph, pvec::IndependentDepolarizingError)Reduce a CSS Tanner graph to a general decoding problem.
Input:
tanner::CSSTannerGraph: the CSS Tanner graph.pvec::IndependentDepolarizingError: the error model.
Output:
gdp::GeneralDecodingProblem: the general decoding problem.csg::CSSToGeneralDecodingProblem: the reduction result.
TensorQEC.save_table — Methodsave_table(tb::TruthTable, filename::String)Save a truth table to a file.
Arguments
tb: The truth table to savefilename: The name of the file to save to
TensorQEC.simulation_tensornetwork — Methodsimulation_tensornetwork(qc::ChainBlock,qc_info::QCInfo)Generate the tensor network representation of the quantum circuit with the given QCInfo, where ancilla qubits are initilized at zero state and partial traced after the circuit.
Arguments
qc: The quantum circuit.qc_info: The qubit information of the quantum circuit
Returns
tn: The tensor network representation of the quantum circuit.input_indices: The input indices of the tensor network.output_indices: The output indices of the tensor network.
TensorQEC.stabilizers — Methodstabilizers(tc::ToricCode)
stabilizers(sc::SurfaceCode)
stabilizers(shor::ShorCode)
stabilizers(steane::SteaneCode)
stabilizers(code832::Code832)Get the stabilizers of the code instances.
TensorQEC.stg2uaimodel — Methodstg2uaimodel(tanner::SimpleTannerGraph, ptn::SimpleTensorNetwork)Convert a Tanner graph and a tensor network to a UAIModel.
Arguments
tanner::SimpleTannerGraph: The Tanner graph.ptn::SimpleTensorNetwork: The tensor network.
Returns
uai::UAIModel: The UAIModel.
TensorQEC.sumofpaulis — Methodsumofpaulis(items::Vector{Pair{T, PauliString{N}}}) where {T, N}Returns a sum of Pauli strings from a vector of pairs of coefficients and Pauli strings. Unlike SumOfPaulis, it will merge the same Pauli strings and sum up the coefficients.
Keyword Arguments
atol::Float64: the absolute tolerance for the coefficients. If the coefficient is less thanatol, it will be ignored.
TensorQEC.syndrome_extraction — Methodsyndrome_extraction(errored_qubits::Vector{Mod2}, H::Matrix{Mod2})
syndrome_extraction(errored_qubits::Vector{Mod2}, tanner::SimpleTannerGraph)
syndrome_extraction(error_patterns::CSSErrorPattern, tanner::CSSTannerGraph)Extract the syndrome from the error pattern.
TensorQEC.syndrome_inference — Methodsyndrome_inference(cl::CliffordNetwork{T}, syn::Dict{Int,Bool}, p::Vector{Vector{Float64}}) where TInfer the error probability of each qubit from the measurement outcome of the stabilizers.
Arguments
cl: The Clifford network.syn: The syndrome dictionary.p: The prior error probability of each physical qubit.
Returns
pinf: The inferred error probability of each physical qubit in coding space. For errored stabilizers, there are two possibilities: X or Y error. For unerrored stabilizers, there are also two possibilities: no error or Z error. For unmeasured qubits, there are four possibilities: no error, X error, Y error, Z error. Therefore the length of each vector inpinfmay be 2 or 4.
TensorQEC.to_perm_matrix — Methodto_perm_matrix(matrix; atol=1e-8)Convert a general matrix to a permutation matrix.
Arguments
m: The matrix representation of the gate.atol: The tolerance to zeros in the matrix.
Returns
pm: The permutation matrix. pm.perm is the permutation vector, pm.vals is the leading coefficient.
TensorQEC.transformed_syndrome_dict — Methodtransformed_syndrome_dict(measure_outcome::Vector{Int}, code::CSSBimatrix)Generate the syndrome dictionary on the transformed stabilizers from the measurement outcome.
Arguments
measure_outcome: The measurement outcome of the stabilizers, which is either 1 or -1.code: The structure storing the encoding information.
Returns
syn_dict: The syndrome dictionary on the transformed stabilizers. 1 is transformed to 0, -1 is transformed to 1.
TensorQEC.yaoblock — Methodyaoblock(x::Pauli)Returns the Yao block corresponding to a Pauli operator.
YaoToEinsum.contract — Methodcontract(c::SimpleTensorNetwork)Contract the tensor network, and return the result tensor.
TensorQEC.@P_str — Macro@P_str(str::String)A macro to convert a string to a Pauli string.
Example
julia> P"IX"
IXMultiprocessing
TensorQEC.SimpleMultiprocessing.multiprocess_run — Functionmultiprocess_run(func, inputs::AbstractVector)Execute function func on inputs with multiple processing.
Example
Suppose we have a file run.jl with the following contents
using GenericTensorNetworks.SimpleMultiprocessing
results = multiprocess_run(x->x^2, randn(8))In an terminal, you may run the script with 4 processes by typing
$ julia -p4 run.jl
From worker 2: [ Info: running argument -0.17544008350172655 on device 2
From worker 5: [ Info: running argument 0.34578117779452555 on device 5
From worker 3: [ Info: running argument 2.0312551239727705 on device 3
From worker 4: [ Info: running argument -0.7319353419291961 on device 4
From worker 2: [ Info: running argument 0.013132180639054629 on device 2
From worker 3: [ Info: running argument 0.9960101782201602 on device 3
From worker 4: [ Info: running argument -0.5613942832743966 on device 4
From worker 5: [ Info: running argument 0.39460402723831134 on device 5