pygsti.extras.interpygate

Interpygate Sub-package

Submodules

Package Contents

Classes

PhysicalProcess

InterpolatedDenseOp

TODO: update docstring

InterpolatedOpFactory

An object that can generate "on-demand" operators (can be SPAM vecs, etc., as well) for a Model.

Functions

vec(matrix)

A function that vectorizes a matrix.

unvec(vectorized)

A function that vectorizes a process in the basis of matrix units, sorted first

run_process_tomography(state_to_density_matrix_fn, n_qubits=1, comm=None, verbose=False, basis='pp', time_dependent=False, opt_args={})

A function to compute the process matrix for a quantum channel given a function

class pygsti.extras.interpygate.PhysicalProcess(num_params, process_shape, aux_shape=None, num_params_evaluated_as_group=0)

Bases: _PhysicalBase

abstract create_process_matrix(self, v, comm=None)
abstract create_process_matrices(self, v, grouped_v, comm=None)
class pygsti.extras.interpygate.InterpolatedDenseOp(target_op, base_interpolator, aux_interpolator=None, initial_point=None, frozen_parameter_values=None, frozen_parameter_indices=None)

Bases: pygsti.modelmembers.operations.DenseOperator

TODO: update docstring An operator that behaves like a dense super-operator matrix.

This class is the common base class for more specific dense operators.

Parameters
  • mx (numpy.ndarray) – The operation as a dense process matrix.

  • evotype (Evotype or str) – The evolution type. The special value “default” is equivalent to specifying the value of pygsti.evotypes.Evotype.default_evotype.

  • state_space (StateSpace, optional) – The state space for this operation. If None a default state space with the appropriate number of qubits is used.

base

Direct access to the underlying process matrix data.

Type

numpy.ndarray

classmethod create_by_interpolating_physical_process(cls, target_op, physical_process, parameter_ranges=None, parameter_points=None, comm=None, mpi_workers_per_process=1, interpolator_and_args=None, verbosity=0)
property num_params(self)

Get the number of independent parameters which specify this object.

Returns

int

to_vector(self)

Get this object’s parameters as a 1D array of values.

Returns

numpy.ndarray

from_vector(self, v, close=False, dirty_value=True)

Initialize this object using a vector of parameters.

Parameters
  • v (numpy array) – The 1D vector of parameters. Length must == num_params()

  • close (bool, optional) – Whether v is close to the current parameter vector.

  • dirty_value (bool, 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

abstract transform_inplace(self, 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 transform of the appropriate dimension is possible, since all operation matrix elements are parameters.

Parameters

s (GaugeGroupElement) – A gauge group element which specifies the “s” matrix (and it’s inverse) used in the above similarity transform.

Returns

None

class pygsti.extras.interpygate.InterpolatedOpFactory(target_factory, argument_indices, base_interpolator, aux_interpolator=None)

Bases: pygsti.modelmembers.operations.opfactory.OpFactory

An object that can generate “on-demand” operators (can be SPAM vecs, etc., as well) for a Model.

It is assigned certain parameter indices (it’s a ModelMember), which definie the block of indices it may assign to its created operations.

The central method of an OpFactory object is the create_op method, which creates an operation that is associated with a given label. This is very similar to a LayerLizard’s function, though a LayerLizard has detailed knowledge and access to a Model’s internals whereas an OpFactory is meant to create a self-contained class of operators (e.g. continuously parameterized gates or on-demand embedding).

This class just provides a skeleton for an operation factory - derived classes add the actual code for creating custom objects.

Parameters
  • state_space (StateSpace) – The state-space of the operation(s) this factory builds.

  • evotype (Evotype) – The evolution type of the operation(s) this factory builds.

classmethod create_by_interpolating_physical_process(cls, target_factory, physical_process, argument_ranges, parameter_ranges, argument_indices=None, comm=None, mpi_workers_per_process=1, interpolator_and_args=None, verbosity=0)
create_object(self, args=None, sslbls=None)

Create the object that implements the operation associated with the given args and sslbls.

Note to developers The difference beween this method and :method:`create_op` is that this method just creates the foundational object without needing to setup its parameter indices (a technical detail which connects the created object with the originating factory’s parameters). The base-class create_op method calls create_object and then performs some additional setup on the returned object before returning it itself. Thus, unless you have a reason for implementing create_op it’s often more convenient and robust to implement this function.

Parameters
  • args (list or tuple) – The arguments for the operation to be created. None means no arguments were supplied.

  • sslbls (list or tuple) – The list of state space labels the created operator should act on. If None, then these labels are unspecified and should be irrelevant to the construction of the operator (which typically, in this case, has some fixed dimension and no noition of state space labels).

Returns

ModelMember – Can be any type of operation, e.g. a LinearOperator, SPAMVec, Instrument, or POVM, depending on the label requested.

property num_params(self)

Get the number of independent parameters which specify this object.

Returns

int

to_vector(self)

Get this object’s parameters as a 1D array of values.

Returns

numpy.ndarray

from_vector(self, v, close=False, dirty_value=True)

Initialize this object using a vector of parameters.

Parameters
  • v (numpy array) – The 1D vector of parameters. Length must == num_params()

  • close (bool, optional) – Whether v is close to the current parameter vector.

  • dirty_value (bool, 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

pygsti.extras.interpygate.vec(matrix)

A function that vectorizes a matrix.

Parameters

matrix (list,numpy.ndarray) – NxN matrix

Returns

numpy.ndarray – N^2x1 dimensional column vector

Raises

ValueError – If the input matrix is not square.

pygsti.extras.interpygate.unvec(vectorized)

A function that vectorizes a process in the basis of matrix units, sorted first by column, then row.

Parameters

vectorized (list,numpy.ndarray) – Nx1 matrix or N-dimensional vector

Returns

numpy.ndarray – NxN dimensional column vector

Raises

ValueError – If the length of the input is not a perfect square

pygsti.extras.interpygate.run_process_tomography(state_to_density_matrix_fn, n_qubits=1, comm=None, verbose=False, basis='pp', time_dependent=False, opt_args={})

A function to compute the process matrix for a quantum channel given a function that maps a pure input state to an output density matrix.

Parameters
  • state_to_density_matrix_fn – (function: array -> array) The function that computes the output density matrix from an input pure state.

  • n_qubits – (int, optional, default 1) The number of qubits expected by the function. Defaults to 1.

  • comm – (MPI.comm object, optional) An MPI communicator object for parallel computation. Defaults to local comm.

  • verbose – (bool, optional, default False) How much detail to send to stdout

  • basis – (str, optional, default ‘pp’) The basis in which to return the process matrix

  • time_dependent – (bool, optional, default False ) If the process is time dependent, then expect the density matrix function to return a list of density matrices, one at each time point.

  • opt_args – (dict, optional) Optional keyword arguments for state_to_density_matrix_fn

Returns

numpy.ndarray

The process matrix representation of the quantum channel in the basis specified by ‘basis’. If ‘time_dependent’=True, then this will be an array of process matrices.