Skip to content

Commit

Permalink
v1.21.0 update
Browse files Browse the repository at this point in the history
  • Loading branch information
WrathfulSpatula committed Sep 10, 2023
1 parent 1dca32a commit c61e73b
Show file tree
Hide file tree
Showing 4 changed files with 98 additions and 18 deletions.
27 changes: 25 additions & 2 deletions pyqrack/qrack_circuit.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,13 @@ class QrackCircuit:
cid(int): Qrack ID of this circuit
"""

def __init__(self, is_collapse = True, clone_cid = -1, is_inverse=False):
def __init__(self, is_collapse = True, clone_cid = -1, is_inverse=False, past_light_cone = []):
if clone_cid < 0:
self.cid = Qrack.qrack_lib.init_qcircuit(is_collapse)
elif is_inverse:
self.cid = Qrack.qrack_lib.qcircuit_inverse(clone_cid)
elif len(past_light_cone) > 0:
self.cid = Qrack.qrack_lib.qcircuit_past_light_cone(clone_cid, len(past_light_cone), self._ulonglong_byref(past_light_cone))
else:
self.cid = Qrack.qrack_lib.init_qcircuit_clone(clone_cid)

Expand All @@ -66,16 +68,37 @@ def _complex_byref(self, a):
return self._double_byref([float(item) for sublist in t for item in sublist])

def clone(self):
"""Make a new circuit that is an exact clone of this circuit
Raises:
RuntimeError: QrackCircuit C++ library raised an exception.
"""
return QrackCircuit(clone_cid = self.cid, is_inverse = False)

def inverse(self):
"""Make a new circuit that is the exact inverse of this circuit
Raises:
RuntimeError: QrackCircuit C++ library raised an exception.
"""
return QrackCircuit(clone_cid = self.cid, is_inverse = True)

def past_light_cone(self, q):
"""Make a new circuit with just this circuits' past light cone for certain qubits.
Args:
q: list of qubit indices to include at beginning of past light cone
Raises:
RuntimeError: QrackCircuit C++ library raised an exception.
"""
return QrackCircuit(clone_cid = self.cid, is_inverse = False, past_light_cone = q)

def get_qubit_count(self):
"""Get count of qubits in circuit
Raises:
RuntimeError: QracQrackCircuitNeuron C++ library raised an exception.
RuntimeError: QrackCircuit C++ library raised an exception.
"""
return Qrack.qrack_lib.get_qcircuit_qubit_count(self.cid)

Expand Down
69 changes: 68 additions & 1 deletion pyqrack/qrack_simulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ def __init__(
self,
qubitCount=-1,
cloneSid=-1,
isTensorNetwork=True,
isSchmidtDecomposeMulti=True,
isSchmidtDecompose=True,
isStabilizerHybrid=True,
Expand All @@ -71,14 +72,23 @@ def __init__(
raise RuntimeError(
"Cannot clone a QrackSimulator and specify its qubit length at the same time, in QrackSimulator constructor!"
)

if isBinaryDecisionTree and isStabilizerHybrid:
raise RuntimeError(
"isBinaryDecisionTree and isStabilizerHybrid are currently incompatible constructor options to QrackSimulator! (Please set one or both options to False.)"
)

self.is_tensor_network = isTensorNetwork

if cloneSid > -1:
self.sid = Qrack.qrack_lib.init_clone(cloneSid)
else:
if qubitCount < 0:
qubitCount = 0

if (
isSchmidtDecompose
isTensorNetwork
and isSchmidtDecompose
and isStabilizerHybrid
and not isBinaryDecisionTree
and isPaged
Expand All @@ -94,6 +104,7 @@ def __init__(
else:
self.sid = Qrack.qrack_lib.init_count_type(
qubitCount,
isTensorNetwork,
isSchmidtDecomposeMulti,
isSchmidtDecompose,
isStabilizerHybrid,
Expand Down Expand Up @@ -1246,7 +1257,11 @@ def mul(self, a, q, o):
Raises:
RuntimeError: QrackSimulator raised an exception.
RuntimeError: QrackSimulator with isTensorNetwork=True option cannot mul()! (Turn off just this option, in the constructor.)
"""
if self.is_tensor_network:
raise RuntimeError("QrackSimulator with isTensorNetwork=True option cannot mul()! (Turn off just this option, in the constructor.)")

