pyqrack-cpu-complex128 2.30.6__tar.gz → 2.31.1__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 (32) hide show
  1. {pyqrack_cpu_complex128-2.30.6 → pyqrack_cpu_complex128-2.31.1}/Makefile +3 -3
  2. {pyqrack_cpu_complex128-2.30.6/pyqrack_cpu_complex128.egg-info → pyqrack_cpu_complex128-2.31.1}/PKG-INFO +1 -1
  3. {pyqrack_cpu_complex128-2.30.6 → pyqrack_cpu_complex128-2.31.1}/pyqrack/qrack_bridge.py +215 -1
  4. {pyqrack_cpu_complex128-2.30.6 → pyqrack_cpu_complex128-2.31.1/pyqrack_cpu_complex128.egg-info}/PKG-INFO +1 -1
  5. {pyqrack_cpu_complex128-2.30.6 → pyqrack_cpu_complex128-2.31.1}/setup.py +1 -1
  6. {pyqrack_cpu_complex128-2.30.6 → pyqrack_cpu_complex128-2.31.1}/LICENSE +0 -0
  7. {pyqrack_cpu_complex128-2.30.6 → pyqrack_cpu_complex128-2.31.1}/MANIFEST.in +0 -0
  8. {pyqrack_cpu_complex128-2.30.6 → pyqrack_cpu_complex128-2.31.1}/README.md +0 -0
  9. {pyqrack_cpu_complex128-2.30.6 → pyqrack_cpu_complex128-2.31.1}/pyproject.toml +0 -0
  10. {pyqrack_cpu_complex128-2.30.6 → pyqrack_cpu_complex128-2.31.1}/pyqrack/__init__.py +0 -0
  11. {pyqrack_cpu_complex128-2.30.6 → pyqrack_cpu_complex128-2.31.1}/pyqrack/neuron_activation_fn.py +0 -0
  12. {pyqrack_cpu_complex128-2.30.6 → pyqrack_cpu_complex128-2.31.1}/pyqrack/pauli.py +0 -0
  13. {pyqrack_cpu_complex128-2.30.6 → pyqrack_cpu_complex128-2.31.1}/pyqrack/qrack_ace_backend.py +0 -0
  14. {pyqrack_cpu_complex128-2.30.6 → pyqrack_cpu_complex128-2.31.1}/pyqrack/qrack_ace_mps_backend.py +0 -0
  15. {pyqrack_cpu_complex128-2.30.6 → pyqrack_cpu_complex128-2.31.1}/pyqrack/qrack_circuit.py +0 -0
  16. {pyqrack_cpu_complex128-2.30.6 → pyqrack_cpu_complex128-2.31.1}/pyqrack/qrack_near_clifford_qec_backend.py +0 -0
  17. {pyqrack_cpu_complex128-2.30.6 → pyqrack_cpu_complex128-2.31.1}/pyqrack/qrack_neuron.py +0 -0
  18. {pyqrack_cpu_complex128-2.30.6 → pyqrack_cpu_complex128-2.31.1}/pyqrack/qrack_neuron_torch_layer.py +0 -0
  19. {pyqrack_cpu_complex128-2.30.6 → pyqrack_cpu_complex128-2.31.1}/pyqrack/qrack_simulator.py +0 -0
  20. {pyqrack_cpu_complex128-2.30.6 → pyqrack_cpu_complex128-2.31.1}/pyqrack/qrack_stabilizer.py +0 -0
  21. {pyqrack_cpu_complex128-2.30.6 → pyqrack_cpu_complex128-2.31.1}/pyqrack/qrack_system/__init__.py +0 -0
  22. {pyqrack_cpu_complex128-2.30.6 → pyqrack_cpu_complex128-2.31.1}/pyqrack/qrack_system/qrack_system.py +0 -0
  23. {pyqrack_cpu_complex128-2.30.6 → pyqrack_cpu_complex128-2.31.1}/pyqrack/quimb_circuit_type.py +0 -0
  24. {pyqrack_cpu_complex128-2.30.6 → pyqrack_cpu_complex128-2.31.1}/pyqrack/stats/__init__.py +0 -0
  25. {pyqrack_cpu_complex128-2.30.6 → pyqrack_cpu_complex128-2.31.1}/pyqrack/stats/load_quantized_data.py +0 -0
  26. {pyqrack_cpu_complex128-2.30.6 → pyqrack_cpu_complex128-2.31.1}/pyqrack/stats/quantize_by_range.py +0 -0
  27. {pyqrack_cpu_complex128-2.30.6 → pyqrack_cpu_complex128-2.31.1}/pyqrack_cpu_complex128.egg-info/SOURCES.txt +0 -0
  28. {pyqrack_cpu_complex128-2.30.6 → pyqrack_cpu_complex128-2.31.1}/pyqrack_cpu_complex128.egg-info/dependency_links.txt +0 -0
  29. {pyqrack_cpu_complex128-2.30.6 → pyqrack_cpu_complex128-2.31.1}/pyqrack_cpu_complex128.egg-info/not-zip-safe +0 -0
  30. {pyqrack_cpu_complex128-2.30.6 → pyqrack_cpu_complex128-2.31.1}/pyqrack_cpu_complex128.egg-info/requires.txt +0 -0
  31. {pyqrack_cpu_complex128-2.30.6 → pyqrack_cpu_complex128-2.31.1}/pyqrack_cpu_complex128.egg-info/top_level.txt +0 -0
  32. {pyqrack_cpu_complex128-2.30.6 → pyqrack_cpu_complex128-2.31.1}/setup.cfg +0 -0
