pyGSTi 0.9.12__cp38-cp38-win32.whl → 0.9.13__cp38-cp38-win32.whl

Sign up to get free protection for your applications and to get access to all the features.
Files changed (225) hide show
  1. pyGSTi-0.9.13.dist-info/METADATA +185 -0
  2. {pyGSTi-0.9.12.dist-info → pyGSTi-0.9.13.dist-info}/RECORD +211 -220
  3. {pyGSTi-0.9.12.dist-info → pyGSTi-0.9.13.dist-info}/WHEEL +1 -1
  4. pygsti/_version.py +2 -2
  5. pygsti/algorithms/contract.py +1 -1
  6. pygsti/algorithms/core.py +62 -35
  7. pygsti/algorithms/fiducialpairreduction.py +95 -110
  8. pygsti/algorithms/fiducialselection.py +17 -8
  9. pygsti/algorithms/gaugeopt.py +2 -2
  10. pygsti/algorithms/germselection.py +87 -77
  11. pygsti/algorithms/mirroring.py +0 -388
  12. pygsti/algorithms/randomcircuit.py +165 -1333
  13. pygsti/algorithms/rbfit.py +0 -234
  14. pygsti/baseobjs/basis.py +94 -396
  15. pygsti/baseobjs/errorgenbasis.py +0 -132
  16. pygsti/baseobjs/errorgenspace.py +0 -10
  17. pygsti/baseobjs/label.py +52 -168
  18. pygsti/baseobjs/opcalc/fastopcalc.cp38-win32.pyd +0 -0
  19. pygsti/baseobjs/opcalc/fastopcalc.pyx +2 -2
  20. pygsti/baseobjs/polynomial.py +13 -595
  21. pygsti/baseobjs/protectedarray.py +72 -132
  22. pygsti/baseobjs/statespace.py +1 -0
  23. pygsti/circuits/__init__.py +1 -1
  24. pygsti/circuits/circuit.py +753 -504
  25. pygsti/circuits/circuitconstruction.py +0 -4
  26. pygsti/circuits/circuitlist.py +47 -5
  27. pygsti/circuits/circuitparser/__init__.py +8 -8
  28. pygsti/circuits/circuitparser/fastcircuitparser.cp38-win32.pyd +0 -0
  29. pygsti/circuits/circuitstructure.py +3 -3
  30. pygsti/circuits/cloudcircuitconstruction.py +27 -14
  31. pygsti/data/datacomparator.py +4 -9
  32. pygsti/data/dataset.py +51 -46
  33. pygsti/data/hypothesistest.py +0 -7
  34. pygsti/drivers/bootstrap.py +0 -49
  35. pygsti/drivers/longsequence.py +46 -10
  36. pygsti/evotypes/basereps_cython.cp38-win32.pyd +0 -0
  37. pygsti/evotypes/chp/opreps.py +0 -61
  38. pygsti/evotypes/chp/statereps.py +0 -32
  39. pygsti/evotypes/densitymx/effectcreps.cpp +9 -10
  40. pygsti/evotypes/densitymx/effectreps.cp38-win32.pyd +0 -0
  41. pygsti/evotypes/densitymx/effectreps.pyx +1 -1
  42. pygsti/evotypes/densitymx/opreps.cp38-win32.pyd +0 -0
  43. pygsti/evotypes/densitymx/opreps.pyx +2 -2
  44. pygsti/evotypes/densitymx/statereps.cp38-win32.pyd +0 -0
  45. pygsti/evotypes/densitymx/statereps.pyx +1 -1
  46. pygsti/evotypes/densitymx_slow/effectreps.py +7 -23
  47. pygsti/evotypes/densitymx_slow/opreps.py +16 -23
  48. pygsti/evotypes/densitymx_slow/statereps.py +10 -3
  49. pygsti/evotypes/evotype.py +39 -2
  50. pygsti/evotypes/stabilizer/effectreps.cp38-win32.pyd +0 -0
  51. pygsti/evotypes/stabilizer/effectreps.pyx +0 -4
  52. pygsti/evotypes/stabilizer/opreps.cp38-win32.pyd +0 -0
  53. pygsti/evotypes/stabilizer/opreps.pyx +0 -4
  54. pygsti/evotypes/stabilizer/statereps.cp38-win32.pyd +0 -0
  55. pygsti/evotypes/stabilizer/statereps.pyx +1 -5
  56. pygsti/evotypes/stabilizer/termreps.cp38-win32.pyd +0 -0
  57. pygsti/evotypes/stabilizer/termreps.pyx +0 -7
  58. pygsti/evotypes/stabilizer_slow/effectreps.py +0 -22
  59. pygsti/evotypes/stabilizer_slow/opreps.py +0 -4
  60. pygsti/evotypes/stabilizer_slow/statereps.py +0 -4
  61. pygsti/evotypes/statevec/effectreps.cp38-win32.pyd +0 -0
  62. pygsti/evotypes/statevec/effectreps.pyx +1 -1
  63. pygsti/evotypes/statevec/opreps.cp38-win32.pyd +0 -0
  64. pygsti/evotypes/statevec/opreps.pyx +2 -2
  65. pygsti/evotypes/statevec/statereps.cp38-win32.pyd +0 -0
  66. pygsti/evotypes/statevec/statereps.pyx +1 -1
  67. pygsti/evotypes/statevec/termreps.cp38-win32.pyd +0 -0
  68. pygsti/evotypes/statevec/termreps.pyx +0 -7
  69. pygsti/evotypes/statevec_slow/effectreps.py +0 -3
  70. pygsti/evotypes/statevec_slow/opreps.py +0 -5
  71. pygsti/extras/__init__.py +0 -1
  72. pygsti/extras/drift/signal.py +1 -1
  73. pygsti/extras/drift/stabilityanalyzer.py +3 -1
  74. pygsti/extras/interpygate/__init__.py +12 -0
  75. pygsti/extras/interpygate/core.py +0 -36
  76. pygsti/extras/interpygate/process_tomography.py +44 -10
  77. pygsti/extras/rpe/rpeconstruction.py +0 -2
  78. pygsti/forwardsims/__init__.py +1 -0
  79. pygsti/forwardsims/forwardsim.py +50 -93
  80. pygsti/forwardsims/mapforwardsim.py +78 -20
  81. pygsti/forwardsims/mapforwardsim_calc_densitymx.cp38-win32.pyd +0 -0
  82. pygsti/forwardsims/mapforwardsim_calc_densitymx.pyx +65 -66
  83. pygsti/forwardsims/mapforwardsim_calc_generic.py +91 -13
  84. pygsti/forwardsims/matrixforwardsim.py +72 -17
  85. pygsti/forwardsims/termforwardsim.py +9 -111
  86. pygsti/forwardsims/termforwardsim_calc_stabilizer.cp38-win32.pyd +0 -0
  87. pygsti/forwardsims/termforwardsim_calc_statevec.cp38-win32.pyd +0 -0
  88. pygsti/forwardsims/termforwardsim_calc_statevec.pyx +0 -651
  89. pygsti/forwardsims/torchfwdsim.py +265 -0
  90. pygsti/forwardsims/weakforwardsim.py +2 -2
  91. pygsti/io/__init__.py +1 -2
  92. pygsti/io/mongodb.py +0 -2
  93. pygsti/io/stdinput.py +6 -22
  94. pygsti/layouts/copalayout.py +10 -12
  95. pygsti/layouts/distlayout.py +0 -40
  96. pygsti/layouts/maplayout.py +103 -25
  97. pygsti/layouts/matrixlayout.py +99 -60
  98. pygsti/layouts/prefixtable.py +1534 -52
  99. pygsti/layouts/termlayout.py +1 -1
  100. pygsti/modelmembers/instruments/instrument.py +3 -3
  101. pygsti/modelmembers/instruments/tpinstrument.py +2 -2
  102. pygsti/modelmembers/modelmember.py +0 -17
  103. pygsti/modelmembers/operations/__init__.py +3 -4
  104. pygsti/modelmembers/operations/affineshiftop.py +206 -0
  105. pygsti/modelmembers/operations/composederrorgen.py +1 -1
  106. pygsti/modelmembers/operations/composedop.py +1 -24
  107. pygsti/modelmembers/operations/denseop.py +5 -5
  108. pygsti/modelmembers/operations/eigpdenseop.py +2 -2
  109. pygsti/modelmembers/operations/embeddederrorgen.py +1 -1
  110. pygsti/modelmembers/operations/embeddedop.py +0 -1
  111. pygsti/modelmembers/operations/experrorgenop.py +5 -2
  112. pygsti/modelmembers/operations/fullarbitraryop.py +1 -0
  113. pygsti/modelmembers/operations/fullcptpop.py +2 -2
  114. pygsti/modelmembers/operations/fulltpop.py +28 -6
  115. pygsti/modelmembers/operations/fullunitaryop.py +5 -4
  116. pygsti/modelmembers/operations/lindbladcoefficients.py +93 -78
  117. pygsti/modelmembers/operations/lindbladerrorgen.py +268 -441
  118. pygsti/modelmembers/operations/linearop.py +7 -27
  119. pygsti/modelmembers/operations/opfactory.py +1 -1
  120. pygsti/modelmembers/operations/repeatedop.py +1 -24
  121. pygsti/modelmembers/operations/staticstdop.py +1 -1
  122. pygsti/modelmembers/povms/__init__.py +3 -3
  123. pygsti/modelmembers/povms/basepovm.py +7 -36
  124. pygsti/modelmembers/povms/complementeffect.py +4 -9
  125. pygsti/modelmembers/povms/composedeffect.py +0 -320
  126. pygsti/modelmembers/povms/computationaleffect.py +1 -1
  127. pygsti/modelmembers/povms/computationalpovm.py +3 -1
  128. pygsti/modelmembers/povms/effect.py +3 -5
  129. pygsti/modelmembers/povms/marginalizedpovm.py +3 -81
  130. pygsti/modelmembers/povms/tppovm.py +74 -2
  131. pygsti/modelmembers/states/__init__.py +2 -5
  132. pygsti/modelmembers/states/composedstate.py +0 -317
  133. pygsti/modelmembers/states/computationalstate.py +3 -3
  134. pygsti/modelmembers/states/cptpstate.py +4 -4
  135. pygsti/modelmembers/states/densestate.py +10 -8
  136. pygsti/modelmembers/states/fullpurestate.py +0 -24
  137. pygsti/modelmembers/states/purestate.py +1 -1
  138. pygsti/modelmembers/states/state.py +5 -6
  139. pygsti/modelmembers/states/tpstate.py +28 -10
  140. pygsti/modelmembers/term.py +3 -6
  141. pygsti/modelmembers/torchable.py +50 -0
  142. pygsti/modelpacks/_modelpack.py +1 -1
  143. pygsti/modelpacks/smq1Q_ZN.py +3 -1
  144. pygsti/modelpacks/smq2Q_XXYYII.py +2 -1
  145. pygsti/modelpacks/smq2Q_XY.py +3 -3
  146. pygsti/modelpacks/smq2Q_XYI.py +2 -2
  147. pygsti/modelpacks/smq2Q_XYICNOT.py +3 -3
  148. pygsti/modelpacks/smq2Q_XYICPHASE.py +3 -3
  149. pygsti/modelpacks/smq2Q_XYXX.py +1 -1
  150. pygsti/modelpacks/smq2Q_XYZICNOT.py +3 -3
  151. pygsti/modelpacks/smq2Q_XYZZ.py +1 -1
  152. pygsti/modelpacks/stdtarget.py +0 -121
  153. pygsti/models/cloudnoisemodel.py +1 -2
  154. pygsti/models/explicitcalc.py +3 -3
  155. pygsti/models/explicitmodel.py +3 -13
  156. pygsti/models/fogistore.py +5 -3
  157. pygsti/models/localnoisemodel.py +1 -2
  158. pygsti/models/memberdict.py +0 -12
  159. pygsti/models/model.py +801 -68
  160. pygsti/models/modelconstruction.py +4 -4
  161. pygsti/models/modelnoise.py +2 -2
  162. pygsti/models/modelparaminterposer.py +1 -1
  163. pygsti/models/oplessmodel.py +1 -1
  164. pygsti/models/qutrit.py +15 -14
  165. pygsti/objectivefns/objectivefns.py +75 -140
  166. pygsti/objectivefns/wildcardbudget.py +2 -7
  167. pygsti/optimize/__init__.py +1 -0
  168. pygsti/optimize/arraysinterface.py +28 -0
  169. pygsti/optimize/customcg.py +0 -12
  170. pygsti/optimize/customlm.py +129 -323
  171. pygsti/optimize/customsolve.py +2 -2
  172. pygsti/optimize/optimize.py +0 -84
  173. pygsti/optimize/simplerlm.py +841 -0
  174. pygsti/optimize/wildcardopt.py +19 -598
  175. pygsti/protocols/confidenceregionfactory.py +28 -14
  176. pygsti/protocols/estimate.py +31 -14
  177. pygsti/protocols/gst.py +238 -142
  178. pygsti/protocols/modeltest.py +19 -12
  179. pygsti/protocols/protocol.py +9 -37
  180. pygsti/protocols/rb.py +450 -79
  181. pygsti/protocols/treenode.py +8 -2
  182. pygsti/protocols/vb.py +108 -206
  183. pygsti/protocols/vbdataframe.py +1 -1
  184. pygsti/report/factory.py +0 -15
  185. pygsti/report/fogidiagram.py +1 -17
  186. pygsti/report/modelfunction.py +12 -3
  187. pygsti/report/mpl_colormaps.py +1 -1
  188. pygsti/report/plothelpers.py +11 -3
  189. pygsti/report/report.py +16 -0
  190. pygsti/report/reportables.py +41 -37
  191. pygsti/report/templates/offline/pygsti_dashboard.css +6 -0
  192. pygsti/report/templates/offline/pygsti_dashboard.js +12 -0
  193. pygsti/report/workspace.py +2 -14
  194. pygsti/report/workspaceplots.py +328 -505
  195. pygsti/tools/basistools.py +9 -36
  196. pygsti/tools/edesigntools.py +124 -96
  197. pygsti/tools/fastcalc.cp38-win32.pyd +0 -0
  198. pygsti/tools/fastcalc.pyx +35 -81
  199. pygsti/tools/internalgates.py +151 -15
  200. pygsti/tools/jamiolkowski.py +5 -5
  201. pygsti/tools/lindbladtools.py +19 -11
  202. pygsti/tools/listtools.py +0 -114
  203. pygsti/tools/matrixmod2.py +1 -1
  204. pygsti/tools/matrixtools.py +173 -339
  205. pygsti/tools/nameddict.py +1 -1
  206. pygsti/tools/optools.py +154 -88
  207. pygsti/tools/pdftools.py +0 -25
  208. pygsti/tools/rbtheory.py +3 -320
  209. pygsti/tools/slicetools.py +64 -12
  210. pyGSTi-0.9.12.dist-info/METADATA +0 -157
  211. pygsti/algorithms/directx.py +0 -711
  212. pygsti/evotypes/qibo/__init__.py +0 -33
  213. pygsti/evotypes/qibo/effectreps.py +0 -78
  214. pygsti/evotypes/qibo/opreps.py +0 -376
  215. pygsti/evotypes/qibo/povmreps.py +0 -98
  216. pygsti/evotypes/qibo/statereps.py +0 -174
  217. pygsti/extras/rb/__init__.py +0 -13
  218. pygsti/extras/rb/benchmarker.py +0 -957
  219. pygsti/extras/rb/dataset.py +0 -378
  220. pygsti/extras/rb/io.py +0 -814
  221. pygsti/extras/rb/simulate.py +0 -1020
  222. pygsti/io/legacyio.py +0 -385
  223. pygsti/modelmembers/povms/denseeffect.py +0 -142
  224. {pyGSTi-0.9.12.dist-info → pyGSTi-0.9.13.dist-info}/LICENSE +0 -0
  225. {pyGSTi-0.9.12.dist-info → pyGSTi-0.9.13.dist-info}/top_level.txt +0 -0
