pyqrack-complex128 1.63.0__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
@@ -1053,9 +1066,16 @@ class QrackSimulator:
1053
1066
  Returns:
1054
1067
  Measurement result of all qubits.
1055
1068
  """
1056
- result = Qrack.qrack_lib.MAll(self.sid)
1069
+ num_q = self.num_qubits()
1070
+ num_words = (num_q + 63) // 64
1071
+ _r = (ctypes.c_ulonglong * num_words)()
1072
+ Qrack.qrack_lib.MAllLong(self.sid, _r)
1057
1073
  self._throw_if_error()
1058
- return result
1074
+ r = 0
1075
+ for w in range(num_words):
1076
+ r <<= 64
1077
+ r |= _r[w]
1078
+ return r
1059
1079
 
1060
1080
  def measure_pauli(self, b, q):
1061
1081
  """Pauli Measurement gate
@@ -1076,7 +1096,7 @@ class QrackSimulator:
1076
1096
  if len(b) != len(q):
1077
1097
  raise RuntimeError("Lengths of list parameters are mismatched.")
1078
1098
  result = Qrack.qrack_lib.Measure(
1079
- 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)
1080
1100
  )
1081
1101
  self._throw_if_error()
1082
1102
  return result
@@ -1097,8 +1117,8 @@ class QrackSimulator:
1097
1117
  Returns:
1098
1118
  list of measurement result.
1099
1119
  """
1100
- m = self._ulonglong_byref([0] * s)
1101
- 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)
1102
1122
  self._throw_if_error()
1103
1123
  return [m[i] for i in range(s)]
1104
1124
 
@@ -1114,7 +1134,8 @@ class QrackSimulator:
1114
1134
  self._throw_if_error()
1115
1135
 
1116
1136
  # arithmetic-logic-unit (ALU)
1117
- def _split_longs(self, a):
1137
+ @staticmethod
1138
+ def _split_longs(a):
1118
1139
  """Split operation
1119
1140
 
1120
1141
  Splits the given integer into 64 bit numbers.
@@ -1137,7 +1158,8 @@ class QrackSimulator:
1137
1158
  a = a >> 64
1138
1159
  return aParts
1139
1160
 
1140
- def _split_longs_2(self, a, m):
1161
+ @staticmethod
1162
+ def _split_longs_2(a, m):
1141
1163
  """Split simultanoues operation
1142
1164
 
1143
1165
  Splits 2 integers into same number of 64 bit numbers.
@@ -1176,13 +1198,13 @@ class QrackSimulator:
1176
1198
  Raises:
1177
1199
  RuntimeError: QrackSimulator raised an exception.
1178
1200
  """
1179
- aParts = self._split_longs(a)
1201
+ aParts = QrackSimulator._split_longs(a)
1180
1202
  Qrack.qrack_lib.ADD(
1181
1203
  self.sid,
1182
1204
  len(aParts),
1183
- self._ulonglong_byref(aParts),
1205
+ QrackSimulator._ulonglong_byref(aParts),
1184
1206
  len(q),
1185
- self._ulonglong_byref(q),
1207
+ QrackSimulator._ulonglong_byref(q),
1186
1208
  )
1187
1209
  self._throw_if_error()
1188
1210
 
@@ -1198,13 +1220,13 @@ class QrackSimulator:
1198
1220
  Raises:
1199
1221
  RuntimeError: QrackSimulator raised an exception.
1200
1222
  """
1201
- aParts = self._split_longs(a)
1223
+ aParts = QrackSimulator._split_longs(a)
1202
1224
  Qrack.qrack_lib.SUB(
1203
1225
  self.sid,
1204
1226
  len(aParts),
1205
- self._ulonglong_byref(aParts),
1227
+ QrackSimulator._ulonglong_byref(aParts),
1206
1228
  len(q),
1207
- self._ulonglong_byref(q),
1229
+ QrackSimulator._ulonglong_byref(q),
1208
1230
  )
1209
1231
  self._throw_if_error()
1210
1232
 
@@ -1222,14 +1244,14 @@ class QrackSimulator:
1222
1244
  Raises:
1223
1245
  RuntimeError: QrackSimulator raised an exception.
1224
1246
  """
1225
- aParts = self._split_longs(a)
1247
+ aParts = QrackSimulator._split_longs(a)
1226
1248
  Qrack.qrack_lib.ADDS(
1227
1249
  self.sid,
1228
1250
  len(aParts),
1229
- self._ulonglong_byref(aParts),
1251
+ QrackSimulator._ulonglong_byref(aParts),
1230
1252
  s,
1231
1253
  len(q),
1232
- self._ulonglong_byref(q),
1254
+ QrackSimulator._ulonglong_byref(q),
1233
1255
  )
1234
1256
  self._throw_if_error()
1235
1257
 
@@ -1247,14 +1269,14 @@ class QrackSimulator:
1247
1269
  Raises:
