pyqrack-complex128 1.65.2__py3-none-macosx_14_0_arm64.whl → 1.78.3__py3-none-macosx_14_0_arm64.whl

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.
@@ -60,6 +60,7 @@ class QrackSimulator:
60
60
  isHostPointer=(
61
61
  True if os.environ.get("PYQRACK_HOST_POINTER_DEFAULT_ON") else False
62
62
  ),
63
+ isSparse=False,
63
64
  noise=0,
64
65
  pyzxCircuit=None,
65
66
  qiskitCircuit=None,
@@ -99,6 +100,7 @@ class QrackSimulator:
99
100
  isCpuGpuHybrid,
100
101
  isOpenCL,
101
102
  isHostPointer,
103
+ isSparse
102
104
  )
103
105
 
104
106
  self._throw_if_error()
@@ -116,36 +118,45 @@ class QrackSimulator:
116
118
  Qrack.qrack_lib.destroy(self.sid)
117
119
  self.sid = None
118
120
 
119
- def _int_byref(self, a):
121
+ @staticmethod
122
+ def _int_byref(a):
120
123
  return (ctypes.c_int * len(a))(*a)
121
124
 
122
- def _ulonglong_byref(self, a):
125
+ @staticmethod
126
+ def _ulonglong_byref(a):
123
127
  return (ctypes.c_ulonglong * len(a))(*a)
124
128
 
125
- def _longlong_byref(self, a):
129
+ @staticmethod
130
+ def _longlong_byref(a):
126
131
  return (ctypes.c_longlong * len(a))(*a)
127
132
 
128
- def _double_byref(self, a):
133
+ @staticmethod
134
+ def _double_byref(a):
129
135
  return (ctypes.c_double * len(a))(*a)
130
136
 
131
- def _complex_byref(self, a):
137
+ @staticmethod
138
+ def _complex_byref(a):
132
139
  t = [(c.real, c.imag) for c in a]
133
- return self._double_byref([float(item) for sublist in t for item in sublist])
140
+ return QrackSimulator._double_byref([float(item) for sublist in t for item in sublist])
134
141
 
135
- def _real1_byref(self, a):
142
+ @staticmethod
143
+ def _real1_byref(a):
136
144
  # This needs to be c_double, if PyQrack is built with fp64.
137
145
  if Qrack.fppow < 6:
138
146
  return (ctypes.c_float * len(a))(*a)
139
147
  return (ctypes.c_double * len(a))(*a)
140
148
 
141
- def _bool_byref(self, a):
149
+ @staticmethod
150
+ def _bool_byref(a):
142
151
  return (ctypes.c_bool * len(a))(*a)
143
152
 
144
- def _qrack_complex_byref(self, a):
153
+ @staticmethod
154
+ def _qrack_complex_byref(a):
145
155
  t = [(c.real, c.imag) for c in a]
146
- return self._real1_byref([float(item) for sublist in t for item in sublist])
156
+ return QrackSimulator._real1_byref([float(item) for sublist in t for item in sublist])
147
157
 
148
- def _to_ubyte(self, nv, v):
158
+ @staticmethod
159
+ def _to_ubyte(nv, v):
149
160
  c = math.floor((nv - 1) / 8) + 1
150
161
  b = (ctypes.c_ubyte * (c * (1 << nv)))()
151
162
  n = 0
@@ -157,7 +168,8 @@ class QrackSimulator:
157
168
 
158
169
  return b
159
170
 
160
- def _to_ulonglong(self, m, v):
171
+ @staticmethod
172
+ def _to_ulonglong(m, v):
161
173
  b = (ctypes.c_ulonglong * (m * len(v)))()
162
174
  n = 0
163
175
  for u in v:
@@ -169,7 +181,8 @@ class QrackSimulator:
169
181
  return b
170
182
 
171
183
  # See https://stackoverflow.com/questions/5389507/iterating-over-every-two-elements-in-a-list#answer-30426000
172
- def _pairwise(self, it):
184
+ @staticmethod
185
+ def _pairwise(it):
173
186
  it = iter(it)
174
187
  while True:
175
188
  try:
@@ -195,7 +208,7 @@ class QrackSimulator:
195
208
 
196
209
  def set_device_list(self, d):
197
210
  """Set the GPU device ID"""
198
- Qrack.qrack_lib.set_device_list(self.sid, len(d), self._longlong_byref(d))
211
+ Qrack.qrack_lib.set_device_list(self.sid, len(d), QrackSimulator._longlong_byref(d))
199
212
  self._throw_if_error()
200
213
 
201
214
  def clone(self):
@@ -359,7 +372,7 @@ class QrackSimulator:
359
372
  raise ValueError(
360
373
  "2x2 matrix 'm' in QrackSimulator.mtrx() must contain at least 4 elements."
361
374
  )
362
- Qrack.qrack_lib.Mtrx(self.sid, self._complex_byref(m), q)
375
+ Qrack.qrack_lib.Mtrx(self.sid, QrackSimulator._complex_byref(m), q)
363
376
  self._throw_if_error()
364
377
 
365
378
  def r(self, b, ph, q):
@@ -399,9 +412,9 @@ class QrackSimulator:
399
412
  Qrack.qrack_lib.Exp(
400
413
  self.sid,
401
414
  len(b),
402
- self._ulonglong_byref(b),
415
+ QrackSimulator._ulonglong_byref(b),
403
416
  ctypes.c_double(ph),
404
- self._ulonglong_byref(q),
417
+ QrackSimulator._ulonglong_byref(q),
405
418
  )
406
419
  self._throw_if_error()
407
420
 
@@ -418,7 +431,7 @@ class QrackSimulator:
418
431
  Raises:
419
432
  RuntimeError: QrackSimulator raised an exception.
420
433
  """
421
- Qrack.qrack_lib.MCX(self.sid, len(c), self._ulonglong_byref(c), q)
434
+ Qrack.qrack_lib.MCX(self.sid, len(c), QrackSimulator._ulonglong_byref(c), q)
422
435
  self._throw_if_error()
423
436
 
424
437
  def mcy(self, c, q):
@@ -434,7 +447,7 @@ class QrackSimulator:
434
447
  Raises:
435
448
  RuntimeError: QrackSimulator raised an exception.
436
449
  """
437
- Qrack.qrack_lib.MCY(self.sid, len(c), self._ulonglong_byref(c), q)
450
+ Qrack.qrack_lib.MCY(self.sid, len(c), QrackSimulator._ulonglong_byref(c), q)
438
451
  self._throw_if_error()
439
452
 
440
453
  def mcz(self, c, q):
@@ -450,7 +463,7 @@ class QrackSimulator:
450
463
  Raises:
451
464
  RuntimeError: QrackSimulator raised an exception.
452
465
  """
453
- Qrack.qrack_lib.MCZ(self.sid, len(c), self._ulonglong_byref(c), q)
466
+ Qrack.qrack_lib.MCZ(self.sid, len(c), QrackSimulator._ulonglong_byref(c), q)
454
467
  self._throw_if_error()
455
468
 
456
469
  def mch(self, c, q):
@@ -466,7 +479,7 @@ class QrackSimulator:
466
479
  Raises:
467
480
  RuntimeError: QrackSimulator raised an exception.
468
481
  """
469
- Qrack.qrack_lib.MCH(self.sid, len(c), self._ulonglong_byref(c), q)
482
+ Qrack.qrack_lib.MCH(self.sid, len(c), QrackSimulator._ulonglong_byref(c), q)
470
483
  self._throw_if_error()
471
484
 
472
485
  def mcs(self, c, q):
@@ -482,7 +495,7 @@ class QrackSimulator:
482
495
  Raises:
483
496
  RuntimeError: QrackSimulator raised an exception.
484
497
  """
485
- Qrack.qrack_lib.MCS(self.sid, len(c), self._ulonglong_byref(c), q)
498
+ Qrack.qrack_lib.MCS(self.sid, len(c), QrackSimulator._ulonglong_byref(c), q)
486
499
  self._throw_if_error()
487
500
 
488
501
  def mct(self, c, q):
@@ -498,7 +511,7 @@ class QrackSimulator:
498
511
  Raises:
499
512
  RuntimeError: QrackSimulator raised an exception.
500
513
  """
501
- Qrack.qrack_lib.MCT(self.sid, len(c), self._ulonglong_byref(c), q)
514
+ Qrack.qrack_lib.MCT(self.sid, len(c), QrackSimulator._ulonglong_byref(c), q)
502
515
  self._throw_if_error()
503
516
 
504
517
  def mcadjs(self, c, q):
