pygsti.modelmembers.operations.composederrorgen
The ComposedErrorgen class and supporting functionality.
Module Contents
Classes
A composition (sum!) of several Lindbladian exponent operators. |
- class pygsti.modelmembers.operations.composederrorgen.ComposedErrorgen(errgens_to_compose, evotype='auto', state_space='auto')
Bases:
pygsti.modelmembers.operations.linearop.LinearOperator
A composition (sum!) of several Lindbladian exponent operators.
That is, a sum (not product) of other error generators.
Parameters
- errgens_to_composelist
List of LinearOperator-derived objects that are summed together (composed) to form this error generator.
- evotypeEvotype or str, optional
The evolution type. The special value “default” is equivalent to specifying the value of pygsti.evotypes.Evotype.default_evotype. The special value “auto” is equivalent to the evolution type of ops_to_compose[0] if there’s at least one operation being composed.
- state_spaceStateSpace or “auto”
State space of this error generator. Can be set to “auto” to take the state space from errgens_to_compose[0] if there’s at least one error generator being composed.
Initialize a new LinearOperator
- property parameter_labels
An array of labels (usually strings) describing this model member’s parameters.
- property num_params
Get the number of independent parameters which specify this error generator.
Returns
- int
the number of independent parameters.
- property total_term_magnitude
Get the total (sum) of the magnitudes of all this operator’s terms.
The magnitude of a term is the absolute value of its coefficient, so this function returns the number you’d get from summing up the absolute-coefficients of all the Taylor terms (at all orders!) you get from expanding this operator in a Taylor series.
Returns
float
- property total_term_magnitude_deriv
The derivative of the sum of all this operator’s terms.
Computes the derivative of the total (sum) of the magnitudes of all this operator’s terms with respect to the operators (local) parameters.
Returns
- numpy array
An array of length self.num_params
- factors
- matrix_basis
- coefficients(return_basis=False, logscale_nonham=False)
Constructs a dictionary of the Lindblad-error-generator coefficients of this error generator.
Note that these are not necessarily the parameter values, as these coefficients are generally functions of the parameters (so as to keep the coefficients positive, for instance).
Parameters
- return_basisbool
Whether to also return a
Basis
containing the elements with which the error generator terms were constructed.- logscale_nonhambool, optional
Whether or not the non-hamiltonian error generator coefficients should be scaled so that the returned dict contains: (1 - exp(-d^2 * coeff)) / d^2 instead of coeff. This essentially converts the coefficient into a rate that is the contribution this term would have within a depolarizing channel where all stochastic generators had this same coefficient. This is the value returned by
error_rates()
.
Returns
- Ltermdictdict
Keys are (termType, basisLabel1, <basisLabel2>) tuples, where termType is “H” (Hamiltonian), “S” (Stochastic), or “A” (Affine). Hamiltonian and Affine terms always have a single basis label (so key is a 2-tuple) whereas Stochastic tuples have 1 basis label to indicate a diagonal term and otherwise have 2 basis labels to specify off-diagonal non-Hamiltonian Lindblad terms. Basis labels are integers starting at 0. Values are complex coefficients.
- basisBasis
A Basis mapping the basis labels used in the keys of Ltermdict to basis matrices.
- coefficient_labels()
The elementary error-generator labels corresponding to the elements of
coefficients_array()
.Returns
- tuple
A tuple of (<type>, <basisEl1> [,<basisEl2]) elements identifying the elementary error generators of this gate.
- coefficients_array()
The weighted coefficients of this error generator in terms of “standard” error generators.
Constructs a 1D array of all the coefficients returned by
coefficients()
, weighted so that different error generators can be weighted differently when a errorgen_penalty_factor is used in an objective function.Returns
- numpy.ndarray
A 1D array of length equal to the number of coefficients in the linear combination of standard error generators that is this error generator.
- coefficients_array_deriv_wrt_params()
The jacobian of
coefficients_array()
with respect to this error generator’s parameters.Returns
- numpy.ndarray
A 2D array of shape (num_coeffs, num_params) where num_coeffs is the number of coefficients in the linear combination of standard error generators that is this error generator, and num_params is this error generator’s number of parameters.
- error_rates()
Constructs a dictionary of the error rates associated with this error generator.
These error rates pertaining to the channel formed by exponentiating this object.
The “error rate” for an individual Hamiltonian error is the angle about the “axis” (generalized in the multi-qubit case) corresponding to a particular basis element, i.e. theta in the unitary channel U = exp(i * theta/2 * BasisElement).
The “error rate” for an individual Stochastic error is the contribution that basis element’s term would have to the error rate of a depolarization channel. For example, if the rate corresponding to the term (‘S’,’X’) is 0.01 this means that the coefficient of the rho -> X*rho*X-rho error generator is set such that if this coefficient were used for all 3 (X,Y, and Z) terms the resulting depolarizing channel would have error rate 3*0.01 = 0.03.
Note that because error generator terms do not necessarily commute with one another, the sum of the returned error rates is not necessarily the error rate of the overall channel.
Returns
- lindblad_term_dictdict
Keys are (termType, basisLabel1, <basisLabel2>) tuples, where termType is “H” (Hamiltonian), “S” (Stochastic), or “A” (Affine). Hamiltonian and Affine terms always have a single basis label (so key is a 2-tuple) whereas Stochastic tuples have 1 basis label to indicate a diagonal term and otherwise have 2 basis labels to specify off-diagonal non-Hamiltonian Lindblad terms. Values are real error rates except for the 2-basis-label case.
- set_coefficients(lindblad_term_dict, action='update', logscale_nonham=False, truncate=True)
Sets the coefficients of terms in this error generator.
The dictionary lindblad_term_dict has tuple-keys describing the type of term and the basis elements used to construct it, e.g. (‘H’,’X’).
Parameters
- lindblad_term_dictdict
Keys are (termType, basisLabel1, <basisLabel2>) tuples, where termType is “H” (Hamiltonian), “S” (Stochastic), or “A” (Affine). Hamiltonian and Affine terms always have a single basis label (so key is a 2-tuple) whereas Stochastic tuples have 1 basis label to indicate a diagonal term and otherwise have 2 basis labels to specify off-diagonal non-Hamiltonian Lindblad terms. Values are the coefficients of these error generators, and should be real except for the 2-basis-label case.
- action{“update”,”add”,”reset”}
How the values in lindblad_term_dict should be combined with existing error-generator coefficients.
- logscale_nonhambool, optional
Whether or not the values in lindblad_term_dict for non-hamiltonian error generators should be interpreted as error rates (of an “equivalent” depolarizing channel, see
errorgen_coefficients()
) instead of raw coefficients. If True, then the non-hamiltonian coefficients are set to -log(1 - d^2*rate)/d^2, where rate is the corresponding value given in lindblad_term_dict. This is what is performed by the functionset_error_rates()
.- truncatebool, optional
Whether to truncate the projections onto the Lindblad terms in order to meet constraints (e.g. to preserve CPTP) when necessary. If False, then an error is thrown when the given coefficients cannot be parameterized as specified.
Returns
None
- set_error_rates(lindblad_term_dict, action='update')
Sets the coeffcients of terms in this error generator.
Cofficients are set so that the contributions of the resulting channel’s error rate are given by the values in lindblad_term_dict. See
error_rates()
for more details.Parameters
- lindblad_term_dictdict
Keys are (termType, basisLabel1, <basisLabel2>) tuples, where termType is “H” (Hamiltonian), “S” (Stochastic), or “A” (Affine). Hamiltonian and Affine terms always have a single basis label (so key is a 2-tuple) whereas Stochastic tuples have 1 basis label to indicate a diagonal term and otherwise have 2 basis labels to specify off-diagonal non-Hamiltonian Lindblad terms. Values are real error rates except for the 2-basis-label case, when they may be complex.
- action{“update”,”add”,”reset”}
How the values in lindblad_term_dict should be combined with existing error rates.
Returns
None
- deriv_wrt_params(wrt_filter=None)
The element-wise derivative this operation.
Construct a matrix whose columns are the vectorized derivatives of the flattened error generator matrix with respect to a single operator parameter. Thus, each column is of length op_dim^2 and there is one column per operation parameter.
Parameters
- wrt_filterlist or numpy.ndarray
List of parameter indices to take derivative with respect to. (None means to use all the this operation’s parameters.)
Returns
- numpy array
Array of derivatives, shape == (dimension^2, num_params)
- hessian_wrt_params(wrt_filter1=None, wrt_filter2=None)
Construct the Hessian of this error generator with respect to its parameters.
This function returns a tensor whose first axis corresponds to the flattened operation matrix and whose 2nd and 3rd axes correspond to the parameters that are differentiated with respect to.
Parameters
- wrt_filter1list or numpy.ndarray
List of parameter indices to take 1st derivatives with respect to. (None means to use all the this operation’s parameters.)
- wrt_filter2list or numpy.ndarray
List of parameter indices to take 2nd derivatives with respect to. (None means to use all the this operation’s parameters.)
Returns
- numpy array
Hessian with shape (dimension^2, num_params1, num_params2)
- append(*factors_to_add)
Add one or more factors to this operator.
Parameters
- *factors_to_addLinearOperator
One or multiple factor operators to add on at the end (summed last) of this operator.
Returns
None
- insert(insert_at, *factors_to_insert)
Insert one or more factors into this operator.
Parameters
- insert_atint
The index at which to insert factors_to_insert. The factor at this index and those after it are shifted back by len(factors_to_insert).
- *factors_to_insertLinearOperator
One or multiple factor operators to insert within this operator.
Returns
None
- remove(*factor_indices)
Remove one or more factors from this operator.
Parameters
- *factorop_indicesint
One or multiple factor indices to remove from this operator.
Returns
None
- to_sparse(on_space='minimal')
Return this error generator as a sparse matrix
Returns
scipy.sparse.csr_matrix
- to_dense(on_space='minimal')
Return this error generator as a dense matrix
Parameters
- on_space{‘minimal’, ‘Hilbert’, ‘HilbertSchmidt’}
The space that the returned dense operation acts upon. For unitary matrices and bra/ket vectors, use ‘Hilbert’. For superoperator matrices and super-bra/super-ket vectors use ‘HilbertSchmidt’. ‘minimal’ means that ‘Hilbert’ is used if possible given this operator’s evolution type, and otherwise ‘HilbertSchmidt’ is used.
Returns
numpy.ndarray
- to_vector()
Get the error generator parameters as an array of values.
Returns
- numpy array
The operation parameters as a 1D array with length num_params().
- from_vector(v, close=False, dirty_value=True)
Initialize the operation using a vector of parameters.
Parameters
- vnumpy array
The 1D vector of operation parameters. Length must == num_params()
- closebool, optional
Whether v is close to this operation’s current set of parameters. Under some circumstances, when this is true this call can be completed more quickly.
- dirty_valuebool, optional
The value to set this object’s “dirty flag” to before exiting this call. This is passed as an argument so it can be updated recursively. Leave this set to True unless you know what you’re doing.
Returns
None
- taylor_order_terms(order, max_polynomial_vars=100, return_coeff_polys=False)
Get the order-th order Taylor-expansion terms of this error generator.
This function either constructs or returns a cached list of the terms at the given order. Each term is “rank-1”, meaning that its action on a density matrix rho can be written:
rho -> A rho B
The coefficients of these terms are typically polynomials of the operation’s parameters, where the polynomial’s variable indices index the global parameters of the operation’s parent (usually a
Model
), not the operation’s local parameter array (i.e. that returned from to_vector).Parameters
- orderint
The order of terms to get.
- max_polynomial_varsint, optional
maximum number of variables the created polynomials can have.
- return_coeff_polysbool
Whether a parallel list of locally-indexed (using variable indices corresponding to this object’s parameters rather than its parent’s) polynomial coefficients should be returned as well.
Returns
- termslist
A list of
RankOneTerm
objects.- coefficientslist
Only present when return_coeff_polys == True. A list of compact polynomial objects, meaning that each element is a (vtape,ctape) 2-tuple formed by concatenating together the output of
Polynomial.compact()
.
- transform_inplace(s)
Update operation matrix O with inv(s) * O * s.
Generally, the transform function updates the parameters of the operation such that the resulting operation matrix is altered as described above. If such an update cannot be done (because the operation parameters do not allow for it), ValueError is raised.
In this particular case any TP gauge transformation is possible, i.e. when s is an instance of TPGaugeGroupElement or corresponds to a TP-like transform matrix.
Parameters
- sGaugeGroupElement
A gauge group element which specifies the “s” matrix (and it’s inverse) used in the above similarity transform.
Returns
None