1248
1270
  RuntimeError: QrackSimulator raised an exception.
1249
1271
  """
1250
- aParts = self._split_longs(a)
1272
+ aParts = QrackSimulator._split_longs(a)
1251
1273
  Qrack.qrack_lib.SUBS(
1252
1274
  self.sid,
1253
1275
  len(aParts),
1254
- self._ulonglong_byref(aParts),
1276
+ QrackSimulator._ulonglong_byref(aParts),
1255
1277
  s,
1256
1278
  len(q),
1257
- self._ulonglong_byref(q),
1279
+ QrackSimulator._ulonglong_byref(q),
1258
1280
  )
1259
1281
  self._throw_if_error()
1260
1282
 
@@ -1285,14 +1307,14 @@ class QrackSimulator:
1285
1307
 
1286
1308
  if len(q) != len(o):
1287
1309
  raise RuntimeError("Lengths of list parameters are mismatched.")
1288
- aParts = self._split_longs(a)
1310
+ aParts = QrackSimulator._split_longs(a)
1289
1311
  Qrack.qrack_lib.MUL(
1290
1312
  self.sid,
1291
1313
  len(aParts),
1292
- self._ulonglong_byref(aParts),
1314
+ QrackSimulator._ulonglong_byref(aParts),
1293
1315
  len(q),
1294
- self._ulonglong_byref(q),
1295
- self._ulonglong_byref(o),
1316
+ QrackSimulator._ulonglong_byref(q),
1317
+ QrackSimulator._ulonglong_byref(o),
1296
1318
  )
1297
1319
  self._throw_if_error()
1298
1320
 
@@ -1324,14 +1346,14 @@ class QrackSimulator:
1324
1346
 
1325
1347
  if len(q) != len(o):
1326
1348
  raise RuntimeError("Lengths of list parameters are mismatched.")
1327
- aParts = self._split_longs(a)
1349
+ aParts = QrackSimulator._split_longs(a)
1328
1350
  Qrack.qrack_lib.DIV(
1329
1351
  self.sid,
1330
1352
  len(aParts),
1331
- self._ulonglong_byref(aParts),
1353
+ QrackSimulator._ulonglong_byref(aParts),
1332
1354
  len(q),
1333
- self._ulonglong_byref(q),
1334
- self._ulonglong_byref(o),
1355
+ QrackSimulator._ulonglong_byref(q),
1356
+ QrackSimulator._ulonglong_byref(o),
1335
1357
  )
1336
1358
  self._throw_if_error()
1337
1359
 
@@ -1352,15 +1374,15 @@ class QrackSimulator:
1352
1374
  """
1353
1375
  if len(q) != len(o):
1354
1376
  raise RuntimeError("Lengths of list parameters are mismatched.")
1355
- aParts, mParts = self._split_longs_2(a, m)
1377
+ aParts, mParts = QrackSimulator._split_longs_2(a, m)
1356
1378
  Qrack.qrack_lib.MULN(
1357
1379
  self.sid,
1358
1380
  len(aParts),
1359
- self._ulonglong_byref(aParts),
1360
- self._ulonglong_byref(mParts),
1381
+ QrackSimulator._ulonglong_byref(aParts),
1382
+ QrackSimulator._ulonglong_byref(mParts),
1361
1383
  len(q),
1362
- self._ulonglong_byref(q),
1363
- self._ulonglong_byref(o),
1384
+ QrackSimulator._ulonglong_byref(q),
1385
+ QrackSimulator._ulonglong_byref(o),
1364
1386
  )
1365
1387
  self._throw_if_error()
1366
1388
 
@@ -1382,15 +1404,15 @@ class QrackSimulator:
1382
1404
  """
1383
1405
  if len(q) != len(o):
1384
1406
  raise RuntimeError("Lengths of list parameters are mismatched.")
1385
- aParts, mParts = self._split_longs_2(a, m)
1407
+ aParts, mParts = QrackSimulator._split_longs_2(a, m)
1386
1408
  Qrack.qrack_lib.DIVN(
1387
1409
  self.sid,
1388
1410
  len(aParts),
1389
- self._ulonglong_byref(aParts),
1390
- self._ulonglong_byref(mParts),
1411
+ QrackSimulator._ulonglong_byref(aParts),
1412
+ QrackSimulator._ulonglong_byref(mParts),
1391
1413
  len(q),
1392
- self._ulonglong_byref(q),
1393
- self._ulonglong_byref(o),
1414
+ QrackSimulator._ulonglong_byref(q),
1415
+ QrackSimulator._ulonglong_byref(o),
1394
1416
  )
1395
1417
  self._throw_if_error()
1396
1418
 
@@ -1421,15 +1443,15 @@ class QrackSimulator:
1421
1443
 
1422
1444
  if len(q) != len(o):
1423
1445
  raise RuntimeError("Lengths of list parameters are mismatched.")
1424
- aParts, mParts = self._split_longs_2(a, m)
1446
+ aParts, mParts = QrackSimulator._split_longs_2(a, m)
1425
1447
  Qrack.qrack_lib.POWN(
1426
1448
  self.sid,
1427
1449
  len(aParts),
1428
- self._ulonglong_byref(aParts),
1429
- self._ulonglong_byref(mParts),
1450
+ QrackSimulator._ulonglong_byref(aParts),
1451
+ QrackSimulator._ulonglong_byref(mParts),
1430
1452
  len(q),
1431
- self._ulonglong_byref(q),
1432
- self._ulonglong_byref(o),
1453
+ QrackSimulator._ulonglong_byref(q),
1454
+ QrackSimulator._ulonglong_byref(o),
1433
1455
  )
1434
1456
  self._throw_if_error()
1435
1457
 
@@ -1447,15 +1469,15 @@ class QrackSimulator:
1447
1469
  Raises:
1448
1470
  RuntimeError: QrackSimulator raised an exception.
1449
1471
  """
