pygsti.processors.processorspec
Defines the QubitProcessorSpec class and supporting functionality.
Module Contents
Classes
The API presented by a quantum processor, and possible classical control processors. 

The device specification for a one or more qudit quantum computer. 

The device specification for a one or more qudit quantum computer. 
 class pygsti.processors.processorspec.ProcessorSpec
Bases:
pygsti.baseobjs.nicelyserializable.NicelySerializable
The API presented by a quantum processor, and possible classical control processors.
Operation names and ideal actions (e.g. gate names and their unitaries) are stored in a processor specification, as is the availability of the different operations and overall proccesor geometry. Processor specifications do not include any information about how operations are parameterized or can be adjusted (at least not yet).
 class pygsti.processors.processorspec.QuditProcessorSpec(qudit_labels, qudit_udims, gate_names, nonstd_gate_unitaries=None, availability=None, geometry=None, prep_names=('rho0',), povm_names=('Mdefault',), instrument_names=(), nonstd_preps=None, nonstd_povms=None, nonstd_instruments=None, aux_info=None)
Bases:
ProcessorSpec
The device specification for a one or more qudit quantum computer.
Parameters
 num_qubitsint
The number of qubits in the device.
 gate_nameslist of strings
The names of gates in the device. This may include standard gate names known by pyGSTi (see below) or names which appear in the nonstd_gate_unitaries argument. The set of standard gate names includes, but is not limited to:
‘Gi’ : the 1Q idle operation
‘Gx’,’Gy’,’Gz’ : 1qubit pi/2 rotations
‘Gxpi’,’Gypi’,’Gzpi’ : 1qubit pi rotations
‘Gh’ : Hadamard
‘Gp’ : phase or Sgate (i.e., ((1,0),(0,i)))
‘Gcphase’,’Gcnot’,’Gswap’ : standard 2qubit gates
Alternative names can be used for all or any of these gates, but then they must be explicitly defined in the nonstd_gate_unitaries dictionary. Including any standard names in nonstd_gate_unitaries overrides the default (builtin) unitary with the one supplied.
 nonstd_gate_unitaries: dictionary of numpy arrays
A dictionary with keys that are gate names (strings) and values that are numpy arrays specifying quantum gates in terms of unitary matrices. This is an additional “lookup” database of unitaries  to add a gate to this QubitProcessorSpec its names still needs to appear in the gate_names list. This dictionary’s values specify additional (target) native gates that can be implemented in the device as unitaries acting on ordinary purestatevectors, in the standard computationl basis. These unitaries need not, and often should not, be unitaries acting on all of the qubits. E.g., a CNOT gate is specified by a key that is the desired name for CNOT, and a value that is the standard 4 x 4 complex matrix for CNOT. All gate names must start with ‘G’. As an advanced behavior, a unitarymatrixreturning function which takes a single argument  a tuple of label arguments  may be given instead of a single matrix to create an operation factory which allows continuouslyparameterized gates. This function must also return an empty/dummy unitary when None is given as it’s argument.
 availabilitydict, optional
A dictionary whose keys are some subset of the keys (which are gate names) nonstd_gate_unitaries and the strings (which are gate names) in gate_names and whose values are lists of qubitlabeltuples. Each qubitlabeltuple must have length equal to the number of qubits the corresponding gate acts upon, and causes that gate to be available to act on the specified qubits. Instead of a list of tuples, values of availability may take the special values “allpermutations” and “allcombinations”, which as their names imply, equate to all possible permutations and combinations of the appropriate number of qubit labels (deterined by the gate’s dimension). If a gate name is not present in availability, the default is “allpermutations”. So, the availability of a gate only needs to be specified when it cannot act in every valid way on the qubits (e.g., the device does not have alltoall connectivity).
 geometry{“line”,”ring”,”grid”,”torus”} or QubitGraph, optional
