pyqrack-cpu-complex128 2.21.1__tar.gz → 2.22.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (30) hide show
  1. {pyqrack_cpu_complex128-2.21.1/pyqrack_cpu_complex128.egg-info → pyqrack_cpu_complex128-2.22.0}/PKG-INFO +1 -1
  2. {pyqrack_cpu_complex128-2.21.1 → pyqrack_cpu_complex128-2.22.0}/pyqrack/qrack_ace_backend.py +93 -292
  3. {pyqrack_cpu_complex128-2.21.1 → pyqrack_cpu_complex128-2.22.0/pyqrack_cpu_complex128.egg-info}/PKG-INFO +1 -1
  4. {pyqrack_cpu_complex128-2.21.1 → pyqrack_cpu_complex128-2.22.0}/setup.py +1 -1
  5. {pyqrack_cpu_complex128-2.21.1 → pyqrack_cpu_complex128-2.22.0}/LICENSE +0 -0
  6. {pyqrack_cpu_complex128-2.21.1 → pyqrack_cpu_complex128-2.22.0}/MANIFEST.in +0 -0
  7. {pyqrack_cpu_complex128-2.21.1 → pyqrack_cpu_complex128-2.22.0}/Makefile +0 -0
  8. {pyqrack_cpu_complex128-2.21.1 → pyqrack_cpu_complex128-2.22.0}/README.md +0 -0
  9. {pyqrack_cpu_complex128-2.21.1 → pyqrack_cpu_complex128-2.22.0}/pyproject.toml +0 -0
  10. {pyqrack_cpu_complex128-2.21.1 → pyqrack_cpu_complex128-2.22.0}/pyqrack/__init__.py +0 -0
  11. {pyqrack_cpu_complex128-2.21.1 → pyqrack_cpu_complex128-2.22.0}/pyqrack/neuron_activation_fn.py +0 -0
  12. {pyqrack_cpu_complex128-2.21.1 → pyqrack_cpu_complex128-2.22.0}/pyqrack/pauli.py +0 -0
  13. {pyqrack_cpu_complex128-2.21.1 → pyqrack_cpu_complex128-2.22.0}/pyqrack/qrack_circuit.py +0 -0
  14. {pyqrack_cpu_complex128-2.21.1 → pyqrack_cpu_complex128-2.22.0}/pyqrack/qrack_near_clifford_qec_backend.py +0 -0
  15. {pyqrack_cpu_complex128-2.21.1 → pyqrack_cpu_complex128-2.22.0}/pyqrack/qrack_neuron.py +0 -0
  16. {pyqrack_cpu_complex128-2.21.1 → pyqrack_cpu_complex128-2.22.0}/pyqrack/qrack_neuron_torch_layer.py +0 -0
  17. {pyqrack_cpu_complex128-2.21.1 → pyqrack_cpu_complex128-2.22.0}/pyqrack/qrack_simulator.py +0 -0
  18. {pyqrack_cpu_complex128-2.21.1 → pyqrack_cpu_complex128-2.22.0}/pyqrack/qrack_stabilizer.py +0 -0
  19. {pyqrack_cpu_complex128-2.21.1 → pyqrack_cpu_complex128-2.22.0}/pyqrack/qrack_system/__init__.py +0 -0
  20. {pyqrack_cpu_complex128-2.21.1 → pyqrack_cpu_complex128-2.22.0}/pyqrack/qrack_system/qrack_system.py +0 -0
  21. {pyqrack_cpu_complex128-2.21.1 → pyqrack_cpu_complex128-2.22.0}/pyqrack/quimb_circuit_type.py +0 -0
  22. {pyqrack_cpu_complex128-2.21.1 → pyqrack_cpu_complex128-2.22.0}/pyqrack/stats/__init__.py +0 -0
  23. {pyqrack_cpu_complex128-2.21.1 → pyqrack_cpu_complex128-2.22.0}/pyqrack/stats/load_quantized_data.py +0 -0
  24. {pyqrack_cpu_complex128-2.21.1 → pyqrack_cpu_complex128-2.22.0}/pyqrack/stats/quantize_by_range.py +0 -0
  25. {pyqrack_cpu_complex128-2.21.1 → pyqrack_cpu_complex128-2.22.0}/pyqrack_cpu_complex128.egg-info/SOURCES.txt +0 -0
  26. {pyqrack_cpu_complex128-2.21.1 → pyqrack_cpu_complex128-2.22.0}/pyqrack_cpu_complex128.egg-info/dependency_links.txt +0 -0
  27. {pyqrack_cpu_complex128-2.21.1 → pyqrack_cpu_complex128-2.22.0}/pyqrack_cpu_complex128.egg-info/not-zip-safe +0 -0
  28. {pyqrack_cpu_complex128-2.21.1 → pyqrack_cpu_complex128-2.22.0}/pyqrack_cpu_complex128.egg-info/requires.txt +0 -0
  29. {pyqrack_cpu_complex128-2.21.1 → pyqrack_cpu_complex128-2.22.0}/pyqrack_cpu_complex128.egg-info/top_level.txt +0 -0
  30. {pyqrack_cpu_complex128-2.21.1 → pyqrack_cpu_complex128-2.22.0}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pyqrack-cpu-complex128