1450
- aParts = self._split_longs(a)
1472
+ aParts = QrackSimulator._split_longs(a)
1451
1473
  Qrack.qrack_lib.MCADD(
1452
1474
  self.sid,
1453
1475
  len(aParts),
1454
- self._ulonglong_byref(aParts),
1476
+ QrackSimulator._ulonglong_byref(aParts),
1455
1477
  len(c),
1456
- self._ulonglong_byref(c),
1478
+ QrackSimulator._ulonglong_byref(c),
1457
1479
  len(q),
1458
- self._ulonglong_byref(q),
1480
+ QrackSimulator._ulonglong_byref(q),
1459
1481
  )
1460
1482
  self._throw_if_error()
1461
1483
 
@@ -1473,15 +1495,15 @@ class QrackSimulator:
1473
1495
  Raises:
1474
1496
  RuntimeError: QrackSimulator raised an exception.
1475
1497
  """
1476
- aParts = self._split_longs(a)
1498
+ aParts = QrackSimulator._split_longs(a)
1477
1499
  Qrack.qrack_lib.MCSUB(
1478
1500
  self.sid,
1479
1501
  len(aParts),
1480
- self._ulonglong_byref(aParts),
1502
+ QrackSimulator._ulonglong_byref(aParts),
1481
1503
  len(c),
1482
- self._ulonglong_byref(c),
1504
+ QrackSimulator._ulonglong_byref(c),
1483
1505
  len(q),
1484
- self._ulonglong_byref(q),
1506
+ QrackSimulator._ulonglong_byref(q),
1485
1507
  )
1486
1508
  self._throw_if_error()
1487
1509
 
@@ -1514,15 +1536,15 @@ class QrackSimulator:
1514
1536
 
1515
1537
  if len(q) != len(o):
1516
1538
  raise RuntimeError("Lengths of list parameters are mismatched.")
1517
- aParts = self._split_longs(a)
1539
+ aParts = QrackSimulator._split_longs(a)
1518
1540
  Qrack.qrack_lib.MCMUL(
1519
1541
  self.sid,
1520
1542
  len(aParts),
1521
- self._ulonglong_byref(aParts),
1543
+ QrackSimulator._ulonglong_byref(aParts),
1522
1544
  len(c),
1523
- self._ulonglong_byref(c),
1545
+ QrackSimulator._ulonglong_byref(c),
1524
1546
  len(q),
1525
- self._ulonglong_byref(q),
1547
+ QrackSimulator._ulonglong_byref(q),
1526
1548
  )
1527
1549
  self._throw_if_error()
1528
1550
 
@@ -1556,15 +1578,15 @@ class QrackSimulator:
1556
1578
 
1557
1579
  if len(q) != len(o):
1558
1580
  raise RuntimeError("Lengths of list parameters are mismatched.")
1559
- aParts = self._split_longs(a)
1581
+ aParts = QrackSimulator._split_longs(a)
1560
1582
  Qrack.qrack_lib.MCDIV(
1561
1583
  self.sid,
1562
1584
  len(aParts),
1563
- self._ulonglong_byref(aParts),
1585
+ QrackSimulator._ulonglong_byref(aParts),
1564
1586
  len(c),
1565
- self._ulonglong_byref(c),
1587
+ QrackSimulator._ulonglong_byref(c),
1566
1588
  len(q),
1567
- self._ulonglong_byref(q),
1589
+ QrackSimulator._ulonglong_byref(q),
1568
1590
  )
1569
1591
  self._throw_if_error()
1570
1592
 
@@ -1587,17 +1609,17 @@ class QrackSimulator:
1587
1609
  """
1588
1610
  if len(q) != len(o):
1589
1611
  raise RuntimeError("Lengths of list parameters are mismatched.")
