pygsti.processors
¶
pyGSTi Processors Python Package
Submodules¶
Package Contents¶
Classes¶
The API presented by a quantum processor, and possible classical control processors. 

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

A prescription for creating ("compiling") a set of gates based on another set. 

An collection of compilations for clifford gates. 
 class pygsti.processors.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.QubitProcessorSpec(num_qubits, gate_names, nonstd_gate_unitaries=None, availability=None, geometry=None, qubit_labels=None, nonstd_gate_symplecticreps=None, aux_info=None)¶
Bases:
ProcessorSpec
The device specification for a one or more qubit quantum computer.
This is objected is geared towards multiqubit devices; many of the contained structures are superfluous in the case of a single qubit.
 Parameters
num_qubits (int) – The number of qubits in the device.
gate_names (list 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.
availability (dict, 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_labels (list or tuple, optional) – The labels (integers or strings) of the qubits. If None, then the integers starting with zero are used.
nonstd_gate_symplecticreps (dict, 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_info (dict, optional) – Any additional information that should be attached to this processor spec.
 _to_nice_serialization(self)¶
 classmethod _from_nice_serialization(cls, state)¶
 property num_qubits(self)¶
The number of qubits.
 property primitive_op_labels(self)¶
All the primitive operation labels derived from the gate names and availabilities
 gate_num_qubits(self, gate_name)¶
The number of qubits that a given gate acts upon.
 Parameters
gate_name (str) – The name of the gate.
 Returns
int
 rename_gate_inplace(self, existing_gate_name, new_gate_name)¶
Renames a gate within this processor specification.
 Parameters
existing_gate_name (str) – The existing gate name you want to change.
new_gate_name (str) – The new gate name.
 Returns
None
 resolved_availability(self, 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_name (str) – 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
 _resolve_availability(self, avail_entry, gate_nqubits, tuple_or_function='auto')¶
 is_available(self, gate_label)¶
Check whether a gate at a given location is available.
 Parameters
gate_label (Label) – The gate name and target labels to check availability of.
 Returns
bool
 available_gatenames(self, 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
sslbls (tuple) – The state space labels to find availability within.
 Returns
tuple of strings – A tuple of gate names (strings).
 available_gatelabels(self, gate_name, sslbls)¶
List all the gate labels that are available for gate_name on at least a subset of sslbls.
 Parameters
gate_name (str) – The gate name.
sslbls (tuple) – The state space labels to find availability within.
 Returns
tuple of Labels – The available gate labels (all with name gate_name).
 force_recompute_gate_relationships(self)¶
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(self, gatename_filter=None)¶
Constructs a dictionary of the symplectic representations for all the Clifford gates in this processor spec.
 Parameters
gatename_filter (iterable, 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(self)¶
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_relations (dict) – Keys are (gatename1, gatename2) and values are either the gate name of the product of the two gates or None, signifying the identity.
gate_inverses (dict) – Keys and values are gate names, mapping a gate name to its inverse gate (if one exists).
 compute_multiqubit_inversion_relations(self)¶
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 :method:`compute_one_qubit_gate_relations`.
 Returns
gate_inverse (dict) – Keys and values are gate names, mapping a gate name to its inverse gate (if one exists).
 compute_clifford_ops_on_qubits(self)¶
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.
 compute_ops_on_qubits(self)¶
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.
 compute_clifford_2Q_connectivity(self)¶
Constructs a graph encoding the connectivity between qubits via 2qubit Clifford gates.
 Returns
QubitGraph – A graph with nodes equal to the qubit labels and edges present whenever there is a 2qubit Clifford gate between the vertex qubits.
 compute_2Q_connectivity(self)¶
Constructs a graph encoding the connectivity between qubits via 2qubit gates.
 Returns
QubitGraph – A graph with nodes equal to the qubit labels and edges present whenever there is a 2qubit gate between the vertex qubits.
 subset(self, 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_include (list or tuple or set) – The gate names that should be included in the returned processor spec.
 Returns
QubitProcessorSpec
 map_qubit_labels(self, mapper)¶
Creates a new QubitProcessorSpec whose qubit labels are updated according to the mapping function mapper.
 Parameters
mapper (dict 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
 property idle_gate_names(self)¶
The gate names that correspond to idle operations.
 property global_idle_gate_name(self)¶
The (first) gate name that corresponds to a global idle operation.
 property global_idle_layer_label(self)¶
Similar to global_idle_gate_name but include the appropriate sslbls (either None or all the qubits)
 class pygsti.processors.CompilationRules(compilation_rules_dict=None)¶
Bases:
object
A prescription for creating (“compiling”) a set of gates based on another set.
A
CompilationRules
object contains a dictionary of gate unitaries, much like aProcessorSpec
, and instructions for creating these gates. The instructions can be given explicitly as circuits corresponding to a given gate, or implicitly as functions. Instructions can be given for gate names (e.g. “Gx”), regardless of the target state space labels of the gate, as well as for specific gate locations (e.g. (“Gx”,2)). Parameters
compilation_rules_dict (dict) – A dictionary of initial rules, which can be specified in multiple formats. NOTE: currently this argument isn’t wired up, and must be left as None.
 classmethod cast(cls, obj)¶
Convert an object into compilation rules, if it isn’t already.
 Parameters
obj (object) – The object to convert.
 Returns
CompilationRules
 add_compilation_rule(self, gate_name, template_circuit_or_fn, unitary=None)¶
Add a compilation rule for a gate name, given as a circuit or function.
 Parameters
gate_name (str) – The gate name to add a rule for.
template_circuit_or_fn (Circuit or callable) – The rule. This can be specified as either a circuit or as a function. If a circuit is given, it must be on the gate’s local state space, assumed to be a kqubit space (for a kqubit gate) with qubit labels 0 to k1. That is, the circuit must have line labels equal to 0…k1. If a function if given, the function must take as a single argument a tuple of state space labels that specify the target labels of the gate.
unitary (numpy.ndarray) – The unitary corresponding to the gate. This can be left as None if gate_name names a standard or internal gate known to pyGSTi.
 Returns
None
 add_specific_compilation_rule(self, gate_label, circuit, unitary)¶
Add a compilation rule for a gate at a specific location (target labels)
 Parameters
gate_label (Label) – The gate label to add a rule for. Includes the gate’s name and its target state space labels (gate_label.sslbls).
circuit (Circuit) – The rule, given as a circuit on the gate’s local state space, i.e. the circuit’s line labels should be the same as gate_label.sslbls.
unitary (numpy.ndarray) – The unitary corresponding to the gate. This can be left as None if gate_label.name names a standard or internal gate known to pyGSTi.
 Returns
None
 create_aux_info(self)¶
Create auxiliary information that should be stored along with the compilation rules herein.
(Currently unused, but perhaps useful in the future.)
 Returns
dict
 apply_to_processorspec(self, processor_spec, action='replace')¶
Use these compilation rules to convert one processor specification into another one.
 Parameters
processor_spec (QubitProcessorSpec) – The initial processor specification, which should contain the gates present within the circuits/functions of this compilation rules object.
action ({"replace", "add"}) – Whether the existing gates in processor_spec are conveyed to the the returned processor spec. If “replace”, then they are not conveyed, if “add” they are.
 Returns
QubitProcessorSpec
 class pygsti.processors.CliffordCompilationRules(native_gates_processorspec, compile_type='absolute')¶
Bases:
CompilationRules
An collection of compilations for clifford gates.
Holds mapping between operation labels (
Label
objects) and circuits (Circuit
objects).A CliffordCompilationRules holds a processor specification of the “native” gates of a processor and uses it to produce compilations of many of/all Clifford operations. Currently, the native gates should all be Clifford gates, so that the processor spec’s compute_clifford_symplectic_reps method gives representations for all of its gates.
Compilations can be either “local” or “nonlocal”. A local compilation ony uses gates that act on its target qubits. All 1qubit gates can be local. A nonlocal compilation uses qubits outside the set of target qubits (e.g. a CNOT between two qubits between which there is no native CNOT). Currently, nonlocal compilations can only be constructed for the CNOT gate.
To speed up the creation of local compilations, a CliffordCompilationRules instance stores “template” compilations, which specify how to construct a compilation for some kqubit gate on qubits labeled 0 to k1. When creating a compilation for a gate, a template is used if a suitable one can be found; otherwise a new template is created and then used.
 Parameters
native_gates_processorspec (QubitProcessorSpec) – The processor specification of “native” Clifford gates which all compilation rules are composed from.
compile_type ({"absolute","paulieq"}) – The “compilation type” for this rules set. If “absolute”, then compilations must match the gate operation being compiled exactly. If “paulieq”, then compilations only need to match the desired gate operation up to a Paui operation (which is useful for compiling multiqubit Clifford gates / stabilizer states without unneeded 1qubit gate overheads).
 classmethod create_standard(cls, base_processor_spec, compile_type='absolute', what_to_compile=('1Qcliffords',), verbosity=1)¶
Create a common set of compilation rules based on a base processor specification.
 Parameters
base_processor_spec (QubitProcessorSpec) – The processor specification of “native” Clifford gates which all the compilation rules will be in terms of.
compile_type ({"absolute","paulieq"}) – The “compilation type” for this rules set. If “absolute”, then compilations must match the gate operation being compiled exactly. If “paulieq”, then compilations only need to match the desired gate operation up to a Paui operation (which is useful for compiling multiqubit Clifford gates / stabilizer states without unneeded 1qubit gate overheads).
what_to_compile ({"1Qcliffords", "localcnots", "allcnots", "paulis"}) – What operations should rules be created for? Allowed values may depend on the value of compile_type.
 Returns
CliffordCompilationRules
 classmethod _find_std_gate(cls, base_processor_spec, std_gate_name)¶
Check to see of a standard/internal gate exists in a processor spec
 _create_local_compilation_of(self, oplabel, unitary=None, srep=None, max_iterations=10, verbosity=1)¶
Constructs a local compilation of oplabel.
An existing template is used if one is available, otherwise a new template is created using an iterative procedure. Raises
CompilationError
when no compilation can be found. Parameters
oplabel (Label) – The label of the gate to compile. If oplabel.name is a recognized standard Clifford name (e.g. ‘H’, ‘P’, ‘X’, ‘CNOT’) then no further information is needed. Otherwise, you must specify either (or both) of unitary or srep unless the compilation for this oplabel has already been previously constructed and force is False. In that case, the previously constructed compilation will be returned in all cases, and so this method does not need to know what the gate actually is.
unitary (numpy.ndarray, optional) – The unitary action of the gate being compiled. If, as is typical, you’re compiling using Clifford gates, then this unitary should correspond to a Clifford operation. If you specify unitary, you don’t need to specify srep  it is computed automatically.
srep (tuple, optional) – The (smatrix, svector) tuple giving the symplectic representation of the gate being compiled.
max_iterations (int, optional) – The maximum number of iterations for the iterative compilation algorithm.
verbosity (int, optional) – An integer >= 0 specifying how much detail to send to stdout.
 Returns
Circuit
 _get_local_compilation_of(self, oplabel, unitary=None, srep=None, max_iterations=10, force=False, verbosity=1)¶
Gets a new local compilation of oplabel.
 Parameters
oplabel (Label) – The label of the gate to compile. If oplabel.name is a recognized standard Clifford name (e.g. ‘H’, ‘P’, ‘X’, ‘CNOT’) then no further information is needed. Otherwise, you must specify either (or both) of unitary or srep.
unitary (numpy.ndarray, optional) – The unitary action of the gate being compiled. If, as is typical, you’re compiling using Clifford gates, then this unitary should correspond to a Clifford operation. If you specify unitary, you don’t need to specify srep  it is computed automatically.
srep (tuple, optional) – The (smatrix, svector) tuple giving the symplectic representation of the gate being compiled.
max_iterations (int, optional) – The maximum number of iterations for the iterative compilation algorithm.
force (bool, optional) – If True, then a compilation is recomputed even if oplabel already exists in this CompilationLibrary. Otherwise compilations are only computed when they are not present.
verbosity (int, optional) – An integer >= 0 specifying how much detail to send to stdout.
 Returns
None
 add_local_compilation_of(self, oplabel, unitary=None, srep=None, max_iterations=10, force=False, verbosity=1)¶
Adds a new local compilation of oplabel.
 Parameters
oplabel (Label) – The label of the gate to compile. If oplabel.name is a recognized standard Clifford name (e.g. ‘H’, ‘P’, ‘X’, ‘CNOT’) then no further information is needed. Otherwise, you must specify either (or both) of unitary or srep.
unitary (numpy.ndarray, optional) – The unitary action of the gate being compiled. If, as is typical, you’re compiling using Clifford gates, then this unitary should correspond to a Clifford operation. If you specify unitary, you don’t need to specify srep  it is computed automatically.
srep (tuple, optional) – The (smatrix, svector) tuple giving the symplectic representation of the gate being compiled.
max_iterations (int, optional) – The maximum number of iterations for the iterative compilation algorithm.
force (bool, optional) – If True, then a compilation is recomputed even if oplabel already exists in this CompilationLibrary. Otherwise compilations are only computed when they are not present.
verbosity (int, optional) – An integer >= 0 specifying how much detail to send to stdout.
 Returns
None
 add_clifford_compilation_template(self, gate_name, nqubits, unitary, srep, available_gatelabels, available_sreps, verbosity=1, max_iterations=10)¶
Adds a new compilation template for gate_name.
 Parameters
gate_name (str) – The gate name to create a compilation for. If it is recognized standard Clifford name (e.g. ‘H’, ‘P’, ‘X’, ‘CNOT’) then unitary and srep can be None. Otherwise, you must specify either (or both) of unitary or srep.
nqubits (int) – The number of qubits this gate acts upon.
unitary (numpy.ndarray) – The unitary action of the gate being templated. If, as is typical, you’re compiling using Clifford gates, then this unitary should correspond to a Clifford operation. If you specify unitary, you don’t need to specify srep  it is computed automatically.
srep (tuple, optional) – The (smatrix, svector) tuple giving the symplectic representation of the gate being templated.
available_glabels (list) – A list of the gate labels (
Label
objects) that are available for use in compilations.available_sreps (dict) – A dictionary of available symplectic representations. Keys are gate labels and values are numpy arrays.
verbosity (int, optional) – An integer >= 0 specifying how much detail to send to stdout.
max_iterations (int, optional) – The maximum number of iterations for the iterative template compilationfinding algorithm.
 Returns
tuple – A tuple of the operation labels (essentially a circuit) specifying the template compilation that was generated.
 _compute_connectivity_of(self, gate_name)¶
Compute the connectivity for gate_name using the (compiled) gates available this library.
Connectivity is defined in terms of nearestneighbor links, and the resulting
QubitGraph
, is stored in self.connectivity[gate_name]. Parameters
gate_name (str) – gate name to compute connectivity for.
 Returns
None
 filter_connectivity(self, gate_name, allowed_filter)¶
Compute the QubitGraph giving the available gate_name gates subject to allowed_filter.
The filter adds constraints to by specifying the availability of gate_name.
 Parameters
gate_name (str) – The gate name.
allowed_filter (dict or set, optional) – Specifies which gates are allowed to be to construct this connectivity. If a dict, keys must be gate names (like “CNOT”) and values
QubitGraph
objects indicating where that gate (if it’s present in the library) may be used. If a set, then it specifies a set of qubits and any gate in the current library that is confined within that set is allowed. If None, then all gates within the library are allowed.
 Returns
QubitGraph
 _create_nonlocal_compilation_of(self, oplabel, allowed_filter=None, verbosity=1, check=True)¶
Constructs a potentially nonlocal compilation of oplabel.
This method currently only generates a compilation for a nonlocal CNOT, up to arbitrary Pauli gates, between a pair of unconnected qubits. It converts this CNOT into a circuit of CNOT gates between connected qubits, using a fixed circuit form. This compilation is not optimal in at least some circumstances.
 Parameters
oplabel (Label) – The label of the gate to compile. Currently, oplabel.name must equal “CNOT”.
allowed_filter (dict or set, optional) – Specifies which gates are allowed to be used in this nonlocal compilation. If a dict, keys must be gate names (like “CNOT”) and values
QubitGraph
objects indicating where that gate (if it’s present in the library) may be used. If a set, then it specifies a set of qubits and any gate in the current library that is confined within that set is allowed. If None, then all gates within the library are allowed.verbosity (int, optional) – An integer >= 0 specifying how much detail to send to stdout.
check (bool, optional) – Whether to perform internal consistency checks.
 Returns
Circuit
 _get_nonlocal_compilation_of(self, oplabel, force=False, allowed_filter=None, verbosity=1, check=True)¶
Get a potentially nonlocal compilation of oplabel.
This function does not add this compilation to the library, it merely returns it. To add it, use :method:`add_nonlocal_compilation_of`.
This method currently only generates a compilation for a nonlocal CNOT, up to arbitrary Pauli gates, between a pair of unconnected qubits. It converts this CNOT into a circuit of CNOT gates between connected qubits, using a fixed circuit form. This compilation is not optimal in at least some circumstances.
 Parameters
oplabel (Label) – The label of the gate to compile. Currently, oplabel.name must equal “CNOT”.
force (bool, optional) – If True, then a compilation is recomputed even if oplabel already exists in this CompilationLibrary. Otherwise compilations are only computed when they are not present.
allowed_filter (dict or set, optional) – Specifies which gates are allowed to be used in this nonlocal compilation. If a dict, keys must be gate names (like “CNOT”) and values
QubitGraph
objects indicating where that gate (if it’s present in the library) may be used. If a set, then it specifies a set of qubits and any gate in the current library that is confined within that set is allowed. If None, then all gates within the library are allowed.verbosity (int, optional) – An integer >= 0 specifying how much detail to send to stdout.
check (bool, optional) – Whether to perform internal consistency checks.
 Returns
Circuit
 add_nonlocal_compilation_of(self, oplabel, force=False, allowed_filter=None, verbosity=1, check=True)¶
Add a potentially nonlocal compilation of oplabel to this library.
This method currently only generates a compilation for a nonlocal CNOT, up to arbitrary Pauli gates, between a pair of unconnected qubits. It converts this CNOT into a circuit of CNOT gates between connected qubits, using a fixed circuit form. This compilation is not optimal in at least some circumstances.
If allowed_filter is None then the compilation is recorded under the key oplabel. Otherwise, the compilation is recorded under the key (oplabel,`context_key`) where context_key is frozenset(allowed_filter) when allowed_filter is a set, and context_key is frozenset(allowed_filter.items()) when allowed_filter is a dict.
 Parameters
oplabel (Label) – The label of the gate to compile. Currently, oplabel.name must equal “CNOT”.
force (bool, optional) – If True, then a compilation is recomputed even if oplabel already exists in this CompilationLibrary. Otherwise compilations are only computed when they are not present.
allowed_filter (dict or set, optional) – Specifies which gates are allowed to be used in this nonlocal compilation. If a dict, keys must be gate names (like “CNOT”) and values
QubitGraph
objects indicating where that gate (if it’s present in the library) may be used. If a set, then it specifies a set of qubits and any gate in the current library that is confined within that set is allowed. If None, then all gates within the library are allowed.verbosity (int, optional) – An integer >= 0 specifying how much detail to send to stdout.
check (bool, optional) – Whether to perform internal consistency checks.
 Returns
None
 retrieve_compilation_of(self, oplabel, force=False, allowed_filter=None, verbosity=1, check=True)¶
Get a compilation of oplabel in the context of allowed_filter, if any.
This is often more convenient than querying the CompilationLibrary directly as a dictionary, because:
If allowed_filter is not None, this handles the correct querying of the dictionary to find out if there is a previously saved compilation with this allowed_filter context.
If a compilation is not present, this method will try to compute one.
This method does not store the compilation. To store the compilation first call the method add_compilation_of().
 Parameters
oplabel (Label) – The label of the gate to compile.
force (bool, optional) – If True, then an attempt is made to recompute a compilation even if oplabel already exists in this CompilationLibrary. Otherwise compilations are only computed when they are not present.
allowed_filter (dict or set, optional) – Specifies which gates are allowed to be used in this nonlocal compilation. If a dict, keys must be gate names (like “CNOT”) and values
QubitGraph
objects indicating where that gate (if it’s present in the library) may be used. If a set, then it specifies a set of qubits and any gate in the current library that is confined within that set is allowed. If None, then all gates within the library are allowed.verbosity (int, optional) – An integer >= 0 specifying how much detail to send to stdout.
check (bool, optional) – Whether to perform internal consistency checks.
 Returns
Circuit
 add_compilation_of(self, oplabel, force=False, allowed_filter=None, verbosity=1, check=True)¶
Adds a compilation of oplabel in the context of allowed_filter, if any.
If allowed_filter is None then the compilation is recorded under the key oplabel. Otherwise, the compilation is recorded under the key (oplabel,`context_key`) where context_key is frozenset(allowed_filter) when allowed_filter is a set, and context_key is frozenset(allowed_filter.items()) when allowed_filter is a dict.
 Parameters
oplabel (Label) – The label of the gate to compile.
force (bool, optional) – If True, then an attempt is made to recompute a compilation even if oplabel already exists in this CompilationLibrary. Otherwise compilations are only computed when they are not present.
allowed_filter (dict or set, optional) – Specifies which gates are allowed to be used in this nonlocal compilation. If a dict, keys must be gate names (like “CNOT”) and values
QubitGraph
objects indicating where that gate (if it’s present in the library) may be used. If a set, then it specifies a set of qubits and any gate in the current library that is confined within that set is allowed. If None, then all gates within the library are allowed.verbosity (int, optional) – An integer >= 0 specifying how much detail to send to stdout.
check (bool, optional) – Whether to perform internal consistency checks.
 Returns
None
 exception pygsti.processors.CompilationError¶
Bases:
Exception
A compilation error, raised by
CompilationLibrary