The type of connectivity among the qubits, specifying a graph used to define neighbor relationships. Alternatively, a
QubitGraph
object with qubit_labels as the node labels may be passed directly. This argument is only used as a convenient way of specifying gate availability (edge connections are used for gates whose availability is unspecified by availability or whose value there is “alledges”). qubit_labelslist or tuple, optional
The labels (integers or strings) of the qubits. If None, then the integers starting with zero are used.
 aux_infodict, optional
Any additional information that should be attached to this processor spec.
TODO: update this docstring for qudits
 property num_qudits
The number of qudits.
 property primitive_op_labels
All the primitive operation labels derived from the gate names and availabilities
 property idle_gate_names
The gate names that correspond to idle operations.
 property global_idle_gate_name
The (first) gate name that corresponds to a global idle operation.
 property global_idle_layer_label
Similar to global_idle_gate_name but include the appropriate sslbls (either None or all the qudits)
 prep_specifier(name)
The specifier for a given state preparation name.
The returned value specifies a state in one of several ways. It can either be a string identifying a standard state preparation (like “rho0”), or a complex array describing a pure state.
Parameters
 namestr
The name of the state preparation to access.
Returns
str or numpy.ndarray
 povm_specifier(name)
The specifier for a given POVM name.
The returned value specifies a POVM in one of several ways. It can either be a string identifying a standard POVM (like “Mz”), or a dictionary with values describing the pure states that each element of the POVM projects onto. Each value can be either a string describing a standard state or a complex array.
Parameters
 namestr
The name of the POVM to access.
Returns
str or numpy.ndarray
 instrument_specifier(name)
The specifier for a given instrument name.
The returned value specifies an instrument in one of several ways. It can either be a string identifying a standard instrument (like “Iz”), or a dictionary with values that are lists/tuples of 2tuples describing each instrument member as the sum of rank1 process matrices. Each 2tuple element can be a string describing a standard state or a complex array describing an arbitrary pure state.
Parameters
 namestr
The name of the state preparation to access.
Returns
str or dict
 gate_num_qudits(gate_name)
The number of qudits that a given gate acts upon.
Parameters
 gate_namestr
The name of the gate.
Returns
int
 rename_gate_inplace(existing_gate_name, new_gate_name)
Renames a gate within this processor specification.
Parameters
 existing_gate_namestr
The existing gate name you want to change.
 new_gate_namestr
The new gate name.
Returns
None
 resolved_availability(gate_name, tuple_or_function='auto')
The availability of a given gate, resolved as either a tuple of sslbltuples or a function.
This function does more than just access the availability attribute, as this may hold special values like “alledges”. It takes the value of self.availability[gate_name] and resolves and converts it into the desired format: either a tuple of statespace labels or a function with a single statespacelabelstuple argument.
Parameters
 gate_namestr
The gate name to get the availability of.
 tuple_or_function{‘tuple’, ‘function’, ‘auto’}
The type of object to return. ‘tuple’ means a tuple of state space label tuples, e.g. ((0,1), (1,2)). ‘function’ means a function that takes a single state space label tuple argument and returns True or False to indicate whether the gate is available on the given target labels. If ‘auto’ is given, then either a tuple or function is returned  whichever is more computationally convenient.
Returns
tuple or function
 is_available(gate_label)
Check whether a gate at a given location is available.
Parameters
 gate_labelLabel
The gate name and target labels to check availability of.
Returns
bool
 available_gatenames(sslbls)
List all the gate names that are available within a set of state space labels.
This function finds all the gate names that are available for at least a subset of sslbls.
Parameters
 sslblstuple
The state space labels to find availability within.
Returns
 tuple of strings
A tuple of gate names (strings).
 available_gatelabels(gate_name, sslbls)
List all the gate labels that are available for gate_name on at least a subset of sslbls.
Parameters
 gate_namestr
The gate name.
 sslblstuple
The state space labels to find availability within.
Returns
 tuple of Labels
The available gate labels (all with name gate_name).
 compute_ops_on_qudits()
Constructs a dictionary mapping tuples of state space labels to the operations available on them.
Returns
 dict
A dictionary with keys that are state space label tuples and values that are lists of gate labels, giving the available gates on those target labels.
 subset(gate_names_to_include='all', qudit_labels_to_keep='all')