1590
- aParts, mParts = self._split_longs_2(a, m)
1612
+ aParts, mParts = QrackSimulator._split_longs_2(a, m)
1591
1613
  Qrack.qrack_lib.MCMULN(
1592
1614
  self.sid,
1593
1615
  len(aParts),
1594
- self._ulonglong_byref(aParts),
1616
+ QrackSimulator._ulonglong_byref(aParts),
1595
1617
  len(c),
1596
- self._ulonglong_byref(c),
1597
- self._ulonglong_byref(mParts),
1618
+ QrackSimulator._ulonglong_byref(c),
1619
+ QrackSimulator._ulonglong_byref(mParts),
1598
1620
  len(q),
1599
- self._ulonglong_byref(q),
1600
- self._ulonglong_byref(o),
1621
+ QrackSimulator._ulonglong_byref(q),
1622
+ QrackSimulator._ulonglong_byref(o),
1601
1623
  )
1602
1624
  self._throw_if_error()
1603
1625
 
@@ -1621,17 +1643,17 @@ class QrackSimulator:
1621
1643
  """
1622
1644
  if len(q) != len(o):
1623
1645
  raise RuntimeError("Lengths of list parameters are mismatched.")
1624
- aParts, mParts = self._split_longs_2(a, m)
1646
+ aParts, mParts = QrackSimulator._split_longs_2(a, m)
1625
1647
  Qrack.qrack_lib.MCDIVN(
1626
1648
  self.sid,
1627
1649
  len(aParts),
1628
- self._ulonglong_byref(aParts),
1650
+ QrackSimulator._ulonglong_byref(aParts),
1629
1651
  len(c),
1630
- self._ulonglong_byref(c),
1631
- self._ulonglong_byref(mParts),
1652
+ QrackSimulator._ulonglong_byref(c),
1653
+ QrackSimulator._ulonglong_byref(mParts),
1632
1654
  len(q),
1633
- self._ulonglong_byref(q),
1634
- self._ulonglong_byref(o),
1655
+ QrackSimulator._ulonglong_byref(q),
1656
+ QrackSimulator._ulonglong_byref(o),
1635
1657
  )
1636
1658
  self._throw_if_error()
1637
1659
 
@@ -1664,17 +1686,17 @@ class QrackSimulator:
1664
1686
 
1665
1687
  if len(q) != len(o):
1666
1688
  raise RuntimeError("Lengths of list parameters are mismatched.")
1667
- aParts, mParts = self._split_longs_2(a, m)
1689
+ aParts, mParts = QrackSimulator._split_longs_2(a, m)
1668
1690
  Qrack.qrack_lib.MCPOWN(
1669
1691
  self.sid,
1670
1692
  len(aParts),
1671
- self._ulonglong_byref(aParts),
1693
+ QrackSimulator._ulonglong_byref(aParts),
1672
1694
  len(c),
1673
- self._ulonglong_byref(c),
1674
- self._ulonglong_byref(mParts),
1695
+ QrackSimulator._ulonglong_byref(c),
1696
+ QrackSimulator._ulonglong_byref(mParts),
1675
1697
  len(q),
1676
- self._ulonglong_byref(q),
1677
- self._ulonglong_byref(o),
1698
+ QrackSimulator._ulonglong_byref(q),
1699
+ QrackSimulator._ulonglong_byref(o),
1678
1700
  )
1679
1701
  self._throw_if_error()
1680
1702
 
@@ -1706,10 +1728,10 @@ class QrackSimulator:
1706
1728
  Qrack.qrack_lib.LDA(
1707
1729
  self.sid,
1708
1730
  len(qi),
1709
- self._ulonglong_byref(qi),
1731
+ QrackSimulator._ulonglong_byref(qi),
1710
1732
  len(qv),
1711
- self._ulonglong_byref(qv),
1712
- self._to_ubyte(len(qv), t),
1733
+ QrackSimulator._ulonglong_byref(qv),
1734
+ QrackSimulator._to_ubyte(len(qv), t),
1713
1735
  )
1714
1736
  self._throw_if_error()
1715
1737
 
@@ -1741,10 +1763,10 @@ class QrackSimulator:
1741
1763
  self.sid,
1742
1764
  s,
1743
1765
  len(qi),
1744
- self._ulonglong_byref(qi),
1766
+ QrackSimulator._ulonglong_byref(qi),
1745
1767
  len(qv),
1746
- self._ulonglong_byref(qv),
1747
- self._to_ubyte(len(qv), t),
1768
+ QrackSimulator._ulonglong_byref(qv),
1769
+ QrackSimulator._to_ubyte(len(qv), t),
1748
1770
  )
1749
1771
  self._throw_if_error()
1750
1772
 
@@ -1776,10 +1798,10 @@ class QrackSimulator:
1776
1798
  self.sid,
1777
1799
  s,
1778
1800
  len(qi),
1779
- self._ulonglong_byref(qi),
1801
+ QrackSimulator._ulonglong_byref(qi),
1780
1802
  len(qv),
1781
- self._ulonglong_byref(qv),
1782
- self._to_ubyte(len(qv), t),
1803
+ QrackSimulator._ulonglong_byref(qv),
1804
+ QrackSimulator._to_ubyte(len(qv), t),
1783
1805
  )
1784
1806
  self._throw_if_error()
1785
1807
 
@@ -1809,7 +1831,7 @@ class QrackSimulator:
1809
1831
  )
1810
1832
 
1811
1833
  Qrack.qrack_lib.Hash(
1812
- 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)
1813
1835
  )
1814
1836
  self._throw_if_error()
1815
1837
 
@@ -2030,7 +2052,7 @@ class QrackSimulator:
2030
2052
  Raises:
2031
2053
  RuntimeError: QrackSimulator raised an exception.
2032
2054
  """