@@ -514,7 +527,7 @@ class QrackSimulator:
514
527
  Raises:
515
528
  RuntimeError: QrackSimulator raised an exception.
516
529
  """
517
- Qrack.qrack_lib.MCAdjS(self.sid, len(c), self._ulonglong_byref(c), q)
530
+ Qrack.qrack_lib.MCAdjS(self.sid, len(c), QrackSimulator._ulonglong_byref(c), q)
518
531
  self._throw_if_error()
519
532
 
520
533
  def mcadjt(self, c, q):
@@ -530,7 +543,7 @@ class QrackSimulator:
530
543
  Raises:
531
544
  RuntimeError: QrackSimulator raised an exception.
532
545
  """
533
- Qrack.qrack_lib.MCAdjT(self.sid, len(c), self._ulonglong_byref(c), q)
546
+ Qrack.qrack_lib.MCAdjT(self.sid, len(c), QrackSimulator._ulonglong_byref(c), q)
534
547
  self._throw_if_error()
535
548
 
536
549
  def mcu(self, c, q, th, ph, la):
@@ -552,7 +565,7 @@ class QrackSimulator:
552
565
  Qrack.qrack_lib.MCU(
553
566
  self.sid,
554
567
  len(c),
555
- self._ulonglong_byref(c),
568
+ QrackSimulator._ulonglong_byref(c),
556
569
  q,
557
570
  ctypes.c_double(th),
558
571
  ctypes.c_double(ph),
@@ -580,7 +593,7 @@ class QrackSimulator:
580
593
  "2x2 matrix 'm' in QrackSimulator.mcmtrx() must contain at least 4 elements."
581
594
  )
582
595
  Qrack.qrack_lib.MCMtrx(
583
- self.sid, len(c), self._ulonglong_byref(c), self._complex_byref(m), q
596
+ self.sid, len(c), QrackSimulator._ulonglong_byref(c), QrackSimulator._complex_byref(m), q
584
597
  )
585
598
  self._throw_if_error()
586
599
 
@@ -596,7 +609,7 @@ class QrackSimulator:
596
609
  Raises:
597
610
  RuntimeError: QrackSimulator raised an exception.
598
611
  """
599
- Qrack.qrack_lib.MACX(self.sid, len(c), self._ulonglong_byref(c), q)
612
+ Qrack.qrack_lib.MACX(self.sid, len(c), QrackSimulator._ulonglong_byref(c), q)
600
613
  self._throw_if_error()
601
614
 
602
615
  def macy(self, c, q):
@@ -612,7 +625,7 @@ class QrackSimulator:
612
625
  Raises:
613
626
  RuntimeError: QrackSimulator raised an exception.
614
627
  """
615
- Qrack.qrack_lib.MACY(self.sid, len(c), self._ulonglong_byref(c), q)
628
+ Qrack.qrack_lib.MACY(self.sid, len(c), QrackSimulator._ulonglong_byref(c), q)
616
629
  self._throw_if_error()
617
630
 
618
631
  def macz(self, c, q):
@@ -628,7 +641,7 @@ class QrackSimulator:
628
641
  Raises:
629
642
  RuntimeError: QrackSimulator raised an exception.
630
643
  """
631
- Qrack.qrack_lib.MACZ(self.sid, len(c), self._ulonglong_byref(c), q)
644
+ Qrack.qrack_lib.MACZ(self.sid, len(c), QrackSimulator._ulonglong_byref(c), q)
632
645
  self._throw_if_error()
633
646
 
634
647
  def mach(self, c, q):
@@ -644,7 +657,7 @@ class QrackSimulator:
644
657
  Raises:
645
658
  RuntimeError: QrackSimulator raised an exception.
646
659
  """
647
- Qrack.qrack_lib.MACH(self.sid, len(c), self._ulonglong_byref(c), q)
660
+ Qrack.qrack_lib.MACH(self.sid, len(c), QrackSimulator._ulonglong_byref(c), q)
648
661
  self._throw_if_error()
649
662
 
650
663
  def macs(self, c, q):
@@ -660,7 +673,7 @@ class QrackSimulator:
660
673
  Raises:
661
674
  RuntimeError: QrackSimulator raised an exception.
662
675
  """
663
- Qrack.qrack_lib.MACS(self.sid, len(c), self._ulonglong_byref(c), q)
676
+ Qrack.qrack_lib.MACS(self.sid, len(c), QrackSimulator._ulonglong_byref(c), q)
664
677
  self._throw_if_error()
665
678
 
666
679
  def mact(self, c, q):
@@ -676,7 +689,7 @@ class QrackSimulator:
676
689
  Raises:
677
690
  RuntimeError: QrackSimulator raised an exception.
678
691
  """
679
- Qrack.qrack_lib.MACT(self.sid, len(c), self._ulonglong_byref(c), q)
692
+ Qrack.qrack_lib.MACT(self.sid, len(c), QrackSimulator._ulonglong_byref(c), q)
680
693
  self._throw_if_error()
681
694
 
682
695
  def macadjs(self, c, q):
@@ -692,7 +705,7 @@ class QrackSimulator:
692
705
  Raises:
693
706
  RuntimeError: QrackSimulator raised an exception.
694
707
  """
695
- Qrack.qrack_lib.MACAdjS(self.sid, len(c), self._ulonglong_byref(c), q)
708
+ Qrack.qrack_lib.MACAdjS(self.sid, len(c), QrackSimulator._ulonglong_byref(c), q)
696
709
  self._throw_if_error()
697
710
 
698
711
  def macadjt(self, c, q):
@@ -708,7 +721,7 @@ class QrackSimulator:
708
721
  Raises:
709
722
  RuntimeError: QrackSimulator raised an exception.
710
723
  """
711
- Qrack.qrack_lib.MACAdjT(self.sid, len(c), self._ulonglong_byref(c), q)
724
+ Qrack.qrack_lib.MACAdjT(self.sid, len(c), QrackSimulator._ulonglong_byref(c), q)
712
725
  self._throw_if_error()
713
726
 
714
727
  def macu(self, c, q, th, ph, la):
@@ -730,7 +743,7 @@ class QrackSimulator:
730
743
  Qrack.qrack_lib.MACU(
731
744
  self.sid,
732
745
  len(c),
733
- self._ulonglong_byref(c),
746
+ QrackSimulator._ulonglong_byref(c),
734
747
  q,
735
748
  ctypes.c_double(th),
736
749
  ctypes.c_double(ph),
@@ -758,7 +771,7 @@ class QrackSimulator:
758
771
  "2x2 matrix 'm' in QrackSimulator.macmtrx() must contain at least 4 elements."
759
772
  )
760
773
  Qrack.qrack_lib.MACMtrx(
761
- self.sid, len(c), self._ulonglong_byref(c), self._complex_byref(m), q
774
+ self.sid, len(c), QrackSimulator._ulonglong_byref(c), QrackSimulator._complex_byref(m), q
762
775
  )
763
776
  self._throw_if_error()
764
777
 
@@ -783,7 +796,7 @@ class QrackSimulator:
783
796
  "2x2 matrix 'm' in QrackSimulator.ucmtrx() must contain at least 4 elements."
784
797
  )
785
798
  Qrack.qrack_lib.UCMtrx(
786
- self.sid, len(c), self._ulonglong_byref(c), self._complex_byref(m), q, p
799
+ self.sid, len(c), QrackSimulator._ulonglong_byref(c), QrackSimulator._complex_byref(m), q, p
787
800
  )
788
801
  self._throw_if_error()
789
802
 
@@ -807,7 +820,7 @@ class QrackSimulator:
807
820
  "Multiplex matrix 'm' in QrackSimulator.multiplex1_mtrx() must contain at least (4 * 2 ** len(c)) elements."
808
821
  )
809
822
  Qrack.qrack_lib.Multiplex1Mtrx(
810
- self.sid, len(c), self._ulonglong_byref(c), q, self._complex_byref(m)
823
+ self.sid, len(c), QrackSimulator._ulonglong_byref(c), q, QrackSimulator._complex_byref(m)
811
824
  )
812
825
  self._throw_if_error()
813
826
 
@@ -822,7 +835,7 @@ class QrackSimulator:
822
835
  Raises:
823
836
  RuntimeError: QrackSimulator raised an exception.
824
837
  """
825
- Qrack.qrack_lib.MX(self.sid, len(q), self._ulonglong_byref(q))
838
+ Qrack.qrack_lib.MX(self.sid, len(q), QrackSimulator._ulonglong_byref(q))
826
839
  self._throw_if_error()
827
840
 
828
841
  def my(self, q):
@@ -836,7 +849,7 @@ class QrackSimulator:
836
849
  Raises:
837
850
  RuntimeError: QrackSimulator raised an exception.
838
851
  """
