pyqrack-cuda 1.44.1__tar.gz → 1.44.3__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_cuda-1.44.1/pyqrack_cuda.egg-info → pyqrack_cuda-1.44.3}/PKG-INFO +1 -1
  2. pyqrack_cuda-1.44.3/pyqrack/qrack_ace_backend.py +610 -0
  3. {pyqrack_cuda-1.44.1 → pyqrack_cuda-1.44.3}/pyqrack/qrack_simulator.py +1 -1
  4. {pyqrack_cuda-1.44.1 → pyqrack_cuda-1.44.3/pyqrack_cuda.egg-info}/PKG-INFO +1 -1
  5. {pyqrack_cuda-1.44.1 → pyqrack_cuda-1.44.3}/setup.py +1 -1
  6. pyqrack_cuda-1.44.1/pyqrack/qrack_ace_backend.py +0 -287
  7. {pyqrack_cuda-1.44.1 → pyqrack_cuda-1.44.3}/LICENSE +0 -0
  8. {pyqrack_cuda-1.44.1 → pyqrack_cuda-1.44.3}/MANIFEST.in +0 -0
  9. {pyqrack_cuda-1.44.1 → pyqrack_cuda-1.44.3}/Makefile +0 -0
  10. {pyqrack_cuda-1.44.1 → pyqrack_cuda-1.44.3}/README.md +0 -0
  11. {pyqrack_cuda-1.44.1 → pyqrack_cuda-1.44.3}/pyproject.toml +0 -0
  12. {pyqrack_cuda-1.44.1 → pyqrack_cuda-1.44.3}/pyqrack/__init__.py +0 -0
  13. {pyqrack_cuda-1.44.1 → pyqrack_cuda-1.44.3}/pyqrack/neuron_activation_fn.py +0 -0
  14. {pyqrack_cuda-1.44.1 → pyqrack_cuda-1.44.3}/pyqrack/pauli.py +0 -0
  15. {pyqrack_cuda-1.44.1 → pyqrack_cuda-1.44.3}/pyqrack/qrack_circuit.py +0 -0
  16. {pyqrack_cuda-1.44.1 → pyqrack_cuda-1.44.3}/pyqrack/qrack_neuron.py +0 -0
  17. {pyqrack_cuda-1.44.1 → pyqrack_cuda-1.44.3}/pyqrack/qrack_neuron_torch_layer.py +0 -0
  18. {pyqrack_cuda-1.44.1 → pyqrack_cuda-1.44.3}/pyqrack/qrack_stabilizer.py +0 -0
  19. {pyqrack_cuda-1.44.1 → pyqrack_cuda-1.44.3}/pyqrack/qrack_system/__init__.py +0 -0
  20. {pyqrack_cuda-1.44.1 → pyqrack_cuda-1.44.3}/pyqrack/qrack_system/qrack_system.py +0 -0
  21. {pyqrack_cuda-1.44.1 → pyqrack_cuda-1.44.3}/pyqrack/quimb_circuit_type.py +0 -0
  22. {pyqrack_cuda-1.44.1 → pyqrack_cuda-1.44.3}/pyqrack/stats/__init__.py +0 -0
  23. {pyqrack_cuda-1.44.1 → pyqrack_cuda-1.44.3}/pyqrack/stats/load_quantized_data.py +0 -0
  24. {pyqrack_cuda-1.44.1 → pyqrack_cuda-1.44.3}/pyqrack/stats/quantize_by_range.py +0 -0
  25. {pyqrack_cuda-1.44.1 → pyqrack_cuda-1.44.3}/pyqrack_cuda.egg-info/SOURCES.txt +0 -0
  26. {pyqrack_cuda-1.44.1 → pyqrack_cuda-1.44.3}/pyqrack_cuda.egg-info/dependency_links.txt +0 -0
  27. {pyqrack_cuda-1.44.1 → pyqrack_cuda-1.44.3}/pyqrack_cuda.egg-info/not-zip-safe +0 -0
  28. {pyqrack_cuda-1.44.1 → pyqrack_cuda-1.44.3}/pyqrack_cuda.egg-info/requires.txt +0 -0
  29. {pyqrack_cuda-1.44.1 → pyqrack_cuda-1.44.3}/pyqrack_cuda.egg-info/top_level.txt +0 -0
  30. {pyqrack_cuda-1.44.1 → pyqrack_cuda-1.44.3}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pyqrack-cuda
3
- Version: 1.44.1
3
+ Version: 1.44.3
4
4
  Summary: pyqrack - Pure Python vm6502q/qrack Wrapper
5
5
  Home-page: https://github.com/vm6502q/pyqrack
6
6
  Author: Daniel Strano
