From 0d54a7c4c1babce04f054897dc09ed6f7628bf6d Mon Sep 17 00:00:00 2001 From: WrathfulSpatula Date: Sat, 5 Oct 2024 10:47:44 -0400 Subject: [PATCH] Bump version (new Qrack) --- pyqrack/qrack_simulator.py | 27 ++++++++++++++++++++++++--- pyqrack/qrack_system/qrack_system.py | 3 +++ setup.py | 2 +- 3 files changed, 28 insertions(+), 4 deletions(-) diff --git a/pyqrack/qrack_simulator.py b/pyqrack/qrack_simulator.py index 9007abc..e59c0ad 100644 --- a/pyqrack/qrack_simulator.py +++ b/pyqrack/qrack_simulator.py @@ -56,7 +56,7 @@ def __init__( isCpuGpuHybrid=True, isOpenCL=True, isHostPointer=False, - isNoisy=False, + noise=0, pyzxCircuit=None, qiskitCircuit=None, ): @@ -90,7 +90,7 @@ def __init__( isStabilizerHybrid, isBinaryDecisionTree, isPaged, - isNoisy, + (noise > 0), isCpuGpuHybrid, isOpenCL, isHostPointer @@ -98,6 +98,9 @@ def __init__( self._throw_if_error() + if noise > 0: + self.set_noise_parameter(noise) + if pyzxCircuit is not None: self.run_pyzx_gates(pyzxCircuit.gates) elif qiskitCircuit is not None: @@ -2148,7 +2151,7 @@ def in_ket(self, ket): self._throw_if_error() def out_ket(self): - """Set state vector + """Get state vector Returns the raw state vector of the simulator. Warning: State vector is not always the internal representation leading @@ -2166,6 +2169,24 @@ def out_ket(self): self._throw_if_error() return [complex(r, i) for r, i in self._pairwise(ket)] + def out_probs(self): + """Get basis dimension probabilities + + Returns the probabilities of each basis dimension in the state vector + of the simulator. + + Raises: + RuntimeError: QrackSimulator raised an exception. + + Returns: + list representing the basis dimension probabilities. + """ + prob_count = 1 << self.num_qubits() + probs = self._qrack_real1_byref([0.0] * prob_count) + Qrack.qrack_lib.OutProbs(self.sid, probs) + self._throw_if_error() + return list(probs) + def prob_all(self, q): """Probabilities of all subset permutations diff --git a/pyqrack/qrack_system/qrack_system.py b/pyqrack/qrack_system/qrack_system.py index 36873bb..1b37e82 100644 --- a/pyqrack/qrack_system/qrack_system.py +++ b/pyqrack/qrack_system/qrack_system.py @@ -82,13 +82,16 @@ def __init__(self): # These next two methods need to have c_double pointers, if PyQrack is built with fp64. self.qrack_lib.InKet.restype = None self.qrack_lib.OutKet.restype = None + self.qrack_lib.OutProbs.restype = None if self.fppow < 6: self.qrack_lib.InKet.argtypes = [c_ulonglong, POINTER(c_float)] self.qrack_lib.OutKet.argtypes = [c_ulonglong, POINTER(c_float)] + self.qrack_lib.OutProbs.argtypes = [c_ulonglong, POINTER(c_float)] else: self.qrack_lib.InKet.argtypes = [c_ulonglong, POINTER(c_double)] self.qrack_lib.OutKet.argtypes = [c_ulonglong, POINTER(c_double)] + self.qrack_lib.OutProbs.argtypes = [c_ulonglong, POINTER(c_double)] self.qrack_lib.init.restype = c_ulonglong self.qrack_lib.init.argtypes = [] diff --git a/setup.py b/setup.py index e7ab24d..2d7dca0 100644 --- a/setup.py +++ b/setup.py @@ -4,7 +4,7 @@ from setuptools import setup -VERSION = "1.30.32" +VERSION = "1.31.0" # Read long description from README. README_PATH = os.path.join(os.path.abspath(os.path.dirname(__file__)), 'README.md')