2033
- 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))
2034
2056
  self._throw_if_error()
2035
2057
 
2036
2058
  def iqft(self, qs):
@@ -2045,7 +2067,7 @@ class QrackSimulator:
2045
2067
  Raises:
2046
2068
  RuntimeError: QrackSimulator raised an exception.
2047
2069
  """
2048
- 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))
2049
2071
  self._throw_if_error()
2050
2072
 
2051
2073
  # pseudo-quantum
@@ -2119,15 +2141,13 @@ class QrackSimulator:
2119
2141
  "QrackSimulator with isTensorNetwork=True option cannot compose()! (Turn off just this option, in the constructor.)"
2120
2142
  )
2121
2143
 
2122
- 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))
2123
2145
  self._throw_if_error()
2124
2146
 
2125
2147
  def decompose(self, q):
2126
2148
  """Decompose system
2127
2149
 
2128
- Decompose the given qubit out of the system.
2129
- Warning: The qubit subsystem state must be separable, or the behavior
2130
- of this method is undefined.
2150
+ Factorize a set of contiguous bits with minimal fidelity loss.
2131
2151
 
2132
2152
  Args:
2133
2153
  q: qubit id
@@ -2137,7 +2157,7 @@ class QrackSimulator:
2137
2157
  RuntimeError: QrackSimulator with isTensorNetwork=True option cannot decompose()! (Turn off just this option, in the constructor.)
2138
2158
 
2139
2159
  Returns:
2140
- State of the systems.
2160
+ Decomposed subsystem simulator.
2141
2161
  """
2142
2162
  if self.is_tensor_network:
2143
2163
  raise RuntimeError(
@@ -2147,17 +2167,15 @@ class QrackSimulator:
2147
2167
  other = QrackSimulator()
2148
2168
  Qrack.qrack_lib.destroy(other.sid)
2149
2169
  l = len(q)
2150
- 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))
2151
2171
  self._throw_if_error()
2152
2172
  return other
2153
2173
 
2154
2174
  def dispose(self, q):
2155
2175
  """Dispose qubits
2156
2176
 
2157
- Minimally decompose a set of contiguous bits from the separably
2158
- composed unit, and discard the separable bits.
2159
- Warning: The qubit subsystem state must be separable, or the behavior
2160
- of this method is undefined.
2177
+ Factorize a set of contiguous bits with minimal fidelity loss,
2178
+ and discard the separable bits.
2161
2179
 
2162
2180
  Args:
2163
2181
  q: qubit
@@ -2165,9 +2183,6 @@ class QrackSimulator:
2165
2183
  Raises:
2166
2184
  RuntimeError: QrackSimulator raised an exception.
2167
2185
  RuntimeError: QrackSimulator with isTensorNetwork=True option cannot dispose()! (Turn off just this option, in the constructor.)
2168
-
2169
- Returns:
2170
- State of the systems.
2171
2186
  """
2172
2187
  if self.is_tensor_network:
2173
2188
  raise RuntimeError(
@@ -2175,7 +2190,7 @@ class QrackSimulator:
2175
2190
  )
2176
2191
 
2177
2192
  l = len(q)
2178
- Qrack.qrack_lib.Dispose(self.sid, l, self._ulonglong_byref(q))
2193
+ Qrack.qrack_lib.Dispose(self.sid, l, QrackSimulator._ulonglong_byref(q))
2179
2194
  self._throw_if_error()
2180
2195
 
2181
2196
  ## miscellaneous
@@ -2245,7 +2260,7 @@ class QrackSimulator:
2245
2260
  Raises:
2246
2261
  RuntimeError: QrackSimulator raised an exception.
2247
2262
  """
2248
- Qrack.qrack_lib.InKet(self.sid, self._qrack_complex_byref(ket))
2263
+ Qrack.qrack_lib.InKet(self.sid, QrackSimulator._qrack_complex_byref(ket))
2249
2264
  self._throw_if_error()
2250
2265
 
2251
2266
  def out_ket(self):
@@ -2262,10 +2277,10 @@ class QrackSimulator:
2262
2277
  list representing the state vector.