@@ -30,7 +30,7 @@ build-deps:
30
30
  rm -rf pyqrack/qrack_system/qrack_cl_precompile
31
31
  ifneq ($(OS),Windows_NT)
32
32
  ifeq ($(QRACK_PRESENT),)
33
- git clone https://github.com/unitaryfund/qrack.git; cd qrack; git checkout 4e51e068abbaf5eb20455d560c24f02ddb2ed1e4; cd ..
33
+ git clone https://github.com/unitaryfund/qrack.git; cd qrack; git checkout c882f49b541f77396627c3865de9c7dbf424912f; cd ..
34
34
  endif
35
35
  mkdir -p qrack/build
36
36
  ifeq ($(UNAME_S),Linux)
@@ -42,9 +42,9 @@ endif
42
42
  endif
43
43
  ifeq ($(UNAME_S),Darwin)
44
44
  ifneq ($(filter $(UNAME_P),x86_64 i386),)
45
- cd qrack/build; cmake -DFPPOW=6 -DENABLE_OPENCL=OFF -DQBCAPPOW=10 -DBoost_INCLUDE_DIR=/opt/homebrew/include -DBoost_LIBRARY_DIRS=/opt/homebrew/lib ..; make qrack_pinvoke qrack_cl_precompile
45
+ cd qrack/build; cmake -DFPPOW=6 -DENABLE_OPENCL=OFF -DENABLE_BLAS=OFF -DENABLE_CLBAST=OFF -DQBCAPPOW=10 -DBoost_INCLUDE_DIR=/opt/homebrew/include -DBoost_LIBRARY_DIRS=/opt/homebrew/lib ..; make qrack_pinvoke qrack_cl_precompile
46
46
  else
47
- cd qrack/build; cmake -DFPPOW=6 -DENABLE_OPENCL=OFF -DENABLE_RDRAND=OFF -DENABLE_COMPLEX_X2=OFF -DENABLE_SSE3=OFF -DQBCAPPOW=10 -DBoost_INCLUDE_DIR=/opt/homebrew/include -DBoost_LIBRARY_DIRS=/opt/homebrew/lib ..; make qrack_pinvoke qrack_cl_precompile
47
+ cd qrack/build; cmake -DFPPOW=6 -DENABLE_OPENCL=OFF -DENABLE_BLAS=OFF -DENABLE_CLBAST=OFF -DENABLE_RDRAND=OFF -DENABLE_COMPLEX_X2=OFF -DENABLE_SSE3=OFF -DQBCAPPOW=10 -DBoost_INCLUDE_DIR=/opt/homebrew/include -DBoost_LIBRARY_DIRS=/opt/homebrew/lib ..; make qrack_pinvoke qrack_cl_precompile
48
48
  endif
49
49
  endif
50
50
  endif
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pyqrack-cpu-complex128
3
- Version: 2.30.6
3
+ Version: 2.31.1
4
4
  Summary: pyqrack - Pure Python vm6502q/qrack Wrapper
5
5
  Home-page: https://github.com/vm6502q/pyqrack
6
6
  Author: Daniel Strano
@@ -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
+ ]
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pyqrack-cpu-complex128
3
- Version: 2.30.6
3
+ Version: 2.31.1
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.30.6"
10
+ VERSION = "2.31.1"
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')