3
- Version: 2.21.1
3
+ Version: 2.22.0
4
4
  Summary: pyqrack - Pure Python vm6502q/qrack Wrapper
5
5
  Home-page: https://github.com/vm6502q/pyqrack
6
6
  Author: Daniel Strano
@@ -7,7 +7,6 @@
7
7
  import math
8
8
  import os
9
9
  import random
10
- from collections import deque
11
10
 
12
11
  from .qrack_system import Qrack
13
12
  from .qrack_simulator import QrackSimulator
@@ -238,7 +237,6 @@ class QrackAceBackend:
238
237
  is_host_pointer=(True if os.environ.get("PYQRACK_HOST_POINTER_DEFAULT_ON") else False),
239
238
  is_near_clifford_tableau_writer=False,
240
239
  noise=0,
241
- history_window=0,
242
240
  is_torus=True,
243
241
  is_1d_chain=False,
244
242
  is_error_detection=True,
@@ -250,7 +248,6 @@ class QrackAceBackend:
250
248
  long_range_columns = to_clone.long_range_columns
251
249
  long_range_rows = to_clone.long_range_rows
252
250
  is_transpose = to_clone.is_transpose
253
- history_window = to_clone.history_window
254
251
  is_torus = to_clone.is_torus
255
252
  is_1d_chain = to_clone.is_1d_chain
256
253
  is_error_detection = to_clone.is_error_detection
@@ -259,15 +256,12 @@ class QrackAceBackend:
259
256
  qubit_count = 0
260
257
  if long_range_columns < 0:
261
258
  long_range_columns = 0
262
- if history_window < 0:
263
- history_window = 0
264
259
 
265
260
  self.is_1d_chain = is_1d_chain
266
261
  self._factor_width(qubit_count, is_transpose)
267
262
  self.long_range_columns = long_range_columns
268
263
  self.long_range_rows = long_range_rows
269
264
  self.is_transpose = is_transpose
270
- self.history_window = history_window
271
265
  self.is_torus = is_torus
272
266
  self.is_error_detection = is_error_detection
273
267
  self.is_boundary_repetition_code = is_boundary_repetition_code
@@ -282,6 +276,14 @@ class QrackAceBackend:
282
276
  self._epsilon = 2**-24
283
277
  self._ps_epsilon = 2**-12
284
278
 
279
+ # Boundary, on a single qubit's one_minus_r (see _get_bloch_angles),
280
+ # between "more separable" (rotation toward consensus is real,
281
+ # useful reconciliation) and "more entangled" (rotation only
282
+ # scrambles a real correlation with another logical qubit's
283
+ # replica -- see _correct). Default is the point where a single
284
+ # qubit's linear entropy is half its maximum.
285
+ self._rot_epsilon = (1.0 - 1.0 / math.sqrt(2)) / 2
286
+
285
287
  self._coupling_map = None
286
288
 
287
289
  # If there's only one or zero "False" columns or rows,
@@ -335,28 +337,6 @@ class QrackAceBackend:
335
337
 
336
338
  self._qubits = []
337
339
  self._lhv = {}
338
- if self.history_window > 0:
339
- if to_clone and to_clone._coupling_history is not None:
340
- self._coupling_history = {
341
- k: deque(v, maxlen=self.history_window)
342
- for k, v in to_clone._coupling_history.items()
343
- }
344
- self._coupling_history_rev = dict(to_clone._coupling_history_rev)
345
- self._pending_skip = {k: set(v) for k, v in to_clone._pending_skip.items()}
346
- self._stale_replicas = {k: set(v) for k, v in to_clone._stale_replicas.items()}
347
- self._witness_map = {k: dict(v) for k, v in to_clone._witness_map.items()}
348
- else:
349
- self._coupling_history = {}
350
- self._coupling_history_rev = {}
351
- self._pending_skip = {}
352
- self._stale_replicas = {}
353
- self._witness_map = {}
354
- else:
355
- self._coupling_history = None
356
- self._coupling_history_rev = None
357
- self._pending_skip = None
358
- self._stale_replicas = None
359
- self._witness_map = None
360
340
  sim_counts = [0] * sim_count
361
341
  sim_id = 0
362
342
  tot_qubits = 0
@@ -883,10 +863,8 @@ class QrackAceBackend:
883
863
  end_caps = [p0, p1, p3, p4]
884
864
  # Classify each end-cap as decisively high / decisively low /
885
865
  # undecided (within epsilon of 0.5), rather than a bare >=0.5
886
- # check -- a replica reading EXACTLY 0.5 (e.g. one just
887
- # H-reverted by _revert_shadow_commitment, genuinely carrying
888
- # zero information) was previously always counted as "high"
889
- # via this boundary convention alone.
866
+ # check -- a replica reading EXACTLY 0.5 was previously always
867
+ # counted as "high" via this boundary convention alone.
890
868
  high_count = sum(1 for x in end_caps if x > (0.5 + self._epsilon))
891
869
  low_count = sum(1 for x in end_caps if x < (0.5 - self._epsilon))
892
870
  undecided_count = len(end_caps) - high_count - low_count
@@ -945,8 +923,40 @@ class QrackAceBackend:
945
923
  # decoherence a physical rotation would cost it.
946
924
  # Indices 1-4 are all crossbar-extension slots with
947
925
  # no comparable real entanglement to lose.