@@ -0,0 +1,610 @@
1
+ # (C) Daniel Strano and the Qrack contributors 2017-2025. All rights reserved.
2
+ #
3
+ # Use of this source code is governed by an MIT-style license that can be
4
+ # found in the LICENSE file or at https://opensource.org/licenses/MIT.
5
+ import math
6
+ import random
7
+ import sys
8
+ import time
9
+
10
+ from .qrack_simulator import QrackSimulator
11
+ from .pauli import Pauli
12
+
13
+
14
+ _IS_QISKIT_AVAILABLE = True
15
+ try:
16
+ from qiskit.circuit.quantumcircuit import QuantumCircuit
17
+ from qiskit.compiler import transpile
18
+ from qiskit.quantum_info.operators.symplectic.clifford import Clifford
19
+ except ImportError:
20
+ _IS_QISKIT_AVAILABLE = False
21
+
22
+
23
+ class QrackAceBackend:
24
+ """A back end for elided quantum error correction
25
+
26
+ This back end uses elided repetition code on a nearest-neighbor topology to emulate
27
+ a utility-scale superconducting chip quantum computer in very little memory.
28
+
29
+ The backend was originally designed assuming a 2D qubit grid like 2019 Sycamore.
30
+ However, it quickly became apparent that users can basically design their own
31
+ connectivity topologies, without breaking the concept. (Not all will work equally well.)
32
+
33
+ Attributes:
34
+ sim(QrackSimulator): Corresponding simulator.
35
+ """
36
+
37
+ def __init__(
38
+ self,
39
+ qubit_count=-1,
40
+ toClone=None
41
+ ):
42
+ self.sim = toClone.sim.clone() if toClone else QrackSimulator(3 * qubit_count)
43
+
44
+
45
+ def _ct_pair_prob(self, q1, q2):
46
+ p1 = self.sim.prob(q1)
47
+ p2 = self.sim.prob(q2)
48
+
49
+ if p1 < p2:
50
+ return p2, q1
51
+
52
+ return p1, q2
53
+
54
+
55
+ def _cz_shadow(self, q1, q2):
56
+ prob_max, t = self._ct_pair_prob(q1, q2)
57
+ if prob_max > 0.5:
58
+ self.sim.z(t)
59
+
60
+
61
+ def _anti_cz_shadow(self, q1, q2):
62
+ self.sim.x(q1)
63
+ self._cz_shadow(q1, q2)
64
+ self.sim.x(q1)
65
+
66
+
67
+ def _cx_shadow(self, c, t):
68
+ self.sim.h(t)
69
+ self._cz_shadow(c, t)
70
+ self.sim.h(t)
71
+
72
+
73
+ def _anti_cx_shadow(self, c, t):
74
+ self.sim.x(t)
75
+ self._cx_shadow(c, t)
76
+ self.sim.x(t)
77
+
78
+
79
+ def _cy_shadow(self, c, t):
80
+ self.sim.adjs(t)
81
+ self._cx_shadow(c, t)
82
+ self.sim.s(t)
83
+
84
+
85
+ def _anti_cy_shadow(self, c, t):
86
+ self.sim.x(t)
87
+ self._cy_shadow(c, t)
88
+ self.sim.x(t)
89
+
90
+
91
+ def _unpack(self, lq, reverse = False):
92
+ return [3 * lq + 2, 3 * lq + 1, 3 * lq] if reverse else [3 * lq, 3 * lq + 1, 3 * lq + 2]
93
+
94
+
95
+ def _encode(self, hq, reverse = False):
96
+ if reverse:
97
+ self._cx_shadow(hq[0], hq[1])
98
+ self.sim.mcx([hq[1]], hq[2])
99
+ else:
100
+ self.sim.mcx([hq[0]], hq[1])
101
+ self._cx_shadow(hq[1], hq[2])
102
+
103
+
104
+ def _decode(self, hq, reverse = False):
105
+ if reverse:
106
+ self.sim.mcx([hq[1]], hq[2])
107
+ self._cx_shadow(hq[0], hq[1])
108
+ else:
109
+ self._cx_shadow(hq[1], hq[2])
110
+ self.sim.mcx([hq[0]], hq[1])
111
+
112
+
113
+ def u(self, th, ph, lm, lq):
114
+ hq = self._unpack(lq)
115
+ self._decode(hq)
116
+ self.sim.u(hq[0], th, ph, lm)
117
+ self._encode(hq)
118
+
119
+
120
+ def r(self, p, th, lq):
121
+ hq = self._unpack(lq)
122
+ self._decode(hq)
123
+ self.sim.r(p, th, hq[0])
124
+ self._encode(hq)
125
+
126
+
127
+ def s(self, lq):
128
+ hq = self._unpack(lq)
129
+ self._decode(hq)
130
+ self.sim.s(hq[0])
131
+ self._encode(hq)
132
+
133
+
134
+ def adjs(self, lq):
135
+ hq = self._unpack(lq)
136
+ self._decode(hq)
137
+ self.sim.adjs(hq[0])
138
+ self._encode(hq)
139
+
140
+
141
+ def x(self, lq):
142
+ hq = self._unpack(lq)
143
+ self._decode(hq)
144
+ self.sim.x(hq[0])
145
+ self._encode(hq)
146
+
147
+
148
+ def y(self, lq):
149
+ hq = self._unpack(lq)
150
+ self._decode(hq)
151
+ self.sim.y(hq[0])
152
+ self._encode(hq)
153
+
154
+
155
+ def z(self, lq):
156
+ hq = self._unpack(lq)
157
+ self._decode(hq)
158
+ self.sim.z(hq[0])
159
+ self._encode(hq)
160
+
161
+
162
+ def h(self, lq):
163
+ hq = self._unpack(lq)
164
+ self._decode(hq)
165
+ self.sim.h(hq[0])
166
+ self._encode(hq)
167
+
168
+
169
+ def t(self, lq):
170
+ hq = self._unpack(lq)
171
+ self._decode(hq)
172
+ self.sim.t(hq[0])
173
+ self._encode(hq)
174
+
175
+
176
+ def adjt(self, lq):
177
+ hq = self._unpack(lq)
178
+ self._decode(hq)
179
+ self.sim.adjt(hq[0])
180
+ self._encode(hq)
181
+
182
+
183
+ def _cpauli(self, lq1, lq2, anti, pauli):
184
+ gate = None
185
+ if pauli == Pauli.PauliX:
186
+ gate = self.sim.macx if anti else self.sim.mcx
187
+ elif pauli == Pauli.PauliY:
188
+ gate = self.sim.macy if anti else self.sim.mcy
189
+ elif pauli == Pauli.PauliZ:
190
+ gate = self.sim.macz if anti else self.sim.mcz
191
+ else:
192
+ return
193
+
194
+ if lq2 == (lq1 + 1):
195
+ hq1 = self._unpack(lq1, True)
196
+ hq2 = self._unpack(lq2, False)
197
+ self._decode(hq1, True)
198
+ self._decode(hq2, False)
199
+ gate([hq1[0]], hq2[0])
200
+ self._encode(hq2, False)
201
+ self._encode(hq1, True)
202
+ elif lq1 == (lq2 + 1):
203
+ hq2 = self._unpack(lq2, True)
204
+ hq1 = self._unpack(lq1, False)
205
+ self._decode(hq2, True)
206
+ self._decode(hq1, False)
207
+ gate([hq1[0]], hq2[0])
208
+ self._encode(hq1, False)
209
+ self._encode(hq2, True)
210
+ else:
211
+ hq1 = self._unpack(lq1)
212
+ hq2 = self._unpack(lq2)
213
+ gate([hq1[0]], hq2[0])
214
+ gate([hq1[1]], hq2[1])
215
+ gate([hq1[2]], hq2[2])
216
+
217
+
218
+ def cx(self, lq1, lq2):
219
+ self._cpauli(lq1, lq2, False, Pauli.PauliX)
220
+
221
+
222
+ def cy(self, lq1, lq2):
223
+ self._cpauli(lq1, lq2, False, Pauli.PauliY)
224
+
225
+
226
+ def cz(self, lq1, lq2):
227
+ self._cpauli(lq1, lq2, False, Pauli.PauliZ)
228
+
229
+
230
+ def acx(self, lq1, lq2):
231
+ self._cpauli(lq1, lq2, True, Pauli.PauliX)
232
+
233
+
234
+ def acy(self, lq1, lq2):
235
+ self._cpauli(lq1, lq2, True, Pauli.PauliY)
236
+
237
+
238
+ def acz(self, lq1, lq2):
239
+ self._cpauli(lq1, lq2, True, Pauli.PauliZ)
240
+
241
+
242
+ def swap(self, lq1, lq2):
243
+ self.cx(lq1, lq2)
244
+ self.cx(lq2, lq1)
245
+ self.cx(lq1, lq2)
246
+
247
+
248
+ def iswap(self, lq1, lq2):
249
+ self.swap(lq1, lq2)
250
+ self.cz(lq1, lq2)
251
+ self.s(lq1)
252
+ self.s(lq2)
253
+
254
+
255
+ def adjiswap(self, lq1, lq2):
256
+ self.adjs(lq2)
257
+ self.adjs(lq1)
258
+ self.cz(lq1, lq2)
259
+ self.swap(lq1, lq2)
260
+
261
+
262
+ def m(self, lq):
263
+ hq = self._unpack(lq)
264
+ syndrome = 0
265
+ bits = []
266
+ for q in hq:
267
+ bits.append(self.sim.m(q))
268
+ if bits[-1]:
269
+ syndrome += 1
270
+ result = True if (syndrome > 1) else False
271
+ for i in range(len(hq)):
272
+ if bits[i] != result:
273
+ self.sim.x(hq[i])
274
+
275
+ return result
276
+
277
+
278
+ def m_all(self):
279
+ result = 0
280
+ for lq in range(self.sim.num_qubits() // 3):
281
+ result <<= 1
282
+ if self.m(lq):
283
+ result |= 1
284
+
285
+ return result
286
+
287
+
288
+ def measure_shots(self, q, s):
289
+ _q = []
290
+ for i in q:
291
+ _q.append(3 * i)
292
+ _q.append(3 * i + 1)
293
+ _q.append(3 * i + 2)
294
+
295
+ samples = self.sim.measure_shots(_q, s)
296
+
297
+ results = []
298
+ for sample in samples:
299
+ logical_sample = 0
300
+ for i in range(len(q)):
301
+ logical_sample <<= 1
302
+ bit_count = 0
303
+ for _ in range(3):
304
+ if sample & 1:
305
+ bit_count += 1
306
+ sample >>= 1
307
+ if bit_count > 1:
308
+ logical_sample |= 1
309
+ results.append(logical_sample)
310
+
311
+ return results
312
+
313
+
314
+ def _apply_op(self, operation):
315
+ name = operation.name
316
+
317
+ if (name == 'id') or (name == 'barrier'):
318
+ # Skip measurement logic
319
+ return
320
+
321
+ conditional = getattr(operation, 'conditional', None)
322
+ if isinstance(conditional, int):
323
+ conditional_bit_set = (self._classical_register >> conditional) & 1
324
+ if not conditional_bit_set:
325
+ return
326
+ elif conditional is not None:
327
+ mask = int(conditional.mask, 16)
328
+ if mask > 0:
329
+ value = self._classical_memory & mask
330
+ while (mask & 0x1) == 0:
331
+ mask >>= 1
332
+ value >>= 1
333
+ if value != int(conditional.val, 16):
334
+ return
335
+
336
+ if (name == 'u1') or (name == 'p'):
337
+ self._sim.u(0, 0, float(operation.params[0]), operation.qubits[0]._index)
338
+ elif name == 'u2':
339
+ self._sim.u(
340
+ math.pi / 2,
341
+ float(operation.params[0]),
342
+ float(operation.params[1]),
343
+ operation.qubits[0]._index
344
+ )
345
+ elif (name == 'u3') or (name == 'u'):
346
+ self._sim.u(
347
+ float(operation.params[0]),
348
+ float(operation.params[1]),
349
+ float(operation.params[2]),
350
+ operation.qubits[0]._index
351
+ )
352
+ elif name == 'r':
353
+ self._sim.u(
354
+ float(operation.params[0]),
355
+ float(operation.params[1]) - math.pi / 2,
356
+ (-1 * float(operation.params[1])) + math.pi / 2,
357
+ operation.qubits[0]._index
358
+ )
359
+ elif name == 'rx':
360
+ self._sim.r(Pauli.PauliX, float(operation.params[0]), operation.qubits[0]._index)
361
+ elif name == 'ry':
362
+ self._sim.r(Pauli.PauliY, float(operation.params[0]), operation.qubits[0]._index)
363
+ elif name == 'rz':
364
+ self._sim.r(Pauli.PauliZ, float(operation.params[0]), operation.qubits[0]._index)
365
+ elif name == 'h':
366
+ self._sim.h(operation.qubits[0]._index)
367
+ elif name == 'x':
368
+ self._sim.x(operation.qubits[0]._index)
369
+ elif name == 'y':
370
+ self._sim.y(operation.qubits[0]._index)
371
+ elif name == 'z':
372
+ self._sim.z(operation.qubits[0]._index)
373
+ elif name == 's':
374
+ self._sim.s(operation.qubits[0]._index)
375
+ elif name == 'sdg':
376
+ self._sim.adjs(operation.qubits[0]._index)
377
+ elif name == 't':
378
+ self._sim.t(operation.qubits[0]._index)
379
+ elif name == 'tdg':
380
+ self._sim.adjt(operation.qubits[0]._index)
381
+ elif name == 'cx':
382
+ self._sim.cx(operation.qubits[0]._index, operation.qubits[1]._index)
383
+ elif name == 'cy':
384
+ self._sim.cy(operation.qubits[0]._index, operation.qubits[1]._index)
385
+ elif name == 'cz':
386
+ self._sim.cz(operation.qubits[0]._index, operation.qubits[1]._index)
387
+ elif name == 'dcx':
388
+ self._sim.mcx(operation.qubits[0]._index, operation.qubits[1]._index)
389
+ self._sim.mcx(operation.qubits[1]._index, operation.qubits[0]._index)
390
+ elif name == 'swap':
391
+ self._sim.swap(operation.qubits[0]._index, operation.qubits[1]._index)
392
+ elif name == 'iswap':
393
+ self._sim.iswap(operation.qubits[0]._index, operation.qubits[1]._index)
394
+ elif name == 'iswap_dg':
395
+ self._sim.adjiswap(operation.qubits[0]._index, operation.qubits[1]._index)
396
+ elif name == 'reset':
397
+ qubits = operation.qubits
398
+ for qubit in qubits:
399
+ if self._sim.m(qubit._index):
400
+ self._sim.x(qubit._index)
401
+ elif name == 'measure':
402
+ qubits = operation.qubits
403
+ clbits = operation.clbits
404
+ cregbits = (
405
+ operation.register
406
+ if hasattr(operation, 'register')
407
+ else len(operation.qubits) * [-1]
408
+ )
409
+
410
+ self._sample_qubits += qubits
411
+ self._sample_clbits += clbits
412
+ self._sample_cregbits += cregbits
413
+
414
+ if not self._sample_measure:
415
+ for index in range(len(qubits)):
416
+ qubit_outcome = self._sim.m(qubits[index]._index)
417
+
418
+ clbit = clbits[index]
419
+ clmask = 1 << clbit
420
+ self._classical_memory = (self._classical_memory & (~clmask)) | (
421
+ qubit_outcome << clbit
422
+ )
423
+
424
+ cregbit = cregbits[index]
425
+ if cregbit < 0:
426
+ cregbit = clbit
427
+
428
+ regbit = 1 << cregbit
429
+ self._classical_register = (
430
+ self._classical_register & (~regbit)
431
+ ) | (qubit_outcome << cregbit)
432
+
433
+ elif name == 'bfunc':
434
+ mask = int(operation.mask, 16)
435
+ relation = operation.relation
436
+ val = int(operation.val, 16)
437
+
438
+ cregbit = operation.register
439
+ cmembit = operation.memory if hasattr(operation, 'memory') else None
440
+
441
+ compared = (self._classical_register & mask) - val
442
+
443
+ if relation == '==':
444
+ outcome = compared == 0
445
+ elif relation == '!=':
446
+ outcome = compared != 0
447
+ elif relation == '<':
448
+ outcome = compared < 0
449
+ elif relation == '<=':
450
+ outcome = compared <= 0
451
+ elif relation == '>':
452
+ outcome = compared > 0
453
+ elif relation == '>=':
454
+ outcome = compared >= 0
455
+ else:
456
+ raise QrackError('Invalid boolean function relation.')
457
+
458
+ # Store outcome in register and optionally memory slot
459
+ regbit = 1 << cregbit
460
+ self._classical_register = (self._classical_register & (~regbit)) | (
461
+ int(outcome) << cregbit
462
+ )
463
+ if cmembit is not None:
464
+ membit = 1 << cmembit
465
+ self._classical_memory = (self._classical_memory & (~membit)) | (
466
+ int(outcome) << cmembit
467
+ )
468
+ else:
469
+ err_msg = 'QrackAceBackend encountered unrecognized operation "{0}"'
470
+ raise RuntimeError(err_msg.format(operation))
471
+
472
+ def _add_sample_measure(self, sample_qubits, sample_clbits, num_samples):
473
+ """Generate data samples from current statevector.
474
+
475
+ Taken almost straight from the terra source code.
476
+
477
+ Args:
478
+ measure_params (list): List of (qubit, clbit) values for
479
+ measure instructions to sample.
480
+ num_samples (int): The number of data samples to generate.
481
+
482
+ Returns:
483
+ list: A list of data values in hex format.
484
+ """
485
+ # Get unique qubits that are actually measured
486
+ measure_qubit = [qubit for qubit in sample_qubits]
487
+ measure_clbit = [clbit for clbit in sample_clbits]
488
+
489
+ # Sample and convert to bit-strings
490
+ if num_samples == 1:
491
+ sample = self._sim.m_all()
492
+ result = 0
493
+ for index in range(len(measure_qubit)):
494
+ qubit = measure_qubit[index]._index
495
+ qubit_outcome = (sample >> qubit) & 1
496
+ result |= qubit_outcome << index
497
+ measure_results = [result]
498
+ else:
499
+ measure_results = self._sim.measure_shots([q._index for q in measure_qubit], num_samples)
500
+
501
+ data = []
502
+ for sample in measure_results:
503
+ for index in range(len(measure_qubit)):
504
+ qubit_outcome = (sample >> index) & 1
505
+ clbit = measure_clbit[index]._index
506
+ clmask = 1 << clbit
507
+ self._classical_memory = (self._classical_memory & (~clmask)) | (
508
+ qubit_outcome << clbit
509
+ )
510
+
511
+ data.append(bin(self._classical_memory)[2:].zfill(self.num_qubits()))
512
+
513
+ return data
514
+
515
+ def run_qiskit_circuit(self, experiment, shots=1):
516
+ if not _IS_QISKIT_AVAILABLE:
517
+ raise RuntimeError(
518
+ "Before trying to run_qiskit_circuit() with QrackAceBackend, you must install Qiskit!"
519
+ )
520
+
521
+ instructions = []
522
+ if isinstance(experiment, QuantumCircuit):
523
+ instructions = experiment.data
524
+ else:
525
+ raise RuntimeError('Unrecognized "run_input" argument specified for run().')
526
+
527
+ self._shots = shots
528
+ self._sample_qubits = []
529
+ self._sample_clbits = []
530
+ self._sample_cregbits = []
531
+ self._sample_measure = True
532
+ _data = []
533
+ shotLoopMax = 1
534
+
535
+ is_initializing = True
536
+ boundary_start = -1
537
+
538
+ for opcount in range(len(instructions)):
539
+ operation = instructions[opcount]
540
+
541
+ if operation.name == 'id' or operation.name == 'barrier':
542
+ continue
543
+
544
+ if is_initializing and (
545
+ (operation.name == 'measure') or (operation.name == 'reset')
546
+ ):
547
+ continue
548
+
549
+ is_initializing = False
550
+
551
+ if (operation.name == 'measure') or (operation.name == 'reset'):
552
+ if boundary_start == -1:
553
+ boundary_start = opcount
554
+
555
+ if (boundary_start != -1) and (operation.name != 'measure'):
556
+ shotsPerLoop = 1
557
+ shotLoopMax = self._shots
558
+ self._sample_measure = False
559
+ break
560
+
561
+ preamble_memory = 0
562
+ preamble_register = 0
563
+ preamble_sim = None
564
+
565
+ if self._sample_measure or boundary_start <= 0:
566
+ boundary_start = 0
567
+ self._sample_measure = True
568
+ shotsPerLoop = self._shots
569
+ shotLoopMax = 1
570
+ else:
571
+ boundary_start -= 1
572
+ if boundary_start > 0:
573
+ self._sim = self
574
+ self._classical_memory = 0
575
+ self._classical_register = 0
576
+
577
+ for operation in instructions[:boundary_start]:
578
+ self._apply_op(operation)
579
+
580
+ preamble_memory = self._classical_memory
581
+ preamble_register = self._classical_register
582
+ preamble_sim = self._sim
583
+
584
+ for shot in range(shotLoopMax):
585
+ if preamble_sim is None:
586
+ self._sim = self
587
+ self._classical_memory = 0
588
+ self._classical_register = 0
589
+ else:
590
+ self._sim = QrackAceBackend(toClone=preamble_sim)
591
+ self._classical_memory = preamble_memory
592
+ self._classical_register = preamble_register
593
+
594
+ for operation in instructions[boundary_start:]:
595
+ self._apply_op(operation)
596
+
597
+ if not self._sample_measure and (len(self._sample_qubits) > 0):
598
+ _data += [bin(self._classical_memory)[2:].zfill(self.num_qubits())]
599
+ self._sample_qubits = []
600
+ self._sample_clbits = []
601
+ self._sample_cregbits = []
602
+
603
+ if self._sample_measure and (len(self._sample_qubits) > 0):
604
+ _data = self._add_sample_measure(
605
+ self._sample_qubits, self._sample_clbits, self._shots
606
+ )
607
+
608
+ del self._sim
609
+
610
+ return _data
@@ -3843,7 +3843,7 @@ class QrackSimulator:
3843
3843
 
3844
3844
  if not self._sample_measure:
3845
3845
  for index in range(len(qubits)):
3846
- qubit_outcome = self._sim.m(qubits[index])
3846
+ qubit_outcome = self._sim.m(qubits[index]._index)
3847
3847
 
3848
3848
  clbit = clbits[index]
3849
3849
  clmask = 1 << clbit
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pyqrack-cuda
3
- Version: 1.44.1
3
+ Version: 1.44.3
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 = "1.44.1"
10
+ VERSION = "1.44.3"
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')
@@ -1,287 +0,0 @@
1
- # (C) Daniel Strano and the Qrack contributors 2017-2025. All rights reserved.
2
- #
3
- # Use of this source code is governed by an MIT-style license that can be
4
- # found in the LICENSE file or at https://opensource.org/licenses/MIT.
5
- import math
6
- import random
7
- import sys
8
- import time
9
-
10
- from .qrack_simulator import QrackSimulator
11
- from .pauli import Pauli
12
-
13
-
14
- class QrackAceBackend:
15
- """A back end for elided quantum error correction
16
-
17
- This back end uses elided repetition code on a nearest-neighbor topology to emulate
18
- a utility-scale superconducting chip quantum computer in very little memory.
19
-
20
- The backend was originally designed assuming a 2D qubit grid like 2019 Sycamore.
21
- However, it quickly became apparent that users can basically design their own
22
- connectivity topologies, without breaking the concept. (Not all will work equally well.)
23
-
24
- Attributes:
25
- sim(QrackSimulator): Corresponding simulator.
26
- """
27
-
28
- def __init__(
29
- self,
30
- qubit_count=-1,
31
- ):
32
- self.sim = QrackSimulator(3 * qubit_count)
33
-
34
-
35
- def _ct_pair_prob(self, q1, q2):
36
- p1 = self.sim.prob(q1)
37
- p2 = self.sim.prob(q2)
38
-
39
- if p1 < p2:
40
- return p2, q1
41
-
42
- return p1, q2
43
-
44
-
45
- def _cz_shadow(self, q1, q2):
46
- prob_max, t = self._ct_pair_prob(q1, q2)
47
- if prob_max > 0.5:
48
- self.sim.z(t)
49
-
50
-
51
- def _anti_cz_shadow(self, q1, q2):
52
- self.sim.x(q1)
53
- self._cz_shadow(q1, q2)
54
- self.sim.x(q1)
55
-
56
-
57
- def _cx_shadow(self, c, t):
58
- self.sim.h(t)
59
- self._cz_shadow(c, t)
60
- self.sim.h(t)
61
-
62
-
63
- def _anti_cx_shadow(self, c, t):
64
- self.sim.x(t)
65
- self._cx_shadow(c, t)
66
- self.sim.x(t)
67
-
68
-
69
- def _cy_shadow(self, c, t):
70
- self.sim.adjs(t)
71
- self._cx_shadow(c, t)
72
- self.sim.s(t)
73
-
74
-
75
- def _anti_cy_shadow(self, c, t):
76
- self.sim.x(t)
77
- self._cy_shadow(c, t)
78
- self.sim.x(t)
79
-
80
-
81
- def _unpack(self, lq, reverse = False):
82
- return [3 * lq + 2, 3 * lq + 1, 3 * lq] if reverse else [3 * lq, 3 * lq + 1, 3 * lq + 2]
83
-
84
-
85
- def _encode(self, hq, reverse = False):
86
- if reverse:
87
- self._cx_shadow(hq[0], hq[1])
88
- self.sim.mcx([hq[1]], hq[2])
89
- else:
90
- self.sim.mcx([hq[0]], hq[1])
91
- self._cx_shadow(hq[1], hq[2])
92
-
93
-
94
- def _decode(self, hq, reverse = False):
95
- if reverse:
96
- self.sim.mcx([hq[1]], hq[2])
97
- self._cx_shadow(hq[0], hq[1])
98
- else:
99
- self._cx_shadow(hq[1], hq[2])
100
- self.sim.mcx([hq[0]], hq[1])
101
-
102
-
103
- def u(self, th, ph, lm, lq):
104
- hq = self._unpack(lq)
105
- self._decode(hq)
106
- self.sim.u(hq[0], th, ph, lm)
107
- self._encode(hq)
108
-
109
-
110
- def s(self, lq):
111
- hq = self._unpack(lq)
112
- self._decode(hq)
113
- self.sim.s(hq[0])
114
- self._encode(hq)
115
-
116
-
117
- def adjs(self, lq):
118
- hq = self._unpack(lq)
119
- self._decode(hq)
120
- self.sim.adjs(hq[0])
121
- self._encode(hq)
122
-
123
-
124
- def x(self, lq):
125
- hq = self._unpack(lq)
126
- self._decode(hq)
127
- self.sim.x(hq[0])
128
- self._encode(hq)
129
-
130
-
131
- def y(self, lq):
132
- hq = self._unpack(lq)
133
- self._decode(hq)
134
- self.sim.y(hq[0])
135
- self._encode(hq)
136
-
137
-
138
- def z(self, lq):
139
- hq = self._unpack(lq)
140
- self._decode(hq)
141
- self.sim.z(hq[0])
142
- self._encode(hq)
143
-
144
-
145
- def h(self, lq):
146
- hq = self._unpack(lq)
147
- self._decode(hq)
148
- self.sim.h(hq[0])
149
- self._encode(hq)
150
-
151
-
152
- def t(self, lq):
153
- hq = self._unpack(lq)
154
- self._decode(hq)
155
- self.sim.t(hq[0])
156
- self._encode(hq)
157
-
158
-
159
- def adjt(self, lq):
160
- hq = self._unpack(lq)
161
- self._decode(hq)
162
- self.sim.adjt(hq[0])
163
- self._encode(hq)
164
-
165
-
166
- def _cpauli(self, lq1, lq2, anti, pauli):
167
- gate = None
168
- if pauli == Pauli.PauliX:
169
- gate = self.sim.macx if anti else self.sim.mcx
170
- elif pauli == Pauli.PauliY:
171
- gate = self.sim.macy if anti else self.sim.mcy
172
- elif pauli == Pauli.PauliZ:
173
- gate = self.sim.macz if anti else self.sim.mcz
174
- else:
175
- return
176
-
177
- if (lq2 == (lq1 + 1)) or (lq1 == (lq2 + 1)):
178
- hq1 = self._unpack(lq1, True)
179
- hq2 = self._unpack(lq2, False)
180
- self._decode(hq1, True)
181
- self._decode(hq2, False)
182
- gate([hq1[0]], hq2[0])
183
- self._encode(hq2, False)
184
- self._encode(hq1, True)
185
- else:
186
- hq1 = self._unpack(lq1)
187
- hq2 = self._unpack(lq2)
188
- gate([hq1[0]], hq2[0])
189
- gate([hq1[1]], hq2[1])
190
- gate([hq1[2]], hq2[2])
191
-
192
-
193
- def cx(self, lq1, lq2):
194
- self._cpauli(lq1, lq2, False, Pauli.PauliX)
195
-
196
-
197
- def cy(self, lq1, lq2):
198
- self._cpauli(lq1, lq2, False, Pauli.PauliY)
199
-
200
-
201
- def cz(self, lq1, lq2):
202
- self._cpauli(lq1, lq2, False, Pauli.PauliZ)
203
-
204
-
205
- def acx(self, lq1, lq2):
206
- self._cpauli(lq1, lq2, True, Pauli.PauliX)
207
-
208
-
209
- def acy(self, lq1, lq2):
210
- self._cpauli(lq1, lq2, True, Pauli.PauliY)
211
-
212
-
213
- def acz(self, lq1, lq2):
214
- self._cpauli(lq1, lq2, True, Pauli.PauliZ)
215
-
216
-
217
- def swap(self, lq1, lq2):
218
- self.cx(lq1, lq2)
219
- self.cx(lq2, lq1)
220
- self.cx(lq1, lq2)
221
-
222
-
223
- def iswap(self, lq1, lq2):
224
- self.swap(lq1, lq2)
225
- self.cz(lq1, lq2)
226
- self.s(lq1)
227
- self.s(lq2)
228
-
229
-
230
- def adjiswap(self, lq1, lq2):
231
- self.adjs(lq2)
232
- self.adjs(lq1)
233
- self.cz(lq1, lq2)
234
- self.swap(lq1, lq2)
235
-
236
-
237
- def m(self, lq):
238
- hq = self._unpack(lq)
239
- syndrome = 0
240
- bits = []
241
- for q in hq:
242
- bits.append(self.sim.m(q))
243
- if bits[-1]:
244
- syndrome += 1
245
- result = True if (syndrome > 1) else False
246
- for i in range(len(hq)):
247
- if bits[i] != result:
248
- self.sim.x(hq[i])
249
-
250
- return result
251
-
252
-
253
- def m_all(self):
254
- result = 0
255
- for lq in range(self.sim.num_qubits() // 3):
256
- result <<= 1
257
- if self.m(lq):
258
- result |= 1
259
-
260
- return result
261
-
262
-
263
- def measure_shots(self, q, s):
264
- _q = []
265
- for i in q:
266
- _q.append(3 * i)
267
- _q.append(3 * i + 1)
268
- _q.append(3 * i + 2)
269
-
270
- samples = self.sim.measure_shots(_q, s)
271
-
272
- results = []
273
- for sample in samples:
274
- logical_sample = 0
275
- for i in range(len(q)):
276
- logical_sample <<= 1
277
- bit_count = 0
278
- for _ in range(3):
279
- if sample & 1:
280
- bit_count += 1
281
- sample >>= 1
282
- if bit_count > 1:
283
- logical_sample |= 1
284
- results.append(logical_sample)
285
-
286
- return results
287
-
File without changes
File without changes
File without changes
File without changes
File without changes