pyGSTi 0.9.12.1__cp310-cp310-win32.whl → 0.9.13__cp310-cp310-win32.whl

Sign up to get free protection for your applications and to get access to all the features.
Files changed (221) hide show
  1. pyGSTi-0.9.13.dist-info/METADATA +197 -0
  2. {pyGSTi-0.9.12.1.dist-info → pyGSTi-0.9.13.dist-info}/RECORD +207 -217
  3. {pyGSTi-0.9.12.1.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 +42 -28
  7. pygsti/algorithms/fiducialselection.py +17 -8
  8. pygsti/algorithms/gaugeopt.py +2 -2
  9. pygsti/algorithms/germselection.py +87 -77
  10. pygsti/algorithms/mirroring.py +0 -388
  11. pygsti/algorithms/randomcircuit.py +165 -1333
  12. pygsti/algorithms/rbfit.py +0 -234
  13. pygsti/baseobjs/basis.py +94 -396
  14. pygsti/baseobjs/errorgenbasis.py +0 -132
  15. pygsti/baseobjs/errorgenspace.py +0 -10
  16. pygsti/baseobjs/label.py +52 -168
  17. pygsti/baseobjs/opcalc/fastopcalc.cp310-win32.pyd +0 -0
  18. pygsti/baseobjs/opcalc/fastopcalc.pyx +2 -2
  19. pygsti/baseobjs/polynomial.py +13 -595
  20. pygsti/baseobjs/statespace.py +1 -0
  21. pygsti/circuits/__init__.py +1 -1
  22. pygsti/circuits/circuit.py +682 -505
  23. pygsti/circuits/circuitconstruction.py +0 -4
  24. pygsti/circuits/circuitlist.py +47 -5
  25. pygsti/circuits/circuitparser/__init__.py +8 -8
  26. pygsti/circuits/circuitparser/fastcircuitparser.cp310-win32.pyd +0 -0
  27. pygsti/circuits/circuitstructure.py +3 -3
  28. pygsti/circuits/cloudcircuitconstruction.py +1 -1
  29. pygsti/data/datacomparator.py +2 -7
  30. pygsti/data/dataset.py +46 -44
  31. pygsti/data/hypothesistest.py +0 -7
  32. pygsti/drivers/bootstrap.py +0 -49
  33. pygsti/drivers/longsequence.py +2 -1
  34. pygsti/evotypes/basereps_cython.cp310-win32.pyd +0 -0
  35. pygsti/evotypes/chp/opreps.py +0 -61
  36. pygsti/evotypes/chp/statereps.py +0 -32
  37. pygsti/evotypes/densitymx/effectcreps.cpp +9 -10
  38. pygsti/evotypes/densitymx/effectreps.cp310-win32.pyd +0 -0
  39. pygsti/evotypes/densitymx/effectreps.pyx +1 -1
  40. pygsti/evotypes/densitymx/opreps.cp310-win32.pyd +0 -0
  41. pygsti/evotypes/densitymx/opreps.pyx +2 -2
  42. pygsti/evotypes/densitymx/statereps.cp310-win32.pyd +0 -0
  43. pygsti/evotypes/densitymx/statereps.pyx +1 -1
  44. pygsti/evotypes/densitymx_slow/effectreps.py +7 -23
  45. pygsti/evotypes/densitymx_slow/opreps.py +16 -23
  46. pygsti/evotypes/densitymx_slow/statereps.py +10 -3
  47. pygsti/evotypes/evotype.py +39 -2
  48. pygsti/evotypes/stabilizer/effectreps.cp310-win32.pyd +0 -0
  49. pygsti/evotypes/stabilizer/effectreps.pyx +0 -4
  50. pygsti/evotypes/stabilizer/opreps.cp310-win32.pyd +0 -0
  51. pygsti/evotypes/stabilizer/opreps.pyx +0 -4
  52. pygsti/evotypes/stabilizer/statereps.cp310-win32.pyd +0 -0
  53. pygsti/evotypes/stabilizer/statereps.pyx +1 -5
  54. pygsti/evotypes/stabilizer/termreps.cp310-win32.pyd +0 -0
  55. pygsti/evotypes/stabilizer/termreps.pyx +0 -7
  56. pygsti/evotypes/stabilizer_slow/effectreps.py +0 -22
  57. pygsti/evotypes/stabilizer_slow/opreps.py +0 -4
  58. pygsti/evotypes/stabilizer_slow/statereps.py +0 -4
  59. pygsti/evotypes/statevec/effectreps.cp310-win32.pyd +0 -0
  60. pygsti/evotypes/statevec/effectreps.pyx +1 -1
  61. pygsti/evotypes/statevec/opreps.cp310-win32.pyd +0 -0
  62. pygsti/evotypes/statevec/opreps.pyx +2 -2
  63. pygsti/evotypes/statevec/statereps.cp310-win32.pyd +0 -0
  64. pygsti/evotypes/statevec/statereps.pyx +1 -1
  65. pygsti/evotypes/statevec/termreps.cp310-win32.pyd +0 -0
  66. pygsti/evotypes/statevec/termreps.pyx +0 -7
  67. pygsti/evotypes/statevec_slow/effectreps.py +0 -3
  68. pygsti/evotypes/statevec_slow/opreps.py +0 -5
  69. pygsti/extras/__init__.py +0 -1
  70. pygsti/extras/drift/stabilityanalyzer.py +3 -1
  71. pygsti/extras/interpygate/__init__.py +12 -0
  72. pygsti/extras/interpygate/core.py +0 -36
  73. pygsti/extras/interpygate/process_tomography.py +44 -10
  74. pygsti/extras/rpe/rpeconstruction.py +0 -2
  75. pygsti/forwardsims/__init__.py +1 -0
  76. pygsti/forwardsims/forwardsim.py +14 -55
  77. pygsti/forwardsims/mapforwardsim.py +69 -18
  78. pygsti/forwardsims/mapforwardsim_calc_densitymx.cp310-win32.pyd +0 -0
  79. pygsti/forwardsims/mapforwardsim_calc_densitymx.pyx +65 -66
  80. pygsti/forwardsims/mapforwardsim_calc_generic.py +91 -13
  81. pygsti/forwardsims/matrixforwardsim.py +63 -15
  82. pygsti/forwardsims/termforwardsim.py +8 -110
  83. pygsti/forwardsims/termforwardsim_calc_stabilizer.cp310-win32.pyd +0 -0
  84. pygsti/forwardsims/termforwardsim_calc_statevec.cp310-win32.pyd +0 -0
  85. pygsti/forwardsims/termforwardsim_calc_statevec.pyx +0 -651
  86. pygsti/forwardsims/torchfwdsim.py +265 -0
  87. pygsti/forwardsims/weakforwardsim.py +2 -2
  88. pygsti/io/__init__.py +1 -2
  89. pygsti/io/mongodb.py +0 -2
  90. pygsti/io/stdinput.py +6 -22
  91. pygsti/layouts/copalayout.py +10 -12
  92. pygsti/layouts/distlayout.py +0 -40
  93. pygsti/layouts/maplayout.py +103 -25
  94. pygsti/layouts/matrixlayout.py +99 -60
  95. pygsti/layouts/prefixtable.py +1534 -52
  96. pygsti/layouts/termlayout.py +1 -1
  97. pygsti/modelmembers/instruments/instrument.py +3 -3
  98. pygsti/modelmembers/instruments/tpinstrument.py +2 -2
  99. pygsti/modelmembers/modelmember.py +0 -17
  100. pygsti/modelmembers/operations/__init__.py +2 -4
  101. pygsti/modelmembers/operations/affineshiftop.py +1 -0
  102. pygsti/modelmembers/operations/composederrorgen.py +1 -1
  103. pygsti/modelmembers/operations/composedop.py +1 -24
  104. pygsti/modelmembers/operations/denseop.py +5 -5
  105. pygsti/modelmembers/operations/eigpdenseop.py +2 -2
  106. pygsti/modelmembers/operations/embeddederrorgen.py +1 -1
  107. pygsti/modelmembers/operations/embeddedop.py +0 -1
  108. pygsti/modelmembers/operations/experrorgenop.py +2 -2
  109. pygsti/modelmembers/operations/fullarbitraryop.py +1 -0
  110. pygsti/modelmembers/operations/fullcptpop.py +2 -2
  111. pygsti/modelmembers/operations/fulltpop.py +28 -6
  112. pygsti/modelmembers/operations/fullunitaryop.py +5 -4
  113. pygsti/modelmembers/operations/lindbladcoefficients.py +93 -78
  114. pygsti/modelmembers/operations/lindbladerrorgen.py +268 -441
  115. pygsti/modelmembers/operations/linearop.py +7 -27
  116. pygsti/modelmembers/operations/opfactory.py +1 -1
  117. pygsti/modelmembers/operations/repeatedop.py +1 -24
  118. pygsti/modelmembers/operations/staticstdop.py +1 -1
  119. pygsti/modelmembers/povms/__init__.py +3 -3
  120. pygsti/modelmembers/povms/basepovm.py +7 -36
  121. pygsti/modelmembers/povms/complementeffect.py +4 -9
  122. pygsti/modelmembers/povms/composedeffect.py +0 -320
  123. pygsti/modelmembers/povms/computationaleffect.py +1 -1
  124. pygsti/modelmembers/povms/computationalpovm.py +3 -1
  125. pygsti/modelmembers/povms/effect.py +3 -5
  126. pygsti/modelmembers/povms/marginalizedpovm.py +0 -79
  127. pygsti/modelmembers/povms/tppovm.py +74 -2
  128. pygsti/modelmembers/states/__init__.py +2 -5
  129. pygsti/modelmembers/states/composedstate.py +0 -317
  130. pygsti/modelmembers/states/computationalstate.py +3 -3
  131. pygsti/modelmembers/states/cptpstate.py +4 -4
  132. pygsti/modelmembers/states/densestate.py +6 -4
  133. pygsti/modelmembers/states/fullpurestate.py +0 -24
  134. pygsti/modelmembers/states/purestate.py +1 -1
  135. pygsti/modelmembers/states/state.py +5 -6
  136. pygsti/modelmembers/states/tpstate.py +28 -10
  137. pygsti/modelmembers/term.py +3 -6
  138. pygsti/modelmembers/torchable.py +50 -0
  139. pygsti/modelpacks/_modelpack.py +1 -1
  140. pygsti/modelpacks/smq1Q_ZN.py +3 -1
  141. pygsti/modelpacks/smq2Q_XXYYII.py +2 -1
  142. pygsti/modelpacks/smq2Q_XY.py +3 -3
  143. pygsti/modelpacks/smq2Q_XYI.py +2 -2
  144. pygsti/modelpacks/smq2Q_XYICNOT.py +3 -3
  145. pygsti/modelpacks/smq2Q_XYICPHASE.py +3 -3
  146. pygsti/modelpacks/smq2Q_XYXX.py +1 -1
  147. pygsti/modelpacks/smq2Q_XYZICNOT.py +3 -3
  148. pygsti/modelpacks/smq2Q_XYZZ.py +1 -1
  149. pygsti/modelpacks/stdtarget.py +0 -121
  150. pygsti/models/cloudnoisemodel.py +1 -2
  151. pygsti/models/explicitcalc.py +3 -3
  152. pygsti/models/explicitmodel.py +3 -13
  153. pygsti/models/fogistore.py +5 -3
  154. pygsti/models/localnoisemodel.py +1 -2
  155. pygsti/models/memberdict.py +0 -12
  156. pygsti/models/model.py +800 -65
  157. pygsti/models/modelconstruction.py +4 -4
  158. pygsti/models/modelnoise.py +2 -2
  159. pygsti/models/modelparaminterposer.py +1 -1
  160. pygsti/models/oplessmodel.py +1 -1
  161. pygsti/models/qutrit.py +15 -14
  162. pygsti/objectivefns/objectivefns.py +73 -138
  163. pygsti/objectivefns/wildcardbudget.py +2 -7
  164. pygsti/optimize/__init__.py +1 -0
  165. pygsti/optimize/arraysinterface.py +28 -0
  166. pygsti/optimize/customcg.py +0 -12
  167. pygsti/optimize/customlm.py +129 -323
  168. pygsti/optimize/customsolve.py +2 -2
  169. pygsti/optimize/optimize.py +0 -84
  170. pygsti/optimize/simplerlm.py +841 -0
  171. pygsti/optimize/wildcardopt.py +19 -598
  172. pygsti/protocols/confidenceregionfactory.py +28 -14
  173. pygsti/protocols/estimate.py +31 -14
  174. pygsti/protocols/gst.py +142 -68
  175. pygsti/protocols/modeltest.py +6 -10
  176. pygsti/protocols/protocol.py +9 -37
  177. pygsti/protocols/rb.py +450 -79
  178. pygsti/protocols/treenode.py +8 -2
  179. pygsti/protocols/vb.py +108 -206
  180. pygsti/protocols/vbdataframe.py +1 -1
  181. pygsti/report/factory.py +0 -15
  182. pygsti/report/fogidiagram.py +1 -17
  183. pygsti/report/modelfunction.py +12 -3
  184. pygsti/report/mpl_colormaps.py +1 -1
  185. pygsti/report/plothelpers.py +8 -2
  186. pygsti/report/reportables.py +41 -37
  187. pygsti/report/templates/offline/pygsti_dashboard.css +6 -0
  188. pygsti/report/templates/offline/pygsti_dashboard.js +12 -0
  189. pygsti/report/workspace.py +2 -14
  190. pygsti/report/workspaceplots.py +326 -504
  191. pygsti/tools/basistools.py +9 -36
  192. pygsti/tools/edesigntools.py +124 -96
  193. pygsti/tools/fastcalc.cp310-win32.pyd +0 -0
  194. pygsti/tools/fastcalc.pyx +35 -81
  195. pygsti/tools/internalgates.py +151 -15
  196. pygsti/tools/jamiolkowski.py +5 -5
  197. pygsti/tools/lindbladtools.py +19 -11
  198. pygsti/tools/listtools.py +0 -114
  199. pygsti/tools/matrixmod2.py +1 -1
  200. pygsti/tools/matrixtools.py +173 -339
  201. pygsti/tools/nameddict.py +1 -1
  202. pygsti/tools/optools.py +154 -88
  203. pygsti/tools/pdftools.py +0 -25
  204. pygsti/tools/rbtheory.py +3 -320
  205. pygsti/tools/slicetools.py +64 -12
  206. pyGSTi-0.9.12.1.dist-info/METADATA +0 -155
  207. pygsti/algorithms/directx.py +0 -711
  208. pygsti/evotypes/qibo/__init__.py +0 -33
  209. pygsti/evotypes/qibo/effectreps.py +0 -78
  210. pygsti/evotypes/qibo/opreps.py +0 -376
  211. pygsti/evotypes/qibo/povmreps.py +0 -98
  212. pygsti/evotypes/qibo/statereps.py +0 -174
  213. pygsti/extras/rb/__init__.py +0 -13
  214. pygsti/extras/rb/benchmarker.py +0 -957
  215. pygsti/extras/rb/dataset.py +0 -378
  216. pygsti/extras/rb/io.py +0 -814
  217. pygsti/extras/rb/simulate.py +0 -1020
  218. pygsti/io/legacyio.py +0 -385
  219. pygsti/modelmembers/povms/denseeffect.py +0 -142
  220. {pyGSTi-0.9.12.1.dist-info → pyGSTi-0.9.13.dist-info}/LICENSE +0 -0
  221. {pyGSTi-0.9.12.1.dist-info → pyGSTi-0.9.13.dist-info}/top_level.txt +0 -0
@@ -1531,654 +1531,3 @@ def circuit_achieved_and_max_sopm(fwdsim, rholabel, elabels, circuit, repcache,
1531
1531
  max_sopm[i] = max_sum_of_pathmags[i]
1532
1532
 
1533
1533
  return achieved_sopm, max_sopm
1534
-
1535
-
1536
-
1537
-
1538
- # State-vector direct-term calcs -------------------------
1539
-
1540
- #cdef vector[vector[TermDirectCRep_ptr]] extract_cterms_direct(python_termrep_lists, INT max_order):
1541
- # cdef vector[vector[TermDirectCRep_ptr]] ret = vector[vector[TermDirectCRep_ptr]](max_order+1)
1542
- # cdef vector[TermDirectCRep*] vec_of_terms
1543
- # for order,termreps in enumerate(python_termrep_lists): # maxorder+1 lists
1544
- # vec_of_terms = vector[TermDirectCRep_ptr](len(termreps))
1545
- # for i,termrep in enumerate(termreps):
1546
- # vec_of_terms[i] = (<TermDirectRep?>termrep).c_term
1547
- # ret[order] = vec_of_terms
1548
- # return ret
1549
-
1550
- #def prs_directly(calc, rholabel, elabels, circuit, repcache, comm=None, mem_limit=None, fastmode=True, wt_tol=0.0, reset_term_weights=True, debug=None):
1551
- #
1552
- # # Create gatelable -> int mapping to be used throughout
1553
- # distinct_gateLabels = sorted(set(circuit))
1554
- # glmap = { gl: i for i,gl in enumerate(distinct_gateLabels) }
1555
- # t0 = pytime.time()
1556
- #
1557
- # # Convert circuit to a vector of ints
1558
- # cdef INT i, j
1559
- # cdef vector[INT] cgatestring
1560
- # for gl in circuit:
1561
- # cgatestring.push_back(<INT>glmap[gl])
1562
- #
1563
- # #TODO: maybe compute these weights elsewhere and pass in?
1564
- # cdef double circuitWeight
1565
- # cdef double remaingingWeightTol = <double?>wt_tol
1566
- # cdef vector[double] remainingWeight = vector[double](<INT>len(elabels))
1567
- # if 'circuitWeights' not in repcache:
1568
- # repcache['circuitWeights'] = {}
1569
- # if reset_term_weights or circuit not in repcache['circuitWeights']:
1570
- # circuitWeight = calc.sos.get_prep(rholabel).total_term_weight()
1571
- # for gl in circuit:
1572
- # circuitWeight *= calc.sos.get_operation(gl).total_term_weight()
1573
- # for i,elbl in enumerate(elabels):
1574
- # remainingWeight[i] = circuitWeight * calc.sos.get_effect(elbl).total_term_weight()
1575
- # repcache['circuitWeights'][circuit] = [ remainingWeight[i] for i in range(remainingWeight.size()) ]
1576
- # else:
1577
- # for i,wt in enumerate(repcache['circuitWeights'][circuit]):
1578
- # assert(wt > 1.0)
1579
- # remainingWeight[i] = wt
1580
- #
1581
- # #if reset_term_weights:
1582
- # # print "Remaining weights: "
1583
- # # for i in range(remainingWeight.size()):
1584
- # # print remainingWeight[i]
1585
- #
1586
- # cdef double order_base = 0.1 # default for now - TODO: make this a calc param like max_order?
1587
- # cdef INT order
1588
- # cdef INT numEs = len(elabels)
1589
- #
1590
- # cdef RepCacheEl repcel;
1591
- # cdef vector[TermDirectCRep_ptr] treps;
1592
- # cdef DCOMPLEX* coeffs;
1593
- # cdef vector[TermDirectCRep*] reps_at_order;
1594
- # cdef np.ndarray coeffs_array;
1595
- # cdef TermDirectRep rep;
1596
- #
1597
- # # Construct dict of gate term reps, then *convert* to c-reps, as this
1598
- # # keeps alive the non-c-reps which keep the c-reps from being deallocated...
1599
- # cdef unordered_map[INT, vector[vector[TermDirectCRep_ptr]] ] op_term_reps = unordered_map[INT, vector[vector[TermDirectCRep_ptr]] ](); # OLD = {}
1600
- # for glbl in distinct_gateLabels:
1601
- # if glbl in repcache:
1602
- # repcel = <RepCacheEl?>repcache[glbl]
1603
- # op_term_reps[ glmap[glbl] ] = repcel.reps
1604
- # for order in range(calc.max_order+1):
1605
- # treps = repcel.reps[order]
1606
- # coeffs_array = calc.sos.operation(glbl).get_direct_order_coeffs(order,order_base)
1607
- # coeffs = <DCOMPLEX*?>(coeffs_array.data)
1608
- # for i in range(treps.size()):
1609
- # treps[i]._coeff = coeffs[i]
1610
- # if reset_term_weights: treps[i]._magnitude = abs(coeffs[i])
1611
- # #for order,treps in enumerate(op_term_reps[ glmap[glbl] ]):
1612
- # # for coeff,trep in zip(calc.sos.operation(glbl).get_direct_order_coeffs(order,order_base), treps):
1613
- # # trep.set_coeff(coeff)
1614
- # else:
1615
- # repcel = RepCacheEl(calc.max_order)
1616
- # for order in range(calc.max_order+1):
1617
- # reps_at_order = vector[TermDirectCRep_ptr](0)
1618
- # for t in calc.sos.operation(glbl).get_direct_order_terms(order,order_base):
1619
- # rep = (<TermDirectRep?>t.torep(None,None,"gate"))
1620
- # repcel.pyterm_references.append(rep)
1621
- # reps_at_order.push_back( rep.c_term )
1622
- # repcel.reps[order] = reps_at_order
1623
- # #OLD
1624
- # #reps = [ [t.torep(None,None,"gate") for t in calc.sos.operation(glbl).get_direct_order_terms(order,order_base)]
1625
- # # for order in range(calc.max_order+1) ]
1626
- # op_term_reps[ glmap[glbl] ] = repcel.reps
1627
- # repcache[glbl] = repcel
1628
- #
1629
- # #OLD
1630
- # #op_term_reps = { glmap[glbl]: [ [t.torep(None,None,"gate") for t in calc.sos.operation(glbl).get_direct_order_terms(order,order_base)]
1631
- # # for order in range(calc.max_order+1) ]
1632
- # # for glbl in distinct_gateLabels }
1633
- #
1634
- # #Similar with rho_terms and E_terms
1635
- # cdef vector[vector[TermDirectCRep_ptr]] rho_term_reps;
1636
- # if rholabel in repcache:
1637
- # repcel = repcache[rholabel]
1638
- # rho_term_reps = repcel.reps
1639
- # for order in range(calc.max_order+1):
1640
- # treps = rho_term_reps[order]
1641
- # coeffs_array = calc.sos.prep(rholabel).get_direct_order_coeffs(order,order_base)
1642
- # coeffs = <DCOMPLEX*?>(coeffs_array.data)
1643
- # for i in range(treps.size()):
1644
- # treps[i]._coeff = coeffs[i]
1645
- # if reset_term_weights: treps[i]._magnitude = abs(coeffs[i])
1646
- #
1647
- # #for order,treps in enumerate(rho_term_reps):
1648
- # # for coeff,trep in zip(calc.sos.prep(rholabel).get_direct_order_coeffs(order,order_base), treps):
1649
- # # trep.set_coeff(coeff)
1650
- # else:
1651
- # repcel = RepCacheEl(calc.max_order)
1652
- # for order in range(calc.max_order+1):
1653
- # reps_at_order = vector[TermDirectCRep_ptr](0)
1654
- # for t in calc.sos.prep(rholabel).get_direct_order_terms(order,order_base):
1655
- # rep = (<TermDirectRep?>t.torep(None,None,"prep"))
1656
- # repcel.pyterm_references.append(rep)
1657
- # reps_at_order.push_back( rep.c_term )
1658
- # repcel.reps[order] = reps_at_order
1659
- # rho_term_reps = repcel.reps
1660
- # repcache[rholabel] = repcel
1661
- #
1662
- # #OLD
1663
- # #rho_term_reps = [ [t.torep(None,None,"prep") for t in calc.sos.prep(rholabel).get_direct_order_terms(order,order_base)]
1664
- # # for order in range(calc.max_order+1) ]
1665
- # #repcache[rholabel] = rho_term_reps
1666
- #
1667
- # #E_term_reps = []
1668
- # cdef vector[vector[TermDirectCRep_ptr]] E_term_reps = vector[vector[TermDirectCRep_ptr]](0);
1669
- # cdef TermDirectCRep_ptr cterm;
1670
- # e_indices = [] # TODO: upgrade to C-type?
1671
- # if all([ elbl in repcache for elbl in elabels]):
1672
- # for order in range(calc.max_order+1):
1673
- # reps_at_order = vector[TermDirectCRep_ptr](0) # the term reps for *all* the effect vectors
1674
- # cur_indices = [] # the Evec-index corresponding to each term rep
1675
- # for j,elbl in enumerate(elabels):
1676
- # repcel = <RepCacheEl?>repcache[elbl]
1677
- # #term_reps = [t.torep(None,None,"effect") for t in calc.sos.effect(elbl).get_direct_order_terms(order,order_base) ]
1678
- #
1679
- # treps = repcel.reps[order]
1680
- # coeffs_array = calc.sos.effect(elbl).get_direct_order_coeffs(order,order_base)
1681
- # coeffs = <DCOMPLEX*?>(coeffs_array.data)
1682
- # for i in range(treps.size()):
1683
- # treps[i]._coeff = coeffs[i]
1684
- # if reset_term_weights: treps[i]._magnitude = abs(coeffs[i])
1685
- # reps_at_order.push_back(treps[i])
1686
- # cur_indices.extend( [j]*reps_at_order.size() )
1687
- #
1688
- # #OLD
1689
- # #term_reps = repcache[elbl][order]
1690
- # #for coeff,trep in zip(calc.sos.effect(elbl).get_direct_order_coeffs(order,order_base), term_reps):
1691
- # # trep.set_coeff(coeff)
1692
- # #cur_term_reps.extend( term_reps )
1693
- # # cur_indices.extend( [j]*len(term_reps) )
1694
- #
1695
- # E_term_reps.push_back(reps_at_order)
1696
- # e_indices.append( cur_indices )
1697
- # # E_term_reps.append( cur_term_reps )
1698
- #
1699
- # else:
1700
- # for elbl in elabels:
1701
- # if elbl not in repcache: repcache[elbl] = RepCacheEl(calc.max_order) #[None]*(calc.max_order+1) # make sure there's room
1702
- # for order in range(calc.max_order+1):
1703
- # reps_at_order = vector[TermDirectCRep_ptr](0) # the term reps for *all* the effect vectors
1704
- # cur_indices = [] # the Evec-index corresponding to each term rep
1705
- # for j,elbl in enumerate(elabels):
1706
- # repcel = <RepCacheEl?>repcache[elbl]
1707
- # treps = vector[TermDirectCRep_ptr](0) # the term reps for *all* the effect vectors
1708
- # for t in calc.sos.effect(elbl).get_direct_order_terms(order,order_base):
1709
- # rep = (<TermDirectRep?>t.torep(None,None,"effect"))
1710
- # repcel.pyterm_references.append(rep)
1711
- # treps.push_back( rep.c_term )
1712
- # reps_at_order.push_back( rep.c_term )
1713
- # repcel.reps[order] = treps
1714
- # cur_indices.extend( [j]*treps.size() )
1715
- # #term_reps = [t.torep(None,None,"effect") for t in calc.sos.effect(elbl).get_direct_order_terms(order,order_base) ]
1716
- # #repcache[elbl][order] = term_reps
1717
- # #cur_term_reps.extend( term_reps )
1718
- # #cur_indices.extend( [j]*len(term_reps) )
1719
- # E_term_reps.push_back(reps_at_order)
1720
- # e_indices.append( cur_indices )
1721
- # #E_term_reps.append( cur_term_reps )
1722
- #
1723
- # #convert to c-reps
1724
- # cdef INT gi
1725
- # #cdef vector[vector[TermDirectCRep_ptr]] rho_term_creps = rho_term_reps # already c-reps...
1726
- # #cdef vector[vector[TermDirectCRep_ptr]] E_term_creps = E_term_reps # already c-reps...
1727
- # #cdef unordered_map[INT, vector[vector[TermDirectCRep_ptr]]] gate_term_creps = op_term_reps # already c-reps...
1728
- # #cdef vector[vector[TermDirectCRep_ptr]] rho_term_creps = extract_cterms_direct(rho_term_reps,calc.max_order)
1729
- # #cdef vector[vector[TermDirectCRep_ptr]] E_term_creps = extract_cterms_direct(E_term_reps,calc.max_order)
1730
- # #for gi,termrep_lists in op_term_reps.items():
1731
- # # gate_term_creps[gi] = extract_cterms_direct(termrep_lists,calc.max_order)
1732
- #
1733
- # E_cindices = vector[vector[INT]](<INT>len(e_indices))
1734
- # for ii,inds in enumerate(e_indices):
1735
- # E_cindices[ii] = vector[INT](<INT>len(inds))
1736
- # for jj,indx in enumerate(inds):
1737
- # E_cindices[ii][jj] = <INT>indx
1738
- #
1739
- # #Note: term calculator "dim" is the full density matrix dim
1740
- # stateDim = int(round(np.sqrt(calc.dim)))
1741
- # if debug is not None:
1742
- # debug['tstartup'] += pytime.time()-t0
1743
- # t0 = pytime.time()
1744
- #
1745
- # #Call C-only function (which operates with C-representations only)
1746
- # cdef vector[float] debugvec = vector[float](10)
1747
- # debugvec[0] = 0.0
1748
- # cdef vector[DCOMPLEX] prs = prs_directly(
1749
- # cgatestring, rho_term_reps, op_term_reps, E_term_reps,
1750
- # #cgatestring, rho_term_creps, gate_term_creps, E_term_creps,
1751
- # E_cindices, numEs, calc.max_order, stateDim, <bool>fastmode, &remainingWeight, remaingingWeightTol, debugvec)
1752
- #
1753
- # debug['total'] += debugvec[0]
1754
- # debug['t1'] += debugvec[1]
1755
- # debug['t2'] += debugvec[2]
1756
- # debug['t3'] += debugvec[3]
1757
- # debug['n1'] += debugvec[4]
1758
- # debug['n2'] += debugvec[5]
1759
- # debug['n3'] += debugvec[6]
1760
- # debug['t4'] += debugvec[7]
1761
- # debug['n4'] += debugvec[8]
1762
- # #if not all([ abs(prs[i].imag) < 1e-4 for i in range(<INT>prs.size()) ]):
1763
- # # print("ERROR: prs = ",[ prs[i] for i in range(<INT>prs.size()) ])
1764
- # #assert(all([ abs(prs[i].imag) < 1e-6 for i in range(<INT>prs.size()) ]))
1765
- # return [ prs[i].real for i in range(<INT>prs.size()) ] # TODO: make this into a numpy array? - maybe pass array to fill to prs_directy above?
1766
- #
1767
- #
1768
- #cdef vector[DCOMPLEX] prs_directly(
1769
- # vector[INT]& circuit, vector[vector[TermDirectCRep_ptr]] rho_term_reps,
1770
- # unordered_map[INT, vector[vector[TermDirectCRep_ptr]]] op_term_reps,
1771
- # vector[vector[TermDirectCRep_ptr]] E_term_reps, vector[vector[INT]] E_term_indices,
1772
- # INT numEs, INT max_order, INT dim, bool fastmode, vector[double]* remainingWeight, double remTol, vector[float]& debugvec):
1773
- #
1774
- # #NOTE: circuit and gate_terms use *integers* as operation labels, not Label objects, to speed
1775
- # # lookups and avoid weird string conversion stuff with Cython
1776
- #
1777
- # cdef INT N = len(circuit)
1778
- # cdef INT* p = <INT*>malloc((N+2) * sizeof(INT))
1779
- # cdef INT i,j,k,order,nTerms
1780
- # cdef INT gn
1781
- #
1782
- # cdef INT t0 = time.clock()
1783
- # cdef INT t, n, nPaths; #for below
1784
- #
1785
- # cdef innerloopfn_direct_ptr innerloop_fn;
1786
- # if fastmode:
1787
- # innerloop_fn = pr_directly_innerloop_savepartials
1788
- # else:
1789
- # innerloop_fn = pr_directly_innerloop
1790
- #
1791
- # #extract raw data from gate_terms dictionary-of-lists for faster lookup
1792
- # #gate_term_prefactors = np.empty( (nOperations,max_order+1,dim,dim)
1793
- # #cdef unordered_map[INT, vector[vector[unordered_map[INT, complex]]]] gate_term_coeffs
1794
- # #cdef vector[vector[unordered_map[INT, complex]]] rho_term_coeffs
1795
- # #cdef vector[vector[unordered_map[INT, complex]]] E_term_coeffs
1796
- # #cdef vector[vector[INT]] e_indices
1797
- #
1798
- # cdef vector[INT]* Einds
1799
- # cdef vector[vector_TermDirectCRep_ptr_ptr] factor_lists
1800
- #
1801
- # assert(max_order <= 2) # only support this partitioning below (so far)
1802
- #
1803
- # cdef vector[DCOMPLEX] prs = vector[DCOMPLEX](numEs)
1804
- #
1805
- # for order in range(max_order+1):
1806
- # #print("DB: pr_as_polynomial order=",order)
1807
- #
1808
- # #for p in partition_into(order, N):
1809
- # for i in range(N+2): p[i] = 0 # clear p
1810
- # factor_lists = vector[vector_TermDirectCRep_ptr_ptr](N+2)
1811
- #
1812
- # if order == 0:
1813
- # #inner loop(p)
1814
- # #factor_lists = [ gate_terms[glbl][pi] for glbl,pi in zip(circuit,p) ]
1815
- # t = time.clock()
1816
- # factor_lists[0] = &rho_term_reps[p[0]]
1817
- # for k in range(N):
1818
- # gn = circuit[k]
1819
- # factor_lists[k+1] = &op_term_reps[circuit[k]][p[k+1]]
1820
- # #if factor_lists[k+1].size() == 0: continue # WHAT???
1821
- # factor_lists[N+1] = &E_term_reps[p[N+1]]
1822
- # Einds = &E_term_indices[p[N+1]]
1823
- #
1824
- # #print("Part0 ",p)
1825
- # nPaths = innerloop_fn(factor_lists,Einds,&prs,dim,remainingWeight,0.0) #remTol) # force 0-order
1826
- # debugvec[1] += float(time.clock() - t)/time.CLOCKS_PER_SEC
1827
- # debugvec[4] += nPaths
1828
- #
1829
- # elif order == 1:
1830
- # t = time.clock(); n=0
1831
- # for i in range(N+2):
1832
- # p[i] = 1
1833
- # #inner loop(p)
1834
- # factor_lists[0] = &rho_term_reps[p[0]]
1835
- # for k in range(N):
1836
- # gn = circuit[k]
1837
- # factor_lists[k+1] = &op_term_reps[gn][p[k+1]]
1838
- # #if len(factor_lists[k+1]) == 0: continue #WHAT???
1839
- # factor_lists[N+1] = &E_term_reps[p[N+1]]
1840
- # Einds = &E_term_indices[p[N+1]]
1841
- #
1842
- # #print "DB: Order1 "
1843
- # nPaths = innerloop_fn(factor_lists,Einds,&prs,dim,remainingWeight,0.0) #remTol) # force 1st-order
1844
- # p[i] = 0
1845
- # n += nPaths
1846
- # debugvec[2] += float(time.clock() - t)/time.CLOCKS_PER_SEC
1847
- # debugvec[5] += n
1848
- #
1849
- # elif order == 2:
1850
- # t = time.clock(); n=0
1851
- # for i in range(N+2):
1852
- # p[i] = 2
1853
- # #inner loop(p)
1854
- # factor_lists[0] = &rho_term_reps[p[0]]
1855
- # for k in range(N):
1856
- # gn = circuit[k]
1857
- # factor_lists[k+1] = &op_term_reps[circuit[k]][p[k+1]]
1858
- # #if len(factor_lists[k+1]) == 0: continue # WHAT???
1859
- # factor_lists[N+1] = &E_term_reps[p[N+1]]
1860
- # Einds = &E_term_indices[p[N+1]]
1861
- #
1862
- # nPaths = innerloop_fn(factor_lists,Einds,&prs,dim,remainingWeight,remTol)
1863
- # p[i] = 0
1864
- # n += nPaths
1865
- #
1866
- # debugvec[3] += float(time.clock() - t)/time.CLOCKS_PER_SEC
1867
- # debugvec[6] += n
1868
- # t = time.clock(); n=0
1869
- #
1870
- # for i in range(N+2):
1871
- # p[i] = 1
1872
- # for j in range(i+1,N+2):
1873
- # p[j] = 1
1874
- # #inner loop(p)
1875
- # factor_lists[0] = &rho_term_reps[p[0]]
1876
- # for k in range(N):
1877
- # gn = circuit[k]
1878
- # factor_lists[k+1] = &op_term_reps[circuit[k]][p[k+1]]
1879
- # #if len(factor_lists[k+1]) == 0: continue #WHAT???
1880
- # factor_lists[N+1] = &E_term_reps[p[N+1]]
1881
- # Einds = &E_term_indices[p[N+1]]
1882
- #
1883
- # nPaths = innerloop_fn(factor_lists,Einds,&prs,dim,remainingWeight,remTol)
1884
- # p[j] = 0
1885
- # n += nPaths
1886
- # p[i] = 0
1887
- # debugvec[7] += float(time.clock() - t)/time.CLOCKS_PER_SEC
1888
- # debugvec[8] += n
1889
- #
1890
- # else:
1891
- # assert(False) # order > 2 not implemented yet...
1892
- #
1893
- # free(p)
1894
- #
1895
- # debugvec[0] += float(time.clock() - t0)/time.CLOCKS_PER_SEC
1896
- # return prs
1897
- #
1898
- #
1899
- #
1900
- #cdef INT pr_directly_innerloop(vector[vector_TermDirectCRep_ptr_ptr] factor_lists, vector[INT]* Einds,
1901
- # vector[DCOMPLEX]* prs, INT dim, vector[double]* remainingWeight, double remainingWeightTol):
1902
- # #print("DB partition = ","listlens = ",[len(fl) for fl in factor_lists])
1903
- #
1904
- # cdef INT i,j,Ei
1905
- # cdef double complex scale, val, newval, pLeft, pRight, p
1906
- # cdef double wt, cwt
1907
- # cdef int nPaths = 0
1908
- #
1909
- # cdef TermDirectCRep* factor
1910
- #
1911
- # cdef INT nFactorLists = factor_lists.size() # may need to recompute this after fast-mode
1912
- # cdef INT* factorListLens = <INT*>malloc(nFactorLists * sizeof(INT))
1913
- # cdef INT last_index = nFactorLists-1
1914
- #
1915
- # for i in range(nFactorLists):
1916
- # factorListLens[i] = factor_lists[i].size()
1917
- # if factorListLens[i] == 0:
1918
- # free(factorListLens)
1919
- # return 0 # nothing to loop over! - (exit before we allocate more)
1920
- #
1921
- # cdef double complex coeff # THESE are only real changes from "as_polynomial"
1922
- # cdef double complex result # version of this function (where they are PolynomialCRep type)
1923
- #
1924
- # cdef StateCRep *prop1 = new StateCRep(dim)
1925
- # cdef StateCRep *prop2 = new StateCRep(dim)
1926
- # cdef StateCRep *tprop
1927
- # cdef EffectCRep* EVec
1928
- #
1929
- # cdef INT* b = <INT*>malloc(nFactorLists * sizeof(INT))
1930
- # for i in range(nFactorLists): b[i] = 0
1931
- #
1932
- # assert(nFactorLists > 0), "Number of factor lists must be > 0!"
1933
- #
1934
- # #for factors in _itertools.product(*factor_lists):
1935
- # while(True):
1936
- # final_factor_indx = b[last_index]
1937
- # Ei = deref(Einds)[final_factor_indx] #final "factor" index == E-vector index
1938
- # wt = deref(remainingWeight)[Ei]
1939
- # if remainingWeightTol == 0.0 or wt > remainingWeightTol: #if we need this "path"
1940
- # # In this loop, b holds "current" indices into factor_lists
1941
- # factor = deref(factor_lists[0])[b[0]] # the last factor (an Evec)
1942
- # coeff = factor._coeff
1943
- # cwt = factor._magnitude
1944
- #
1945
- # for i in range(1,nFactorLists):
1946
- # coeff *= deref(factor_lists[i])[b[i]]._coeff
1947
- # cwt *= deref(factor_lists[i])[b[i]]._magnitude
1948
- #
1949
- # #pLeft / "pre" sim
1950
- # factor = deref(factor_lists[0])[b[0]] # 0th-factor = rhoVec
1951
- # prop1.copy_from(factor._pre_state)
1952
- # for j in range(<INT>factor._pre_ops.size()):
1953
- # factor._pre_ops[j].acton(prop1,prop2)
1954
- # tprop = prop1; prop1 = prop2; prop2 = tprop
1955
- # for i in range(1,last_index):
1956
- # factor = deref(factor_lists[i])[b[i]]
1957
- # for j in range(<INT>factor._pre_ops.size()):
1958
- # factor._pre_ops[j].acton(prop1,prop2)
1959
- # tprop = prop1; prop1 = prop2; prop2 = tprop # final state in prop1
1960
- # factor = deref(factor_lists[last_index])[b[last_index]] # the last factor (an Evec)
1961
- #
1962
- # # can't propagate effects, so effect's post_ops are constructed to act on *state*
1963
- # EVec = factor._post_effect
1964
- # for j in range(<INT>factor._post_ops.size()):
1965
- # rhoVec = factor._post_ops[j].acton(prop1,prop2)
1966
- # tprop = prop1; prop1 = prop2; prop2 = tprop # final state in prop1
1967
- # pLeft = EVec.amplitude(prop1)
1968
- #
1969
- # #pRight / "post" sim
1970
- # factor = deref(factor_lists[0])[b[0]] # 0th-factor = rhoVec
1971
- # prop1.copy_from(factor._post_state)
1972
- # for j in range(<INT>factor._post_ops.size()):
1973
- # factor._post_ops[j].acton(prop1,prop2)
1974
- # tprop = prop1; prop1 = prop2; prop2 = tprop # final state in prop1
1975
- # for i in range(1,last_index):
1976
- # factor = deref(factor_lists[i])[b[i]]
1977
- # for j in range(<INT>factor._post_ops.size()):
1978
- # factor._post_ops[j].acton(prop1,prop2)
1979
- # tprop = prop1; prop1 = prop2; prop2 = tprop # final state in prop1
1980
- # factor = deref(factor_lists[last_index])[b[last_index]] # the last factor (an Evec)
1981
- #
1982
- # EVec = factor._pre_effect
1983
- # for j in range(<INT>factor._pre_ops.size()):
1984
- # factor._pre_ops[j].acton(prop1,prop2)
1985
- # tprop = prop1; prop1 = prop2; prop2 = tprop # final state in prop1
1986
- # pRight = EVec.amplitude(prop1).conjugate()
1987
- #
1988
- # #Add result to appropriate polynomial
1989
- # result = coeff * pLeft * pRight
1990
- # deref(prs)[Ei] = deref(prs)[Ei] + result #TODO - see why += doesn't work here
1991
- # deref(remainingWeight)[Ei] = wt - cwt # "weight" of this path
1992
- # nPaths += 1 # just for debuggins
1993
- #
1994
- # #increment b ~ itertools.product & update vec_index_noop = np.dot(self.multipliers, b)
1995
- # for i in range(nFactorLists-1,-1,-1):
1996
- # if b[i]+1 < factorListLens[i]:
1997
- # b[i] += 1
1998
- # break
1999
- # else:
2000
- # b[i] = 0
2001
- # else:
2002
- # break # can't increment anything - break while(True) loop
2003
- #
2004
- # #Clenaup: free allocated memory
2005
- # del prop1
2006
- # del prop2
2007
- # free(factorListLens)
2008
- # free(b)
2009
- # return nPaths
2010
- #
2011
- #
2012
- #cdef INT pr_directly_innerloop_savepartials(vector[vector_TermDirectCRep_ptr_ptr] factor_lists,
2013
- # vector[INT]* Einds, vector[DCOMPLEX]* prs, INT dim,
2014
- # vector[double]* remainingWeight, double remainingWeightTol):
2015
- # #print("DB partition = ","listlens = ",[len(fl) for fl in factor_lists])
2016
- #
2017
- # cdef INT i,j,Ei
2018
- # cdef double complex scale, val, newval, pLeft, pRight, p
2019
- #
2020
- # cdef INT incd
2021
- # cdef TermDirectCRep* factor
2022
- #
2023
- # cdef INT nFactorLists = factor_lists.size() # may need to recompute this after fast-mode
2024
- # cdef INT* factorListLens = <INT*>malloc(nFactorLists * sizeof(INT))
2025
- # cdef INT last_index = nFactorLists-1
2026
- #
2027
- # for i in range(nFactorLists):
2028
- # factorListLens[i] = factor_lists[i].size()
2029
- # if factorListLens[i] == 0:
2030
- # free(factorListLens)
2031
- # return 0 # nothing to loop over! (exit before we allocate anything else)
2032
- #
2033
- # cdef double complex coeff
2034
- # cdef double complex result
2035
- #
2036
- # #fast mode
2037
- # cdef vector[StateCRep*] leftSaved = vector[StateCRep_ptr](nFactorLists-1) # saved[i] is state after i-th
2038
- # cdef vector[StateCRep*] rightSaved = vector[StateCRep_ptr](nFactorLists-1) # factor has been applied
2039
- # cdef vector[DCOMPLEX] coeffSaved = vector[DCOMPLEX](nFactorLists-1)
2040
- # cdef StateCRep *shelved = new StateCRep(dim)
2041
- # cdef StateCRep *prop2 = new StateCRep(dim) # prop2 is always a temporary allocated state not owned by anything else
2042
- # cdef StateCRep *prop1
2043
- # cdef StateCRep *tprop
2044
- # cdef EffectCRep* EVec
2045
- #
2046
- # cdef INT* b = <INT*>malloc(nFactorLists * sizeof(INT))
2047
- # for i in range(nFactorLists): b[i] = 0
2048
- # assert(nFactorLists > 0), "Number of factor lists must be > 0!"
2049
- #
2050
- # incd = 0
2051
- #
2052
- # #Fill saved arrays with allocated states
2053
- # for i in range(nFactorLists-1):
2054
- # leftSaved[i] = new StateCRep(dim)
2055
- # rightSaved[i] = new StateCRep(dim)
2056
- #
2057
- # #for factors in _itertools.product(*factor_lists):
2058
- # #for incd,fi in incd_product(*[range(len(l)) for l in factor_lists]):
2059
- # while(True):
2060
- # # In this loop, b holds "current" indices into factor_lists
2061
- # #print "DB: iter-product BEGIN"
2062
- #
2063
- # if incd == 0: # need to re-evaluate rho vector
2064
- # #print "DB: re-eval at incd=0"
2065
- # factor = deref(factor_lists[0])[b[0]]
2066
- #
2067
- # #print "DB: re-eval left"
2068
- # prop1 = leftSaved[0] # the final destination (prop2 is already alloc'd)
2069
- # prop1.copy_from(factor._pre_state)
2070
- # for j in range(<INT>factor._pre_ops.size()):
2071
- # #print "DB: re-eval left item"
2072
- # factor._pre_ops[j].acton(prop1,prop2)
2073
- # tprop = prop1; prop1 = prop2; prop2 = tprop # swap prop1 <-> prop2
2074
- # rhoVecL = prop1
2075
- # leftSaved[0] = prop1 # final state -> saved
2076
- # # (prop2 == the other allocated state)
2077
- #
2078
- # #print "DB: re-eval right"
2079
- # prop1 = rightSaved[0] # the final destination (prop2 is already alloc'd)
2080
- # prop1.copy_from(factor._post_state)
2081
- # for j in range(<INT>factor._post_ops.size()):
2082
- # #print "DB: re-eval right item"
2083
- # factor._post_ops[j].acton(prop1,prop2)
2084
- # tprop = prop1; prop1 = prop2; prop2 = tprop # swap prop1 <-> prop2
2085
- # rhoVecR = prop1
2086
- # rightSaved[0] = prop1 # final state -> saved
2087
- # # (prop2 == the other allocated state)
2088
- #
2089
- # #print "DB: re-eval coeff"
2090
- # coeff = factor._coeff
2091
- # coeffSaved[0] = coeff
2092
- # incd += 1
2093
- # else:
2094
- # #print "DB: init from incd"
2095
- # rhoVecL = leftSaved[incd-1]
2096
- # rhoVecR = rightSaved[incd-1]
2097
- # coeff = coeffSaved[incd-1]
2098
- #
2099
- # # propagate left and right states, saving as we go
2100
- # for i in range(incd,last_index):
2101
- # #print "DB: propagate left begin"
2102
- # factor = deref(factor_lists[i])[b[i]]
2103
- # prop1 = leftSaved[i] # destination
2104
- # prop1.copy_from(rhoVecL) #starting state
2105
- # for j in range(<INT>factor._pre_ops.size()):
2106
- # #print "DB: propagate left item"
2107
- # factor._pre_ops[j].acton(prop1,prop2)
2108
- # tprop = prop1; prop1 = prop2; prop2 = tprop
2109
- # rhoVecL = prop1
2110
- # leftSaved[i] = prop1
2111
- # # (prop2 == the other allocated state)
2112
- #
2113
- # #print "DB: propagate right begin"
2114
- # prop1 = rightSaved[i] # destination
2115
- # prop1.copy_from(rhoVecR) #starting state
2116
- # for j in range(<INT>factor._post_ops.size()):
2117
- # #print "DB: propagate right item"
2118
- # factor._post_ops[j].acton(prop1,prop2)
2119
- # tprop = prop1; prop1 = prop2; prop2 = tprop
2120
- # rhoVecR = prop1
2121
- # rightSaved[i] = prop1
2122
- # # (prop2 == the other allocated state)
2123
- #
2124
- # #print "DB: propagate coeff mult"
2125
- # coeff *= factor._coeff
2126
- # coeffSaved[i] = coeff
2127
- #
2128
- # # for the last index, no need to save, and need to construct
2129
- # # and apply effect vector
2130
- # prop1 = shelved # so now prop1 (and prop2) are alloc'd states
2131
- #
2132
- # #print "DB: left ampl"
2133
- # factor = deref(factor_lists[last_index])[b[last_index]] # the last factor (an Evec)
2134
- # EVec = factor._post_effect
2135
- # prop1.copy_from(rhoVecL) # initial state (prop2 already alloc'd)
2136
- # for j in range(<INT>factor._post_ops.size()):
2137
- # factor._post_ops[j].acton(prop1,prop2)
2138
- # tprop = prop1; prop1 = prop2; prop2 = tprop
2139
- # pLeft = EVec.amplitude(prop1) # output in prop1, so this is final amplitude
2140
- #
2141
- # #print "DB: right ampl"
2142
- # EVec = factor._pre_effect
2143
- # prop1.copy_from(rhoVecR)
2144
- # for j in range(<INT>factor._pre_ops.size()):
2145
- # factor._pre_ops[j].acton(prop1,prop2)
2146
- # tprop = prop1; prop1 = prop2; prop2 = tprop
2147
- # pRight = EVec.amplitude(prop1).conjugate()
2148
- #
2149
- # shelved = prop1 # return prop1 to the "shelf" since we'll use prop1 for other things next
2150
- #
2151
- # #print "DB: final block"
2152
- # #print "DB running coeff = ",dict(coeff._coeffs)
2153
- # #print "DB factor coeff = ",dict(factor._coeff._coeffs)
2154
- # result = coeff * factor._coeff
2155
- # #print "DB result = ",dict(result._coeffs)
2156
- # result *= pLeft * pRight
2157
- # final_factor_indx = b[last_index]
2158
- # Ei = deref(Einds)[final_factor_indx] #final "factor" index == E-vector index
2159
- # deref(prs)[Ei] += result
2160
- # #print "DB prs[",INT(Ei),"] = ",dict(deref(prs)[Ei]._coeffs)
2161
- #
2162
- # #assert(debug < 100) #DEBUG
2163
- # #print "DB: end product loop"
2164
- #
2165
- # #increment b ~ itertools.product & update vec_index_noop = np.dot(self.multipliers, b)
2166
- # for i in range(nFactorLists-1,-1,-1):
2167
- # if b[i]+1 < factorListLens[i]:
2168
- # b[i] += 1; incd = i
2169
- # break
2170
- # else:
2171
- # b[i] = 0
2172
- # else:
2173
- # break # can't increment anything - break while(True) loop
2174
- #
2175
- # #Cleanup: free allocated memory
2176
- # for i in range(nFactorLists-1):
2177
- # del leftSaved[i]
2178
- # del rightSaved[i]
2179
- # del prop2
2180
- # del shelved
2181
- # free(factorListLens)
2182
- # free(b)
2183
- # return 0 #TODO: fix nPaths
2184
-