926
+ # Only rotate a replica that is itself reasonably
927
+ # separable (its own reduced state still has a
928
+ # meaningfully-defined Bloch direction). A replica
929
+ # that's picked up genuine entanglement with another
930
+ # logical qubit's replica (e.g. via a real gate_fn
931
+ # coupling in _apply_coupling -- not just slot0; any
932
+ # of slots 1-4 can end up real-coupled depending on
933
+ # geometry) reads a Bloch vector dominated by
934
+ # simulator floating-point noise, not real
935
+ # information. Rotating it "toward consensus" in that
936
+ # regime doesn't change its own (already ~I/2)
937
+ # reduced state, but DOES apply an uncontrolled local
938
+ # unitary to one member of a real entangled pair,
939
+ # which scrambles the correlation basis the partner
940
+ # will later be measured against -- marginals stay
941
+ # near 0.5 (so this doesn't show up as a marginal
942
+ # bug), but pairwise correlation with the entangled
943
+ # partner is destroyed. Empirically confirmed via a
944
+ # boundary-to-boundary Bell-pair test: with
945
+ # unconditional rotation, Z-correlation between two
946
+ # coupled boundary qubits was ~0.51 (no better than
947
+ # uncorrelated) despite marginals reading correctly
948
+ # at ~0.5; gating this rotation on the replica's own
949
+ # separability (one_minus_r <= self._rot_epsilon)
950
+ # restores strong correlation. self._rot_epsilon
951
+ # defaults to (1 - 1/sqrt(2)) / 2, the point where a
952
+ # single qubit's linear entropy is half its maximum
953
+ # (Bloch length 1/sqrt(2)) -- past that point a
954
+ # replica is "more entangled than separable" and is
955
+ # left alone; short of it, the rotation still does
956
+ # real, useful reconciliation work.
948
957
  for x in range(1, 5):
949
- self._rotate_to_bloch(hq[x], a_target - a[x], i_target - i[x])
958
+ if [r0, r1, r2, r3, r4][x] <= self._rot_epsilon:
959
+ self._rotate_to_bloch(hq[x], a_target - a[x], i_target - i[x])
950
960
  # If every replica reads as maximally mixed (w_total ~ 0),
951
961
  # there is no well-defined direction to rotate toward at
952
962
  # all -- skip the rotation rather than rotate toward an
@@ -1086,7 +1096,8 @@ class QrackAceBackend:
1086
1096
  # comparable real entanglement to lose) are actually
1087
1097
  # rotated.
1088
1098
  for x in range(1, 3):
1089
- self._rotate_to_bloch(hq[x], a_target - a[x], i_target - i[x])
1099
+ if [r0, r1, r2][x] <= self._rot_epsilon:
1100
+ self._rotate_to_bloch(hq[x], a_target - a[x], i_target - i[x])
1090
1101
 
1091
1102
  if phase:
1092
1103
  for q in qb:
@@ -1113,17 +1124,14 @@ class QrackAceBackend:
1113
1124
  hq = self._unpack(lq)
1114
1125
  if len(hq) < 2:
1115
1126
  b = hq[0]
1116
- self._invalidate_for_gate(lq)
1117
1127
  self.sim[b[0]].u(b[1], th, ph, lm)
1118
1128
  return
1119
1129
 
1120
- skip = self._invalidate_for_gate(lq)
1121
1130
  qb, _ = QrackAceBackend._get_qb_lhv_indices(hq)
1122
1131
 
1123
1132
  for q in qb:
1124
1133
  b = hq[q]
1125
- if (b[0], b[1]) not in skip:
1126
- self.sim[b[0]].u(b[1], th, ph, lm)
1134
+ self.sim[b[0]].u(b[1], th, ph, lm)
1127
1135
 
1128
1136
  lhv = self._lhv.get(lq)
1129
1137
  if lhv is not None:
@@ -1131,87 +1139,18 @@ class QrackAceBackend:
1131
1139
 
1132
1140
  # Correction deferred to next 2-qubit gate (_cpauli calls _correct)
1133
1141
 