2263
2278
  """
2264
2279
  amp_count = 1 << self.num_qubits()
2265
- ket = self._qrack_complex_byref([complex(0, 0)] * amp_count)
2280
+ ket = QrackSimulator._qrack_complex_byref([complex(0, 0)] * amp_count)
2266
2281
  Qrack.qrack_lib.OutKet(self.sid, ket)
2267
2282
  self._throw_if_error()
2268
- return [complex(r, i) for r, i in self._pairwise(ket)]
2283
+ return [complex(r, i) for r, i in QrackSimulator._pairwise(ket)]
2269
2284
 
2270
2285
  def out_probs(self):
2271
2286
  """Get basis dimension probabilities
@@ -2280,11 +2295,77 @@ class QrackSimulator:
2280
2295
  list representing the basis dimension probabilities.
2281
2296
  """
2282
2297
  prob_count = 1 << self.num_qubits()
2283
- probs = self._real1_byref([0.0] * prob_count)
2298
+ probs = QrackSimulator._real1_byref([0.0] * prob_count)
2284
2299
  Qrack.qrack_lib.OutProbs(self.sid, probs)
2285
2300
  self._throw_if_error()
2286
2301
  return list(probs)
2287
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
+
2288
2369
  def prob_all(self, q):
2289
2370
  """Probabilities of all subset permutations
2290
2371
 
@@ -2299,8 +2380,8 @@ class QrackSimulator:
2299
2380
  Returns:
2300
2381
  list representing the state vector.
2301
2382
  """
2302
- probs = self._real1_byref([0.0] * (1 << len(q)))
2303
- 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)
2304
2385
  self._throw_if_error()
2305
2386
  return list(probs)
2306
2387
 
@@ -2362,7 +2443,7 @@ class QrackSimulator:
2362
2443
  if len(q) != len(c):
2363
2444
  raise RuntimeError("prob_perm argument lengths do not match.")
2364
2445
  result = Qrack.qrack_lib.PermutationProb(
2365
- 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)
2366
2447
  )
2367
2448
  self._throw_if_error()
2368
2449
  return result
@@ -2390,7 +2471,7 @@ class QrackSimulator:
2390
2471
  if len(q) != len(c):
2391
2472
  raise RuntimeError("prob_perm argument lengths do not match.")
2392
2473
  result = Qrack.qrack_lib.PermutationProbRdm(
2393
- 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
2394
2475
  )
2395
2476
  self._throw_if_error()
2396
2477
  return result
@@ -2411,7 +2492,7 @@ class QrackSimulator:
2411
2492
  Expectation value
2412
2493
  """
2413
2494
  result = Qrack.qrack_lib.PermutationExpectation(
2414
- self.sid, len(q), self._ulonglong_byref(q)
2495
+ self.sid, len(q), QrackSimulator._ulonglong_byref(q)
2415
2496
  )
2416
2497
  self._throw_if_error()
2417
2498
  return result
@@ -2434,7 +2515,7 @@ class QrackSimulator:
2434
2515
  Expectation value
