pyqrack-cpu-complex128 2.30.6__tar.gz → 2.31.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.
- {pyqrack_cpu_complex128-2.30.6/pyqrack_cpu_complex128.egg-info → pyqrack_cpu_complex128-2.31.0}/PKG-INFO +1 -1
- {pyqrack_cpu_complex128-2.30.6 → pyqrack_cpu_complex128-2.31.0}/pyqrack/qrack_bridge.py +215 -1
- {pyqrack_cpu_complex128-2.30.6 → pyqrack_cpu_complex128-2.31.0/pyqrack_cpu_complex128.egg-info}/PKG-INFO +1 -1
- {pyqrack_cpu_complex128-2.30.6 → pyqrack_cpu_complex128-2.31.0}/setup.py +1 -1
- {pyqrack_cpu_complex128-2.30.6 → pyqrack_cpu_complex128-2.31.0}/LICENSE +0 -0
- {pyqrack_cpu_complex128-2.30.6 → pyqrack_cpu_complex128-2.31.0}/MANIFEST.in +0 -0
- {pyqrack_cpu_complex128-2.30.6 → pyqrack_cpu_complex128-2.31.0}/Makefile +0 -0
- {pyqrack_cpu_complex128-2.30.6 → pyqrack_cpu_complex128-2.31.0}/README.md +0 -0
- {pyqrack_cpu_complex128-2.30.6 → pyqrack_cpu_complex128-2.31.0}/pyproject.toml +0 -0
- {pyqrack_cpu_complex128-2.30.6 → pyqrack_cpu_complex128-2.31.0}/pyqrack/__init__.py +0 -0
- {pyqrack_cpu_complex128-2.30.6 → pyqrack_cpu_complex128-2.31.0}/pyqrack/neuron_activation_fn.py +0 -0
- {pyqrack_cpu_complex128-2.30.6 → pyqrack_cpu_complex128-2.31.0}/pyqrack/pauli.py +0 -0
- {pyqrack_cpu_complex128-2.30.6 → pyqrack_cpu_complex128-2.31.0}/pyqrack/qrack_ace_backend.py +0 -0
- {pyqrack_cpu_complex128-2.30.6 → pyqrack_cpu_complex128-2.31.0}/pyqrack/qrack_ace_mps_backend.py +0 -0
- {pyqrack_cpu_complex128-2.30.6 → pyqrack_cpu_complex128-2.31.0}/pyqrack/qrack_circuit.py +0 -0
- {pyqrack_cpu_complex128-2.30.6 → pyqrack_cpu_complex128-2.31.0}/pyqrack/qrack_near_clifford_qec_backend.py +0 -0
- {pyqrack_cpu_complex128-2.30.6 → pyqrack_cpu_complex128-2.31.0}/pyqrack/qrack_neuron.py +0 -0
- {pyqrack_cpu_complex128-2.30.6 → pyqrack_cpu_complex128-2.31.0}/pyqrack/qrack_neuron_torch_layer.py +0 -0
- {pyqrack_cpu_complex128-2.30.6 → pyqrack_cpu_complex128-2.31.0}/pyqrack/qrack_simulator.py +0 -0
- {pyqrack_cpu_complex128-2.30.6 → pyqrack_cpu_complex128-2.31.0}/pyqrack/qrack_stabilizer.py +0 -0
- {pyqrack_cpu_complex128-2.30.6 → pyqrack_cpu_complex128-2.31.0}/pyqrack/qrack_system/__init__.py +0 -0
- {pyqrack_cpu_complex128-2.30.6 → pyqrack_cpu_complex128-2.31.0}/pyqrack/qrack_system/qrack_system.py +0 -0
- {pyqrack_cpu_complex128-2.30.6 → pyqrack_cpu_complex128-2.31.0}/pyqrack/quimb_circuit_type.py +0 -0
- {pyqrack_cpu_complex128-2.30.6 → pyqrack_cpu_complex128-2.31.0}/pyqrack/stats/__init__.py +0 -0
- {pyqrack_cpu_complex128-2.30.6 → pyqrack_cpu_complex128-2.31.0}/pyqrack/stats/load_quantized_data.py +0 -0
- {pyqrack_cpu_complex128-2.30.6 → pyqrack_cpu_complex128-2.31.0}/pyqrack/stats/quantize_by_range.py +0 -0
- {pyqrack_cpu_complex128-2.30.6 → pyqrack_cpu_complex128-2.31.0}/pyqrack_cpu_complex128.egg-info/SOURCES.txt +0 -0
- {pyqrack_cpu_complex128-2.30.6 → pyqrack_cpu_complex128-2.31.0}/pyqrack_cpu_complex128.egg-info/dependency_links.txt +0 -0
- {pyqrack_cpu_complex128-2.30.6 → pyqrack_cpu_complex128-2.31.0}/pyqrack_cpu_complex128.egg-info/not-zip-safe +0 -0
- {pyqrack_cpu_complex128-2.30.6 → pyqrack_cpu_complex128-2.31.0}/pyqrack_cpu_complex128.egg-info/requires.txt +0 -0
- {pyqrack_cpu_complex128-2.30.6 → pyqrack_cpu_complex128-2.31.0}/pyqrack_cpu_complex128.egg-info/top_level.txt +0 -0
- {pyqrack_cpu_complex128-2.30.6 → pyqrack_cpu_complex128-2.31.0}/setup.cfg +0 -0
|
@@ -13,7 +13,8 @@
|
|
|
13
13
|
# then recompressed to at most 2^max_bonds Schmidt components (greedy, or Born-rule groups) before being
|
|
14
14
|
# written back, so patch engines never need ancilla qubits beyond their bonds.
|
|
15
15
|
#
|
|
16
|
-
# Same API as the pure-Python reference implementation (pyqrack.QrackPyBridge), plus pauli_expectation()
|
|
16
|
+
# Same API as the pure-Python reference implementation (pyqrack.QrackPyBridge), plus pauli_expectation()
|
|
17
|
+
# and run_qiskit_circuit() (needs the optional Qiskit dependency).
|
|
17
18
|
# If the loaded Qrack library predates QBridge, pyqrack.QrackBridge is QrackPyBridge instead.
|
|
18
19
|
#
|
|
19
20
|
# Use of this source code is governed by an MIT-style license that can be
|
|
@@ -28,6 +29,13 @@ import numpy as np
|
|
|
28
29
|
|
|
29
30
|
from .qrack_system import Qrack
|
|
30
31
|
|
|
32
|
+
_IS_QISKIT_AVAILABLE = True
|
|
33
|
+
try:
|
|
34
|
+
from qiskit.circuit import ControlledGate, QuantumCircuit
|
|
35
|
+
from qiskit.quantum_info import Operator
|
|
36
|
+
except ImportError:
|
|
37
|
+
_IS_QISKIT_AVAILABLE = False
|
|
38
|
+
|
|
31
39
|
_SQ = 1 / math.sqrt(2)
|
|
32
40
|
_X = [0, 1, 1, 0]
|
|
33
41
|
_Y = [0, -1j, 1j, 0]
|
|
@@ -54,6 +62,9 @@ def _ulonglong_byref(a):
|
|
|
54
62
|
class QrackBridge:
|
|
55
63
|
"""Bridged patching on native Qrack patches (see module docstring).
|
|
56
64
|
|
|
65
|
+
For expected XEB across different 2D nearest-neighbor experiments, see the data set, regression model,
|
|
66
|
+
and calculator at https://tinyurl.com/qrackacexeb.
|
|
67
|
+
|
|
57
68
|
Args:
|
|
58
69
|
qubit_count: number of logical qubits
|
|
59
70
|
max_bonds: bond qubits per cut (bond dimension 2^max_bonds)
|
|
@@ -304,3 +315,206 @@ class QrackBridge:
|
|
|
304
315
|
self._throw_if_error()
|
|
305
316
|
a = np.frombuffer(buf, dtype=np.float32 if Qrack.fppow < 6 else np.float64)
|
|
306
317
|
return a[0::2].astype(float) + 1j * a[1::2].astype(float)
|
|
318
|
+
|
|
319
|
+
# --- Qiskit (optional dependency) ------------------------------------------------
|
|
320
|
+
# Duck-typed like QrackSimulator.run_qiskit_circuit(). The bridge has no single-shot collapse, so
|
|
321
|
+
# measurement must be terminal per qubit: after a qubit is measured, no later gate may touch it.
|
|
322
|
+
# Gates on other qubits may still follow, and resets on untouched qubits are no-ops.
|
|
323
|
+
|
|
324
|
+
_QISKIT_SKIP = frozenset(("id", "barrier", "delay", "global_phase"))
|
|
325
|
+
_QISKIT_CONTROL_FLOW = frozenset(("if_else", "while_loop", "for_loop", "switch_case", "box", "break_loop", "continue_loop"))
|
|
326
|
+
|
|
327
|
+
def patch_of(self, q):
|
|
328
|
+
"""Index of the patch holding logical qubit q."""
|
|
329
|
+
return self.side[q][0]
|
|
330
|
+
|
|
331
|
+
@staticmethod
|
|
332
|
+
def _qiskit_check_bound(op):
|
|
333
|
+
if getattr(op, "is_parameterized", lambda: False)():
|
|
334
|
+
raise RuntimeError(
|
|
335
|
+
'QrackBridge cannot run "%s" with unbound parameters; call assign_parameters() first.' % op.name
|
|
336
|
+
)
|
|
337
|
+
|
|
338
|
+
@staticmethod
|
|
339
|
+
def _qiskit_float_params(op):
|
|
340
|
+
QrackBridge._qiskit_check_bound(op)
|
|
341
|
+
return [float(p) for p in op.params]
|
|
342
|
+
|
|
343
|
+
@staticmethod
|
|
344
|
+
def _qiskit_1q_matrix(op):
|
|
345
|
+
try:
|
|
346
|
+
m = op.to_matrix()
|
|
347
|
+
except Exception:
|
|
348
|
+
m = Operator(op).data
|
|
349
|
+
return [complex(x) for x in np.asarray(m).flatten()]
|
|
350
|
+
|
|
351
|
+
def _qiskit_controlled(self, op, qubits):
|
|
352
|
+
"""Apply a controlled single-qubit gate natively, if the bridge supports its qubits; else False."""
|
|
353
|
+
if not isinstance(op, ControlledGate) or op.base_gate.num_qubits != 1:
|
|
354
|
+
return False
|
|
355
|
+
controls, target = qubits[:-1], qubits[-1]
|
|
356
|
+
if len(controls) != op.num_ctrl_qubits:
|
|
357
|
+
return False
|
|
358
|
+
if len(controls) > 1 and len({self.patch_of(q) for q in qubits}) > 1:
|
|
359
|
+
# QBridge accepts several controls only when every qubit shares one patch.
|
|
360
|
+
return False
|
|
361
|
+
QrackBridge._qiskit_check_bound(op)
|
|
362
|
+
m = self._qiskit_1q_matrix(op.base_gate)
|
|
363
|
+
if op.name == "cu":
|
|
364
|
+
# CUGate.base_gate drops gamma, the phase on the controlled subspace.
|
|
365
|
+
g = complex(math.cos(float(op.params[3])), math.sin(float(op.params[3])))
|
|
366
|
+
m = [g * x for x in m]
|
|
367
|
+
full = (1 << len(controls)) - 1
|
|
368
|
+
state = op.ctrl_state
|
|
369
|
+
if state == full:
|
|
370
|
+
self.mcmtrx(controls, m, target)
|
|
371
|
+
elif state == 0:
|
|
372
|
+
self.macmtrx(controls, m, target)
|
|
373
|
+
else:
|
|
374
|
+
# Mixed control state: flip the open controls locally around a closed-control gate.
|
|
375
|
+
opens = [q for i, q in enumerate(controls) if not ((state >> i) & 1)]
|
|
376
|
+
for q in opens:
|
|
377
|
+
self.x(q)
|
|
378
|
+
self.mcmtrx(controls, m, target)
|
|
379
|
+
for q in opens:
|
|
380
|
+
self.x(q)
|
|
381
|
+
return True
|
|
382
|
+
|
|
383
|
+
def _apply_qiskit_op(self, op, qubits):
|
|
384
|
+
name = op.name
|
|
385
|
+
if name in QrackBridge._QISKIT_SKIP:
|
|
386
|
+
return
|
|
387
|
+
if name in QrackBridge._QISKIT_CONTROL_FLOW:
|
|
388
|
+
raise RuntimeError(
|
|
389
|
+
'QrackBridge cannot run control flow ("%s"): it has no mid-circuit measurement.' % name
|
|
390
|
+
)
|
|
391
|
+
if len(qubits) == 1:
|
|
392
|
+
q = qubits[0]
|
|
393
|
+
if name == "x":
|
|
394
|
+
self.x(q)
|
|
395
|
+
elif name == "y":
|
|
396
|
+
self.y(q)
|
|
397
|
+
elif name == "z":
|
|
398
|
+
self.z(q)
|
|
399
|
+
elif name == "h":
|
|
400
|
+
self.h(q)
|
|
401
|
+
elif name == "s":
|
|
402
|
+
self.s(q)
|
|
403
|
+
elif name == "sdg":
|
|
404
|
+
self.adjs(q)
|
|
405
|
+
elif name == "t":
|
|
406
|
+
self.t(q)
|
|
407
|
+
elif name == "tdg":
|
|
408
|
+
self.adjt(q)
|
|
409
|
+
elif name in ("u", "u3"):
|
|
410
|
+
self.u(q, *QrackBridge._qiskit_float_params(op))
|
|
411
|
+
elif name == "u2":
|
|
412
|
+
ph, lm = QrackBridge._qiskit_float_params(op)
|
|
413
|
+
self.u(q, math.pi / 2, ph, lm)
|
|
414
|
+
elif name in ("u1", "p"):
|
|
415
|
+
self.u(q, 0.0, 0.0, QrackBridge._qiskit_float_params(op)[0])
|
|
416
|
+
elif name == "reset":
|
|
417
|
+
raise RuntimeError("QrackBridge cannot reset a qubit that gates have already touched.")
|
|
418
|
+
else:
|
|
419
|
+
QrackBridge._qiskit_check_bound(op)
|
|
420
|
+
self.mtrx(QrackBridge._qiskit_1q_matrix(op), q)
|
|
421
|
+
return
|
|
422
|
+
if name == "swap":
|
|
423
|
+
self.swap(*qubits)
|
|
424
|
+
elif name == "iswap":
|
|
425
|
+
self.iswap(*qubits)
|
|
426
|
+
elif name in ("iswap_dg", "adjiswap"):
|
|
427
|
+
self.adjiswap(*qubits)
|
|
428
|
+
elif name == "fsim":
|
|
429
|
+
th, ph = QrackBridge._qiskit_float_params(op)
|
|
430
|
+
self.fsim(th, ph, *qubits)
|
|
431
|
+
elif self._qiskit_controlled(op, qubits):
|
|
432
|
+
pass
|
|
433
|
+
elif op.definition is not None:
|
|
434
|
+
self._run_qiskit_definition(op, qubits)
|
|
435
|
+
else:
|
|
436
|
+
raise RuntimeError('QrackBridge encountered unrecognized operation "%s"' % name)
|
|
437
|
+
|
|
438
|
+
def _run_qiskit_definition(self, op, qubits):
|
|
439
|
+
QrackBridge._qiskit_check_bound(op)
|
|
440
|
+
d = op.definition
|
|
441
|
+
for inst in d.data:
|
|
442
|
+
if inst.operation.name == "measure" or inst.clbits:
|
|
443
|
+
raise RuntimeError('QrackBridge cannot expand "%s": its definition measures.' % op.name)
|
|
444
|
+
self._apply_qiskit_op(inst.operation, [qubits[d.find_bit(b).index] for b in inst.qubits])
|
|
445
|
+
|
|
446
|
+
def run_qiskit_circuit(self, experiment, shots=1):
|
|
447
|
+
"""Apply a Qiskit QuantumCircuit to this bridge and sample its terminal measurements.
|
|
448
|
+
|
|
449
|
+
Gates run natively where QrackBridge has a coupler: any single-qubit gate; any controlled
|
|
450
|
+
single-qubit gate (one control across patches, several within one patch; open controls use
|
|
451
|
+
macmtrx); swap, iswap, iswap_dg and fsim between any qubits. Anything else, including
|
|
452
|
+
multi-control gates that span patches, is expanded through its Qiskit definition. The circuit
|
|
453
|
+
qubit i is logical qubit i. Use qiskit.providers.qrack.QrackBridgeSimulator for transpilation.
|
|
454
|
+
|
|
455
|
+
Args:
|
|
456
|
+
experiment: QuantumCircuit (parameters bound); at most num_qubits() qubits
|
|
457
|
+
shots: number of samples of the measured clbits
|
|
458
|
+
|
|
459
|
+
Returns:
|
|
460
|
+
list of bit strings (one per shot, clbit 0 rightmost, width = experiment.num_clbits);
|
|
461
|
+
empty if the circuit measures nothing. The bridge keeps the pre-measurement state.
|
|
462
|
+
"""
|
|
463
|
+
if not _IS_QISKIT_AVAILABLE:
|
|
464
|
+
raise RuntimeError(
|
|
465
|
+
"Before trying to run_qiskit_circuit() with QrackBridge, you must install Qiskit!"
|
|
466
|
+
)
|
|
467
|
+
if not isinstance(experiment, QuantumCircuit):
|
|
468
|
+
raise RuntimeError('Unrecognized "experiment" argument specified for run_qiskit_circuit().')
|
|
469
|
+
if experiment.num_qubits > self.n:
|
|
470
|
+
raise RuntimeError(
|
|
471
|
+
"Circuit has %d qubits, but this QrackBridge has %d." % (experiment.num_qubits, self.n)
|
|
472
|
+
)
|
|
473
|
+
|
|
474
|
+
touched = set()
|
|
475
|
+
measured = {} # clbit -> qubit; the last measurement into a clbit wins
|
|
476
|
+
measured_qubits = set()
|
|
477
|
+
for inst in experiment.data:
|
|
478
|
+
op = inst.operation
|
|
479
|
+
qubits = [experiment.find_bit(q).index for q in inst.qubits]
|
|
480
|
+
if op.name == "measure":
|
|
481
|
+
for q, c in zip(qubits, inst.clbits):
|
|
482
|
+
measured[experiment.find_bit(c).index] = q
|
|
483
|
+
measured_qubits.add(q)
|
|
484
|
+
continue
|
|
485
|
+
if op.name in QrackBridge._QISKIT_SKIP:
|
|
486
|
+
continue
|
|
487
|
+
if op.name == "reset" and not (set(qubits) & touched):
|
|
488
|
+
continue
|
|
489
|
+
if set(qubits) & measured_qubits:
|
|
490
|
+
raise RuntimeError(
|
|
491
|
+
'QrackBridge cannot apply "%s" after measuring one of its qubits (no mid-circuit measurement).'
|
|
492
|
+
% op.name
|
|
493
|
+
)
|
|
494
|
+
touched.update(qubits)
|
|
495
|
+
self._apply_qiskit_op(op, qubits)
|
|
496
|
+
|
|
497
|
+
if not measured or shots < 1:
|
|
498
|
+
return []
|
|
499
|
+
sample_qubits = sorted(set(measured.values()))
|
|
500
|
+
if len(sample_qubits) > 64:
|
|
501
|
+
raise RuntimeError("QrackBridge.measure_shots() samples at most 64 qubits per call.")
|
|
502
|
+
bit_of = {q: j for j, q in enumerate(sample_qubits)}
|
|
503
|
+
width = experiment.num_clbits
|
|
504
|
+
out = []
|
|
505
|
+
for sample in self.measure_shots(sample_qubits, shots):
|
|
506
|
+
word = 0
|
|
507
|
+
for c, q in measured.items():
|
|
508
|
+
word |= ((sample >> bit_of[q]) & 1) << c
|
|
509
|
+
out.append(bin(word)[2:].zfill(width))
|
|
510
|
+
return out
|
|
511
|
+
|
|
512
|
+
@staticmethod
|
|
513
|
+
def get_qiskit_basis_gates():
|
|
514
|
+
"""Gate names QrackBridge.run_qiskit_circuit() runs without expanding definitions."""
|
|
515
|
+
return [
|
|
516
|
+
"id", "u", "u1", "u2", "u3", "p", "rx", "ry", "rz", "r", "h", "x", "y", "z",
|
|
517
|
+
"s", "sdg", "sx", "sxdg", "t", "tdg",
|
|
518
|
+
"cx", "cy", "cz", "ch", "cp", "crx", "cry", "crz", "cu", "cu1", "cu3", "csx",
|
|
519
|
+
"ccx", "ccz", "mcx", "mcp", "swap", "iswap", "iswap_dg", "fsim", "measure", "reset",
|
|
520
|
+
]
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{pyqrack_cpu_complex128-2.30.6 → pyqrack_cpu_complex128-2.31.0}/pyqrack/neuron_activation_fn.py
RENAMED
|
File without changes
|
|
File without changes
|
{pyqrack_cpu_complex128-2.30.6 → pyqrack_cpu_complex128-2.31.0}/pyqrack/qrack_ace_backend.py
RENAMED
|
File without changes
|
{pyqrack_cpu_complex128-2.30.6 → pyqrack_cpu_complex128-2.31.0}/pyqrack/qrack_ace_mps_backend.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{pyqrack_cpu_complex128-2.30.6 → pyqrack_cpu_complex128-2.31.0}/pyqrack/qrack_neuron_torch_layer.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
{pyqrack_cpu_complex128-2.30.6 → pyqrack_cpu_complex128-2.31.0}/pyqrack/qrack_system/__init__.py
RENAMED
|
File without changes
|
{pyqrack_cpu_complex128-2.30.6 → pyqrack_cpu_complex128-2.31.0}/pyqrack/qrack_system/qrack_system.py
RENAMED
|
File without changes
|
{pyqrack_cpu_complex128-2.30.6 → pyqrack_cpu_complex128-2.31.0}/pyqrack/quimb_circuit_type.py
RENAMED
|
File without changes
|
|
File without changes
|
{pyqrack_cpu_complex128-2.30.6 → pyqrack_cpu_complex128-2.31.0}/pyqrack/stats/load_quantized_data.py
RENAMED
|
File without changes
|
{pyqrack_cpu_complex128-2.30.6 → pyqrack_cpu_complex128-2.31.0}/pyqrack/stats/quantize_by_range.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|