Construct a smaller processor specification by keeping only a select set of gates from this processor spec.
Parameters
 gate_names_to_includelist or tuple or set
The gate names that should be included in the returned processor spec.
Returns
QuditProcessorSpec
 map_qudit_labels(mapper)
Creates a new QuditProcessorSpec whose qudit labels are updated according to the mapping function mapper.
Parameters
 mapperdict or function
A dictionary whose keys are the existing self.qudit_labels values and whose value are the new labels, or a function which takes a single (existing quditlabel) argument and returns a new qudit label.
Returns
QuditProcessorSpec
 class pygsti.processors.processorspec.QubitProcessorSpec(num_qubits, gate_names, nonstd_gate_unitaries=None, availability=None, geometry=None, qubit_labels=None, nonstd_gate_symplecticreps=None, prep_names=('rho0',), povm_names=('Mdefault',), instrument_names=(), nonstd_preps=None, nonstd_povms=None, nonstd_instruments=None, aux_info=None)
Bases:
QuditProcessorSpec
The device specification for a one or more qudit quantum computer.
Parameters
 num_qubitsint
The number of qubits in the device.
 gate_nameslist of strings
The names of gates in the device. This may include standard gate names known by pyGSTi (see below) or names which appear in the nonstd_gate_unitaries argument. The set of standard gate names includes, but is not limited to:
‘Gi’ : the 1Q idle operation
‘Gx’,’Gy’,’Gz’ : 1qubit pi/2 rotations
‘Gxpi’,’Gypi’,’Gzpi’ : 1qubit pi rotations
‘Gh’ : Hadamard
‘Gp’ : phase or Sgate (i.e., ((1,0),(0,i)))
‘Gcphase’,’Gcnot’,’Gswap’ : standard 2qubit gates
Alternative names can be used for all or any of these gates, but then they must be explicitly defined in the nonstd_gate_unitaries dictionary. Including any standard names in nonstd_gate_unitaries overrides the default (builtin) unitary with the one supplied.
 nonstd_gate_unitaries: dictionary of numpy arrays
A dictionary with keys that are gate names (strings) and values that are numpy arrays specifying quantum gates in terms of unitary matrices. This is an additional “lookup” database of unitaries  to add a gate to this QubitProcessorSpec its names still needs to appear in the gate_names list. This dictionary’s values specify additional (target) native gates that can be implemented in the device as unitaries acting on ordinary purestatevectors, in the standard computationl basis. These unitaries need not, and often should not, be unitaries acting on all of the qubits. E.g., a CNOT gate is specified by a key that is the desired name for CNOT, and a value that is the standard 4 x 4 complex matrix for CNOT. All gate names must start with ‘G’. As an advanced behavior, a unitarymatrixreturning function which takes a single argument  a tuple of label arguments  may be given instead of a single matrix to create an operation factory which allows continuouslyparameterized gates. This function must also return an empty/dummy unitary when None is given as it’s argument.
 availabilitydict, optional
A dictionary whose keys are some subset of the keys (which are gate names) nonstd_gate_unitaries and the strings (which are gate names) in gate_names and whose values are lists of qubitlabeltuples. Each qubitlabeltuple must have length equal to the number of qubits the corresponding gate acts upon, and causes that gate to be available to act on the specified qubits. Instead of a list of tuples, values of availability may take the special values “allpermutations” and “allcombinations”, which as their names imply, equate to all possible permutations and combinations of the appropriate number of qubit labels (deterined by the gate’s dimension). If a gate name is not present in availability, the default is “allpermutations”. So, the availability of a gate only needs to be specified when it cannot act in every valid way on the qubits (e.g., the device does not have alltoall connectivity).
 geometry{“line”,”ring”,”grid”,”torus”} or QubitGraph, optional
The type of connectivity among the qubits, specifying a graph used to define neighbor relationships. Alternatively, a
QubitGraph
object with qubit_labels as the node labels may be passed directly. This argument is only used as a convenient way of specifying gate availability (edge connections are used for gates whose availability is unspecified by availability or whose value there is “alledges”). qubit_labelslist or tuple, optional
The labels (integers or strings) of the qubits. If None, then the integers starting with zero are used.
 nonstd_gate_symplecticrepsdict, optional