2435
2516
  """
2436
2517
  result = Qrack.qrack_lib.PermutationExpectationRdm(
2437
- self.sid, len(q), self._ulonglong_byref(q), r
2518
+ self.sid, len(q), QrackSimulator._ulonglong_byref(q), r
2438
2519
  )
2439
2520
  self._throw_if_error()
2440
2521
  return result
@@ -2460,7 +2541,7 @@ class QrackSimulator:
2460
2541
  raise RuntimeError("factorized_expectation argument lengths do not match.")
2461
2542
  m = max([(x.bit_length() + 63) // 64 for x in c])
2462
2543
  result = Qrack.qrack_lib.FactorizedExpectation(
2463
- 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)
2464
2545
  )
2465
2546
  self._throw_if_error()
2466
2547
  return result
@@ -2490,7 +2571,7 @@ class QrackSimulator:
2490
2571
  )
2491
2572
  m = max([(x.bit_length() + 63) // 64 for x in c])
2492
2573
  result = Qrack.qrack_lib.FactorizedExpectationRdm(
2493
- 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
2494
2575
  )
2495
2576
  self._throw_if_error()
2496
2577
  return result
@@ -2517,7 +2598,7 @@ class QrackSimulator:
2517
2598
  "factorized_expectation_rdm argument lengths do not match."
2518
2599
  )
2519
2600
  result = Qrack.qrack_lib.FactorizedExpectationFp(
2520
- 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)
2521
2602
  )
2522
2603
  self._throw_if_error()
2523
2604
  return result
@@ -2546,7 +2627,7 @@ class QrackSimulator:
2546
2627
  "factorized_expectation_fp_rdm argument lengths do not match."
2547
2628
  )
2548
2629
  result = Qrack.qrack_lib.FactorizedExpectationFpRdm(
2549
- 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
2550
2631
  )
2551
2632
  self._throw_if_error()
2552
2633
  return result
@@ -2570,7 +2651,7 @@ class QrackSimulator:
2570
2651
  if (3 * len(q)) != len(b):
2571
2652
  raise RuntimeError("unitary_expectation argument lengths do not match.")
2572
2653
  result = Qrack.qrack_lib.UnitaryExpectation(
2573
- 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)
2574
2655
  )
2575
2656
  self._throw_if_error()
2576
2657
  return result
@@ -2594,7 +2675,7 @@ class QrackSimulator:
2594
2675
  if (len(q) << 2) != len(b):
2595
2676
  raise RuntimeError("matrix_expectation argument lengths do not match.")
2596
2677
  result = Qrack.qrack_lib.MatrixExpectation(
2597
- 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)
2598
2679
  )
2599
2680
  self._throw_if_error()
2600
2681
  return result
@@ -2626,9 +2707,9 @@ class QrackSimulator:
2626
2707
  result = Qrack.qrack_lib.UnitaryExpectationEigenVal(
2627
2708
  self.sid,
2628
2709
  len(q),
2629
- self._ulonglong_byref(q),
2630
- self._real1_byref(b),
2631
- self._real1_byref(e),
2710
+ QrackSimulator._ulonglong_byref(q),
2711
+ QrackSimulator._real1_byref(b),
2712
+ QrackSimulator._real1_byref(e),
2632
2713
  )
2633
2714
  self._throw_if_error()
2634
2715
  return result
@@ -2660,9 +2741,9 @@ class QrackSimulator:
2660
2741
  result = Qrack.qrack_lib.MatrixExpectationEigenVal(
2661
2742
  self.sid,
2662
2743
  len(q),
2663
- self._ulonglong_byref(q),
2664
- self._complex_byref(b),
2665
- self._real1_byref(e),
2744
+ QrackSimulator._ulonglong_byref(q),
2745
+ QrackSimulator._complex_byref(b),
2746
+ QrackSimulator._real1_byref(e),
2666
2747
  )
2667
2748
  self._throw_if_error()
2668
2749
  return result
@@ -2687,7 +2768,7 @@ class QrackSimulator:
2687
2768
  if len(q) != len(b):
2688
2769
  raise RuntimeError("pauli_expectation argument lengths do not match.")
2689
2770
  result = Qrack.qrack_lib.PauliExpectation(
2690
- 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)
2691
2772
  )
2692
2773
  self._throw_if_error()
2693
2774
  return result
@@ -2707,7 +2788,7 @@ class QrackSimulator:
2707
2788
  Returns:
2708
2789
  float variance
2709
2790
  """
2710
- 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))
2711
2792
  self._throw_if_error()
2712
2793
  return result
2713
2794
 
@@ -2729,7 +2810,7 @@ class QrackSimulator:
2729
2810
  variance
