original_docstring: 
          Compute the weighted residuals between two models/calcs.
  
          Residuals are the differences in corresponding operation matrix
          and spam vector elements.
  
          Parameters
          ----------
          other_calc : ForwardSimulator
              the other gate calculator to difference against.
  
          transform_mx : numpy array, optional
              if not None, transform this model by
              G => inv(transform_mx) * G * transform_mx, for each operation matrix G
              (and similar for rho and E vectors) before taking the difference.
              This transformation is applied only for the difference and does
              not alter the values stored in this model.
  
          item_weights : dict, optional
              Dictionary of weighting factors for individual gates and spam
              operators. Weights applied such that they act multiplicatively on
              the *squared* differences, so that the residuals themselves are
              scaled by the square roots of these weights.  Keys can be gate, state
              preparation, POVM effect, or spam labels, as well as the two special
              labels `"gates"` and `"spam"` which apply to all of the gate or SPAM
              elements, respectively (but are overridden by specific element
              values).  Values are floating point numbers.  By default, all weights
              are 1.0.
  
          Returns
          -------
          residuals : numpy.ndarray
              A 1D array of residuals (differences w.r.t. other)
          nSummands : int
              The (weighted) number of elements accounted for by the residuals.
          
docstring: Compute the weighted residuals between two models/calcs.
  Residuals are the differences in corresponding operation matrix
  and spam vector elements.
  
  Parameters
  
  other_calc : ForwardSimulator
  the other gate calculator to difference against.
  
  transform_mx : numpy array, optional
  if not None, transform this model by
  G => inv(transform_mx) * G * transform_mx, for each operation matrix G
  (and similar for rho and E vectors) before taking the difference.
  This transformation is applied only for the difference and does
  not alter the values stored in this model.
  
  item_weights : dict, optional
  Dictionary of weighting factors for individual gates and spam
  operators. Weights applied such that they act multiplicatively on
  the *squared* differences, so that the residuals themselves are
  scaled by the square roots of these weights.  Keys can be gate, state
  preparation, POVM effect, or spam labels, as well as the two special
  labels `"gates"` and `"spam"` which apply to all of the gate or SPAM
  elements, respectively (but are overridden by specific element
  values).  Values are floating point numbers.  By default, all weights
  are 1.0.
  
  Returns
  
  residuals : numpy.ndarray
  A 1D array of residuals (differences w.r.t. other)
  nSummands : int
  The (weighted) number of elements accounted for by the residuals.
docstring_tokens: Compute the weighted residuals between two models / calcs . Residuals are the differences in corresponding operation matrix and spam vector elements . Parameters other_calc : ForwardSimulator the other gate calculator to difference against . transform_mx : numpy array optional if not None transform this model by G = > inv ( transform_mx ) * G * transform_mx for each operation matrix G ( and similar for rho and E vectors ) before taking the difference . This transformation is applied only for the difference and does not alter the values stored in this model . item_weights : dict optional Dictionary of weighting factors for individual gates and spam operators . Weights applied such that they act multiplicatively on the * squared * differences so that the residuals themselves are scaled by the square roots of these weights . Keys can be gate state preparation POVM effect or spam labels as well as the two special labels ` " gates " ` and ` " spam " ` which apply to all of the gate or SPAM elements respectively ( but are overridden by specific element values ) . Values are floating point numbers . By default all weights are 1 . 0 . Returns residuals : numpy . ndarray A 1D array of residuals ( differences w . r . t . other ) nSummands : int The ( weighted ) number of elements accounted for by the residuals .
code: def residuals(self, other_calc, transform_mx=None, item_weights=None):
          """
          Compute the weighted residuals between two models/calcs.
  
          Residuals are the differences in corresponding operation matrix
          and spam vector elements.
  
          Parameters
          ----------
          other_calc : ForwardSimulator
              the other gate calculator to difference against.
  
          transform_mx : numpy array, optional
              if not None, transform this model by
              G => inv(transform_mx) * G * transform_mx, for each operation matrix G
              (and similar for rho and E vectors) before taking the difference.
              This transformation is applied only for the difference and does
              not alter the values stored in this model.
  
          item_weights : dict, optional
              Dictionary of weighting factors for individual gates and spam
              operators. Weights applied such that they act multiplicatively on
              the *squared* differences, so that the residuals themselves are
              scaled by the square roots of these weights.  Keys can be gate, state
              preparation, POVM effect, or spam labels, as well as the two special
              labels `"gates"` and `"spam"` which apply to all of the gate or SPAM
              elements, respectively (but are overridden by specific element
              values).  Values are floating point numbers.  By default, all weights
              are 1.0.
  
          Returns
          -------
          residuals : numpy.ndarray
              A 1D array of residuals (differences w.r.t. other)
          nSummands : int
              The (weighted) number of elements accounted for by the residuals.
          """
          resids = []
          T = transform_mx
          nSummands = 0.0
          if item_weights is None: item_weights = {}
          sqrt_itemWeights = {k: _np.sqrt(v) for k, v in item_weights.items()}
          opWeight = sqrt_itemWeights.get('gates', 1.0)
          spamWeight = sqrt_itemWeights.get('spam', 1.0)
  
          if T is not None:
              Ti = _np.linalg.inv(T)  # TODO: generalize inverse op (call T.inverse() if T were a "transform" object?)
              for opLabel, gate in self.operations.items():
                  wt = sqrt_itemWeights.get(opLabel, opWeight)
                  resids.append(
                      wt * gate.residuals(
                          other_calc.operations[opLabel], T, Ti))
                  nSummands += wt**2 * (gate.dim)**2
  
              for lbl, rhoV in self.preps.items():
                  wt = sqrt_itemWeights.get(lbl, spamWeight)
                  resids.append(
                      wt * rhoV.residuals(other_calc.preps[lbl], T, Ti))
                  nSummands += wt**2 * rhoV.dim
  
              for lbl, Evec in self.effects.items():
                  wt = sqrt_itemWeights.get(lbl, spamWeight)
                  resids.append(
                      wt * Evec.residuals(other_calc.effects[lbl], T, Ti))
  
                  nSummands += wt**2 * Evec.dim
  
          else:
              for opLabel, gate in self.operations.items():
                  wt = sqrt_itemWeights.get(opLabel, opWeight)
                  resids.append(
                      wt * gate.residuals(other_calc.operations[opLabel]))
                  nSummands += wt**2 * (gate.dim)**2
  
              for lbl, rhoV in self.preps.items():
                  wt = sqrt_itemWeights.get(lbl, spamWeight)
                  resids.append(
                      wt * rhoV.residuals(other_calc.preps[lbl]))
                  nSummands += wt**2 * rhoV.dim
  
              for lbl, Evec in self.effects.items():
                  wt = sqrt_itemWeights.get(lbl, spamWeight)
                  resids.append(
                      wt * Evec.residuals(other_calc.effects[lbl]))
                  nSummands += wt**2 * Evec.dim
  
          resids = [r.flatten() for r in resids]
          resids = _np.concatenate(resids)
          return resids, nSummands