@@ -29,6 +29,8 @@ from pygsti.tools import mpitools as _mpit
29
29
  from pygsti.tools import sharedmemtools as _smt
30
30
  from pygsti.tools import slicetools as _slct
31
31
  from pygsti.tools.matrixtools import _fas
32
+ from pygsti.tools import listtools as _lt
33
+ from pygsti.circuits import CircuitList as _CircuitList
32
34
 
33
35
  _dummy_profiler = _DummyProfiler()
34
36
 
@@ -132,12 +134,18 @@ class SimpleMatrixForwardSimulator(_ForwardSimulator):
132
134
  obj_wrtFilter = [] # values = object-local param indices
133
135
  relevant_gpindices = [] # indices into original wrt_filter'd indices
134
136
 
135
- gpindices = obj.gpindices_as_array()
137
+ if isinstance(obj.gpindices, slice):
138
+ gpindices_list = _slct.indices(obj.gpindices)
139
+ elif obj.gpindices is None:
140
+ gpindices_list = []
141
+ else:
142
+ gpindices_list = list(obj.gpindices)
143
+ gpindices_set = set(gpindices_list)
136
144
 
137
145
  for ii, i in enumerate(wrt_filter):
138
- if i in gpindices:
146
+ if i in gpindices_set:
139
147
  relevant_gpindices.append(ii)