1134
- def _revert_shadow_commitment(self, lq1):
1135
- """Revert shadow-committed replicas recorded under lq1. H-reverts
1136
- each committed shadow replica (undoing the stale Z-basis commitment),
1137
- stores the reverted tuples in _pending_skip[lq2] so the NEXT gate on
1138
- that boundary qubit skips those replicas entirely (rotating an H-reverted
1139
- shadow replica from the wrong starting state gives a wrong result; the
1140
- right behavior is to skip it and let the next coupling gate re-derive
1141
- from scratch), and returns the reverted set for the immediate caller to
1142
- skip as well (for case A, where the control's own rotation should also
1143
- skip its own shadow replicas that were just un-committed)."""
1144
- if self._coupling_history is None:
1145
- return set()
1146
- hist = self._coupling_history.pop(lq1, None)
1147
- if hist is None:
1148
- return set()
1149
- reverted_all = set()
1150
- for lq2, targets in hist:
1151
- reverted = set()
1152
- for t_sim, t_idx in targets:
1153
- self.sim[t_sim].h(t_idx)
1154
- reverted.add((t_sim, t_idx))
1155
- # Store as pending skip for the NEXT gate on lq2 (case B):
1156
- # when the boundary qubit's own gate runs, it should skip
1157
- # these replicas rather than applying its gate to the freshly-
1158
- # H-reverted, uncommitted state.
1159
- if reverted:
1160
- existing = self._pending_skip.get(lq2, set())
1161
- self._pending_skip[lq2] = existing | reverted
1162
- existing_stale = self._stale_replicas.get(lq2, set())
1163
- self._stale_replicas[lq2] = existing_stale | reverted
1164
- self._coupling_history_rev.pop(lq2, None)
1165
- reverted_all |= reverted
1166
- return reverted_all
1167
-
1168
- def _invalidate_for_gate(self, lq):
1169
- """Called by every single-qubit gate dispatcher. Returns the set of
1170
- (sim_id, idx) shadow replicas that should be SKIPPED in the calling
1171
- gate's own application loop.
1172
- - Case A: lq is the coherent-partner (lq1) in a live history entry.
1173
- A gate on the control side invalidates the shadow commitment: reverts
1174
- the shadow targets via H (returning them to uncommitted 0.5), stores
1175
- them in pending_skip[lq2] for the NEXT gate on the boundary qubit,
1176
- and returns them for the immediate caller to skip as well (since the
1177
- control's own replica at slot0 may also be in the reverted set).
1178
- - Case B: lq is the boundary recipient (lq2) of a commitment that a
1179
- prior case-A revert already H-reverted. Consumes the pending_skip
1180
- set so the boundary gate doesn't apply itself to the freshly-
1181
- uncommitted replicas (which would give the wrong result from the
1182
- wrong starting state). Case B NEVER triggers a fresh revert --
1183
- only case A does, because only a gate on the control side actually
1184
- invalidates the commitment; a gate on the boundary side just needs
1185
- to avoid corrupting the already-reverted starting state."""
1186
- if self._coupling_history is None:
1187
- return set()
1188
- skip = set()
1189
- # Case A: lq is the coherent control side -- fire the revert.
1190
- if lq in self._coupling_history:
1191
- skip |= self._revert_shadow_commitment(lq)
1192
- # Case B: lq is the boundary side -- ONLY consume pending_skip,
1193
- # never trigger a fresh revert (that would incorrectly revert
1194
- # a still-valid commitment that no control-side gate has touched).
1195
- pending = self._pending_skip.pop(lq, None)
1196
- if pending:
1197
- skip |= pending
1198
- return skip
1199
-
1200
1142
  def r(self, p, th, lq):
1201
1143
  hq = self._unpack(lq)
1202
1144
  if len(hq) < 2:
1203
1145
  b = hq[0]
1204
- self._invalidate_for_gate(lq)
1205
1146
  self.sim[b[0]].r(p, th, b[1])
1206
1147
  return
1207
1148
 
1208
1149
  qb, _ = QrackAceBackend._get_qb_lhv_indices(hq)
1209
- skip = self._invalidate_for_gate(lq)
1210
1150
 
1211
1151
  for q in qb:
1212
1152
  b = hq[q]
1213
- if (b[0], b[1]) not in skip:
1214
- self.sim[b[0]].r(p, th, b[1])
1153
+ self.sim[b[0]].r(p, th, b[1])
1215
1154
 
1216
1155
  lhv = self._lhv.get(lq)
1217
1156
  if lhv is not None:
@@ -1228,17 +1167,14 @@ class QrackAceBackend:
1228
1167
  hq = self._unpack(lq)
1229
1168
  if len(hq) < 2:
1230
1169
  b = hq[0]
1231
- self._invalidate_for_gate(lq)
1232
1170
  self.sim[b[0]].h(b[1])
1233
1171
  return
1234
1172
 
1235
- skip = self._invalidate_for_gate(lq)
1236
1173
  qb, _ = QrackAceBackend._get_qb_lhv_indices(hq)
1237
1174
 
1238
1175
  for q in qb:
1239
1176
  b = hq[q]
1240
- if (b[0], b[1]) not in skip:
1241
- self.sim[b[0]].h(b[1])
1177
+ self.sim[b[0]].h(b[1])
1242
1178
 
1243
1179
  lhv = self._lhv.get(lq)
1244
1180
  if lhv is not None:
@@ -1250,17 +1186,14 @@ class QrackAceBackend:
1250
1186
  hq = self._unpack(lq)
1251
1187
  if len(hq) < 2:
1252
1188
  b = hq[0]
1253
- self._invalidate_for_gate(lq)
1254
1189
  self.sim[b[0]].s(b[1])
1255
1190
  return
1256
1191
 
1257
- skip = self._invalidate_for_gate(lq)
1258
1192
  qb, _ = QrackAceBackend._get_qb_lhv_indices(hq)
1259
1193
 
1260
1194
  for q in qb:
1261
1195
  b = hq[q]
1262
- if (b[0], b[1]) not in skip:
1263
- self.sim[b[0]].s(b[1])
1196
+ self.sim[b[0]].s(b[1])
1264
1197
 
1265
1198
  lhv = self._lhv.get(lq)
1266
1199
  if lhv is not None:
@@ -1270,17 +1203,14 @@ class QrackAceBackend:
1270
1203
  hq = self._unpack(lq)
1271
1204
  if len(hq) < 2:
1272
1205
  b = hq[0]
1273
- self._invalidate_for_gate(lq)
1274
1206
  self.sim[b[0]].adjs(b[1])
1275
1207
  return
1276
1208
 