839
- Qrack.qrack_lib.MY(self.sid, len(q), self._ulonglong_byref(q))
852
+ Qrack.qrack_lib.MY(self.sid, len(q), QrackSimulator._ulonglong_byref(q))
840
853
  self._throw_if_error()
841
854
 
842
855
  def mz(self, q):
@@ -850,7 +863,7 @@ class QrackSimulator:
850
863
  Raises:
851
864
  RuntimeError: QrackSimulator raised an exception.
852
865
  """
853
- Qrack.qrack_lib.MZ(self.sid, len(q), self._ulonglong_byref(q))
866
+ Qrack.qrack_lib.MZ(self.sid, len(q), QrackSimulator._ulonglong_byref(q))
854
867
  self._throw_if_error()
855
868
 
856
869
  def mcr(self, b, ph, c, q):
@@ -873,7 +886,7 @@ class QrackSimulator:
873
886
  ctypes.c_ulonglong(b),
874
887
  ctypes.c_double(ph),
875
888
  len(c),
876
- self._ulonglong_byref(c),
889
+ QrackSimulator._ulonglong_byref(c),
877
890
  q,
878
891
  )
879
892
  self._throw_if_error()
@@ -897,11 +910,11 @@ class QrackSimulator:
897
910
  Qrack.qrack_lib.MCExp(
898
911
  self.sid,
899
912
  len(b),
900
- self._ulonglong_byref(b),
913
+ QrackSimulator._ulonglong_byref(b),
901
914
  ctypes.c_double(ph),
902
915
  len(cs),
903
- self._ulonglong_byref(cs),
904
- self._ulonglong_byref(q),
916
+ QrackSimulator._ulonglong_byref(cs),
917
+ QrackSimulator._ulonglong_byref(q),
905
918
  )
906
919
  self._throw_if_error()
907
920
 
@@ -983,7 +996,7 @@ class QrackSimulator:
983
996
  Raises:
984
997
  RuntimeError: QrackSimulator raised an exception.
985
998
  """
986
- Qrack.qrack_lib.CSWAP(self.sid, len(c), self._ulonglong_byref(c), qi1, qi2)
999
+ Qrack.qrack_lib.CSWAP(self.sid, len(c), QrackSimulator._ulonglong_byref(c), qi1, qi2)
987
1000
  self._throw_if_error()
988
1001
 
989
1002
  def acswap(self, c, qi1, qi2):
@@ -999,7 +1012,7 @@ class QrackSimulator:
999
1012
  Raises:
1000
1013
  RuntimeError: QrackSimulator raised an exception.
1001
1014
  """
1002
- Qrack.qrack_lib.ACSWAP(self.sid, len(c), self._ulonglong_byref(c), qi1, qi2)
1015
+ Qrack.qrack_lib.ACSWAP(self.sid, len(c), QrackSimulator._ulonglong_byref(c), qi1, qi2)
1003
1016
  self._throw_if_error()
1004
1017
 
1005
1018
  # standard operations
@@ -1083,7 +1096,7 @@ class QrackSimulator:
1083
1096
  if len(b) != len(q):
1084
1097
  raise RuntimeError("Lengths of list parameters are mismatched.")
1085
1098
  result = Qrack.qrack_lib.Measure(
1086
- self.sid, len(b), self._int_byref(b), self._ulonglong_byref(q)
1099
+ self.sid, len(b), QrackSimulator._int_byref(b), QrackSimulator._ulonglong_byref(q)
1087
1100
  )
1088
1101
  self._throw_if_error()
1089
1102
  return result
@@ -1104,8 +1117,8 @@ class QrackSimulator:
1104
1117
  Returns:
1105
1118
  list of measurement result.
1106
1119
  """
1107
- m = self._ulonglong_byref([0] * s)
1108
- Qrack.qrack_lib.MeasureShots(self.sid, len(q), self._ulonglong_byref(q), s, m)
1120
+ m = QrackSimulator._ulonglong_byref([0] * s)
1121
+ Qrack.qrack_lib.MeasureShots(self.sid, len(q), QrackSimulator._ulonglong_byref(q), s, m)
1109
1122
  self._throw_if_error()
1110
1123
  return [m[i] for i in range(s)]
1111
1124
 
@@ -1121,7 +1134,8 @@ class QrackSimulator:
1121
1134
  self._throw_if_error()
1122
1135
 
1123
1136
  # arithmetic-logic-unit (ALU)
1124
- def _split_longs(self, a):
1137
+ @staticmethod
1138
+ def _split_longs(a):
1125
1139
  """Split operation
1126
1140
 
1127
1141
  Splits the given integer into 64 bit numbers.
@@ -1144,7 +1158,8 @@ class QrackSimulator:
1144
1158
  a = a >> 64
1145
1159
  return aParts
1146
1160
 
1147
- def _split_longs_2(self, a, m):
1161
+ @staticmethod
1162
+ def _split_longs_2(a, m):
1148
1163
  """Split simultanoues operation
1149
1164
 
1150
1165
  Splits 2 integers into same number of 64 bit numbers.
@@ -1183,13 +1198,13 @@ class QrackSimulator:
1183
1198
  Raises:
1184
1199
  RuntimeError: QrackSimulator raised an exception.
1185
1200
  """
1186
- aParts = self._split_longs(a)
1201
+ aParts = QrackSimulator._split_longs(a)
1187
1202
  Qrack.qrack_lib.ADD(
1188
1203
  self.sid,
1189
1204
  len(aParts),
1190
- self._ulonglong_byref(aParts),
1205
+ QrackSimulator._ulonglong_byref(aParts),
1191
1206
  len(q),
1192
- self._ulonglong_byref(q),
1207
+ QrackSimulator._ulonglong_byref(q),
1193
1208
  )
1194
1209
  self._throw_if_error()
1195
1210
 
@@ -1205,13 +1220,13 @@ class QrackSimulator:
1205
1220
  Raises:
1206
1221
  RuntimeError: QrackSimulator raised an exception.
1207
1222
  """
1208
- aParts = self._split_longs(a)
1223
+ aParts = QrackSimulator._split_longs(a)
1209
1224
  Qrack.qrack_lib.SUB(
1210
1225
  self.sid,
1211
1226
  len(aParts),
1212
- self._ulonglong_byref(aParts),
1227
+ QrackSimulator._ulonglong_byref(aParts),
1213
1228
  len(q),
1214
- self._ulonglong_byref(q),
1229
+ QrackSimulator._ulonglong_byref(q),
1215
1230
  )
1216
1231
  self._throw_if_error()
1217
1232
 
@@ -1229,14 +1244,14 @@ class QrackSimulator:
1229
1244
  Raises:
1230
1245
  RuntimeError: QrackSimulator raised an exception.
1231
1246
  """
1232
- aParts = self._split_longs(a)
1247
+ aParts = QrackSimulator._split_longs(a)
1233
1248
  Qrack.qrack_lib.ADDS(
1234
1249
  self.sid,
1235
1250
  len(aParts),
1236
- self._ulonglong_byref(aParts),
1251
+ QrackSimulator._ulonglong_byref(aParts),
1237
1252
  s,
1238
1253
  len(q),
1239
- self._ulonglong_byref(q),
1254
+ QrackSimulator._ulonglong_byref(q),
1240
1255
  )
1241
1256
  self._throw_if_error()
1242
1257
 
@@ -1254,14 +1269,14 @@ class QrackSimulator:
1254
1269
  Raises:
1255
1270
  RuntimeError: QrackSimulator raised an exception.
1256
1271
  """
1257
- aParts = self._split_longs(a)
1272
+ aParts = QrackSimulator._split_longs(a)
1258
1273
  Qrack.qrack_lib.SUBS(
1259
1274
  self.sid,
1260
1275
  len(aParts),
1261
- self._ulonglong_byref(aParts),
1276
+ QrackSimulator._ulonglong_byref(aParts),
1262
1277
  s,
1263
1278
  len(q),
1264
- self._ulonglong_byref(q),
1279
+ QrackSimulator._ulonglong_byref(q),
1265
1280
  )
1266
1281
  self._throw_if_error()
1267
1282
 
@@ -1292,14 +1307,14 @@ class QrackSimulator:
1292
1307
 
1293
1308
  if len(q) != len(o):
1294
1309
  raise RuntimeError("Lengths of list parameters are mismatched.")