A dictionary similar to nonstd_gate_unitaries that supplies, instead of a unitary matrix, the symplectic representation of a Clifford operations, given as a 2tuple of numpy arrays.
 aux_infodict, optional
Any additional information that should be attached to this processor spec.
 property qubit_labels
The qubit labels.
 property qubit_graph
The qubit graph (geometry).
 property num_qubits
The number of qudits.
 gate_num_qubits(gate_name)
The number of qubits that a given gate acts upon.
Parameters
 gate_namestr
The name of the gate.
Returns
int
 compute_ops_on_qubits()
Constructs a dictionary mapping tuples of state space labels to the operations available on them.
Returns
 dict
A dictionary with keys that are state space label tuples and values that are lists of gate labels, giving the available gates on those target labels.
 subset(gate_names_to_include='all', qubit_labels_to_keep='all')
Construct a smaller processor specification by keeping only a select set of gates from this processor spec.
Parameters
 gate_names_to_includelist or tuple or set
The gate names that should be included in the returned processor spec.
Returns
QubitProcessorSpec
 map_qubit_labels(mapper)
Creates a new QubitProcessorSpec whose qubit labels are updated according to the mapping function mapper.
Parameters
 mapperdict or function
A dictionary whose keys are the existing self.qubit_labels values and whose value are the new labels, or a function which takes a single (existing qubitlabel) argument and returns a new qubit label.
Returns
QubitProcessorSpec
 force_recompute_gate_relationships()
Invalidates LRU caches for all compute_* methods of this object, forcing them to recompute their values.
The compute_* methods of this processor spec compute various relationships and properties of its gates. These routines can be computationally intensive, and so their values are cached for performance. If the gates of a processor spec changes and its compute_* methods are used, force_recompute_gate_relationships should be called.
 compute_clifford_symplectic_reps(gatename_filter=None)
Constructs a dictionary of the symplectic representations for all the Clifford gates in this processor spec.
Parameters
 gatename_filteriterable, optional
A list, tuple, or set of gate names whose symplectic representations should be returned (if they exist).
Returns
 dict
keys are gate names, values are (symplectic_matrix, phase_vector) tuples.
 compute_one_qubit_gate_relations()
Computes the basic pairwise relationships relationships between the gates.
1. It multiplies all possible combinations of two 1qubit gates together, from the full model available to in this device. If the two gates multiple to another 1qubit gate from this set of gates this is recorded in the dictionary self.oneQgate_relations. If the 1qubit gate with name name1 followed by the 1qubit gate with name name2 multiple (up to phase) to the gate with name3, then self.oneQgate_relations[name1,`name2`] = name3.
2. If the inverse of any 1qubit gate is contained in the model, this is recorded in the dictionary self.gate_inverse.
Returns
 gate_relationsdict
Keys are (gatename1, gatename2) and values are either the gate name of the product of the two gates or None, signifying the identity.
 gate_inversesdict
Keys and values are gate names, mapping a gate name to its inverse gate (if one exists).
 compute_multiqubit_inversion_relations()
Computes the inverses of multiqubit (>1 qubit) gates.
Finds whether any of the multiqubit gates in this device also have their inverse in the model. That is, if the unitaries for the multiqubit gate with name name1 followed by the multiqubit gate (of the same dimension) with name name2 multiple (up to phase) to the identity, then gate_inverse[name1] = name2 and gate_inverse[name2] = name1
1qubit gates are not computed by this method, as they are be computed by the method
compute_one_qubit_gate_relations()
.Returns
 gate_inversedict
Keys and values are gate names, mapping a gate name to its inverse gate (if one exists).
 compute_clifford_ops_on_qubits()
Constructs a dictionary mapping tuples of state space labels to the clifford operations available on them.
Returns
 dict
A dictionary with keys that are state space label tuples and values that are lists of gate labels, giving the available Clifford gates on those target labels.