1277
- skip = self._invalidate_for_gate(lq)
1278
1209
  qb, _ = QrackAceBackend._get_qb_lhv_indices(hq)
1279
1210
 
1280
1211
  for q in qb:
1281
1212
  b = hq[q]
1282
- if (b[0], b[1]) not in skip:
1283
- self.sim[b[0]].adjs(b[1])
1213
+ self.sim[b[0]].adjs(b[1])
1284
1214
 
1285
1215
  lhv = self._lhv.get(lq)
1286
1216
  if lhv is not None:
@@ -1290,17 +1220,14 @@ class QrackAceBackend:
1290
1220
  hq = self._unpack(lq)
1291
1221
  if len(hq) < 2:
1292
1222
  b = hq[0]
1293
- self._invalidate_for_gate(lq)
1294
1223
  self.sim[b[0]].sx(b[1])
1295
1224
  return
1296
1225
 
1297
- skip = self._invalidate_for_gate(lq)
1298
1226
  qb, _ = QrackAceBackend._get_qb_lhv_indices(hq)
1299
1227
 
1300
1228
  for q in qb:
1301
1229
  b = hq[q]
1302
- if (b[0], b[1]) not in skip:
1303
- self.sim[b[0]].sx(b[1])
1230
+ self.sim[b[0]].sx(b[1])
1304
1231
 
1305
1232
  lhv = self._lhv.get(lq)
1306
1233
  if lhv is not None:
@@ -1310,17 +1237,14 @@ class QrackAceBackend:
1310
1237
  hq = self._unpack(lq)
1311
1238
  if len(hq) < 2:
1312
1239
  b = hq[0]
1313
- self._invalidate_for_gate(lq)
1314
1240
  self.sim[b[0]].adjsx(b[1])
1315
1241
  return
1316
1242
 
1317
- skip = self._invalidate_for_gate(lq)
1318
1243
  qb, _ = QrackAceBackend._get_qb_lhv_indices(hq)
1319
1244
 
1320
1245
  for q in qb:
1321
1246
  b = hq[q]
1322
- if (b[0], b[1]) not in skip:
1323
- self.sim[b[0]].adjsx(b[1])
1247
+ self.sim[b[0]].adjsx(b[1])
1324
1248
 
1325
1249
  lhv = self._lhv.get(lq)
1326
1250
  if lhv is not None:
@@ -1454,17 +1378,14 @@ class QrackAceBackend:
1454
1378
  hq = self._unpack(lq)
1455
1379
  if len(hq) < 2:
1456
1380
  b = hq[0]
1457
- self._invalidate_for_gate(lq)
1458
1381
  self.sim[b[0]].x(b[1])
1459
1382
  return
1460
1383
 
1461
- skip = self._invalidate_for_gate(lq)
1462
1384
  qb, _ = QrackAceBackend._get_qb_lhv_indices(hq)
1463
1385
 
1464
1386
  for q in qb:
1465
1387
  b = hq[q]
1466
- if (b[0], b[1]) not in skip:
1467
- self.sim[b[0]].x(b[1])
1388
+ self.sim[b[0]].x(b[1])
1468
1389
 
1469
1390
  lhv = self._lhv.get(lq)
1470
1391
  if lhv is not None:
@@ -1474,17 +1395,14 @@ class QrackAceBackend:
1474
1395
  hq = self._unpack(lq)
1475
1396
  if len(hq) < 2:
1476
1397
  b = hq[0]
1477
- self._invalidate_for_gate(lq)
1478
1398
  self.sim[b[0]].y(b[1])
1479
1399
  return
1480
1400
 
1481
- skip = self._invalidate_for_gate(lq)
1482
1401
  qb, _ = QrackAceBackend._get_qb_lhv_indices(hq)
1483
1402
 
1484
1403
  for q in qb:
1485
1404
  b = hq[q]
1486
- if (b[0], b[1]) not in skip:
1487
- self.sim[b[0]].y(b[1])
1405
+ self.sim[b[0]].y(b[1])
1488
1406
 
1489
1407
  lhv = self._lhv.get(lq)
1490
1408
  if lhv is not None:
@@ -1494,17 +1412,14 @@ class QrackAceBackend:
1494
1412
  hq = self._unpack(lq)
1495
1413
  if len(hq) < 2:
1496
1414
  b = hq[0]
1497
- self._invalidate_for_gate(lq)
1498
1415
  self.sim[b[0]].z(b[1])
1499
1416
  return
1500
1417
 
1501
- skip = self._invalidate_for_gate(lq)
1502
1418
  qb, _ = QrackAceBackend._get_qb_lhv_indices(hq)
1503
1419
 
1504
1420
  for q in qb:
1505
1421
  b = hq[q]
1506
- if (b[0], b[1]) not in skip:
1507
- self.sim[b[0]].z(b[1])
1422
+ self.sim[b[0]].z(b[1])
1508
1423
 
1509
1424
  lhv = self._lhv.get(lq)
1510
1425
  if lhv is not None:
@@ -1514,17 +1429,14 @@ class QrackAceBackend:
1514
1429
  hq = self._unpack(lq)
1515
1430
  if len(hq) < 2:
1516
1431
  b = hq[0]
1517
- self._invalidate_for_gate(lq)
1518
1432
  self.sim[b[0]].t(b[1])