1295
- aParts = self._split_longs(a)
1310
+ aParts = QrackSimulator._split_longs(a)
1296
1311
  Qrack.qrack_lib.MUL(
1297
1312
  self.sid,
1298
1313
  len(aParts),
1299
- self._ulonglong_byref(aParts),
1314
+ QrackSimulator._ulonglong_byref(aParts),
1300
1315
  len(q),
1301
- self._ulonglong_byref(q),
1302
- self._ulonglong_byref(o),
1316
+ QrackSimulator._ulonglong_byref(q),
1317
+ QrackSimulator._ulonglong_byref(o),
1303
1318
  )
1304
1319
  self._throw_if_error()
1305
1320
 
@@ -1331,14 +1346,14 @@ class QrackSimulator:
1331
1346
 
1332
1347
  if len(q) != len(o):
1333
1348
  raise RuntimeError("Lengths of list parameters are mismatched.")
1334
- aParts = self._split_longs(a)
1349
+ aParts = QrackSimulator._split_longs(a)
1335
1350
  Qrack.qrack_lib.DIV(
1336
1351
  self.sid,
1337
1352
  len(aParts),
1338
- self._ulonglong_byref(aParts),
1353
+ QrackSimulator._ulonglong_byref(aParts),
1339
1354
  len(q),
1340
- self._ulonglong_byref(q),
1341
- self._ulonglong_byref(o),
1355
+ QrackSimulator._ulonglong_byref(q),
1356
+ QrackSimulator._ulonglong_byref(o),
1342
1357
  )
1343
1358
  self._throw_if_error()
1344
1359
 
@@ -1359,15 +1374,15 @@ class QrackSimulator:
1359
1374
  """
1360
1375
  if len(q) != len(o):
1361
1376
  raise RuntimeError("Lengths of list parameters are mismatched.")
1362
- aParts, mParts = self._split_longs_2(a, m)
1377
+ aParts, mParts = QrackSimulator._split_longs_2(a, m)
1363
1378
  Qrack.qrack_lib.MULN(
1364
1379
  self.sid,
1365
1380
  len(aParts),
1366
- self._ulonglong_byref(aParts),
1367
- self._ulonglong_byref(mParts),
1381
+ QrackSimulator._ulonglong_byref(aParts),
1382
+ QrackSimulator._ulonglong_byref(mParts),
1368
1383
  len(q),
1369
- self._ulonglong_byref(q),
1370
- self._ulonglong_byref(o),
1384
+ QrackSimulator._ulonglong_byref(q),
1385
+ QrackSimulator._ulonglong_byref(o),
1371
1386
  )
1372
1387
  self._throw_if_error()
1373
1388
 
@@ -1389,15 +1404,15 @@ class QrackSimulator:
1389
1404
  """
1390
1405
  if len(q) != len(o):
1391
1406
  raise RuntimeError("Lengths of list parameters are mismatched.")
1392
- aParts, mParts = self._split_longs_2(a, m)
1407
+ aParts, mParts = QrackSimulator._split_longs_2(a, m)
1393
1408
  Qrack.qrack_lib.DIVN(
1394
1409
  self.sid,
1395
1410
  len(aParts),
1396
- self._ulonglong_byref(aParts),
1397
- self._ulonglong_byref(mParts),
1411
+ QrackSimulator._ulonglong_byref(aParts),
1412
+ QrackSimulator._ulonglong_byref(mParts),
1398
1413
  len(q),
1399
- self._ulonglong_byref(q),
1400
- self._ulonglong_byref(o),
1414
+ QrackSimulator._ulonglong_byref(q),
1415
+ QrackSimulator._ulonglong_byref(o),
1401
1416
  )
1402
1417
  self._throw_if_error()
1403
1418
 
@@ -1428,15 +1443,15 @@ class QrackSimulator:
1428
1443
 
1429
1444
  if len(q) != len(o):
1430
1445
  raise RuntimeError("Lengths of list parameters are mismatched.")
1431
- aParts, mParts = self._split_longs_2(a, m)
1446
+ aParts, mParts = QrackSimulator._split_longs_2(a, m)
1432
1447
  Qrack.qrack_lib.POWN(
1433
1448
  self.sid,
1434
1449
  len(aParts),
1435
- self._ulonglong_byref(aParts),
1436
- self._ulonglong_byref(mParts),
1450
+ QrackSimulator._ulonglong_byref(aParts),
1451
+ QrackSimulator._ulonglong_byref(mParts),
1437
1452
  len(q),
1438
- self._ulonglong_byref(q),
1439
- self._ulonglong_byref(o),
1453
+ QrackSimulator._ulonglong_byref(q),
1454
+ QrackSimulator._ulonglong_byref(o),
1440
1455
  )
1441
1456
  self._throw_if_error()
1442
1457
 
@@ -1454,15 +1469,15 @@ class QrackSimulator:
1454
1469
  Raises:
1455
1470
  RuntimeError: QrackSimulator raised an exception.
1456
1471
  """
1457
- aParts = self._split_longs(a)
1472
+ aParts = QrackSimulator._split_longs(a)
1458
1473
  Qrack.qrack_lib.MCADD(
1459
1474
  self.sid,
1460
1475
  len(aParts),
1461
- self._ulonglong_byref(aParts),
1476
+ QrackSimulator._ulonglong_byref(aParts),
1462
1477
  len(c),
1463
- self._ulonglong_byref(c),
1478
+ QrackSimulator._ulonglong_byref(c),
1464
1479
  len(q),
1465
- self._ulonglong_byref(q),
1480
+ QrackSimulator._ulonglong_byref(q),
1466
1481
  )
1467
1482
  self._throw_if_error()
1468
1483
 
@@ -1480,15 +1495,15 @@ class QrackSimulator:
1480
1495
  Raises:
1481
1496
  RuntimeError: QrackSimulator raised an exception.
1482
1497
  """
1483
- aParts = self._split_longs(a)
1498
+ aParts = QrackSimulator._split_longs(a)
1484
1499
  Qrack.qrack_lib.MCSUB(
1485
1500
  self.sid,
1486
1501
  len(aParts),
1487
- self._ulonglong_byref(aParts),
1502
+ QrackSimulator._ulonglong_byref(aParts),
1488
1503
  len(c),
1489
- self._ulonglong_byref(c),
1504
+ QrackSimulator._ulonglong_byref(c),
1490
1505
  len(q),
1491
- self._ulonglong_byref(q),
1506
+ QrackSimulator._ulonglong_byref(q),
1492
1507
  )
1493
1508
  self._throw_if_error()
1494
1509
 
@@ -1521,15 +1536,15 @@ class QrackSimulator:
1521
1536
 
1522
1537
  if len(q) != len(o):
1523
1538
  raise RuntimeError("Lengths of list parameters are mismatched.")
1524
- aParts = self._split_longs(a)
1539
+ aParts = QrackSimulator._split_longs(a)
1525
1540
  Qrack.qrack_lib.MCMUL(
1526
1541
  self.sid,
1527
1542
  len(aParts),
1528
- self._ulonglong_byref(aParts),
1543
+ QrackSimulator._ulonglong_byref(aParts),
1529
1544
  len(c),
1530
- self._ulonglong_byref(c),
1545
+ QrackSimulator._ulonglong_byref(c),
1531
1546
  len(q),
1532
- self._ulonglong_byref(q),
1547
+ QrackSimulator._ulonglong_byref(q),
1533
1548
  )
1534
1549
  self._throw_if_error()
1535
1550
 
@@ -1563,15 +1578,15 @@ class QrackSimulator:
1563
1578
 
1564
1579
  if len(q) != len(o):
1565
1580
  raise RuntimeError("Lengths of list parameters are mismatched.")
1566
- aParts = self._split_longs(a)
1581
+ aParts = QrackSimulator._split_longs(a)
1567
1582
  Qrack.qrack_lib.MCDIV(
1568
1583
  self.sid,
1569
1584
  len(aParts),
1570
- self._ulonglong_byref(aParts),
1585
+ QrackSimulator._ulonglong_byref(aParts),
1571
1586
  len(c),
1572
- self._ulonglong_byref(c),
1587
+ QrackSimulator._ulonglong_byref(c),
1573
1588
  len(q),
1574
- self._ulonglong_byref(q),
1589
+ QrackSimulator._ulonglong_byref(q),
1575
1590
  )
1576
1591
  self._throw_if_error()
1577
1592
 