2730
2811
  """
2731
2812
  result = Qrack.qrack_lib.VarianceRdm(
2732
- self.sid, len(q), self._ulonglong_byref(q), r
2813
+ self.sid, len(q), QrackSimulator._ulonglong_byref(q), r
2733
2814
  )
2734
2815
  self._throw_if_error()
2735
2816
  return result
@@ -2755,7 +2836,7 @@ class QrackSimulator:
2755
2836
  raise RuntimeError("factorized_variance argument lengths do not match.")
2756
2837
  m = max([(x.bit_length() + 63) // 64 for x in c])
2757
2838
  result = Qrack.qrack_lib.FactorizedVariance(
2758
- 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)
2759
2840
  )
2760
2841
  self._throw_if_error()
2761
2842
  return result
@@ -2783,7 +2864,7 @@ class QrackSimulator:
2783
2864
  raise RuntimeError("factorized_variance_rdm argument lengths do not match.")
2784
2865
  m = max([(x.bit_length() + 63) // 64 for x in c])
2785
2866
  result = Qrack.qrack_lib.FactorizedVarianceRdm(
2786
- 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
2787
2868
  )
2788
2869
  self._throw_if_error()
2789
2870
  return result
@@ -2808,7 +2889,7 @@ class QrackSimulator:
2808
2889
  if (len(q) << 1) != len(c):
2809
2890
  raise RuntimeError("factorized_variance_rdm argument lengths do not match.")
2810
2891
  result = Qrack.qrack_lib.FactorizedVarianceFp(
2811
- 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)
2812
2893
  )
2813
2894
  self._throw_if_error()
2814
2895
  return result
@@ -2837,7 +2918,7 @@ class QrackSimulator:
2837
2918
  "factorized_variance_fp_rdm argument lengths do not match."
2838
2919
  )
2839
2920
  result = Qrack.qrack_lib.FactorizedVarianceFpRdm(
2840
- 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
2841
2922
  )
2842
2923
  self._throw_if_error()
2843
2924
  return result
@@ -2861,7 +2942,7 @@ class QrackSimulator:
2861
2942
  if (3 * len(q)) != len(b):
2862
2943
  raise RuntimeError("unitary_variance argument lengths do not match.")
2863
2944
  result = Qrack.qrack_lib.UnitaryVariance(
2864
- 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)
2865
2946
  )
2866
2947
  self._throw_if_error()
2867
2948
  return result
@@ -2885,7 +2966,7 @@ class QrackSimulator:
2885
2966
  if (len(q) << 2) != len(b):
2886
2967
  raise RuntimeError("matrix_variance argument lengths do not match.")
2887
2968
  result = Qrack.qrack_lib.MatrixVariance(
2888
- 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)
2889
2970
  )
2890
2971
  self._throw_if_error()
2891
2972
  return result
@@ -2917,9 +2998,9 @@ class QrackSimulator:
2917
2998
  result = Qrack.qrack_lib.UnitaryVarianceEigenVal(
2918
2999
  self.sid,
2919
3000
  len(q),
2920
- self._ulonglong_byref(q),
2921
- self._real1_byref(b),
2922
- self._real1_byref(e),
3001
+ QrackSimulator._ulonglong_byref(q),
3002
+ QrackSimulator._real1_byref(b),
3003
+ QrackSimulator._real1_byref(e),
2923
3004
  )
2924
3005
  self._throw_if_error()
2925
3006
  return result
@@ -2951,9 +3032,9 @@ class QrackSimulator:
2951
3032
  result = Qrack.qrack_lib.MatrixVarianceEigenVal(
2952
3033
  self.sid,
2953
3034
  len(q),
2954
- self._ulonglong_byref(q),
2955
- self._complex_byref(b),
2956
- self._real1_byref(e),
3035
+ QrackSimulator._ulonglong_byref(q),
3036
+ QrackSimulator._complex_byref(b),
3037
+ QrackSimulator._real1_byref(e),
2957
3038
  )
2958
3039
  self._throw_if_error()
2959
3040
  return result
@@ -2978,7 +3059,7 @@ class QrackSimulator:
2978
3059
  if len(q) != len(b):
2979
3060
  raise RuntimeError("pauli_variance argument lengths do not match.")
2980
3061
  result = Qrack.qrack_lib.PauliVariance(
2981
- 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)
2982
3063
  )
2983
3064
  self._throw_if_error()
2984
3065
  return result
@@ -3002,7 +3083,7 @@ class QrackSimulator:
3002
3083
  if len(b) != len(q):
3003
3084
  raise RuntimeError("Lengths of list parameters are mismatched.")
3004
3085
  result = Qrack.qrack_lib.JointEnsembleProbability(
3005
- self.sid, len(b), self._ulonglong_byref(b), q
3086
+ self.sid, len(b), QrackSimulator._ulonglong_byref(b), q
3006
3087
  )
3007
3088
  self._throw_if_error()
3008
3089
  return result
@@ -3031,7 +3112,7 @@ class QrackSimulator:
3031
3112
  )
3032
3113
 
3033
3114
  Qrack.qrack_lib.PhaseParity(
3034
- 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)
3035
3116
  )
3036
3117
  self._throw_if_error()
3037
3118
 
@@ -3057,7 +3138,7 @@ class QrackSimulator:
3057
3138
  "QrackStabilizer cannot phase_root_n()! (Create a QrackSimulator instead, also with isTensorNetwork=False.)"
3058
3139
  )
3059
3140
 
3060
- 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))
3061
3142
  self._throw_if_error()
3062
3143
 
3063
3144
  def try_separate_1qb(self, qi1):
@@ -3114,7 +3195,7 @@ class QrackSimulator:
3114
3195
  State of all the qubits.
3115
3196
  """
3116
3197
  result = Qrack.qrack_lib.TrySeparateTol(
3117
- self.sid, len(qs), self._ulonglong_byref(qs), t
3198
+ self.sid, len(qs), QrackSimulator._ulonglong_byref(qs), t
3118
3199
  )
3119
3200
  self._throw_if_error()
3120
3201
  return result
@@ -3130,7 +3211,7 @@ class QrackSimulator:
3130
3211
  Raises:
3131
3212
  Runtimeerror: QrackSimulator raised an exception.
3132
3213
  """
3133
- 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))
3134
3215
  self._throw_if_error()
3135
3216
 
3136
3217
  def get_unitary_fidelity(self):
@@ -3254,6 +3335,41 @@ class QrackSimulator:
3254
3335
  Qrack.qrack_lib.SetNoiseParameter(self.sid, np)
3255
3336
  self._throw_if_error()
3256
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
+
3257
3373
  def normalize(self):
3258
3374
  """Normalize the state
3259
3375
 
@@ -4389,6 +4505,7 @@ class QrackSimulator:
4389
4505
 
4390
4506
  return _data
4391
4507
 
4508
+ @staticmethod
4392
4509
  def get_qiskit_basis_gates():
4393
4510
  return [
4394
4511
  "id",