1519
1433
  return
1520
1434
 
1521
- skip = self._invalidate_for_gate(lq)
1522
1435
  qb, _ = QrackAceBackend._get_qb_lhv_indices(hq)
1523
1436
 
1524
1437
  for q in qb:
1525
1438
  b = hq[q]
1526
- if (b[0], b[1]) not in skip:
1527
- self.sim[b[0]].t(b[1])
1439
+ self.sim[b[0]].t(b[1])
1528
1440
 
1529
1441
  lhv = self._lhv.get(lq)
1530
1442
  if lhv is not None:
@@ -1534,17 +1446,14 @@ class QrackAceBackend:
1534
1446
  hq = self._unpack(lq)
1535
1447
  if len(hq) < 2:
1536
1448
  b = hq[0]
1537
- self._invalidate_for_gate(lq)
1538
1449
  self.sim[b[0]].adjt(b[1])
1539
1450
  return
1540
1451
 
1541
- skip = self._invalidate_for_gate(lq)
1542
1452
  qb, _ = QrackAceBackend._get_qb_lhv_indices(hq)
1543
1453
 
1544
1454
  for q in qb:
1545
1455
  b = hq[q]
1546
- if (b[0], b[1]) not in skip:
1547
- self.sim[b[0]].adjt(b[1])
1456
+ self.sim[b[0]].adjt(b[1])
1548
1457
 
1549
1458
  lhv = self._lhv.get(lq)
1550
1459
  if lhv is not None:
@@ -1609,16 +1518,6 @@ class QrackAceBackend:
1609
1518
 
1610
1519
  def _apply_coupling(self, pauli, anti, qb1, hq1, qb2, hq2, lq1_lr, lq1=None, lq2=None):
1611
1520
  shadow_targets = []
1612
- witnessed_targets = [] # (shadow_target, witness_replica) pairs --
1613
- # "easy case": a replica of the SAME target
1614
- # logical qubit lives in the SAME simulator
1615
- # as the control replica used for this
1616
- # shadow pair, and is therefore always
1617
- # exactly correct regardless of how many
1618
- # later gates happen to the control. No
1619
- # bounded window, no reactive invalidation
1620
- # needed for these -- see
1621
- # _resolve_witnessed_shadow.
1622
1521
 
1623
1522
  # Logical-level error-detection gadget: captures lq1's LOGICAL
1624
1523
  # value (and lq2's too, for CZ specifically -- see below) into a
@@ -1660,7 +1559,7 @@ class QrackAceBackend:
1660
1559
  # Control bit-flip
1661
1560
  self.cx(lq1, anc1)
1662
1561
  if len(hq1) > 1:
1663
- if hq1[0][0] != hq2[0][0]:
1562
+ if hq2[0][0] != hq1[0][0]:
1664
1563
  anc1b = self._detect_ancilla1_lq[hq2[0][0]]
1665
1564
  # Control bit-flip
1666
1565
  self.cx(lq1, anc1b)
@@ -1674,6 +1573,32 @@ class QrackAceBackend:
1674
1573
  self.cx(lq1, anc2)
1675
1574
  self._in_gadget_capture = False
1676
1575
 
1576
+ # A target replica (q2) that shares a simulator with ANY control
1577
+ # replica in qb1 is going to receive a REAL, exact gate from that
1578
+ # control at some point in the loop below (the `b1[0] == b2[0]`
1579
+ # branch) -- possibly on a LATER q1 iteration than the current
1580
+ # one. If an EARLIER q1 iteration also shadow-couples to that
1581
+ # same q2 (purely from an incidental b1[1] == b2[1] index match,
1582
+ # unrelated to the real pairing), that shadow write corrupts the
1583
+ # target before the authoritative real gate ever touches it: a
1584
+ # probabilistic X flip from an independent control replica can
1585
+ # invert the correlation sign the real CNOT is about to
1586
+ # establish. Confirmed directly: for a boundary-to-boundary
1587
+ # coupling, measuring the raw physical replica pairs that DO
1588
+ # share a simulator (bypassing all of _correct/m's classical
1589
+ # reconciliation, and with is_error_detection off) showed near-
1590
+ # perfect agreement for the one pair untouched by any earlier
1591
+ # shadow write, but only ~50-60% agreement (chance level) for
1592
+ # the pairs a prior iteration's shadow write had already
1593
+ # perturbed. Precomputing which q2 indices are real-gated by
1594
+ # *something* in qb1, and excluding them from shadow_fn
1595
+ # entirely (regardless of which q1 the shadow attempt comes
1596
+ # from), avoids ever shadow-writing over a target that a real
1597
+ # gate elsewhere in this same call is authoritative for.
1598
+ real_gated_q2 = {
1599
+ q2 for q2 in qb2 if any(hq1[q1][0] == hq2[q2][0] for q1 in qb1)
1600
+ }
1601
+
1677
1602
  for q1 in qb1:
1678
1603
  b1 = hq1[q1]
1679
1604
  gate_fn, shadow_fn = self._get_gate(pauli, anti, b1[0])
@@ -1696,11 +1621,9 @@ class QrackAceBackend:
1696
1621
  # (harmless, but confusing). Removed rather than kept:
1697
1622
  # there is no length-2 replica structure anywhere in this
1698
1623
  # class for it to ever fire on.
