Skip to content

Commit 310557f

Browse files
committed
Add details on error causing violation to FT check result
1 parent ac9c3f1 commit 310557f

2 files changed

Lines changed: 67 additions & 35 deletions

File tree

examples/cat_state.ipynb

Lines changed: 51 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
" self.d = max_faults * 2 + 1\n",
4141
"\n",
4242
" def stabilizers(self):\n",
43+
" \"\"\"Cat state stabilizes the pairwise parity operators of the physical qubits.\"\"\"\n",
4344
" return [\n",
4445
" PauliString(f\"Z{i}*Z{j}\")\n",
4546
" for (i, j) in zip(range(self.num_qubits), range(1, self.num_qubits))\n",
@@ -50,22 +51,23 @@
5051
" return PauliString(\"X\" * self.num_qubits)\n",
5152
"\n",
5253
" def physical_z_stabilizers(self):\n",
54+
" \"\"\"The initial state is |0> for all (physical) qubits\"\"\"\n",
5355
" return [PauliString(f\"Z{i}\") for i in range(self.num_qubits)]"
5456
]
5557
},
5658
{
5759
"cell_type": "code",
58-
"execution_count": 5,
60+
"execution_count": null,
5961
"id": "4702c9af",
6062
"metadata": {},
6163
"outputs": [
6264
{
6365
"name": "stderr",
6466
"output_type": "stream",
6567
"text": [
66-
"[ Info: '`bitwuzla -rwl 1`' is used as smt solver for FT_condition case\n",
67-
"[ Info: '`bitwuzla -rwl 1`' has solved the problem\n",
68-
"[ Info: The assignment that generates the bug has been written to ./_temp_check_FT_condition_.output\n"
68+
"Precompiling QuantumSE...\n",
69+
" 1534.5 ms ✓ QuantumSE\n",
70+
" 1 dependency successfully precompiled in 2 seconds. 65 already precompiled.\n"
6971
]
7072
},
7173
{
@@ -75,40 +77,50 @@
7577
"shape: (4, 8)\n",
7678
"shape: (4, 8)\n",
7779
"1\n",
78-
">>> 45 INIT target_qubit=1\n",
80+
">>> 1 INIT target_qubit=1\n",
7981
"2\n",
80-
">>> 47 H target_qubit=1\n",
82+
">>> 3 H target_qubit=1\n",
8183
"3\n",
82-
">>> 48 INIT target_qubit=2\n",
84+
">>> 4 INIT target_qubit=2\n",
8385
"4\n",
84-
">>> 52 CNOT target_qubit1=1, target_qubit2=2\n",
86+
">>> 8 CNOT target_qubit1=1, target_qubit2=2\n",
8587
"5\n",
86-
">>> 53 INIT target_qubit=3\n",
88+
">>> 9 INIT target_qubit=3\n",
8789
"6\n",
88-
">>> 57 CNOT target_qubit1=1, target_qubit2=3\n",
90+
">>> 13 CNOT target_qubit1=1, target_qubit2=3\n",
8991
"7\n",
90-
">>> 58 INIT target_qubit=4\n",
92+
">>> 14 INIT target_qubit=4\n",
9193
"8\n",
92-
">>> 62 CNOT target_qubit1=1, target_qubit2=4\n",
94+
">>> 18 CNOT target_qubit1=1, target_qubit2=4\n",
9395
"9\n",
94-
">>> 63 INIT target_qubit=5\n",
96+
">>> 19 INIT target_qubit=5\n",
9597
"10\n",
96-
">>> 67 CNOT target_qubit1=1, target_qubit2=5\n",
98+
">>> 23 CNOT target_qubit1=2, target_qubit2=5\n",
9799
"11\n",
98-
">>> 71 CNOT target_qubit1=2, target_qubit2=5\n",
100+
">>> 27 CNOT target_qubit1=3, target_qubit2=5\n",
99101
"12\n",
100-
">>> 75 CNOT target_qubit1=2, target_qubit2=5\n",
101-
"13\n",
102-
">>> 79 CNOT target_qubit1=3, target_qubit2=5\n",
103-
"14\n",
104-
">>> 83 CNOT target_qubit1=3, target_qubit2=5\n",
105-
"15\n",
106-
">>> 87 CNOT target_qubit1=4, target_qubit2=5\n",
107-
"16\n",
108-
">>> 88 DestructiveM target_qubit=5, sym_name=DestructiveM_cat_prep_5_2\n",
109-
">>> Fail!\n",
110-
"The cat state preparation circuit is not fault-tolerant.\n"
102+
">>> 28 DestructiveM target_qubit=5, sym_name=DestructiveM_cat_prep_5_1\n",
103+
">>> Fail!\n"
111104
]
105+
},
106+
{
107+
"name": "stderr",
108+
"output_type": "stream",
109+
"text": [
110+
"[ Info: '`bitwuzla -rwl 1`' is used as smt solver for FT_condition case\n",
111+
"[ Info: '`bitwuzla -rwl 1`' has solved the problem\n",
112+
"[ Info: The assignment that generates the bug has been written to ./_temp_check_FT_condition_.output\n"
113+
]
114+
},
115+
{
116+
"data": {
117+
"text/plain": [
118+
"False"
119+
]
120+
},
121+
"execution_count": 3,
122+
"metadata": {},
123+
"output_type": "execute_result"
112124
}
113125
],
114126
"source": [
@@ -131,29 +143,34 @@
131143
" res = 0;\n",
132144
" h state[0];\n",
133145
"\n",
134-
" // QASM ranges are inclusive for both start and end\n",
146+
" // QASM loops supported\n",
135147
" for int i in [1:(size-1)] {\n",
136148
" reset state[i];\n",
137149
" cx state[0], state[i];\n",
138150
" }\n",
139151
"\n",
140152
" // Parity check\n",
141153
" reset ancilla;\n",
142-
" for int i in [1:(size-1)] {\n",
143-
" cx state[i-1], ancilla;\n",
144-
" cx state[i], ancilla;\n",
154+
" { // Fails check\n",
155+
" cx state[1], ancilla;\n",
156+
" cx state[2], ancilla;\n",
145157
" }\n",
158+
"\n",
159+
" /*\n",
160+
" { //passes check\n",
161+
" cx state[2], ancilla;\n",
162+
" cx state[3], ancilla;\n",
163+
" }*/\n",
146164
" res = measure ancilla;\n",
147165
" }\n",
148166
"}\n",
149167
"\"\"\".replace(\"__NUM_QUBITS__\", str(num_qubits))\n",
150168
"\n",
151169
"res = ft_check(code, circuit, \"cat_prep\", \"prepare\", num_ancilla=1)\n",
152170
"\n",
153-
"if res:\n",
154-
" print(\"The cat state preparation circuit is fault-tolerant.\")\n",
155-
"else:\n",
156-
" print(\"The cat state preparation circuit is not fault-tolerant.\")"
171+
"if not res.is_ft:\n",
172+
" print(\"Circuit is not fault tolerant.\")\n",
173+
" print(f\"Error cause: {res.error_cause}\")\n"
157174
]
158175
},
159176
{

src/ucc_ft/checker.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -688,9 +688,17 @@ def error_free_symbolic_output(
688688
pass
689689

690690

691+
@dataclass
692+
class FTErrorLocation:
693+
source_line: int
694+
qubit_index: int
695+
error_type: str
696+
697+
691698
class FTCheckResult:
692-
def __init__(self, is_ft: bool):
699+
def __init__(self, is_ft: bool, error_cause: FTErrorLocation = None):
693700
self.is_ft = is_ft
701+
self.error_cause = error_cause
694702

695703
def __bool__(self):
696704
return self.is_ft
@@ -796,5 +804,12 @@ def ft_check_ideal(
796804
meas_result=meas_result,
797805
meas_gt=meas_gt,
798806
):
807+
# Extract the error information and relate back to the line in the code
808+
# err_location = FTErrorLocation(
809+
# source_line=,
810+
# qubit_index=cfg.qubit_index,
811+
# error_type=cfg.error_type,
812+
# )
813+
# return FTCheckResult(False, err_location)
799814
return FTCheckResult(False)
800815
return FTCheckResult(True)

0 commit comments

Comments
 (0)