@@ -1594,17 +1609,17 @@ class QrackSimulator:
1594
1609
  """
1595
1610
  if len(q) != len(o):
1596
1611
  raise RuntimeError("Lengths of list parameters are mismatched.")
1597
- aParts, mParts = self._split_longs_2(a, m)
1612
+ aParts, mParts = QrackSimulator._split_longs_2(a, m)
1598
1613
  Qrack.qrack_lib.MCMULN(
1599
1614
  self.sid,
1600
1615
  len(aParts),
1601
- self._ulonglong_byref(aParts),
1616
+ QrackSimulator._ulonglong_byref(aParts),
1602
1617
  len(c),
1603
- self._ulonglong_byref(c),
1604
- self._ulonglong_byref(mParts),
1618
+ QrackSimulator._ulonglong_byref(c),
1619
+ QrackSimulator._ulonglong_byref(mParts),
1605
1620
  len(q),
1606
- self._ulonglong_byref(q),
1607
- self._ulonglong_byref(o),
1621
+ QrackSimulator._ulonglong_byref(q),
1622
+ QrackSimulator._ulonglong_byref(o),
1608
1623
  )
1609
1624
  self._throw_if_error()
1610
1625
 
@@ -1628,17 +1643,17 @@ class QrackSimulator:
1628
1643
  """
1629
1644
  if len(q) != len(o):
1630
1645
  raise RuntimeError("Lengths of list parameters are mismatched.")
1631
- aParts, mParts = self._split_longs_2(a, m)
1646
+ aParts, mParts = QrackSimulator._split_longs_2(a, m)
1632
1647
  Qrack.qrack_lib.MCDIVN(
1633
1648
  self.sid,
1634
1649
  len(aParts),
1635
- self._ulonglong_byref(aParts),
1650
+ QrackSimulator._ulonglong_byref(aParts),
1636
1651
  len(c),
1637
- self._ulonglong_byref(c),
1638
- self._ulonglong_byref(mParts),
1652
+ QrackSimulator._ulonglong_byref(c),
1653
+ QrackSimulator._ulonglong_byref(mParts),
1639
1654
  len(q),
1640
- self._ulonglong_byref(q),
1641
- self._ulonglong_byref(o),
1655
+ QrackSimulator._ulonglong_byref(q),
1656
+ QrackSimulator._ulonglong_byref(o),
1642
1657
  )
1643
1658
  self._throw_if_error()
1644
1659
 
@@ -1671,17 +1686,17 @@ class QrackSimulator:
1671
1686
 
1672
1687
  if len(q) != len(o):
1673
1688
  raise RuntimeError("Lengths of list parameters are mismatched.")
1674
- aParts, mParts = self._split_longs_2(a, m)
1689
+ aParts, mParts = QrackSimulator._split_longs_2(a, m)
1675
1690
  Qrack.qrack_lib.MCPOWN(
1676
1691
  self.sid,
1677
1692
  len(aParts),
1678
- self._ulonglong_byref(aParts),
1693
+ QrackSimulator._ulonglong_byref(aParts),
1679
1694
  len(c),
1680
- self._ulonglong_byref(c),
1681
- self._ulonglong_byref(mParts),
1695
+ QrackSimulator._ulonglong_byref(c),
1696
+ QrackSimulator._ulonglong_byref(mParts),
1682
1697
  len(q),
1683
- self._ulonglong_byref(q),
1684
- self._ulonglong_byref(o),
1698
+ QrackSimulator._ulonglong_byref(q),
1699
+ QrackSimulator._ulonglong_byref(o),
1685
1700
  )
1686
1701
  self._throw_if_error()
1687
1702
 
@@ -1713,10 +1728,10 @@ class QrackSimulator:
1713
1728
  Qrack.qrack_lib.LDA(
1714
1729
  self.sid,
1715
1730
  len(qi),
1716
- self._ulonglong_byref(qi),
1731
+ QrackSimulator._ulonglong_byref(qi),
1717
1732
  len(qv),
1718
- self._ulonglong_byref(qv),
1719
- self._to_ubyte(len(qv), t),
1733
+ QrackSimulator._ulonglong_byref(qv),
1734
+ QrackSimulator._to_ubyte(len(qv), t),
1720
1735
  )
1721
1736
  self._throw_if_error()
1722
1737
 
@@ -1748,10 +1763,10 @@ class QrackSimulator:
1748
1763
  self.sid,
1749
1764
  s,
1750
1765
  len(qi),
1751
- self._ulonglong_byref(qi),
1766
+ QrackSimulator._ulonglong_byref(qi),
1752
1767
  len(qv),
1753
- self._ulonglong_byref(qv),
1754
- self._to_ubyte(len(qv), t),
1768
+ QrackSimulator._ulonglong_byref(qv),
1769
+ QrackSimulator._to_ubyte(len(qv), t),
1755
1770
  )
1756
1771
  self._throw_if_error()
1757
1772
 
@@ -1783,10 +1798,10 @@ class QrackSimulator:
1783
1798
  self.sid,
1784
1799
  s,
1785
1800
  len(qi),
1786
- self._ulonglong_byref(qi),
1801
+ QrackSimulator._ulonglong_byref(qi),
1787
1802
  len(qv),
1788
- self._ulonglong_byref(qv),
1789
- self._to_ubyte(len(qv), t),
1803
+ QrackSimulator._ulonglong_byref(qv),
1804
+ QrackSimulator._to_ubyte(len(qv), t),
1790
1805
  )
1791
1806
  self._throw_if_error()
1792
1807
 
@@ -1816,7 +1831,7 @@ class QrackSimulator:
1816
1831
  )
1817
1832
 
1818
1833
  Qrack.qrack_lib.Hash(
1819
- self.sid, len(q), self._ulonglong_byref(q), self._to_ubyte(len(q), t)
1834
+ self.sid, len(q), QrackSimulator._ulonglong_byref(q), QrackSimulator._to_ubyte(len(q), t)
1820
1835
  )
1821
1836
  self._throw_if_error()
1822
1837
 
@@ -2037,7 +2052,7 @@ class QrackSimulator:
2037
2052
  Raises:
2038
2053
  RuntimeError: QrackSimulator raised an exception.
2039
2054
  """
2040
- Qrack.qrack_lib.QFT(self.sid, len(qs), self._ulonglong_byref(qs))
2055
+ Qrack.qrack_lib.QFT(self.sid, len(qs), QrackSimulator._ulonglong_byref(qs))
2041
2056
  self._throw_if_error()
2042
2057
 
2043
2058
  def iqft(self, qs):
@@ -2052,7 +2067,7 @@ class QrackSimulator:
2052
2067
  Raises:
2053
2068
  RuntimeError: QrackSimulator raised an exception.
2054
2069
  """
2055
- Qrack.qrack_lib.IQFT(self.sid, len(qs), self._ulonglong_byref(qs))
2070
+ Qrack.qrack_lib.IQFT(self.sid, len(qs), QrackSimulator._ulonglong_byref(qs))
2056
2071
  self._throw_if_error()
2057
2072
 
2058
2073
  # pseudo-quantum
@@ -2126,15 +2141,13 @@ class QrackSimulator:
2126
2141
  "QrackSimulator with isTensorNetwork=True option cannot compose()! (Turn off just this option, in the constructor.)"
2127
2142
  )
2128
2143
 
2129
- Qrack.qrack_lib.Compose(self.sid, other.sid, self._ulonglong_byref(q))
2144
+ Qrack.qrack_lib.Compose(self.sid, other.sid, QrackSimulator._ulonglong_byref(q))
2130
2145
  self._throw_if_error()
2131
2146
 
2132
2147
  def decompose(self, q):
2133
2148
  """Decompose system
2134
2149
 
2135
- Decompose the given qubit out of the system.
2136
- Warning: The qubit subsystem state must be separable, or the behavior
2137
- of this method is undefined.
2150
+ Factorize a set of contiguous bits with minimal fidelity loss.
2138
2151
 
2139
2152
  Args:
2140
2153
  q: qubit id
@@ -2144,7 +2157,7 @@ class QrackSimulator:
2144
2157
  RuntimeError: QrackSimulator with isTensorNetwork=True option cannot decompose()! (Turn off just this option, in the constructor.)
2145
2158
 
2146
2159
  Returns:
2147
- State of the systems.
2160
+ Decomposed subsystem simulator.
2148
2161
  """
2149
2162
  if self.is_tensor_network:
2150
2163
  raise RuntimeError(
@@ -2154,17 +2167,15 @@ class QrackSimulator:
2154
2167
  other = QrackSimulator()
2155
2168
  Qrack.qrack_lib.destroy(other.sid)
2156
2169
  l = len(q)
2157
- other.sid = Qrack.qrack_lib.Decompose(self.sid, l, self._ulonglong_byref(q))
2170
+ other.sid = Qrack.qrack_lib.Decompose(self.sid, l, QrackSimulator._ulonglong_byref(q))
2158
2171
  self._throw_if_error()
2159
2172
  return other
2160
2173
 
2161
2174
  def dispose(self, q):
2162
2175
  """Dispose qubits
2163
2176
 
2164
- Minimally decompose a set of contiguous bits from the separably
2165
- composed unit, and discard the separable bits.
2166
- Warning: The qubit subsystem state must be separable, or the behavior
2167
- of this method is undefined.
2177
+ Factorize a set of contiguous bits with minimal fidelity loss,
2178
+ and discard the separable bits.
2168
2179
 
2169
2180
  Args:
2170
2181
  q: qubit
@@ -2172,9 +2183,6 @@ class QrackSimulator:
2172
2183
  Raises:
2173
2184
  RuntimeError: QrackSimulator raised an exception.
2174
2185
  RuntimeError: QrackSimulator with isTensorNetwork=True option cannot dispose()! (Turn off just this option, in the constructor.)
2175
-
2176
- Returns:
2177
- State of the systems.
2178
2186
  """
2179
2187
  if self.is_tensor_network:
2180
2188
  raise RuntimeError(
@@ -2182,7 +2190,7 @@ class QrackSimulator:
2182
2190
  )
2183
2191
 
2184
2192
  l = len(q)
2185
- Qrack.qrack_lib.Dispose(self.sid, l, self._ulonglong_byref(q))
2193
+ Qrack.qrack_lib.Dispose(self.sid, l, QrackSimulator._ulonglong_byref(q))
2186
2194
  self._throw_if_error()
2187
2195
 
2188
2196
  ## miscellaneous
@@ -2252,7 +2260,7 @@ class QrackSimulator:
2252
2260
  Raises:
2253
2261
  RuntimeError: QrackSimulator raised an exception.
2254
2262
  """
2255
- Qrack.qrack_lib.InKet(self.sid, self._qrack_complex_byref(ket))
2263
+ Qrack.qrack_lib.InKet(self.sid, QrackSimulator._qrack_complex_byref(ket))
2256
2264
  self._throw_if_error()
2257
2265
 
2258
2266
  def out_ket(self):
@@ -2269,10 +2277,10 @@ class QrackSimulator:
2269
2277
  list representing the state vector.
2270
2278
  """
2271
2279
  amp_count = 1 << self.num_qubits()
2272
- ket = self._qrack_complex_byref([complex(0, 0)] * amp_count)
2280
+ ket = QrackSimulator._qrack_complex_byref([complex(0, 0)] * amp_count)
2273
2281
  Qrack.qrack_lib.OutKet(self.sid, ket)
2274
2282
  self._throw_if_error()
2275
- return [complex(r, i) for r, i in self._pairwise(ket)]
2283
+ return [complex(r, i) for r, i in QrackSimulator._pairwise(ket)]
2276
2284
 
2277
2285
  def out_probs(self):
2278
2286
  """Get basis dimension probabilities
@@ -2287,11 +2295,77 @@ class QrackSimulator:
2287
2295
  list representing the basis dimension probabilities.
2288
2296
  """
2289
2297
  prob_count = 1 << self.num_qubits()
2290
- probs = self._real1_byref([0.0] * prob_count)
2298
+ probs = QrackSimulator._real1_byref([0.0] * prob_count)
2291
2299
  Qrack.qrack_lib.OutProbs(self.sid, probs)
2292
2300
  self._throw_if_error()
2293
2301
  return list(probs)
2294
2302
 
2303
+ def out_rdm(self, q):
2304
+ """Get reduced density matrix
2305
+
2306
+ Returns the raw reduced density matrix of the simulator, for the qubit list.
2307
+ Warning: State vector or is not always the internal representation leading
2308
+ to sub-optimal performance of the method.
2309
+
2310
+ Raises:
2311
+ RuntimeError: QrackSimulator raised an exception.
2312
+
2313
+ Returns:
2314
+ flat list structure representing the reduced density matrix.
2315
+ """
2316
+ amp_count = 1 << len(q)
2317
+ sqr_amp_count = amp_count * amp_count
2318
+ flat_rdm = QrackSimulator._qrack_complex_byref([complex(0, 0)] * sqr_amp_count)
2319
+ Qrack.qrack_lib.OutReducedDensityMatrix(self.sid, len(q), QrackSimulator._ulonglong_byref(q), flat_rdm)
2320
+ self._throw_if_error()
2321
+ return [complex(r, i) for r, i in QrackSimulator._pairwise(flat_rdm)]
2322
+
2323
+ def highest_prob_perm(self):
2324
+ """Get the permutation (bit string) with the highest probability
2325
+
2326
+ Returns the single highest-probability bit string in the Hilbert space
2327
+
2328
+ Raises:
2329
+ RuntimeError: QrackSimulator raised an exception.
2330
+
2331
+ Returns:
2332
+ Highest probability dimension index
2333
+ """
2334
+ num_q = self.num_qubits()
2335
+ num_words = (num_q + 63) // 64
2336
+ _r = (ctypes.c_ulonglong * num_words)()
2337
+ Qrack.qrack_lib.HighestProbAll(self.sid, _r)
2338
+ self._throw_if_error()
2339
+ r = 0
2340
+ for w in range(num_words):
2341
+ r <<= 64
2342
+ r |= _r[w]
2343
+ return r
2344
+
2345
+ def highest_n_prob_perm(self, n):
2346
+ """Get the top n permutations (bit strings) with the highest probability
2347
+
2348
+ Returns the top n highest-probability bit strings in the Hilbert space
2349
+
2350
+ Raises:
2351
+ RuntimeError: QrackSimulator raised an exception.
2352
+
2353
+ Returns:
2354
+ Top n highest probability dimension indices
2355
+ """
2356
+ num_q = self.num_qubits()
2357
+ num_words = (num_q + 63) // 64
2358
+ _r = (ctypes.c_ulonglong * (num_words * n))()
2359
+ Qrack.qrack_lib.HighestProbAllN(self.sid, n, _r)
2360
+ self._throw_if_error()
2361
+ r = [0] * n
2362
+ for i in range(n):
2363
+ r[i] = 0
2364
+ for w in range(num_words):
2365
+ r[i] <<= 64
2366
+ r[i] |= _r[(i * num_words) + w]
2367
+ return r
2368
+
2295
2369
  def prob_all(self, q):
2296
2370
  """Probabilities of all subset permutations
2297
2371
 
@@ -2306,8 +2380,8 @@ class QrackSimulator:
2306
2380
  Returns:
2307
2381
  list representing the state vector.
2308
2382
  """
2309
- probs = self._real1_byref([0.0] * (1 << len(q)))
2310
- Qrack.qrack_lib.ProbAll(self.sid, len(q), self._ulonglong_byref(q), probs)
2383
+ probs = QrackSimulator._real1_byref([0.0] * (1 << len(q)))
2384
+ Qrack.qrack_lib.ProbAll(self.sid, len(q), QrackSimulator._ulonglong_byref(q), probs)
2311
2385
  self._throw_if_error()
2312
2386
  return list(probs)
2313
2387
 
@@ -2369,7 +2443,7 @@ class QrackSimulator:
2369
2443
  if len(q) != len(c):
2370
2444
  raise RuntimeError("prob_perm argument lengths do not match.")
2371
2445
  result = Qrack.qrack_lib.PermutationProb(
2372
- self.sid, len(q), self._ulonglong_byref(q), self._bool_byref(c)
2446
+ self.sid, len(q), QrackSimulator._ulonglong_byref(q), QrackSimulator._bool_byref(c)
2373
2447
  )
2374
2448
  self._throw_if_error()
2375
2449
  return result
@@ -2397,7 +2471,7 @@ class QrackSimulator:
2397
2471
  if len(q) != len(c):
2398
2472
  raise RuntimeError("prob_perm argument lengths do not match.")
2399
2473
  result = Qrack.qrack_lib.PermutationProbRdm(
2400
- self.sid, len(q), self._ulonglong_byref(q), self._bool_byref(c), r
2474
+ self.sid, len(q), QrackSimulator._ulonglong_byref(q), QrackSimulator._bool_byref(c), r
2401
2475
  )
2402
2476
  self._throw_if_error()
2403
2477
  return result
@@ -2418,7 +2492,7 @@ class QrackSimulator:
2418
2492
  Expectation value
2419
2493
  """
2420
2494
  result = Qrack.qrack_lib.PermutationExpectation(
2421
- self.sid, len(q), self._ulonglong_byref(q)
2495
+ self.sid, len(q), QrackSimulator._ulonglong_byref(q)
2422
2496
  )
2423
2497
  self._throw_if_error()
2424
2498
  return result
@@ -2441,7 +2515,7 @@ class QrackSimulator:
2441
2515
  Expectation value
2442
2516
  """
2443
2517
  result = Qrack.qrack_lib.PermutationExpectationRdm(
2444
- self.sid, len(q), self._ulonglong_byref(q), r
2518
+ self.sid, len(q), QrackSimulator._ulonglong_byref(q), r
2445
2519
  )
2446
2520
  self._throw_if_error()
2447
2521
  return result
@@ -2467,7 +2541,7 @@ class QrackSimulator:
2467
2541
  raise RuntimeError("factorized_expectation argument lengths do not match.")
2468
2542
  m = max([(x.bit_length() + 63) // 64 for x in c])
2469
2543
  result = Qrack.qrack_lib.FactorizedExpectation(
2470
- self.sid, len(q), self._ulonglong_byref(q), m, self._to_ulonglong(m, c)
2544
+ self.sid, len(q), QrackSimulator._ulonglong_byref(q), m, QrackSimulator._to_ulonglong(m, c)
2471
2545
  )
2472
2546
  self._throw_if_error()
2473
2547
  return result
@@ -2497,7 +2571,7 @@ class QrackSimulator:
2497
2571
  )
2498
2572
  m = max([(x.bit_length() + 63) // 64 for x in c])
2499
2573
  result = Qrack.qrack_lib.FactorizedExpectationRdm(
2500
- self.sid, len(q), self._ulonglong_byref(q), m, self._to_ulonglong(m, c), r
2574
+ self.sid, len(q), QrackSimulator._ulonglong_byref(q), m, QrackSimulator._to_ulonglong(m, c), r
2501
2575
  )
2502
2576
  self._throw_if_error()
2503
2577
  return result
@@ -2524,7 +2598,7 @@ class QrackSimulator:
2524
2598
  "factorized_expectation_rdm argument lengths do not match."
2525
2599
  )
2526
2600
  result = Qrack.qrack_lib.FactorizedExpectationFp(
2527
- self.sid, len(q), self._ulonglong_byref(q), self._real1_byref(c)
2601
+ self.sid, len(q), QrackSimulator._ulonglong_byref(q), QrackSimulator._real1_byref(c)
2528
2602
  )
2529
2603
  self._throw_if_error()
2530
2604
  return result
@@ -2553,7 +2627,7 @@ class QrackSimulator:
2553
2627
  "factorized_expectation_fp_rdm argument lengths do not match."
2554
2628
  )
2555
2629
  result = Qrack.qrack_lib.FactorizedExpectationFpRdm(
2556
- self.sid, len(q), self._ulonglong_byref(q), self._real1_byref(c), r
2630
+ self.sid, len(q), QrackSimulator._ulonglong_byref(q), QrackSimulator._real1_byref(c), r
2557
2631
  )
2558
2632
  self._throw_if_error()
2559
2633
  return result
@@ -2577,7 +2651,7 @@ class QrackSimulator:
2577
2651
  if (3 * len(q)) != len(b):
2578
2652
  raise RuntimeError("unitary_expectation argument lengths do not match.")
2579
2653
  result = Qrack.qrack_lib.UnitaryExpectation(
2580
- self.sid, len(q), self._ulonglong_byref(q), self._real1_byref(b)
2654
+ self.sid, len(q), QrackSimulator._ulonglong_byref(q), QrackSimulator._real1_byref(b)
2581
2655
  )
2582
2656
  self._throw_if_error()
2583
2657
  return result
@@ -2601,7 +2675,7 @@ class QrackSimulator:
2601
2675
  if (len(q) << 2) != len(b):
2602
2676
  raise RuntimeError("matrix_expectation argument lengths do not match.")
2603
2677
  result = Qrack.qrack_lib.MatrixExpectation(
2604
- self.sid, len(q), self._ulonglong_byref(q), self._complex_byref(b)
2678
+ self.sid, len(q), QrackSimulator._ulonglong_byref(q), QrackSimulator._complex_byref(b)
2605
2679
  )
2606
2680
  self._throw_if_error()
2607
2681
  return result
@@ -2633,9 +2707,9 @@ class QrackSimulator:
2633
2707
  result = Qrack.qrack_lib.UnitaryExpectationEigenVal(
2634
2708
  self.sid,
2635
2709
  len(q),
2636
- self._ulonglong_byref(q),
2637
- self._real1_byref(b),
2638
- self._real1_byref(e),
2710
+ QrackSimulator._ulonglong_byref(q),
2711
+ QrackSimulator._real1_byref(b),
2712
+ QrackSimulator._real1_byref(e),
2639
2713
  )
2640
2714
  self._throw_if_error()
2641
2715
  return result
@@ -2667,9 +2741,9 @@ class QrackSimulator:
2667
2741
  result = Qrack.qrack_lib.MatrixExpectationEigenVal(
2668
2742
  self.sid,
2669
2743
  len(q),
2670
- self._ulonglong_byref(q),
2671
- self._complex_byref(b),
2672
- self._real1_byref(e),
2744
+ QrackSimulator._ulonglong_byref(q),
2745
+ QrackSimulator._complex_byref(b),
2746
+ QrackSimulator._real1_byref(e),
2673
2747
  )
2674
2748
  self._throw_if_error()
2675
2749
  return result
@@ -2694,7 +2768,7 @@ class QrackSimulator:
2694
2768
  if len(q) != len(b):
2695
2769
  raise RuntimeError("pauli_expectation argument lengths do not match.")
2696
2770
  result = Qrack.qrack_lib.PauliExpectation(
2697
- self.sid, len(q), self._ulonglong_byref(q), self._ulonglong_byref(b)
2771
+ self.sid, len(q), QrackSimulator._ulonglong_byref(q), QrackSimulator._ulonglong_byref(b)
2698
2772
  )
2699
2773
  self._throw_if_error()
2700
2774
  return result
@@ -2714,7 +2788,7 @@ class QrackSimulator:
2714
2788
  Returns:
2715
2789
  float variance
2716
2790
  """
2717
- result = Qrack.qrack_lib.Variance(self.sid, len(q), self._ulonglong_byref(q))
2791
+ result = Qrack.qrack_lib.Variance(self.sid, len(q), QrackSimulator._ulonglong_byref(q))
2718
2792
  self._throw_if_error()
2719
2793
  return result
2720
2794
 
@@ -2736,7 +2810,7 @@ class QrackSimulator:
2736
2810
  variance
2737
2811
  """
2738
2812
  result = Qrack.qrack_lib.VarianceRdm(
2739
- self.sid, len(q), self._ulonglong_byref(q), r
2813
+ self.sid, len(q), QrackSimulator._ulonglong_byref(q), r
2740
2814
  )
2741
2815
  self._throw_if_error()
2742
2816
  return result
@@ -2762,7 +2836,7 @@ class QrackSimulator:
2762
2836
  raise RuntimeError("factorized_variance argument lengths do not match.")
2763
2837
  m = max([(x.bit_length() + 63) // 64 for x in c])
2764
2838
  result = Qrack.qrack_lib.FactorizedVariance(
2765
- self.sid, len(q), self._ulonglong_byref(q), m, self._to_ulonglong(m, c)
2839
+ self.sid, len(q), QrackSimulator._ulonglong_byref(q), m, QrackSimulator._to_ulonglong(m, c)
2766
2840
  )
2767
2841
  self._throw_if_error()
2768
2842
  return result
@@ -2790,7 +2864,7 @@ class QrackSimulator:
2790
2864
  raise RuntimeError("factorized_variance_rdm argument lengths do not match.")
2791
2865
  m = max([(x.bit_length() + 63) // 64 for x in c])
2792
2866
  result = Qrack.qrack_lib.FactorizedVarianceRdm(
2793
- self.sid, len(q), self._ulonglong_byref(q), m, self._to_ulonglong(m, c), r
2867
+ self.sid, len(q), QrackSimulator._ulonglong_byref(q), m, QrackSimulator._to_ulonglong(m, c), r
2794
2868
  )
2795
2869
  self._throw_if_error()
2796
2870
  return result
@@ -2815,7 +2889,7 @@ class QrackSimulator:
2815
2889
  if (len(q) << 1) != len(c):
2816
2890
  raise RuntimeError("factorized_variance_rdm argument lengths do not match.")
2817
2891
  result = Qrack.qrack_lib.FactorizedVarianceFp(
2818
- self.sid, len(q), self._ulonglong_byref(q), self._real1_byref(c)
2892
+ self.sid, len(q), QrackSimulator._ulonglong_byref(q), QrackSimulator._real1_byref(c)
2819
2893
  )
2820
2894
  self._throw_if_error()
2821
2895
  return result
@@ -2844,7 +2918,7 @@ class QrackSimulator:
2844
2918
  "factorized_variance_fp_rdm argument lengths do not match."
2845
2919
  )
2846
2920
  result = Qrack.qrack_lib.FactorizedVarianceFpRdm(
2847
- self.sid, len(q), self._ulonglong_byref(q), self._real1_byref(c), r
2921
+ self.sid, len(q), QrackSimulator._ulonglong_byref(q), QrackSimulator._real1_byref(c), r
2848
2922
  )
2849
2923
  self._throw_if_error()
2850
2924
  return result
@@ -2868,7 +2942,7 @@ class QrackSimulator:
2868
2942
  if (3 * len(q)) != len(b):
2869
2943
  raise RuntimeError("unitary_variance argument lengths do not match.")
2870
2944
  result = Qrack.qrack_lib.UnitaryVariance(
2871
- self.sid, len(q), self._ulonglong_byref(q), self._real1_byref(b)
2945
+ self.sid, len(q), QrackSimulator._ulonglong_byref(q), QrackSimulator._real1_byref(b)
2872
2946
  )
2873
2947
  self._throw_if_error()
2874
2948
  return result
@@ -2892,7 +2966,7 @@ class QrackSimulator:
2892
2966
  if (len(q) << 2) != len(b):
2893
2967
  raise RuntimeError("matrix_variance argument lengths do not match.")
2894
2968
  result = Qrack.qrack_lib.MatrixVariance(
2895
- self.sid, len(q), self._ulonglong_byref(q), self._complex_byref(b)
2969
+ self.sid, len(q), QrackSimulator._ulonglong_byref(q), QrackSimulator._complex_byref(b)
2896
2970
  )
2897
2971
  self._throw_if_error()
2898
2972
  return result
@@ -2924,9 +2998,9 @@ class QrackSimulator:
2924
2998
  result = Qrack.qrack_lib.UnitaryVarianceEigenVal(
2925
2999
  self.sid,
2926
3000
  len(q),
2927
- self._ulonglong_byref(q),
2928
- self._real1_byref(b),
2929
- self._real1_byref(e),
3001
+ QrackSimulator._ulonglong_byref(q),
3002
+ QrackSimulator._real1_byref(b),
3003
+ QrackSimulator._real1_byref(e),
2930
3004
  )
2931
3005
  self._throw_if_error()
2932
3006
  return result
@@ -2958,9 +3032,9 @@ class QrackSimulator:
2958
3032
  result = Qrack.qrack_lib.MatrixVarianceEigenVal(
2959
3033
  self.sid,
2960
3034
  len(q),
2961
- self._ulonglong_byref(q),
2962
- self._complex_byref(b),
2963
- self._real1_byref(e),
3035
+ QrackSimulator._ulonglong_byref(q),
3036
+ QrackSimulator._complex_byref(b),
3037
+ QrackSimulator._real1_byref(e),
2964
3038
  )
2965
3039
  self._throw_if_error()
2966
3040
  return result
@@ -2985,7 +3059,7 @@ class QrackSimulator:
2985
3059
  if len(q) != len(b):
2986
3060
  raise RuntimeError("pauli_variance argument lengths do not match.")
2987
3061
  result = Qrack.qrack_lib.PauliVariance(
2988
- self.sid, len(q), self._ulonglong_byref(q), self._ulonglong_byref(b)
3062
+ self.sid, len(q), QrackSimulator._ulonglong_byref(q), QrackSimulator._ulonglong_byref(b)
2989
3063
  )
2990
3064
  self._throw_if_error()
2991
3065
  return result
@@ -3009,7 +3083,7 @@ class QrackSimulator:
3009
3083
  if len(b) != len(q):
3010
3084
  raise RuntimeError("Lengths of list parameters are mismatched.")
3011
3085
  result = Qrack.qrack_lib.JointEnsembleProbability(
3012
- self.sid, len(b), self._ulonglong_byref(b), q
3086
+ self.sid, len(b), QrackSimulator._ulonglong_byref(b), q
3013
3087
  )
3014
3088
  self._throw_if_error()
3015
3089
  return result
@@ -3038,7 +3112,7 @@ class QrackSimulator:
3038
3112
  )
3039
3113
 
3040
3114
  Qrack.qrack_lib.PhaseParity(
3041
- self.sid, ctypes.c_double(la), len(q), self._ulonglong_byref(q)
3115
+ self.sid, ctypes.c_double(la), len(q), QrackSimulator._ulonglong_byref(q)
3042
3116
  )
3043
3117
  self._throw_if_error()
3044
3118
 
@@ -3064,7 +3138,7 @@ class QrackSimulator:
3064
3138
  "QrackStabilizer cannot phase_root_n()! (Create a QrackSimulator instead, also with isTensorNetwork=False.)"
3065
3139
  )
3066
3140
 
3067
- Qrack.qrack_lib.PhaseRootN(self.sid, n, len(q), self._ulonglong_byref(q))
3141
+ Qrack.qrack_lib.PhaseRootN(self.sid, n, len(q), QrackSimulator._ulonglong_byref(q))
3068
3142
  self._throw_if_error()
3069
3143
 
3070
3144
  def try_separate_1qb(self, qi1):
@@ -3121,7 +3195,7 @@ class QrackSimulator:
3121
3195
  State of all the qubits.
3122
3196
  """
3123
3197
  result = Qrack.qrack_lib.TrySeparateTol(
3124
- self.sid, len(qs), self._ulonglong_byref(qs), t
3198
+ self.sid, len(qs), QrackSimulator._ulonglong_byref(qs), t
3125
3199
  )
3126
3200
  self._throw_if_error()
3127
3201
  return result
@@ -3137,7 +3211,7 @@ class QrackSimulator:
3137
3211
  Raises:
3138
3212
  Runtimeerror: QrackSimulator raised an exception.
3139
3213
  """
3140
- result = Qrack.qrack_lib.Separate(self.sid, len(qs), self._ulonglong_byref(qs))
3214
+ result = Qrack.qrack_lib.Separate(self.sid, len(qs), QrackSimulator._ulonglong_byref(qs))
3141
3215
  self._throw_if_error()
3142
3216
 
3143
3217
  def get_unitary_fidelity(self):
@@ -3261,6 +3335,41 @@ class QrackSimulator:
3261
3335
  Qrack.qrack_lib.SetNoiseParameter(self.sid, np)
3262
3336
  self._throw_if_error()
3263
3337
 
3338
+ def set_ace_max_qb(self, qb):
3339
+ """Set "automatic circuit elision" (ACE) max qubits
3340
+
3341
+ If isSchmidtDecompose=True, maximum entangled subsytem size
3342
+ of this simulator will be capped to 'qb', and entangling
3343
+ gates that would exceed that size are replaced with gate
3344
+ shadows.
3345
+
3346
+ Args:
3347
+ qb: maximum subsystem qubits
3348
+
3349
+ Raises:
3350
+ RuntimeError: QrackSimulator raised an exception.
3351
+ """
3352
+ Qrack.qrack_lib.SetAceMaxQb(self.sid, qb)
3353
+ self._throw_if_error()
3354
+
3355
+ def set_sparse_ace_max_mb(self, mb):
3356
+ """Set sparse "automatic circuit elision" (ACE) max memory
3357
+
3358
+ If isSchmidtDecompose=True, isSparse=True, and
3359
+ isOpenCL=False, maximum subsytem size memory MB of this
3360
+ simulator will be capped to 'mb', and entangling gates
3361
+ that would exceed that size are replaced with gate
3362
+ shadows.
3363
+
3364
+ Args:
3365
+ mb: maximum subsystem memory in MB
3366
+
3367
+ Raises:
3368
+ RuntimeError: QrackSimulator raised an exception.
3369
+ """
3370
+ Qrack.qrack_lib.SetSparseAceMaxMb(self.sid, mb)
3371
+ self._throw_if_error()
3372
+
3264
3373
  def normalize(self):
3265
3374
  """Normalize the state
3266
3375
 
@@ -4396,6 +4505,7 @@ class QrackSimulator:
4396
4505
 
4397
4506
  return _data
4398
4507
 
4508
+ @staticmethod
4399
4509
  def get_qiskit_basis_gates():
4400
4510
  return [
4401
4511
  "id",