1699
- elif lq1_lr or (b1[1] == b2[1]):
1624
+ elif (q2 not in real_gated_q2) and (lq1_lr or (b1[1] == b2[1])):
1700
1625
  shadow_fn(b1, b2)
1701
1626
  shadow_targets.append(b2)
1702
- if witness is not None and witness != b2:
1703
- witnessed_targets.append((b2, witness))
1704
1627
 
1705
1628
  is_flipped = False
1706
1629
  if anc1 is not None:
@@ -1728,10 +1651,7 @@ class QrackAceBackend:
1728
1651
  p1 = self.sim[anc_sim].prob(anc_idx)
1729
1652
  anc_sim, anc_idx = self._qubits[anc1b][0]
1730
1653
  p2 = self.sim[anc_sim].prob(anc_idx)
1731
- if (self._ps_epsilon >= (1.0 - p1)) and (self._ps_epsilon >= (1.0 - p2)):
1732
- b1 = self.force_m(anc1, True)
1733
- b2 = self.force_m(anc1b, True)
1734
- elif self._ps_epsilon >= (1.0 - p1):
1654
+ if self._ps_epsilon >= (1.0 - p1):
1735
1655
  b1 = self.force_m(anc1, True)
1736
1656
  if self._ps_epsilon >= p2:
1737
1657
  b2 = self.force_m(anc1b, True)
@@ -1789,30 +1709,6 @@ class QrackAceBackend:
1789
1709
  self.x(lq2)
1790
1710
  self._in_gadget_capture = False
1791
1711
 
1792
- if lq2 is not None and witnessed_targets and self._witness_map is not None:
1793
- wmap = self._witness_map.setdefault(lq2, {})
1794
- for target_replica, witness_replica in witnessed_targets:
1795
- wmap[target_replica] = witness_replica
1796
-
1797
- if (
1798
- self._coupling_history is not None
1799
- and lq1 is not None
1800
- and lq2 is not None
1801
- and shadow_targets
1802
- ):
1803
- # Only the NON-witnessed shadow targets need the bounded,
1804
- # reactive history/invalidation machinery -- witnessed ones are
1805
- # always resolvable directly and don't need tracking here at all.
1806
- witnessed_set = {t for t, _ in witnessed_targets}
1807
- unwitnessed = tuple(t for t in shadow_targets if t not in witnessed_set)
1808
- if unwitnessed:
1809
- entry = (lq2, tuple(unwitnessed))
1810
- hist = self._coupling_history.setdefault(
1811
- lq1, deque(maxlen=self.history_window)
1812
- )
1813
- hist.append(entry)
1814
- self._coupling_history_rev[lq2] = lq1
1815
-
1816
1712
  # A "coupled twirling" scheme was tried here -- after every real
1817
1713
  # inter-logical-qubit coupling gate, SWAP which physical qubit is
1818
1714
  # registered as hq[side] with one of its level-0 scratch qubits, to
@@ -2025,35 +1921,6 @@ class QrackAceBackend:
2025
1921
  sims2 = {r[0] for r in hq2}
2026
1922
 
2027
1923
  if sims1.isdisjoint(sims2):
2028
- # Zero shared physical substrate: a SWAP is, by definition,
2029
- # just "exchange which logical index refers to which
2030
- # subsystem" -- for two qubits with no shared simulator or
2031
- # replica at all, that IS the swap, exactly, with zero gates
2032
- # and zero error, regardless of what either is entangled
2033
- # with elsewhere (SWAP is a relabeling of tensor-factor
2034
- # indices; nothing about that depends on which name we call
2035
- # either subsystem). This also sidesteps the separate
2036
- # _apply_coupling local-index-match limitation entirely for
2037
- # this case, since no shadow coupling is attempted between
2038
- # these qubits at all.
2039
- #
2040
- # Must fully resolve any pending shadow/consensus state tied
2041
- # to EACH qubit's CURRENT identity before relabeling --
2042
- # otherwise a cross-reference recorded under the old identity
2043
- # (e.g. coupling_history[lq1], witness_map[lq2]) would
2044
- # silently end up describing the wrong physical qubit
2045
- # afterward. Reuses the same resolution methods prob() and
2046
- # every single-qubit gate already depend on for correctness,
2047
- # rather than hand-rolling new bookkeeping that could miss a
2048
- # cross-reference.
2049
- self._invalidate_for_gate(lq1)
2050
- self._invalidate_for_gate(lq2)
2051
- if len(hq1) >= 2:
2052
- self._resolve_witnessed_shadow(lq1)
2053
- self._resolve_pending_skip(lq1)
2054
- if len(hq2) >= 2:
2055
- self._resolve_witnessed_shadow(lq2)
2056
- self._resolve_pending_skip(lq2)
2057
1924
  self._correct(lq1)
2058
1925
  self._correct(lq2)
2059
1926
 
@@ -2100,6 +1967,13 @@ class QrackAceBackend:
2100
1967
  self.cx(lq1, lq2)
2101
1968
  return
2102
1969
 
1970
+ # Boundary-to-boundary handling
1971
+ if (len(hq1) > 1) and (len(hq2) > 1):
1972
+ self.cx(lq1, lq2)
1973
+ self.cx(lq2, lq1)
1974
+ self.cx(lq1, lq2)
1975
+ return
1976
+
2103
1977
  # Fast/exact path: every replica of lq1 lines up, position-for-