140
- obj_wrtFilter.append(list(gpindices).index(i))
148
+ obj_wrtFilter.append(gpindices_list.index(i))
141
149
  relevant_gpindices = _np.array(relevant_gpindices, _np.int64)
142
150
  if len(relevant_gpindices) == 1:
143
151
  #Don't return a length-1 list, as this doesn't index numpy arrays
@@ -590,7 +598,7 @@ class SimpleMatrixForwardSimulator(_ForwardSimulator):
590
598
  use_scaling = False # Hardcoded for now
591
599
  assert(time is None), "MatrixForwardSimulator cannot be used to simulate time-dependent circuits"
592
600
 
593
- expanded_circuit_outcomes = circuit.expand_instruments_and_separate_povm(self.model, outcomes)
601
+ expanded_circuit_outcomes = self.model.expand_instruments_and_separate_povm(circuit, outcomes)
594
602
  outcome_to_index = {outc: i for i, outc in enumerate(outcomes)}
595
603
  for spc, spc_outcomes in expanded_circuit_outcomes.items(): # spc is a SeparatePOVMCircuit
596
604
  indices = [outcome_to_index[o] for o in spc_outcomes]
@@ -1025,7 +1033,7 @@ class MatrixForwardSimulator(_DistributableForwardSimulator, SimpleMatrixForward
1025
1033
  return hProdCache
1026
1034
 
1027
1035
  def create_layout(self, circuits, dataset=None, resource_alloc=None, array_types=('E',),
1028
- derivative_dimension=None, verbosity=0):
1036
+ derivative_dimensions=None, verbosity=0, layout_creation_circuit_cache= None):
1029
1037
  """
1030
1038
  Constructs an circuit-outcome-probability-array (COPA) layout for a list of circuits.
1031
1039
 
@@ -1046,15 +1054,22 @@ class MatrixForwardSimulator(_DistributableForwardSimulator, SimpleMatrixForward
1046
1054
  array_types : tuple, optional
1047
1055
  A tuple of string-valued array types. See :meth:`ForwardSimulator.create_layout`.
1048
1056
 
1049
- derivative_dimension : int, optional
1057
+ derivative_dimensions : int or tuple[int], optional
1050
1058
  Optionally, the parameter-space dimension used when taking first
1051
1059
  and second derivatives with respect to the cirucit outcome probabilities. This must be
1052
1060
  non-None when `array_types` contains `'ep'` or `'epp'` types.
1061
+ If a tuple, then must be length 1.
1053
1062
 
1054
1063
  verbosity : int or VerbosityPrinter
1055
1064
  Determines how much output to send to stdout. 0 means no output, higher
1056
1065
  integers mean more output.
1057
1066
 
1067
+ layout_creation_circuit_cache : dict, optional (default None)
1068
+ A precomputed dictionary serving as a cache for completed
1069
+ circuits. I.e. circuits with prep labels and POVM labels appended.
1070
+ Along with other useful pre-computed circuit structures used in layout
1071
+ creation.
1072
+
1058
1073
  Returns
1059
1074
  -------
1060
1075
  MatrixCOPALayout
@@ -1075,7 +1090,13 @@ class MatrixForwardSimulator(_DistributableForwardSimulator, SimpleMatrixForward
1075
1090
  printer = _VerbosityPrinter.create_printer(verbosity, resource_alloc)
1076
1091
  nprocs = resource_alloc.comm_size
1077
1092
  comm = resource_alloc.comm
1078
- num_params = derivative_dimension if (derivative_dimension is not None) else self.model.num_params
1093
+ if isinstance(derivative_dimensions, int):
1094
+ num_params = derivative_dimensions
1095
+ elif isinstance(derivative_dimensions, tuple):
1096
+ assert len(derivative_dimensions) == 1
1097
+ num_params = derivative_dimensions[0]
1098
+ else:
1099
+ num_params = self.model.num_params
1079
1100
  C = 1.0 / (1024.0**3)
1080
1101
 
1081
1102
  if mem_limit is not None:
@@ -1098,7 +1119,8 @@ class MatrixForwardSimulator(_DistributableForwardSimulator, SimpleMatrixForward
1098
1119
  assert(_np.prod((na,) + npp) <= nprocs), "Processor grid size exceeds available processors!"
1099
1120
 
1100
1121
  layout = _MatrixCOPALayout(circuits, self.model, dataset, natoms,
1101
- na, npp, param_dimensions, param_blk_sizes, resource_alloc, verbosity)
1122
+ na, npp, param_dimensions, param_blk_sizes, resource_alloc, verbosity,
1123
+ layout_creation_circuit_cache=layout_creation_circuit_cache)
1102
1124
 
1103
1125
  if mem_limit is not None:
1104
1126
  loc_nparams1 = num_params / npp[0] if len(npp) > 0 else 0
@@ -1125,13 +1147,6 @@ class MatrixForwardSimulator(_DistributableForwardSimulator, SimpleMatrixForward
1125
1147
  (blk1, blk2), max_atom_cachesize,
1126
1148
  self.model.evotype.minimal_dim(self.model.state_space))
1127
1149
 
1128
- #def approx_mem_estimate(natoms, np1, np2):
1129
- # approx_cachesize = (num_circuits / natoms) * 1.3 # inflate expected # circuits per atom => cache_size
1130
- # return _bytes_for_array_types(array_types, num_elements, num_elements / natoms,
1131
- # num_circuits, num_circuits / natoms,
1132
- # (num_params, num_params), (num_params / np1, num_params / np2),
1133
- # approx_cachesize, self.model.state_space.dim)
1134
-
1135
1150
  GB = 1.0 / 1024.0**3
1136
1151
  if mem_estimate > mem_limit:
1137
1152
  raise MemoryError("Not enough memory for desired layout! (limit=%.1fGB, required=%.1fGB)" % (
@@ -1140,6 +1155,46 @@ class MatrixForwardSimulator(_DistributableForwardSimulator, SimpleMatrixForward
1140
1155
  printer.log(" Esimated memory required = %.1fGB" % (mem_estimate * GB))
1141
1156
 
1142
1157
  return layout
1158
+
1159
+ @staticmethod
1160
+ def create_copa_layout_circuit_cache(circuits, model, dataset=None):
1161
+ """
1162
+ Helper function for pre-computing/pre-processing circuits structures
1163
+ used in matrix layout creation.
1164
+ """
1165
+ cache = dict()
1166
+ completed_circuits, split_circuits = model.complete_circuits(circuits, return_split=True)
1167
+
1168
+ cache['completed_circuits'] = {ckt: comp_ckt for ckt, comp_ckt in zip(circuits, completed_circuits)}
1169
+ cache['split_circuits'] = {ckt: split_ckt for ckt, split_ckt in zip(circuits, split_circuits)}
1170
+
1171
+ if dataset is not None:
1172
+ aliases = circuits.op_label_aliases if isinstance(circuits, _CircuitList) else None
1173
+ ds_circuits = _lt.apply_aliases_to_circuits(circuits, aliases)
1174
+ unique_outcomes_list = []
1175
+ for ckt in ds_circuits:
1176
+ ds_row = dataset[ckt]
1177
+ unique_outcomes_list.append(ds_row.unique_outcomes if ds_row is not None else None)
1178
+ else:
1179
+ unique_outcomes_list = [None]*len(circuits)
1180
+
1181
+ expanded_circuit_outcome_list = model.bulk_expand_instruments_and_separate_povm(circuits,
1182
+ observed_outcomes_list = unique_outcomes_list,
1183
+ split_circuits = split_circuits)
1184
+
1185
+ expanded_circuit_cache = {ckt: expanded_ckt for ckt,expanded_ckt in zip(circuits, expanded_circuit_outcome_list)}
1186
+
1187
+ cache['expanded_and_separated_circuits'] = expanded_circuit_cache
1188
+
1189
+ expanded_subcircuits_no_spam_cache = dict()
1190
+ for expc_outcomes in cache['expanded_and_separated_circuits'].values():
1191
+ for sep_povm_c, _ in expc_outcomes.items(): # for each expanded cir from unique_i-th circuit
1192
+ exp_nospam_c = sep_povm_c.circuit_without_povm[1:]
1193
+ expanded_subcircuits_no_spam_cache[exp_nospam_c] = exp_nospam_c.expand_subcircuits()
1194
+
1195
+ cache['expanded_subcircuits_no_spam'] = expanded_subcircuits_no_spam_cache
1196
+
1197
+ return cache
1143
1198
 
1144
1199
  def _scale_exp(self, scale_exps):
1145
1200
  old_err = _np.seterr(over='ignore')
@@ -1187,7 +1242,8 @@ class MatrixForwardSimulator(_DistributableForwardSimulator, SimpleMatrixForward
1187
1242
  # dp_dOps[i,j] = dot( e, dot( d_gs, rho ) )[0,i,j,0]
1188
1243
  # dp_dOps = squeeze( dot( e, dot( d_gs, rho ) ), axis=(0,3))
1189
1244
  old_err2 = _np.seterr(invalid='ignore', over='ignore')
1190
- dp_dOps = _np.squeeze(_np.dot(e, _np.dot(d_gs, rho)), axis=(0, 3)) * scale_vals[:, None]
1245
+ path = _np.einsum_path('hk,ijkl,lm->ij', e, d_gs, rho, optimize='optimal')
1246
+ dp_dOps = _np.einsum('hk,ijkl,lm->ij', e, d_gs, rho, optimize=path[0]) * scale_vals[:, None]
1191
1247
  _np.seterr(**old_err2)
1192
1248
  # may overflow, but OK ; shape == (len(circuit_list), nDerivCols)
1193
1249
  # may also give invalid value due to scale_vals being inf and dot-prod being 0. In
@@ -1227,7 +1283,6 @@ class MatrixForwardSimulator(_DistributableForwardSimulator, SimpleMatrixForward
1227
1283
  # dp_drhos[i,J0+J] = sum_kl e[0,k] gs[i,k,l] drhoP[l,J]
1228
1284
  # dp_drhos[i,J0+J] = dot(e, gs, drhoP)[0,i,J]
1229
1285
  # dp_drhos[:,J0+J] = squeeze(dot(e, gs, drhoP),axis=(0,))[:,J]
1230
-
1231
1286
  dp_drhos = _np.zeros((nCircuits, nOpDerivCols))
1232
1287
  _fas(dp_drhos, [None, rho_gpindices],
1233
1288
  _np.squeeze(_np.dot(_np.dot(e, gs),
@@ -214,7 +214,7 @@ class TermForwardSimulator(_DistributableForwardSimulator):
214
214
  @classmethod
215
215
  def _from_nice_serialization(cls, state):
216
216
  #Note: resets processor-distribution information
217
- return cls(state['mode'], state['max_taylor_order'],
217
+ return cls(None, state['mode'], state['max_taylor_order'],
218
218
  state['desired_pathintegral_approximation_error'],
219
219
  state['allowed_pathintegral_approximation_error'],
220
220
  state['minimum_retained_term_magnitude'],
@@ -243,16 +243,6 @@ class TermForwardSimulator(_DistributableForwardSimulator):
243
243
  # and this is done by the parent model which will cause _set_evotype to be called.
244
244
  return state
245
245
 
246
- #OLD - now we have a _set_evotype method.
247
- #@_ForwardSimulator.model.setter
248
- #def model(self, val):
249
- # _ForwardSimulator.model.fset(self, val) # set the base class property (self.model)
250
- #
251
- # #Do some additional initialization
252
- # if self.model.evotype not in ("svterm", "cterm"):
253
- # #raise ValueError(f"Evolution type {self.model.evotype} is incompatible with term-based calculations")
254
- # _warnings.warn("Evolution type %s is incompatible with term-based calculations" % self.model.evotype)
255
-
256
246
  def copy(self):
257
247
  """
