pyqrack-cuda 1.33.2__tar.gz → 1.34.4__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_cuda-1.33.2 → pyqrack_cuda-1.34.4}/Makefile +1 -1
- {pyqrack_cuda-1.33.2/pyqrack_cuda.egg-info → pyqrack_cuda-1.34.4}/PKG-INFO +1 -1
- {pyqrack_cuda-1.33.2 → pyqrack_cuda-1.34.4}/pyqrack/qrack_circuit.py +25 -16
- {pyqrack_cuda-1.33.2 → pyqrack_cuda-1.34.4}/pyqrack/qrack_simulator.py +66 -54
- pyqrack_cuda-1.34.4/pyqrack/qrack_system/qrack_lib/libqrack_pinvoke.so +0 -0
- {pyqrack_cuda-1.33.2 → pyqrack_cuda-1.34.4/pyqrack_cuda.egg-info}/PKG-INFO +1 -1
- {pyqrack_cuda-1.33.2 → pyqrack_cuda-1.34.4}/pyqrack_cuda.egg-info/SOURCES.txt +1 -0
- {pyqrack_cuda-1.33.2 → pyqrack_cuda-1.34.4}/setup.py +4 -4
- {pyqrack_cuda-1.33.2 → pyqrack_cuda-1.34.4}/LICENSE +0 -0
- {pyqrack_cuda-1.33.2 → pyqrack_cuda-1.34.4}/MANIFEST.in +0 -0
- {pyqrack_cuda-1.33.2 → pyqrack_cuda-1.34.4}/README.md +0 -0
- {pyqrack_cuda-1.33.2 → pyqrack_cuda-1.34.4}/pyproject.toml +0 -0
- {pyqrack_cuda-1.33.2 → pyqrack_cuda-1.34.4}/pyqrack/__init__.py +0 -0
- {pyqrack_cuda-1.33.2 → pyqrack_cuda-1.34.4}/pyqrack/neuron_activation_fn.py +0 -0
- {pyqrack_cuda-1.33.2 → pyqrack_cuda-1.34.4}/pyqrack/pauli.py +0 -0
- {pyqrack_cuda-1.33.2 → pyqrack_cuda-1.34.4}/pyqrack/qrack_neuron.py +0 -0
- {pyqrack_cuda-1.33.2 → pyqrack_cuda-1.34.4}/pyqrack/qrack_system/__init__.py +0 -0
- {pyqrack_cuda-1.33.2 → pyqrack_cuda-1.34.4}/pyqrack/qrack_system/qrack_system.py +0 -0
- {pyqrack_cuda-1.33.2 → pyqrack_cuda-1.34.4}/pyqrack/quimb_circuit_type.py +0 -0
- {pyqrack_cuda-1.33.2 → pyqrack_cuda-1.34.4}/pyqrack/util/__init__.py +0 -0
- {pyqrack_cuda-1.33.2 → pyqrack_cuda-1.34.4}/pyqrack/util/convert_qiskit_circuit_to_qasm_experiment.py +0 -0
- {pyqrack_cuda-1.33.2 → pyqrack_cuda-1.34.4}/pyqrack_cuda.egg-info/dependency_links.txt +0 -0
- {pyqrack_cuda-1.33.2 → pyqrack_cuda-1.34.4}/pyqrack_cuda.egg-info/not-zip-safe +0 -0
- {pyqrack_cuda-1.33.2 → pyqrack_cuda-1.34.4}/pyqrack_cuda.egg-info/requires.txt +0 -0
- {pyqrack_cuda-1.33.2 → pyqrack_cuda-1.34.4}/pyqrack_cuda.egg-info/top_level.txt +0 -0
- {pyqrack_cuda-1.33.2 → pyqrack_cuda-1.34.4}/setup.cfg +0 -0
@@ -18,7 +18,7 @@ help:
|
|
18
18
|
build-deps:
|
19
19
|
ifneq ($(OS),Windows_NT)
|
20
20
|
ifeq ($(QRACK_PRESENT),)
|
21
|
-
git clone https://github.com/unitaryfund/qrack.git; cd qrack; git checkout
|
21
|
+
git clone https://github.com/unitaryfund/qrack.git; cd qrack; git checkout d102dd0b166452c47027698eb25ef1430ff50bed; cd ..
|
22
22
|
endif
|
23
23
|
mkdir -p qrack/build
|
24
24
|
ifeq ($(UNAME_S),Linux)
|
@@ -385,6 +385,18 @@ class QrackCircuit:
|
|
385
385
|
|
386
386
|
return circ
|
387
387
|
|
388
|
+
def _u3_to_mtrx(params):
|
389
|
+
th = float(params[0])
|
390
|
+
ph = float(params[1])
|
391
|
+
lm = float(params[2])
|
392
|
+
|
393
|
+
c = math.cos(th / 2)
|
394
|
+
s = math.sin(th / 2)
|
395
|
+
el = np.exp(1j * lm)
|
396
|
+
ep = np.exp(1j * ph)
|
397
|
+
|
398
|
+
return [ c + 0j, -el * s, ep * s, el * ep * c]
|
399
|
+
|
388
400
|
def in_from_qiskit_circuit(circ):
|
389
401
|
"""Read a Qiskit circuit into a QrackCircuit
|
390
402
|
|
@@ -404,29 +416,26 @@ class QrackCircuit:
|
|
404
416
|
|
405
417
|
out = QrackCircuit()
|
406
418
|
|
407
|
-
basis_gates = ["u", "cx"]
|
408
|
-
circ = transpile(circ, basis_gates=basis_gates, optimization_level=
|
419
|
+
basis_gates = ["x", "y", "z", "u", "cx", "cy", "cz", "cu"]
|
420
|
+
circ = transpile(circ, basis_gates=basis_gates, optimization_level=0)
|
409
421
|
for gate in circ.data:
|
410
422
|
o = gate.operation
|
411
|
-
|
412
|
-
|
413
|
-
|
414
|
-
|
415
|
-
|
416
|
-
|
417
|
-
|
418
|
-
|
419
|
-
op =
|
420
|
-
|
421
|
-
-np.exp(1j * lm) * s,
|
422
|
-
np.exp(1j * ph) * s,
|
423
|
-
np.exp(1j * (ph + lm)) * c
|
424
|
-
]
|
423
|
+
op = []
|
424
|
+
if o.name in ["x", "cx"]:
|
425
|
+
op = [0, 1, 1, 0]
|
426
|
+
elif o.name in ["y", "cy"]:
|
427
|
+
op = [0, -1j, 1j, 0]
|
428
|
+
elif o.name in ["z", "cz"]:
|
429
|
+
op = [1, 0, 0, -1]
|
430
|
+
else:
|
431
|
+
op = QrackCircuit._u3_to_mtrx(o.params)
|
432
|
+
if o.name in ["x", "y", "z", "u"]:
|
425
433
|
out.mtrx(op, circ.find_bit(gate.qubits[0])[0])
|
426
434
|
else:
|
427
435
|
ctrls = []
|
428
436
|
for c in gate.qubits[0:1]:
|
429
437
|
ctrls.append(circ.find_bit(c)[0])
|
438
|
+
|
430
439
|
out.ucmtrx(ctrls, [0, 1, 1, 0], circ.find_bit(gate.qubits[1])[0], 1)
|
431
440
|
|
432
441
|
return out
|
@@ -21,6 +21,11 @@ try:
|
|
21
21
|
except ImportError:
|
22
22
|
_IS_QISKIT_AVAILABLE = False
|
23
23
|
|
24
|
+
try:
|
25
|
+
from qiskit import qasm3
|
26
|
+
except ImportError:
|
27
|
+
pass
|
28
|
+
|
24
29
|
_IS_NUMPY_AVAILABLE = True
|
25
30
|
try:
|
26
31
|
import numpy as np
|
@@ -3187,9 +3192,7 @@ class QrackSimulator:
|
|
3187
3192
|
|
3188
3193
|
stabilizer_count = int(lines[2])
|
3189
3194
|
|
3190
|
-
|
3191
|
-
circ_qubits = [Qubit(reg, i) for i in range(stabilizer_qubits)]
|
3192
|
-
clifford_circ = QuantumCircuit(reg)
|
3195
|
+
clifford_circ = None
|
3193
3196
|
line_number = 3
|
3194
3197
|
for i in range(stabilizer_count):
|
3195
3198
|
shard_map_size = int(lines[line_number])
|
@@ -3201,10 +3204,6 @@ class QrackSimulator:
|
|
3201
3204
|
line_number += 1
|
3202
3205
|
shard_map[int(line[0])] = int(line[1])
|
3203
3206
|
|
3204
|
-
sub_reg = []
|
3205
|
-
for index, _ in sorted(shard_map.items(), key=lambda x: x[1]):
|
3206
|
-
sub_reg.append(circ_qubits[index])
|
3207
|
-
|
3208
3207
|
line_number += 1
|
3209
3208
|
tableau = []
|
3210
3209
|
row_count = shard_map_size << 1
|
@@ -3221,16 +3220,8 @@ class QrackSimulator:
|
|
3221
3220
|
tableau = np.array(tableau, bool)
|
3222
3221
|
|
3223
3222
|
clifford = Clifford(tableau, validate=False, copy=False)
|
3224
|
-
|
3225
|
-
|
3226
|
-
for instr in circ.data:
|
3227
|
-
qubits = instr.qubits
|
3228
|
-
n_qubits = []
|
3229
|
-
for qubit in qubits:
|
3230
|
-
n_qubits.append(sub_reg[circ.find_bit(qubit)[0]])
|
3231
|
-
instr.qubits = tuple(n_qubits)
|
3232
|
-
clifford_circ.data.append(instr)
|
3233
|
-
del circ
|
3223
|
+
clifford_circ = clifford.to_circuit()
|
3224
|
+
clifford_circ = QrackSimulator._reorder_qubits(clifford_circ, shard_map)
|
3234
3225
|
|
3235
3226
|
non_clifford_gates = []
|
3236
3227
|
g = 0
|
@@ -3291,6 +3282,35 @@ class QrackSimulator:
|
|
3291
3282
|
|
3292
3283
|
return circ
|
3293
3284
|
|
3285
|
+
def _reorder_qubits(circuit, mapping):
|
3286
|
+
"""
|
3287
|
+
Reorders qubits in the circuit according to the given mapping using SWAP gates.
|
3288
|
+
(Thanks to "Elara," an OpenAI GPT, for this implementation)
|
3289
|
+
|
3290
|
+
Parameters:
|
3291
|
+
- circuit (QuantumCircuit): The circuit to modify.
|
3292
|
+
- mapping (dict): Dictionary mapping internal qubit indices to logical qubit indices.
|
3293
|
+
|
3294
|
+
Returns:
|
3295
|
+
- QuantumCircuit: The modified circuit with qubits reordered.
|
3296
|
+
"""
|
3297
|
+
swaps = []
|
3298
|
+
|
3299
|
+
# Determine swaps to fix the order
|
3300
|
+
for logical_index in sorted(mapping):
|
3301
|
+
internal_index = mapping[logical_index]
|
3302
|
+
if logical_index != internal_index:
|
3303
|
+
swaps.append((logical_index, internal_index))
|
3304
|
+
# Update the reverse mapping for subsequent swaps
|
3305
|
+
mapping[logical_index] = logical_index
|
3306
|
+
mapping[internal_index] = internal_index
|
3307
|
+
|
3308
|
+
# Apply the swaps to the circuit
|
3309
|
+
for qubit1, qubit2 in swaps:
|
3310
|
+
circuit.swap(qubit1, qubit2)
|
3311
|
+
|
3312
|
+
return circuit
|
3313
|
+
|
3294
3314
|
def file_to_optimized_qiskit_circuit(filename):
|
3295
3315
|
"""Convert an output state file to a Qiskit circuit
|
3296
3316
|
|
@@ -3397,16 +3417,14 @@ class QrackSimulator:
|
|
3397
3417
|
|
3398
3418
|
if (np.isclose(np.abs(non_clifford[0][0]), 0) and np.isclose(np.abs(non_clifford[1][1]), 0)):
|
3399
3419
|
# If we're buffering full negation (plus phase), the control qubit can be dropped.
|
3400
|
-
c = QuantumCircuit(
|
3420
|
+
c = QuantumCircuit(circ.qubits)
|
3401
3421
|
if op.name == "cx":
|
3402
|
-
c.x(
|
3422
|
+
c.x(qubits[1])
|
3403
3423
|
elif op.name == "cy":
|
3404
|
-
c.y(
|
3424
|
+
c.y(qubits[1])
|
3405
3425
|
else:
|
3406
|
-
c.z(
|
3407
|
-
|
3408
|
-
instr.qubits = (qubits[1],)
|
3409
|
-
circ.data[j] = copy.deepcopy(instr)
|
3426
|
+
c.z(qubits[1])
|
3427
|
+
circ.data[j] = copy.deepcopy(c.data[0])
|
3410
3428
|
|
3411
3429
|
j += 1
|
3412
3430
|
continue
|
@@ -3417,11 +3435,9 @@ class QrackSimulator:
|
|
3417
3435
|
break
|
3418
3436
|
|
3419
3437
|
# We're blocked, so we insert our buffer at this place in the circuit definition.
|
3420
|
-
c = QuantumCircuit(
|
3421
|
-
c.unitary(non_clifford, 0)
|
3422
|
-
|
3423
|
-
instr.qubits = (qubits[0],)
|
3424
|
-
circ.data.insert(j, copy.deepcopy(instr))
|
3438
|
+
c = QuantumCircuit(circ.qubits)
|
3439
|
+
c.unitary(non_clifford, qubits[0])
|
3440
|
+
circ.data.insert(j, copy.deepcopy(c.data[0]))
|
3425
3441
|
|
3426
3442
|
non_clifford = np.copy(ident)
|
3427
3443
|
break
|
@@ -3508,21 +3524,18 @@ class QrackSimulator:
|
|
3508
3524
|
orig_instr = circ.data[j]
|
3509
3525
|
del circ.data[j]
|
3510
3526
|
|
3511
|
-
h = QuantumCircuit(1)
|
3512
|
-
h.h(0)
|
3513
|
-
instr = h.data[0]
|
3514
|
-
|
3515
3527
|
# We're replacing CNOT with CNOT in the opposite direction plus four H gates
|
3516
|
-
|
3517
|
-
|
3518
|
-
|
3519
|
-
|
3520
|
-
|
3521
|
-
|
3522
|
-
|
3523
|
-
|
3524
|
-
|
3525
|
-
|
3528
|
+
rep = QuantumCircuit(circ.qubits)
|
3529
|
+
rep.h(qubits[0])
|
3530
|
+
circ.data.insert(j, copy.deepcopy(rep.data[0]))
|
3531
|
+
rep.h(qubits[1])
|
3532
|
+
circ.data.insert(j, copy.deepcopy(rep.data[1]))
|
3533
|
+
rep.cx(qubits[1], qubits[0])
|
3534
|
+
circ.data.insert(j, copy.deepcopy(rep.data[2]))
|
3535
|
+
rep.h(qubits[0])
|
3536
|
+
circ.data.insert(j, copy.deepcopy(rep.data[3]))
|
3537
|
+
rep.h(qubits[1])
|
3538
|
+
circ.data.insert(j, copy.deepcopy(rep.data[4]))
|
3526
3539
|
|
3527
3540
|
j += 4
|
3528
3541
|
continue
|
@@ -3533,11 +3546,9 @@ class QrackSimulator:
|
|
3533
3546
|
break
|
3534
3547
|
|
3535
3548
|
# We're blocked, so we insert our buffer at this place in the circuit definition.
|
3536
|
-
c = QuantumCircuit(
|
3537
|
-
c.unitary(non_clifford, 0)
|
3538
|
-
|
3539
|
-
instr.qubits = (qubits[0],)
|
3540
|
-
circ.data.insert(j + 1, copy.deepcopy(instr))
|
3549
|
+
c = QuantumCircuit(circ.qubits)
|
3550
|
+
c.unitary(non_clifford, qubits[0])
|
3551
|
+
circ.data.insert(j + 1, copy.deepcopy(c.data[0]))
|
3541
3552
|
|
3542
3553
|
break
|
3543
3554
|
|
@@ -3549,18 +3560,19 @@ class QrackSimulator:
|
|
3549
3560
|
j -= 1
|
3550
3561
|
continue
|
3551
3562
|
|
3552
|
-
c = QuantumCircuit(
|
3553
|
-
c.unitary(to_inject, 0)
|
3554
|
-
|
3555
|
-
instr.qubits = (qubits[0],)
|
3556
|
-
circ.data[j] = copy.deepcopy(instr)
|
3563
|
+
c = QuantumCircuit(circ.qubits)
|
3564
|
+
c.unitary(to_inject, qubits[0])
|
3565
|
+
circ.data.insert(j, copy.deepcopy(c.data[0]))
|
3557
3566
|
j -= 1
|
3558
3567
|
|
3559
3568
|
basis_gates=["u", "rz", "h", "x", "y", "z", "sx", "sxdg", "sy", "sydg", "s", "sdg", "t", "tdg", "cx", "cy", "cz", "swap"]
|
3560
3569
|
circ = transpile(circ, basis_gates=basis_gates, optimization_level=2)
|
3561
3570
|
|
3562
3571
|
#Eliminate unused ancillae
|
3563
|
-
|
3572
|
+
try:
|
3573
|
+
qasm = qasm3.dumps(circ)
|
3574
|
+
except:
|
3575
|
+
qasm = circ.qasm()
|
3564
3576
|
qasm = qasm.replace("qreg q[" + str(circ.width()) + "];", "qreg q[" + str(width) + "];")
|
3565
3577
|
highest_index = max([int(x) for x in re.findall(r"\[(.*?)\]", qasm) if x.isdigit()])
|
3566
3578
|
if highest_index != width:
|
Binary file
|
@@ -13,6 +13,7 @@ pyqrack/qrack_simulator.py
|
|
13
13
|
pyqrack/quimb_circuit_type.py
|
14
14
|
pyqrack/qrack_system/__init__.py
|
15
15
|
pyqrack/qrack_system/qrack_system.py
|
16
|
+
pyqrack/qrack_system/qrack_lib/libqrack_pinvoke.so
|
16
17
|
pyqrack/util/__init__.py
|
17
18
|
pyqrack/util/convert_qiskit_circuit_to_qasm_experiment.py
|
18
19
|
pyqrack_cuda.egg-info/PKG-INFO
|
@@ -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.
|
10
|
+
VERSION = "1.34.4"
|
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')
|
@@ -64,15 +64,15 @@ setup(
|
|
64
64
|
"Programming Language :: Python :: 3.10",
|
65
65
|
"Programming Language :: Python :: 3.11",
|
66
66
|
"Programming Language :: Python :: 3.12",
|
67
|
-
"Topic :: Scientific/Engineering"
|
67
|
+
"Topic :: Scientific/Engineering",
|
68
68
|
],
|
69
69
|
keywords="pyqrack qrack simulator quantum gpu",
|
70
70
|
install_requires=[],
|
71
71
|
setup_requires=['cmake'],
|
72
72
|
extras_require={
|
73
73
|
"dev": [
|
74
|
-
"pytest>=7.3.1"
|
75
|
-
]
|
74
|
+
"pytest>=7.3.1",
|
75
|
+
],
|
76
76
|
},
|
77
77
|
include_package_data=True,
|
78
78
|
zip_safe=False
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|