qec 0.0.11__py3-none-any.whl → 0.2.0__py3-none-any.whl

Sign up to get free protection for your applications and to get access to all the features.
qec/__init__.py ADDED
File without changes
@@ -0,0 +1,2 @@
1
+ from qec.quantum_codes.five_qubit_code import FiveQubitCode
2
+ from qec.quantum_codes.codetables_de import CodeTablesDE
@@ -0,0 +1,93 @@
1
+ from qec.stabilizer_code import StabilizerCode
2
+ from qec.utils.codetables_de_utils import get_codetables_de_matrix, pcm_to_csr_matrix
3
+
4
+
5
+ class CodeTablesDE(StabilizerCode):
6
+ """
7
+ A code object built from data obtained from Markus Grassl's codetables.de website (with `q=4`).
8
+
9
+ This class inherits from `StabilizerCode` and initialises the code
10
+ by querying the codetables.de website for the specified parameters `(n, k)`,
11
+ constructing the stabilizer (PCM) matrix, and passing it up to the
12
+ `StabilizerCode` parent class.
13
+
14
+ Parameters
15
+ ----------
16
+ physical_qubit_count : int
17
+ Length of the code (number of physical qubits).
18
+ logical_qubit_count : int
19
+ Dimension of the code (number of logical qubits).
20
+
21
+ Attributes
22
+ ----------
23
+ name : str
24
+ Name assigned to this code instance. Defaults to "CodeTablesDE".
25
+ url : str
26
+ The URL from which this code's data was retrieved.
27
+ code_distance : int
28
+ The code's minimum distance. This is updated if the reported upper bound
29
+ from the codetables.de website is smaller than the base class default.
30
+
31
+ See Also
32
+ --------
33
+ StabilizerCode : Parent class providing stabilizer code functionality.
34
+ get_codetables_de_matrix : Function that queries codetables.de to retrieve code data.
35
+ pcm_to_csr_matrix : Function that converts a PCM-like list of column indices into a CSR matrix.
36
+
37
+ Notes
38
+ -----
39
+ - The data is retrieved from:
40
+ https://codetables.de
41
+ maintained by Markus Grassl.
42
+ """
43
+
44
+ def __init__(self, physical_qubit_count: int, logical_qubit_count: int):
45
+ """
46
+ Initialise a code from Markus Grassl's codetables.de website with `q=4`, `n`, and `k`.
47
+
48
+ This method queries the codetables.de database for a stabilizer matrix
49
+ describing a code with parameters (q=4, n, k). The matrix is then
50
+ converted to a CSR (Compressed Sparse Row) format and passed to
51
+ the parent `StabilizerCode` class.
52
+
53
+ Parameters
54
+ ----------
55
+ n : int
56
+ Length of the code (number of physical qubits).
57
+ k : int
58
+ Dimension of the code (number of logical qubits).
59
+
60
+ Notes
61
+ -----
62
+ - `d_upper` from the query result is used to potentially update `self.code_distance`
63
+ if it is smaller than the default distance assigned by `StabilizerCode`.
64
+ - Since this code is defined over GF(4), `q` is hardcoded as 4.
65
+ - Data is retrieved from Markus Grassl's website (https://codetables.de).
66
+
67
+ Raises
68
+ ------
69
+ ValueError
70
+ If no valid matrix data can be retrieved from codetables.de, or
71
+ if the site indicates that such a code does not exist.
72
+ """
73
+ # Retrieve code data from codetables.de
74
+ ct_dict = get_codetables_de_matrix(
75
+ q=4, n=physical_qubit_count, k=logical_qubit_count
76
+ )
77
+
78
+ # Construct the stabilizer matrix in CSR format
79
+ # The matrix is 2*n columns wide, as is typical for GF(4) stabilizers.
80
+ stabilizer_matrix = pcm_to_csr_matrix(
81
+ ct_dict["pcm"], num_cols=2 * int(ct_dict["n"])
82
+ )
83
+
84
+ # Initialise the parent class with this stabilizer matrix
85
+ super().__init__(stabilizers=stabilizer_matrix)
86
+
87
+ # Name of this code and the URL from which we retrieved it
88
+ self.name = "CodeTablesDE"
89
+ self.url = ct_dict["url"]
90
+
91
+ # Update distance if the reported upper bound is smaller than the default
92
+ if int(ct_dict["d_upper"]) < self.code_distance:
93
+ self.code_distance = int(ct_dict["d_upper"])
@@ -0,0 +1,67 @@
1
+ from qec.stabilizer_code.stabilizer_code import StabilizerCode
2
+
3
+
4
+ class FiveQubitCode(StabilizerCode):
5
+ """
6
+ Five-Qubit Quantum Error-Correcting Code.
7
+
8
+ The `FiveQubitCode` class implements the [[5, 1, 3]] quantum stabilizer code,
9
+ which is the smallest possible quantum error-correcting code capable of
10
+ correcting an arbitrary single-qubit error. This code encodes one logical
11
+ qubit into five physical qubits and has a distance of three, allowing it
12
+ to detect up to two errors and correct one.
13
+
14
+ Parameters
15
+ ----------
16
+ None
17
+
18
+ Attributes
19
+ ----------
20
+ code_distance : int
21
+ The distance of the quantum code. For the five-qubit code, this is set to 3.
22
+
23
+ Inherits
24
+ --------
25
+ StabilizerCode
26
+ The base class providing functionalities for stabilizer-based quantum
27
+ error-correcting codes, including initialization, distance computation,
28
+ and parameter retrieval.
29
+
30
+ Examples
31
+ --------
32
+ >>> five_qubit = FiveQubitCode()
33
+ >>> five_qubit.phyiscal_qubit_count
34
+ 5
35
+ >>> five_qubit.logical_qubit_count
36
+ 1
37
+ >>> five_qubit.code_distance
38
+ 3
39
+ """
40
+
41
+ def __init__(self):
42
+ """
43
+ Initialize the Five-Qubit Code with predefined Pauli stabilizers.
44
+
45
+ The constructor sets up the stabilizer generators for the [[5, 1, 3]]
46
+ quantum code using their corresponding Pauli strings. It then calls the
47
+ superclass initializer to establish the stabilizer matrix and other
48
+ essential parameters.
49
+
50
+ Parameters
51
+ ----------
52
+ None
53
+
54
+ Raises
55
+ ------
56
+ ValueError
57
+ If the provided stabilizer generators do not satisfy the necessary
58
+ commutation relations required for a valid stabilizer code.
59
+ """
60
+ # Define the Pauli stabilizer generators for the five-qubit code
61
+ pauli_stabilizers = [["XZZXI"], ["IXZZX"], ["XIXZZ"], ["ZXIXZ"]]
62
+
63
+ # Initialize the StabilizerCode with the defined stabilizers and a custom name
64
+ super().__init__(stabilizers=pauli_stabilizers, name="5-Qubit Code")
65
+
66
+ # Set the distance attribute specific to the five-qubit code
67
+ self.code_distance = 3
@@ -0,0 +1 @@
1
+ from qec.stabilizer_code.stabilizer_code import StabilizerCode
@@ -0,0 +1,6 @@
1
+ from qec.stabilizer_code import StabilizerCode
2
+
3
+
4
+ class CSSCode(StabilizerCode):
5
+ def __init__(self):
6
+ NotImplemented