code_tokens: def residuals ( self , other_calc , transform_mx = None , item_weights = None ) : resids = [ ] T = transform_mx nSummands = 0.0 if item_weights is None : item_weights = { } sqrt_itemWeights = { k : _np . sqrt ( v ) for k , v in item_weights . items ( ) } opWeight = sqrt_itemWeights . get ( 'gates' , 1.0 ) spamWeight = sqrt_itemWeights . get ( 'spam' , 1.0 ) if T is not None : Ti = _np . linalg . inv ( T ) for opLabel , gate in self . operations . items ( ) : wt = sqrt_itemWeights . get ( opLabel , opWeight ) resids . append ( wt * gate . residuals ( other_calc . operations [ opLabel ] , T , Ti ) ) nSummands += wt ** 2 * ( gate . dim ) ** 2 for lbl , rhoV in self . preps . items ( ) : wt = sqrt_itemWeights . get ( lbl , spamWeight ) resids . append ( wt * rhoV . residuals ( other_calc . preps [ lbl ] , T , Ti ) ) nSummands += wt ** 2 * rhoV . dim for lbl , Evec in self . effects . items ( ) : wt = sqrt_itemWeights . get ( lbl , spamWeight ) resids . append ( wt * Evec . residuals ( other_calc . effects [ lbl ] , T , Ti ) ) nSummands += wt ** 2 * Evec . dim else : for opLabel , gate in self . operations . items ( ) : wt = sqrt_itemWeights . get ( opLabel , opWeight ) resids . append ( wt * gate . residuals ( other_calc . operations [ opLabel ] ) ) nSummands += wt ** 2 * ( gate . dim ) ** 2 for lbl , rhoV in self . preps . items ( ) : wt = sqrt_itemWeights . get ( lbl , spamWeight ) resids . append ( wt * rhoV . residuals ( other_calc . preps [ lbl ] ) ) nSummands += wt ** 2 * rhoV . dim for lbl , Evec in self . effects . items ( ) : wt = sqrt_itemWeights . get ( lbl , spamWeight ) resids . append ( wt * Evec . residuals ( other_calc . effects [ lbl ] ) ) nSummands += wt ** 2 * Evec . dim resids = [ r . flatten ( ) for r in resids ] resids = _np . concatenate ( resids ) return resids , nSummands
short_docstring: Compute the weighted residuals between two models/calcs.
short_docstring_tokens: Compute the weighted residuals between two models / calcs .
comment: """
          Compute the weighted residuals between two models/calcs.
  
          Residuals are the differences in corresponding operation matrix
          and spam vector elements.
  
          Parameters
          ----------
          other_calc : ForwardSimulator
              the other gate calculator to difference against.
  
          transform_mx : numpy array, optional
              if not None, transform this model by
              G => inv(transform_mx) * G * transform_mx, for each operation matrix G
              (and similar for rho and E vectors) before taking the difference.
              This transformation is applied only for the difference and does
              not alter the values stored in this model.
  
          item_weights : dict, optional
              Dictionary of weighting factors for individual gates and spam
              operators. Weights applied such that they act multiplicatively on
              the *squared* differences, so that the residuals themselves are
              scaled by the square roots of these weights.  Keys can be gate, state
              preparation, POVM effect, or spam labels, as well as the two special
              labels `"gates"` and `"spam"` which apply to all of the gate or SPAM
              elements, respectively (but are overridden by specific element
              values).  Values are floating point numbers.  By default, all weights
              are 1.0.
  
          Returns
          -------
          residuals : numpy.ndarray
              A 1D array of residuals (differences w.r.t. other)
          nSummands : int
              The (weighted) number of elements accounted for by the residuals.
          """$SEP$# TODO: generalize inverse op (call T.inverse() if T were a "transform" object?)