2104
1978
  # position, with the corresponding replica of lq2 on the SAME
2105
1979
  # underlying simulator. A native swap() there is pure index
@@ -2244,85 +2118,12 @@ class QrackAceBackend:
2244
2118
  self.cz(lq1, lq2)
2245
2119
  self.swap(lq1, lq2)
2246
2120
 
2247
- def _resolve_pending_skip(self, lq):
2248
- """If lq has replicas recorded as STALE (H-reverted after an
2249
- invalidating control-side rotation, then skipped by their own
2250
- later gate because _invalidate_for_gate's Case B already popped
2251
- _pending_skip to decide what to skip -- consuming that record
2252
- before it could ever reach measurement time), force those
2253
- specific replicas to match hq[0] directly.
2254
-
2255
- NOTE: this deliberately does NOT read _pending_skip, because
2256
- _invalidate_for_gate's Case B already pops (consumes) it the
2257
- moment the boundary qubit's own next gate runs -- by the time
2258
- prob()/m() is called at actual measurement time, _pending_skip is
2259
- already empty even though the replicas never got their intended
2260
- rotation. _stale_replicas is a SEPARATE record, populated
2261
- alongside _pending_skip in _revert_shadow_commitment, that is
2262
- NOT touched by Case B's pop -- only by this method, at the point
2263
- where staleness actually needs to be resolved.
2264
-
2265
- Forcing to match hq[0] requires no randomness (unlike an earlier
2266
- force-correlate-with-control attempt) because hq[0] -- the
2267
- replica sharing a real simulator with the control, via the exact
2268
- gate_fn path in _apply_coupling -- is never itself added to
2269
- shadow_targets/_pending_skip/_stale_replicas, and is verified
2270
- exact following the _ct_pair_prob/_cz_shadow phase-kickback fix."""
2271
- if self._stale_replicas is None:
2272
- return
2273
- stale = self._stale_replicas.pop(lq, None)
2274
- if not stale:
2275
- return
2276
- hq = self._unpack(lq)
2277
- b0 = hq[0]
2278
- ground_truth = self.sim[b0[0]].m(b0[1])
2279
- for (t_sim, t_idx) in stale:
2280
- self.sim[t_sim].force_m(t_idx, ground_truth)
2281
-
2282
- def _resolve_witnessed_shadow(self, lq):
2283
- """The 'easy case' generalization of history_window: if lq has any
2284
- shadow replicas with a recorded witness (a replica of the SAME
2285
- logical qubit living in the SAME simulator as the control used for
2286
- that shadow coupling), force each one to match its witness's
2287
- CURRENT value now, unconditionally.
2288
-
2289
- This is deliberately unbounded -- no history_window, no deque, no
2290
- reactive invalidation on the control's later gates at all. It
2291
- doesn't need any of that, because the witness is a real quantum
2292
- register: it automatically, continuously reflects the correct
2293
- joint state through ANY NUMBER of intervening gates on the
2294
- control (or on itself), for free, simply by being the same real
2295
- simulator. No matter how long resolution is deferred -- one gate
2296
- later or a thousand -- matching the witness at the moment it's
2297
- actually needed is exactly as correct as matching it immediately
2298
- would have been. This is why the fix for the 'easy case' doesn't
2299
- need a window at all, bounded or otherwise: unlike the harder,
2300
- no-witness case (still handled by the existing bounded
2301
- _coupling_history / _stale_replicas machinery, left for a
2302
- belief-propagation-style treatment another day), there's no
2303
- approximation being deferred here, so there's nothing for a
2304
- window size to trade off against."""
2305
- if self._witness_map is None:
2306
- return
2307
- wmap = self._witness_map.pop(lq, None)
2308
- if not wmap:
2309
- return
2310
- for (t_sim, t_idx), (w_sim, w_idx) in wmap.items():
2311
- ground_truth = self.sim[w_sim].m(w_idx)
2312
- self.sim[t_sim].force_m(t_idx, ground_truth)
2313
-
2314
2121
  def prob(self, lq):
2315
2122
  hq = self._unpack(lq)
2316
2123
  if len(hq) < 2:
2317
2124
  b = hq[0]
2318
2125
  return self.sim[b[0]].prob(b[1])
2319
2126
 
2320
- if self._witness_map is not None:
2321
- self._resolve_witnessed_shadow(lq)
2322
-
2323
- if self._stale_replicas is not None:
2324
- self._resolve_pending_skip(lq)
2325
-
2326
2127
  self._correct(lq)
2327
2128
  if len(hq) == 5:
2328
2129
  # RMS
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pyqrack-cpu-complex128
3
- Version: 2.21.1
3
+ Version: 2.22.0
4
4
  Summary: pyqrack - Pure Python vm6502q/qrack Wrapper
5
5
  Home-page: https://github.com/vm6502q/pyqrack
6
6
  Author: Daniel Strano
@@ -7,7 +7,7 @@ from setuptools import setup
7
7
  from setuptools.command.build_py import build_py
8
8
 
9
9
 
10
- VERSION = "2.21.1"
10
+ VERSION = "2.22.0"
11
11
 
12
12
  # Read long description from README.
13
13
  README_PATH = os.path.join(os.path.abspath(os.path.dirname(__file__)), 'README.md')