258
248
  Return a shallow copy of this TermForwardSimulator.
@@ -267,7 +257,7 @@ class TermForwardSimulator(_DistributableForwardSimulator):
267
257
  self.oob_check_interval, self.cache)
268
258
 
269
259
  def create_layout(self, circuits, dataset=None, resource_alloc=None, array_types=('E',),
270
- derivative_dimension=None, verbosity=0):
260
+ derivative_dimension=None, verbosity=0, layout_creation_circuit_cache=None):
271
261
  """
272
262
  Constructs an circuit-outcome-probability-array (COPA) layout for a list of circuits.
273
263
 
@@ -296,6 +286,12 @@ class TermForwardSimulator(_DistributableForwardSimulator):
296
286
  verbosity : int or VerbosityPrinter
297
287
  Determines how much output to send to stdout. 0 means no output, higher
298
288
  integers mean more output.
289
+
290
+ layout_creation_circuit_cache:
291
+ A precomputed dictionary serving as a cache for completed
292
+ circuits. I.e. circuits with prep labels and POVM labels appended.
293
+ Along with other useful pre-computed circuit structures used in layout
294
+ creation.
299
295
 
300
296
  Returns
301
297
  -------
@@ -330,6 +326,7 @@ class TermForwardSimulator(_DistributableForwardSimulator):
330
326
  printer.log(" %d atoms, parameter block size limits %s" % (natoms, str(param_blk_sizes)))
331
327
  assert(_np.prod((na,) + npp) <= nprocs), "Processor grid size exceeds available processors!"
332
328
 
329
+ # TODO: Layout circuit creation cache unused for TermCOPALayout
333
330
  layout = _TermCOPALayout(circuits, self.model, dataset, natoms, na, npp, param_dimensions,
334
331
  param_blk_sizes, resource_alloc, printer)
335
332
  #MEM debug_prof.print_memory("CreateLayout2 - nAtoms = %d" % len(layout.atoms), True)
@@ -409,105 +406,6 @@ class TermForwardSimulator(_DistributableForwardSimulator):
409
406
  hpolys[0], hpolys[1], self.model.to_vector(), (nEls, len(wrtInds1), len(wrtInds2)))
410
407
  _fas(array_to_fill, [slice(0, array_to_fill.shape[0]), dest_param_slice1, dest_param_slice2], hprobs)
411
408
 
412
- #DIRECT FNS - keep these around, but they need to be updated (as do routines in fastreplib.pyx)
413
- #def _prs_directly(self, layout_atom, resource_alloc): #comm=None, mem_limit=None, reset_wts=True, repcache=None):
414
- # """
415
- # Compute probabilities of `layout`'s circuits using "direct" mode.
416
- #
417
- # Parameters
418
- # ----------
419
- # layout : CircuitOutcomeProbabilityArrayLayout
420
- # The layout.
421
- #
422
- # comm : mpi4py.MPI.Comm, optional
423
- # When not None, an MPI communicator for distributing the computation
424
- # across multiple processors. Distribution is performed over
425
- # subtrees of eval_tree (if it is split).
426
- #
427
- # mem_limit : int, optional
428
- # A rough memory limit in bytes.
429
- #
430
- # reset_wts : bool, optional
431
- # Whether term magnitudes should be updated based on current term coefficients
432
- # (which are based on the current point in model-parameter space) or not.
433
- #
434
- # repcache : dict, optional
435
- # A cache of term representations for increased performance.
436
- # """
437
- # prs = _np.empty(layout_atom.num_elements, 'd')
438
- # #print("Computing prs directly for %d circuits" % len(circuit_list))
439
- # if repcache is None: repcache = {} # new repcache...
440
- # k = 0 # *linear* evaluation order so we know final indices are just running
441
- # for i in eval_tree.evaluation_order():
442
- # circuit = eval_tree[i]
443
- # #print("Computing prs directly: circuit %d of %d" % (i,len(circuit_list)))
444
- # assert(self.evotype == "svterm") # for now, just do SV case
445
- # fastmode = False # start with slow mode
446
- # wtTol = 0.1
447
- # rholabel = circuit[0]
448
- # opStr = circuit[1:]
449
- # elabels = eval_tree.simplified_circuit_elabels[i]
450
- # prs[k:k + len(elabels)] = replib.SV_prs_directly(self, rholabel, elabels, opStr,
451
- # repcache, comm, mem_limit, fastmode, wtTol, reset_wts,
452
- # self.times_debug)
453
- # k += len(elabels)
454
- # #print("PRS = ",prs)
455
- # return prs
456
- #
457
- #def _dprs_directly(self, eval_tree, wrt_slice, comm=None, mem_limit=None, reset_wts=True, repcache=None):
458
- # """
459
- # Compute probability derivatives of `eval_tree`'s circuits using "direct" mode.
460
- #
461
- # Parameters
462
- # ----------
463
- # eval_tree : TermEvalTree
464
- # The evaluation tree.
465
- #
466
- # wrt_slice : slice
467
- # A slice specifying which model parameters to differentiate with respect to.
468
- #
469
- # comm : mpi4py.MPI.Comm, optional
470
- # When not None, an MPI communicator for distributing the computation
471
- # across multiple processors. Distribution is performed over
472
- # subtrees of eval_tree (if it is split).
473
- #
474
- # mem_limit : int, optional
475
- # A rough memory limit in bytes.
476
- #
477
- # reset_wts : bool, optional
478
- # Whether term magnitudes should be updated based on current term coefficients
479
- # (which are based on the current point in model-parameter space) or not.
480
- #
481
- # repcache : dict, optional
482
- # A cache of term representations for increased performance.
483
- # """
484
- # #Note: Finite difference derivatives are SLOW!
485
- # if wrt_slice is None:
486
- # wrt_indices = list(range(self.Np))
487
- # elif isinstance(wrt_slice, slice):
488
- # wrt_indices = _slct.indices(wrt_slice)
489
- # else:
490
- # wrt_indices = wrt_slice
491
- #
492
- # eps = 1e-6 # HARDCODED
493
- # probs = self._prs_directly(eval_tree, comm, mem_limit, reset_wts, repcache)
494
- # dprobs = _np.empty((eval_tree.num_final_elements(), len(wrt_indices)), 'd')
495
- # orig_vec = self.to_vector().copy()
496
- # iParamToFinal = {i: ii for ii, i in enumerate(wrt_indices)}
497
- # for i in range(self.Np):
498
- # #print("direct dprobs cache %d of %d" % (i,self.Np))
499
- # if i in iParamToFinal: # LATER: add MPI support?
500
- # iFinal = iParamToFinal[i]
501
- # vec = orig_vec.copy(); vec[i] += eps
502
- # self.from_vector(vec, close=True)
503
- # dprobs[:, iFinal] = (self._prs_directly(eval_tree,
504
- # comm=None,
505
- # mem_limit=None,
506
- # reset_wts=False,
507
- # repcache=repcache) - probs) / eps
508
- # self.from_vector(orig_vec, close=True)
509
- # return dprobs
510
-
511
409
  ## ----- Find a "minimal" path set (i.e. find thresholds for each circuit -----
512
410
  def _compute_pruned_pathmag_threshold(self, rholabel, elabels, circuit, polynomial_vindices_per_int,
513
411
  repcache, circuitsetup_cache,