pyqrack-cpu 1.44.1__py3-none-manylinux_2_39_x86_64.whl → 1.44.2__py3-none-manylinux_2_39_x86_64.whl
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.
Potentially problematic release.
This version of pyqrack-cpu might be problematic. Click here for more details.
- pyqrack/qrack_ace_backend.py +316 -1
- pyqrack/qrack_simulator.py +1 -1
- {pyqrack_cpu-1.44.1.dist-info → pyqrack_cpu-1.44.2.dist-info}/METADATA +1 -1
- {pyqrack_cpu-1.44.1.dist-info → pyqrack_cpu-1.44.2.dist-info}/RECORD +7 -7
- {pyqrack_cpu-1.44.1.dist-info → pyqrack_cpu-1.44.2.dist-info}/WHEEL +0 -0
- {pyqrack_cpu-1.44.1.dist-info → pyqrack_cpu-1.44.2.dist-info}/licenses/LICENSE +0 -0
- {pyqrack_cpu-1.44.1.dist-info → pyqrack_cpu-1.44.2.dist-info}/top_level.txt +0 -0
pyqrack/qrack_ace_backend.py
CHANGED
|
@@ -11,6 +11,15 @@ from .qrack_simulator import QrackSimulator
|
|
|
11
11
|
from .pauli import Pauli
|
|
12
12
|
|
|
13
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
|
+
|
|
14
23
|
class QrackAceBackend:
|
|
15
24
|
"""A back end for elided quantum error correction
|
|
16
25
|
|
|
@@ -28,8 +37,9 @@ class QrackAceBackend:
|
|
|
28
37
|
def __init__(
|
|
29
38
|
self,
|
|
30
39
|
qubit_count=-1,
|
|
40
|
+
toClone=None
|
|
31
41
|
):
|
|
32
|
-
self.sim = QrackSimulator(3 * qubit_count)
|
|
42
|
+
self.sim = toClone.sim.clone() if toClone else QrackSimulator(3 * qubit_count)
|
|
33
43
|
|
|
34
44
|
|
|
35
45
|
def _ct_pair_prob(self, q1, q2):
|
|
@@ -107,6 +117,13 @@ class QrackAceBackend:
|
|
|
107
117
|
self._encode(hq)
|
|
108
118
|
|
|
109
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
|
+
|
|
110
127
|
def s(self, lq):
|
|
111
128
|
hq = self._unpack(lq)
|
|
112
129
|
self._decode(hq)
|
|
@@ -285,3 +302,301 @@ class QrackAceBackend:
|
|
|
285
302
|
|
|
286
303
|
return results
|
|
287
304
|
|
|
305
|
+
|
|
306
|
+
def _apply_op(self, operation):
|
|
307
|
+
name = operation.name
|
|
308
|
+
|
|
309
|
+
if (name == 'id') or (name == 'barrier'):
|
|
310
|
+
# Skip measurement logic
|
|
311
|
+
return
|
|
312
|
+
|
|
313
|
+
conditional = getattr(operation, 'conditional', None)
|
|
314
|
+
if isinstance(conditional, int):
|
|
315
|
+
conditional_bit_set = (self._classical_register >> conditional) & 1
|
|
316
|
+
if not conditional_bit_set:
|
|
317
|
+
return
|
|
318
|
+
elif conditional is not None:
|
|
319
|
+
mask = int(conditional.mask, 16)
|
|
320
|
+
if mask > 0:
|
|
321
|
+
value = self._classical_memory & mask
|
|
322
|
+
while (mask & 0x1) == 0:
|
|
323
|
+
mask >>= 1
|
|
324
|
+
value >>= 1
|
|
325
|
+
if value != int(conditional.val, 16):
|
|
326
|
+
return
|
|
327
|
+
|
|
328
|
+
if (name == 'u1') or (name == 'p'):
|
|
329
|
+
self._sim.u(0, 0, float(operation.params[0]), operation.qubits[0]._index)
|
|
330
|
+
elif name == 'u2':
|
|
331
|
+
self._sim.u(
|
|
332
|
+
math.pi / 2,
|
|
333
|
+
float(operation.params[0]),
|
|
334
|
+
float(operation.params[1]),
|
|
335
|
+
operation.qubits[0]._index
|
|
336
|
+
)
|
|
337
|
+
elif (name == 'u3') or (name == 'u'):
|
|
338
|
+
self._sim.u(
|
|
339
|
+
float(operation.params[0]),
|
|
340
|
+
float(operation.params[1]),
|
|
341
|
+
float(operation.params[2]),
|
|
342
|
+
operation.qubits[0]._index
|
|
343
|
+
)
|
|
344
|
+
elif name == 'r':
|
|
345
|
+
self._sim.u(
|
|
346
|
+
float(operation.params[0]),
|
|
347
|
+
float(operation.params[1]) - math.pi / 2,
|
|
348
|
+
(-1 * float(operation.params[1])) + math.pi / 2,
|
|
349
|
+
operation.qubits[0]._index
|
|
350
|
+
)
|
|
351
|
+
elif name == 'rx':
|
|
352
|
+
self._sim.r(Pauli.PauliX, float(operation.params[0]), operation.qubits[0]._index)
|
|
353
|
+
elif name == 'ry':
|
|
354
|
+
self._sim.r(Pauli.PauliY, float(operation.params[0]), operation.qubits[0]._index)
|
|
355
|
+
elif name == 'rz':
|
|
356
|
+
self._sim.r(Pauli.PauliZ, float(operation.params[0]), operation.qubits[0]._index)
|
|
357
|
+
elif name == 'h':
|
|
358
|
+
self._sim.h(operation.qubits[0]._index)
|
|
359
|
+
elif name == 'x':
|
|
360
|
+
self._sim.x(operation.qubits[0]._index)
|
|
361
|
+
elif name == 'y':
|
|
362
|
+
self._sim.y(operation.qubits[0]._index)
|
|
363
|
+
elif name == 'z':
|
|
364
|
+
self._sim.z(operation.qubits[0]._index)
|
|
365
|
+
elif name == 's':
|
|
366
|
+
self._sim.s(operation.qubits[0]._index)
|
|
367
|
+
elif name == 'sdg':
|
|
368
|
+
self._sim.adjs(operation.qubits[0]._index)
|
|
369
|
+
elif name == 't':
|
|
370
|
+
self._sim.t(operation.qubits[0]._index)
|
|
371
|
+
elif name == 'tdg':
|
|
372
|
+
self._sim.adjt(operation.qubits[0]._index)
|
|
373
|
+
elif name == 'cx':
|
|
374
|
+
self._sim.cx(operation.qubits[0]._index, operation.qubits[1]._index)
|
|
375
|
+
elif name == 'cy':
|
|
376
|
+
self._sim.cy(operation.qubits[0]._index, operation.qubits[1]._index)
|
|
377
|
+
elif name == 'cz':
|
|
378
|
+
self._sim.cz(operation.qubits[0]._index, operation.qubits[1]._index)
|
|
379
|
+
elif name == 'dcx':
|
|
380
|
+
self._sim.mcx(operation.qubits[0]._index, operation.qubits[1]._index)
|
|
381
|
+
self._sim.mcx(operation.qubits[1]._index, operation.qubits[0]._index)
|
|
382
|
+
elif name == 'swap':
|
|
383
|
+
self._sim.swap(operation.qubits[0]._index, operation.qubits[1]._index)
|
|
384
|
+
elif name == 'iswap':
|
|
385
|
+
self._sim.iswap(operation.qubits[0]._index, operation.qubits[1]._index)
|
|
386
|
+
elif name == 'iswap_dg':
|
|
387
|
+
self._sim.adjiswap(operation.qubits[0]._index, operation.qubits[1]._index)
|
|
388
|
+
elif name == 'reset':
|
|
389
|
+
qubits = operation.qubits
|
|
390
|
+
for qubit in qubits:
|
|
391
|
+
if self._sim.m(qubit._index):
|
|
392
|
+
self._sim.x(qubit._index)
|
|
393
|
+
elif name == 'measure':
|
|
394
|
+
qubits = operation.qubits
|
|
395
|
+
clbits = operation.clbits
|
|
396
|
+
cregbits = (
|
|
397
|
+
operation.register
|
|
398
|
+
if hasattr(operation, 'register')
|
|
399
|
+
else len(operation.qubits) * [-1]
|
|
400
|
+
)
|
|
401
|
+
|
|
402
|
+
self._sample_qubits += qubits
|
|
403
|
+
self._sample_clbits += clbits
|
|
404
|
+
self._sample_cregbits += cregbits
|
|
405
|
+
|
|
406
|
+
if not self._sample_measure:
|
|
407
|
+
for index in range(len(qubits)):
|
|
408
|
+
qubit_outcome = self._sim.m(qubits[index]._index)
|
|
409
|
+
|
|
410
|
+
clbit = clbits[index]
|
|
411
|
+
clmask = 1 << clbit
|
|
412
|
+
self._classical_memory = (self._classical_memory & (~clmask)) | (
|
|
413
|
+
qubit_outcome << clbit
|
|
414
|
+
)
|
|
415
|
+
|
|
416
|
+
cregbit = cregbits[index]
|
|
417
|
+
if cregbit < 0:
|
|
418
|
+
cregbit = clbit
|
|
419
|
+
|
|
420
|
+
regbit = 1 << cregbit
|
|
421
|
+
self._classical_register = (
|
|
422
|
+
self._classical_register & (~regbit)
|
|
423
|
+
) | (qubit_outcome << cregbit)
|
|
424
|
+
|
|
425
|
+
elif name == 'bfunc':
|
|
426
|
+
mask = int(operation.mask, 16)
|
|
427
|
+
relation = operation.relation
|
|
428
|
+
val = int(operation.val, 16)
|
|
429
|
+
|
|
430
|
+
cregbit = operation.register
|
|
431
|
+
cmembit = operation.memory if hasattr(operation, 'memory') else None
|
|
432
|
+
|
|
433
|
+
compared = (self._classical_register & mask) - val
|
|
434
|
+
|
|
435
|
+
if relation == '==':
|
|
436
|
+
outcome = compared == 0
|
|
437
|
+
elif relation == '!=':
|
|
438
|
+
outcome = compared != 0
|
|
439
|
+
elif relation == '<':
|
|
440
|
+
outcome = compared < 0
|
|
441
|
+
elif relation == '<=':
|
|
442
|
+
outcome = compared <= 0
|
|
443
|
+
elif relation == '>':
|
|
444
|
+
outcome = compared > 0
|
|
445
|
+
elif relation == '>=':
|
|
446
|
+
outcome = compared >= 0
|
|
447
|
+
else:
|
|
448
|
+
raise QrackError('Invalid boolean function relation.')
|
|
449
|
+
|
|
450
|
+
# Store outcome in register and optionally memory slot
|
|
451
|
+
regbit = 1 << cregbit
|
|
452
|
+
self._classical_register = (self._classical_register & (~regbit)) | (
|
|
453
|
+
int(outcome) << cregbit
|
|
454
|
+
)
|
|
455
|
+
if cmembit is not None:
|
|
456
|
+
membit = 1 << cmembit
|
|
457
|
+
self._classical_memory = (self._classical_memory & (~membit)) | (
|
|
458
|
+
int(outcome) << cmembit
|
|
459
|
+
)
|
|
460
|
+
else:
|
|
461
|
+
err_msg = 'QrackAceBackend encountered unrecognized operation "{0}"'
|
|
462
|
+
raise RuntimeError(err_msg.format(operation))
|
|
463
|
+
|
|
464
|
+
def _add_sample_measure(self, sample_qubits, sample_clbits, num_samples):
|
|
465
|
+
"""Generate data samples from current statevector.
|
|
466
|
+
|
|
467
|
+
Taken almost straight from the terra source code.
|
|
468
|
+
|
|
469
|
+
Args:
|
|
470
|
+
measure_params (list): List of (qubit, clbit) values for
|
|
471
|
+
measure instructions to sample.
|
|
472
|
+
num_samples (int): The number of data samples to generate.
|
|
473
|
+
|
|
474
|
+
Returns:
|
|
475
|
+
list: A list of data values in hex format.
|
|
476
|
+
"""
|
|
477
|
+
# Get unique qubits that are actually measured
|
|
478
|
+
measure_qubit = [qubit for qubit in sample_qubits]
|
|
479
|
+
measure_clbit = [clbit for clbit in sample_clbits]
|
|
480
|
+
|
|
481
|
+
# Sample and convert to bit-strings
|
|
482
|
+
if num_samples == 1:
|
|
483
|
+
sample = self._sim.m_all()
|
|
484
|
+
result = 0
|
|
485
|
+
for index in range(len(measure_qubit)):
|
|
486
|
+
qubit = measure_qubit[index]._index
|
|
487
|
+
qubit_outcome = (sample >> qubit) & 1
|
|
488
|
+
result |= qubit_outcome << index
|
|
489
|
+
measure_results = [result]
|
|
490
|
+
else:
|
|
491
|
+
measure_results = self._sim.measure_shots([q._index for q in measure_qubit], num_samples)
|
|
492
|
+
|
|
493
|
+
data = []
|
|
494
|
+
for sample in measure_results:
|
|
495
|
+
for index in range(len(measure_qubit)):
|
|
496
|
+
qubit_outcome = (sample >> index) & 1
|
|
497
|
+
clbit = measure_clbit[index]._index
|
|
498
|
+
clmask = 1 << clbit
|
|
499
|
+
self._classical_memory = (self._classical_memory & (~clmask)) | (
|
|
500
|
+
qubit_outcome << clbit
|
|
501
|
+
)
|
|
502
|
+
|
|
503
|
+
data.append(bin(self._classical_memory)[2:].zfill(self.num_qubits()))
|
|
504
|
+
|
|
505
|
+
return data
|
|
506
|
+
|
|
507
|
+
def run_qiskit_circuit(self, experiment, shots=1):
|
|
508
|
+
if not _IS_QISKIT_AVAILABLE:
|
|
509
|
+
raise RuntimeError(
|
|
510
|
+
"Before trying to run_qiskit_circuit() with QrackAceBackend, you must install Qiskit!"
|
|
511
|
+
)
|
|
512
|
+
|
|
513
|
+
instructions = []
|
|
514
|
+
if isinstance(experiment, QuantumCircuit):
|
|
515
|
+
instructions = experiment.data
|
|
516
|
+
else:
|
|
517
|
+
raise RuntimeError('Unrecognized "run_input" argument specified for run().')
|
|
518
|
+
|
|
519
|
+
self._shots = shots
|
|
520
|
+
self._sample_qubits = []
|
|
521
|
+
self._sample_clbits = []
|
|
522
|
+
self._sample_cregbits = []
|
|
523
|
+
self._sample_measure = True
|
|
524
|
+
_data = []
|
|
525
|
+
shotLoopMax = 1
|
|
526
|
+
|
|
527
|
+
is_initializing = True
|
|
528
|
+
boundary_start = -1
|
|
529
|
+
|
|
530
|
+
for opcount in range(len(instructions)):
|
|
531
|
+
operation = instructions[opcount]
|
|
532
|
+
|
|
533
|
+
if operation.name == 'id' or operation.name == 'barrier':
|
|
534
|
+
continue
|
|
535
|
+
|
|
536
|
+
if is_initializing and (
|
|
537
|
+
(operation.name == 'measure') or (operation.name == 'reset')
|
|
538
|
+
):
|
|
539
|
+
continue
|
|
540
|
+
|
|
541
|
+
is_initializing = False
|
|
542
|
+
|
|
543
|
+
if (operation.name == 'measure') or (operation.name == 'reset'):
|
|
544
|
+
if boundary_start == -1:
|
|
545
|
+
boundary_start = opcount
|
|
546
|
+
|
|
547
|
+
if (boundary_start != -1) and (operation.name != 'measure'):
|
|
548
|
+
shotsPerLoop = 1
|
|
549
|
+
shotLoopMax = self._shots
|
|
550
|
+
self._sample_measure = False
|
|
551
|
+
break
|
|
552
|
+
|
|
553
|
+
preamble_memory = 0
|
|
554
|
+
preamble_register = 0
|
|
555
|
+
preamble_sim = None
|
|
556
|
+
|
|
557
|
+
if self._sample_measure or boundary_start <= 0:
|
|
558
|
+
boundary_start = 0
|
|
559
|
+
self._sample_measure = True
|
|
560
|
+
shotsPerLoop = self._shots
|
|
561
|
+
shotLoopMax = 1
|
|
562
|
+
else:
|
|
563
|
+
boundary_start -= 1
|
|
564
|
+
if boundary_start > 0:
|
|
565
|
+
self._sim = self
|
|
566
|
+
self._classical_memory = 0
|
|
567
|
+
self._classical_register = 0
|
|
568
|
+
|
|
569
|
+
for operation in instructions[:boundary_start]:
|
|
570
|
+
self._apply_op(operation)
|
|
571
|
+
|
|
572
|
+
preamble_memory = self._classical_memory
|
|
573
|
+
preamble_register = self._classical_register
|
|
574
|
+
preamble_sim = self._sim
|
|
575
|
+
|
|
576
|
+
for shot in range(shotLoopMax):
|
|
577
|
+
if preamble_sim is None:
|
|
578
|
+
self._sim = self
|
|
579
|
+
self._classical_memory = 0
|
|
580
|
+
self._classical_register = 0
|
|
581
|
+
else:
|
|
582
|
+
self._sim = QrackAceBackend(toClone=preamble_sim)
|
|
583
|
+
self._classical_memory = preamble_memory
|
|
584
|
+
self._classical_register = preamble_register
|
|
585
|
+
|
|
586
|
+
for operation in instructions[boundary_start:]:
|
|
587
|
+
self._apply_op(operation)
|
|
588
|
+
|
|
589
|
+
if not self._sample_measure and (len(self._sample_qubits) > 0):
|
|
590
|
+
_data += [bin(self._classical_memory)[2:].zfill(self.num_qubits())]
|
|
591
|
+
self._sample_qubits = []
|
|
592
|
+
self._sample_clbits = []
|
|
593
|
+
self._sample_cregbits = []
|
|
594
|
+
|
|
595
|
+
if self._sample_measure and (len(self._sample_qubits) > 0):
|
|
596
|
+
_data = self._add_sample_measure(
|
|
597
|
+
self._sample_qubits, self._sample_clbits, self._shots
|
|
598
|
+
)
|
|
599
|
+
|
|
600
|
+
del self._sim
|
|
601
|
+
|
|
602
|
+
return _data
|
pyqrack/qrack_simulator.py
CHANGED
|
@@ -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,11 +1,11 @@
|
|
|
1
1
|
pyqrack/__init__.py,sha256=yH4CMEDLk59IphSl9303zTP8Pmj3usIQMSDCOb42KCc,768
|
|
2
2
|
pyqrack/neuron_activation_fn.py,sha256=NYG78IFCiJ586E9oA6lJl38Rl18_WFfcdL6I2NYfiPs,594
|
|
3
3
|
pyqrack/pauli.py,sha256=wg500wDOwdIU4lEVJoMmjtbAdmtakZYzLPjdzC2rwUQ,654
|
|
4
|
-
pyqrack/qrack_ace_backend.py,sha256=
|
|
4
|
+
pyqrack/qrack_ace_backend.py,sha256=p1h3c6pHU3OqPmF2Ak6zx06v6tYd3e-1C2GzSJ56ve4,18549
|
|
5
5
|
pyqrack/qrack_circuit.py,sha256=TyppOMNk_0nolChMRewf4CfQGuYiEUJ8qUWWN6y03PE,19093
|
|
6
6
|
pyqrack/qrack_neuron.py,sha256=oEvMnkFFOUBXFbIXYYY-Nir3yTo0nyw_xoRdNXeSEgk,8843
|
|
7
7
|
pyqrack/qrack_neuron_torch_layer.py,sha256=Xn6MF1hSLT0bFequx4AJTsxFdg3gO01WB9rmDE7sP9w,5824
|
|
8
|
-
pyqrack/qrack_simulator.py,sha256=
|
|
8
|
+
pyqrack/qrack_simulator.py,sha256=KeLEW49mkifX0C0caux9l3HHcF73YF6iewTBqWzv0Go,135714
|
|
9
9
|
pyqrack/qrack_stabilizer.py,sha256=CJhj8GLPH-ZM38joHr9ZL-6_IY2JC8Zql7COoePJC0U,2129
|
|
10
10
|
pyqrack/quimb_circuit_type.py,sha256=Sk-Tmn38kUYmAkJJ75btWuhYZyTXOOezmowFhfdiGDc,621
|
|
11
11
|
pyqrack/qrack_system/__init__.py,sha256=-oZ9dsb1hixsnrkUJRY_C5DzQ_l6MtifF_Z465BgqV4,334
|
|
@@ -15,8 +15,8 @@ pyqrack/qrack_system/qrack_lib/libqrack_pinvoke.so.9.19.1,sha256=jGH5FdZqL24sYRJ
|
|
|
15
15
|
pyqrack/stats/__init__.py,sha256=Hla85my2fY_roR9lIjGBVpEG7ySOTMwjWa8D6-kgCnY,276
|
|
16
16
|
pyqrack/stats/load_quantized_data.py,sha256=10-ZULlnSX45br7fDtJuiCzcMTAL4eI3QyhSENXZjgM,1162
|
|
17
17
|
pyqrack/stats/quantize_by_range.py,sha256=OjY0I8PGbellrRfdIyiC0RLdpdbbJex3C2D_bapNIqE,2211
|
|
18
|
-
pyqrack_cpu-1.44.
|
|
19
|
-
pyqrack_cpu-1.44.
|
|
20
|
-
pyqrack_cpu-1.44.
|
|
21
|
-
pyqrack_cpu-1.44.
|
|
22
|
-
pyqrack_cpu-1.44.
|
|
18
|
+
pyqrack_cpu-1.44.2.dist-info/licenses/LICENSE,sha256=HxB-7SaWTuewAk1nz-3_3FUD6QhgX73kNT_taKVUTq8,1069
|
|
19
|
+
pyqrack_cpu-1.44.2.dist-info/METADATA,sha256=H2hNU0OSd2BZcdxHYINynTZYteEV5hg0JysX_JZN5s0,6702
|
|
20
|
+
pyqrack_cpu-1.44.2.dist-info/WHEEL,sha256=doDm-6Syt8k_BJ5JAagnRBCT6Lp00BS6WvJ8r832rUs,109
|
|
21
|
+
pyqrack_cpu-1.44.2.dist-info/top_level.txt,sha256=YE_3q9JTGRLMilNg2tGP1y7uU-Dx8PDao2OhwoIbv8E,8
|
|
22
|
+
pyqrack_cpu-1.44.2.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|