if len(q) != len(o):
raise RuntimeError("Lengths of list parameters are mismatched.")
aParts = self._split_longs(a)
Expand Down Expand Up @@ -1275,7 +1290,11 @@ def div(self, a, q, o):
Raises:
RuntimeError: QrackSimulator raised an exception.
RuntimeError: QrackSimulator with isTensorNetwork=True option cannot div()! (Turn off just this option, in the constructor.)
"""
if self.is_tensor_network:
raise RuntimeError("QrackSimulator with isTensorNetwork=True option cannot div()! (Turn off just this option, in the constructor.)")

if len(q) != len(o):
raise RuntimeError("Lengths of list parameters are mismatched.")
aParts = self._split_longs(a)
Expand Down Expand Up @@ -1362,7 +1381,11 @@ def pown(self, a, m, q, o):
Raises:
RuntimeError: QrackSimulator raised an exception.
RuntimeError: QrackSimulator with isTensorNetwork=True option cannot pown()! (Turn off just this option, in the constructor.)
"""
if self.is_tensor_network:
raise RuntimeError("QrackSimulator with isTensorNetwork=True option cannot pown()! (Turn off just this option, in the constructor.)")

if len(q) != len(o):
raise RuntimeError("Lengths of list parameters are mismatched.")
aParts, mParts = self._split_longs_2(a, m)
Expand Down Expand Up @@ -1445,7 +1468,11 @@ def mcmul(self, a, c, q, o):
Raises:
RuntimeError: QrackSimulator raised an exception.
RuntimeError: QrackSimulator with isTensorNetwork=True option cannot mcmul()! (Turn off just this option, in the constructor.)
"""
if self.is_tensor_network:
raise RuntimeError("QrackSimulator with isTensorNetwork=True option cannot mcmul()! (Turn off just this option, in the constructor.)")

if len(q) != len(o):
raise RuntimeError("Lengths of list parameters are mismatched.")
aParts = self._split_longs(a)
Expand Down Expand Up @@ -1477,7 +1504,11 @@ def mcdiv(self, a, c, q, o):
Raises:
RuntimeError: QrackSimulator raised an exception.
RuntimeError: QrackSimulator with isTensorNetwork=True option cannot mcdiv()! (Turn off just this option, in the constructor.)
"""
if self.is_tensor_network:
raise RuntimeError("QrackSimulator with isTensorNetwork=True option cannot mcdiv()! (Turn off just this option, in the constructor.)")

if len(q) != len(o):
raise RuntimeError("Lengths of list parameters are mismatched.")
aParts = self._split_longs(a)
Expand Down Expand Up @@ -1575,7 +1606,11 @@ def mcpown(self, a, c, m, q, o):
Raises:
RuntimeError: QrackSimulator raised an exception.
RuntimeError: QrackSimulator with isTensorNetwork=True option cannot mcpown()! (Turn off just this option, in the constructor.)
"""
if self.is_tensor_network:
raise RuntimeError("QrackSimulator with isTensorNetwork=True option cannot mcpown()! (Turn off just this option, in the constructor.)")

if len(q) != len(o):
raise RuntimeError("Lengths of list parameters are mismatched.")
aParts, mParts = self._split_longs_2(a, m)
Expand Down Expand Up @@ -1606,7 +1641,11 @@ def lda(self, qi, qv, t):
Raises:
RuntimeError: QrackSimulator raised an exception.
RuntimeError: QrackSimulator with isTensorNetwork=True option cannot lda()! (Turn off just this option, in the constructor.)
"""
if self.is_tensor_network:
raise RuntimeError("QrackSimulator with isTensorNetwork=True option cannot lda()! (Turn off just this option, in the constructor.)")

