qec
numqi.qec.stabilizer_to_code(stab_list, logicalZ_list, tag_print=True)
convert stabilizer to code subspace
TODO: add logicalX_list for fix the phase of code subspace
Parameters:
Name | Type | Description | Default |
---|---|---|---|
stab_list
|
list[str]
|
list of Pauli string for stabilizer, e.g. ['XZZXI', 'IXZZX', 'XIXZZ', 'ZXIXZ'] |
required |
logicalZ_list
|
list[str]
|
logical Z operator list, e.g. ['ZZZZZ'] |
required |
tag_print
|
bool
|
whether to print the code subspace |
True
|
Returns:
Name | Type | Description |
---|---|---|
code_list |
ndarray
|
shape=(2k,2n), code subspace, code_list[i] is the code subspace for logical i |
numqi.qec.get_code_subspace(key=None, **kwargs)
get code subspace for some well-known quantum error correction codes
Parameters:
Name | Type | Description | Default |
---|---|---|---|
key
|
str | None
|
key of the code, if None, print available key |
None
|
kwargs
|
dict
|
additional parameters for some codes |
{}
|
Returns:
Name | Type | Description |
---|---|---|
ret |
ndarray
|
shape=(2,2**n), code subspace, ret[i] is the code subspace for logical i |
info |
dict
|
additional information |
numqi.qec.get_code_feasible_constraint(num_qubit, dimK, distance)
get the SDP constraint for the feasibility of a quantum code
arxiv-link SDP bounds for quantum codes
see eq(142)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
num_qubit
|
int
|
the number of qubits |
required |
dimK
|
int
|
the dimension of the code space |
required |
distance
|
int
|
the distance of the code |
required |
Returns:
Name | Type | Description |
---|---|---|
cvxX |
dict
|
the variable for the code |
cvxA |
Expression
|
the approximation of the quantum weight enumerator (Shor-Laflamme) |
cvxB |
Expression
|
the approximation of the dual quantum weight enumerator (Shor-Laflamme) |
cvxS |
Expression
|
the approximation of the quantum weight enumerator (Rains' shadow) |
constraint |
list
|
the list of constraints |
numqi.qec.is_code_feasible(num_qubit, dimK, distance, drop_constraint=None, solver=None)
check if a quantum code is feasible
arxiv-link SDP bounds for quantum codes
see eq(142)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
num_qubit
|
int
|
the number of qubits |
required |
dimK
|
int
|
the dimension of the code space |
required |
distance
|
int
|
the distance of the code |
required |
drop_constraint
|
list
|
the list of constraint to be dropped. if all constraints are kept, SDP problem probably raises NumericalError |
None
|
solver
|
str
|
the solver to be used, we find MOSEK is generally more stable |
None
|
Returns:
Name | Type | Description |
---|---|---|
ret |
bool
|
if False, the code is definitely infeasible. if True, the code could be feasible |
numqi.qec.get_Krawtchouk_polynomial(q, k)
get the Krawtchouk polynomial
Parameters:
Name | Type | Description | Default |
---|---|---|---|
q
|
int
|
the prime power |
required |
k
|
int
|
the degree of the polynomial |
required |
Returns:
Name | Type | Description |
---|---|---|
ret |
ndarray
|
the Krawtchouk polynomial of shape |
numqi.qec.is_code_feasible_linear_programming(num_qubit, dimK, distance)
check if a quantum code is feasible using linear programming
arxiv-link SDP bounds for quantum codes
see eq(19) and eq(20)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
num_qubit
|
int
|
the number of qubits |
required |
dimK
|
int
|
the dimension of the code space |
required |
distance
|
int
|
the distance of the code |
required |
Returns:
Name | Type | Description |
---|---|---|
ret |
bool
|
if False, the code is definitely infeasible. if True, the code could be feasible |
info |
dict
|
the information of the code |
numqi.qec.hf_state(x)
convert state string to vector, should NOT be used in performance-critical code
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x
|
str
|
state string, e.g. '0000 1111', supporting sign "+-i", e.g. '0000 -i1111' |
required |
Returns:
Name | Type | Description |
---|---|---|
ret |
ndarray
|
shape=(2**n,), state vector |
numqi.qec.hf_pauli(x)
convert Pauli string to matrix, should NOT be used in performance-critical code
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x
|
str
|
Pauli string, e.g. 'IXYZ' |
required |
Returns:
Name | Type | Description |
---|---|---|
ret |
ndarray
|
shape=(2n,2n), Pauli matrix |
numqi.qec.get_pauli_with_weight_sparse(num_qubit, weight, tag_neighbor=False)
get pauli operator with given ewight
Parameters:
Name | Type | Description | Default |
---|---|---|---|
num_qubit
|
int
|
number of qubit |
required |
weight
|
int
|
weight of pauli operator |
required |
tag_neighbor
|
bool
|
if True, the qubit is connected in a ring |
False
|
Returns:
Name | Type | Description |
---|---|---|
str_list |
list[str]
|
list of string of pauli operator |
error_list |
csr_array
|
pauli operator of shape |
numqi.qec.make_pauli_error_list_sparse(num_qubit, distance, kind='torch-csr01', tag_neighbor=False)
make Pauli error operator sorted by weight
Parameters:
Name | Type | Description | Default |
---|---|---|---|
num_qubit
|
int
|
number of qubits |
required |
distance
|
int
|
distance of QECC |
required |
kind
|
str
|
kind of output, 'numpy', 'torch', 'scipy-csr0', 'scipy-csr01', 'torch-csr0', 'torch-csr01' |
'torch-csr01'
|
tag_neighbor
|
bool
|
if True, consider only neighbor errors |
False
|
Returns:
Name | Type | Description |
---|---|---|
error_str_list |
list[str]
|
list of Pauli error string |
error_list |
ndarray | Tensor | csr_matrix
|
list of Pauli error operator. When |
numqi.qec.pauli_csr_to_kind(x0, kind)
convert scipy.sparse.csr_array to desired kind
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x0
|
csr_array
|
input matrix |
required |
kind
|
str
|
kind of output, 'numpy', 'torch', 'scipy-csr0', 'scipy-csr01', 'torch-csr0', 'torch-csr01'
numpy: np.ndarray full matrix
torch: torch.Tensor full matrix
scipy-csr0: scipy.sparse.csr_matrix of shape |
required |
Returns:
Name | Type | Description |
---|---|---|
ret |
ndarray | Tensor | csr_matrix
|
output matrix |
numqi.qec.get_weight_enumerator(code, wt_to_pauli_dict=None, index=None, tagB=True, use_circuit=False, use_tqdm=False)
get Shor-Laflamme quantum weight enumerator
Parameters:
Name | Type | Description | Default |
---|---|---|---|
code
|
ndarray
|
shape=(dim, 2**num_qubit), code space |
required |
wt_to_pauli_dict
|
(dict, None)
|
dict of weight to pauli operator, {weight: pauli_operator}, generated from
|
None
|
index
|
(int, list[int], None)
|
weight of pauli operator, if None, return all weight |
None
|
tagB
|
bool
|
if True, return both A and B |
True
|
use_circuit
|
bool
|
if True, use circuit to calculate |
False
|
use_tqdm
|
bool
|
if True, plot progress bar, only valid when |
False
|
Returns:
Name | Type | Description |
---|---|---|
retA |
(ndarray, float)
|
Shor-Laflamme quantum weight enumerator |
retB |
(ndarray, float)
|
Shor-Laflamme dual quantum weight enumerator |