@@ -197,7 +197,8 @@ def mapfill_probs_atom(fwdsim, np.ndarray[double, mode="c", ndim=1] array_to_fil
197197cdef dm_mapfill_probs(double [:] array_to_fill,
198198                      vector[vector[INT]] c_layout_atom,
199199                      vector[OpCRep* ] c_opreps,
200-                       vector[StateCRep* ] c_rhoreps, vector[EffectCRep* ] c_ereps,
200+                       vector[StateCRep* ] c_rhoreps, 
201+                       vector[EffectCRep* ] c_ereps,
201202                      vector[StateCRep* ]*  prho_cache,
202203                      vector[vector[INT]] elabel_indices_per_circuit,
203204                      vector[vector[INT]] final_indices_per_circuit,
@@ -207,7 +208,7 @@ cdef dm_mapfill_probs(double[:] array_to_fill,
207208    #  elements point to (instead of copying the states) - we just guarantee that in the end
208209    #  all of the cache entries are filled with allocated (by 'new') states that the caller
209210    #  can deallocate at will.
210-     cdef INT k,l,i,istart, icache, iFirstOp, precomp_id 
211+     cdef INT k,l,i,istart, icache, iFirstOp
211212    cdef double  p
212213    cdef StateCRep * init_state
213214    cdef StateCRep * prop1
@@ -220,6 +221,12 @@ cdef dm_mapfill_probs(double[:] array_to_fill,
220221    cdef vector[INT] final_indices
221222    cdef vector[INT] elabel_indices
222223
224+     # vector to store values of ids for caching of effect reps (particularly when using
225+     # composed effect reps).
226+     #  this should be initialized to a number that is *never* a Python id()
227+     cdef int  len_c_ereps =   c_ereps.size()
228+     cdef vector[INT] precomp_id =  vector[INT](len_c_ereps, 0 )
229+ 
223230    # Invariants required for proper memory management:
224231    #  - upon loop entry, prop2 is allocated and prop1 is not (it doesn't "own" any memory)
225232    #  - all rho_cache entries have been allocated via "new"
@@ -267,14 +274,14 @@ cdef dm_mapfill_probs(double[:] array_to_fill,
267274        # print "begin prob comps: %.2fs since last, %.2fs elapsed" % (pytime.time()-t1, pytime.time()-t0) # DEBUG
268275        final_indices =  final_indices_per_circuit[i]
269276        elabel_indices =  elabel_indices_per_circuit[i]
277+         
270278        # print("Op actons done - computing %d probs" % elabel_indices.size());t1 = pytime.time() # DEBUG
271279
272280        precomp_state =  prop2  #  used as cache/scratch space
273-         precomp_id =  0   #  this should be a number that is *never* a Python id()
274281        for  j in  range (< INT> elabel_indices.size()):
275282            # print("Erep prob %d of %d: elapsed = %.2fs" % (j, elabel_indices.size(), pytime.time() - t1))
276283            # OLD: array_to_fill[ final_indices[j] ] = c_ereps[elabel_indices[j]].probability(final_state) #outcome probability
277-             array_to_fill[ final_indices[j] ] =  c_ereps[elabel_indices[j]].probability_using_cache(final_state, precomp_state, precomp_id) # outcome probability
284+             array_to_fill[ final_indices[j] ] =  c_ereps[elabel_indices[j]].probability_using_cache(final_state, precomp_state, precomp_id[elabel_indices[j]] ) # outcome probability
278285
279286        if  icache !=  - 1 :
280287            deref(prho_cache)[icache] =  final_state #  store this state in the cache
0 commit comments