Qrack.qrack_lib.LDA(
self.sid,
len(qi),
Expand All @@ -1630,7 +1669,11 @@ def adc(self, s, qi, qv, t):
Raises:
RuntimeError: QrackSimulator raised an exception.
RuntimeError: QrackSimulator with isTensorNetwork=True option cannot adc()! (Turn off just this option, in the constructor.)
"""
if self.is_tensor_network:
raise RuntimeError("QrackSimulator with isTensorNetwork=True option cannot adc()! (Turn off just this option, in the constructor.)")

Qrack.qrack_lib.ADC(
self.sid,
s,
Expand All @@ -1655,7 +1698,11 @@ def sbc(self, s, qi, qv, t):
Raises:
RuntimeError: QrackSimulator raised an exception.
RuntimeError: QrackSimulator with isTensorNetwork=True option cannot sbc()! (Turn off just this option, in the constructor.)
"""
if self.is_tensor_network:
raise RuntimeError("QrackSimulator with isTensorNetwork=True option cannot sbc()! (Turn off just this option, in the constructor.)")

Qrack.qrack_lib.SBC(
self.sid,
s,
Expand All @@ -1681,7 +1728,11 @@ def hash(self, q, t):
Raises:
RuntimeError: QrackSimulator raised an exception.
RuntimeError: QrackSimulator with isTensorNetwork=True option cannot hash()! (Turn off just this option, in the constructor.)
"""
if self.is_tensor_network:
raise RuntimeError("QrackSimulator with isTensorNetwork=True option cannot hash()! (Turn off just this option, in the constructor.)")

Qrack.qrack_lib.Hash(
self.sid, len(q), self._ulonglong_byref(q), self._to_ubyte(len(q), t)
)
Expand Down Expand Up @@ -1986,7 +2037,11 @@ def compose(self, other, q):
Raises:
RuntimeError: QrackSimulator raised an exception.
RuntimeError: QrackSimulator with isTensorNetwork=True option cannot compose()! (Turn off just this option, in the constructor.)
"""
if self.is_tensor_network:
raise RuntimeError("QrackSimulator with isTensorNetwork=True option cannot compose()! (Turn off just this option, in the constructor.)")

Qrack.qrack_lib.Compose(self.sid, other.sid, self._ulonglong_byref(q))
self._throw_if_error()

Expand All @@ -2002,10 +2057,14 @@ def decompose(self, q):
Raises:
RuntimeError: QrackSimulator raised an exception.
RuntimeError: QrackSimulator with isTensorNetwork=True option cannot decompose()! (Turn off just this option, in the constructor.)
Returns:
State of the systems.
"""
if self.is_tensor_network:
raise RuntimeError("QrackSimulator with isTensorNetwork=True option cannot decompose()! (Turn off just this option, in the constructor.)")

other = QrackSimulator()
Qrack.qrack_lib.destroy(other.sid)
l = len(q)
Expand All @@ -2026,10 +2085,14 @@ def dispose(self, q):
Raises:
RuntimeError: QrackSimulator raised an exception.
RuntimeError: QrackSimulator with isTensorNetwork=True option cannot dispose()! (Turn off just this option, in the constructor.)
Returns:
State of the systems.
"""
if self.is_tensor_network:
raise RuntimeError("QrackSimulator with isTensorNetwork=True option cannot dispose()! (Turn off just this option, in the constructor.)")

l = len(q)
Qrack.qrack_lib.Dispose(self.sid, l, self._ulonglong_byref(q))
self._throw_if_error()
Expand Down Expand Up @@ -2388,7 +2451,11 @@ def phase_parity(self, la, q):
Raises:
RuntimeError: QrackSimulator raised an exception.
RuntimeError: QrackSimulator with isTensorNetwork=True option cannot phase_parity()! (Turn off just this option, in the constructor.)
"""
if self.is_tensor_network:
raise RuntimeError("QrackSimulator with isTensorNetwork=True option cannot phase_parity()! (Turn off just this option, in the constructor.)")

Qrack.qrack_lib.PhaseParity(
self.sid, ctypes.c_double(la), len(q), self._ulonglong_byref(q)
)
Expand Down
16 changes: 3 additions & 13 deletions pyqrack/qrack_system/qrack_system.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,19 +97,6 @@ def __init__(self):
c_bool,
c_bool,
c_bool,
c_bool
]

self.qrack_lib.init_count_type.restype = c_ulonglong
self.qrack_lib.init_count_type.argtypes = [
c_ulonglong,
c_bool,
c_bool,
c_bool,
c_bool,
c_bool,
c_bool,
c_bool,
c_bool,
c_bool
]
Expand Down Expand Up @@ -1002,6 +989,9 @@ def __init__(self):
self.qrack_lib.qcircuit_inverse.restype = c_ulonglong
self.qrack_lib.qcircuit_inverse.argtypes = [c_ulonglong]

self.qrack_lib.qcircuit_past_light_cone.restype = c_ulonglong
self.qrack_lib.qcircuit_past_light_cone.argtypes = [c_ulonglong, c_ulonglong, POINTER(c_ulonglong)]

self.qrack_lib.destroy_qcircuit.restype = None
self.qrack_lib.destroy_qcircuit.argtypes = [c_ulonglong]

Expand Down
4 changes: 2 additions & 2 deletions source/index.rst
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
PyQrack
=================
=======

Introduction
------------
Expand All @@ -8,7 +8,7 @@ Introduction
An introductory talk to Qrack can be found here `Intro to Qrack: a framework for fast quantum simulation by Daniel Strano | Quantum Software Talks <https://www.youtube.com/watch?v=yxyqJDC4SUo>`_.

Hardware Compilation
---------------
--------------------

Efficient Unitary Clifford+RZ Simulation
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Expand Down

0 comments on commit c61e73b

Please sign in to comment.