pygsti.processors

pyGSTi Processors Python Package

Submodules

Package Contents

Classes

ProcessorSpec

The API presented by a quantum processor, and possible classical control processors.

QuditProcessorSpec

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

QubitProcessorSpec

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

CompilationRules

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

CliffordCompilationRules

An collection of compilations for clifford gates.

RandomCompilation

A class for performing randomized circuit compilation.

Functions

pauli_randomize_circuit(→ pygsti.circuits.circuit.Circuit)

Performs random compilation on a given circuit by inserting Pauli gates between layers.

randomize_central_pauli(→ pygsti.circuits.circuit.Circuit)

Perform circuit randomization by propagating a central Pauli layer through the circuit.

update_u3_parameters(→ List[pygsti.baseobjs.label.Label])

Updates the parameters of U3 gates in a given layer based on the provided Pauli random compiling vectors.

mod_2pi(→ float)

Modifies an angle to be within the range of -π to π.

pauli_vector_to_u3_layer(→ pygsti.baseobjs.label.Label)

Converts a Pauli vector into a corresponding layer of U3 gates.

haar_random_u3_layer(→ pygsti.baseobjs.label.Label)

Generates a layer of Haar-random U3 gates.

haar_random_u3(→ pygsti.baseobjs.label.Label)

Generates a Haar-random U3 gate.

u3_cx_cz_inv(→ pygsti.circuits.circuit.Circuit)

Computes the inverse of a circuit composed of U3, CX and CZ gates.

gate_inverse(→ pygsti.baseobjs.label.Label)

Computes the inverse of a given gate label.

inverse_u3(→ Tuple[float, float, float])

Computes the inverse parameters for a U3 gate given its parameters.

pad_layer(→ List[pygsti.baseobjs.label.Label])

Pads a layer of gates with idle gates for any unused qubits.

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.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’ : 1-qubit pi/2 rotations

  • ‘Gxpi’,’Gypi’,’Gzpi’ : 1-qubit pi rotations

  • ‘Gh’ : Hadamard

  • ‘Gp’ : phase or S-gate (i.e., ((1,0),(0,i)))

  • ‘Gcphase’,’Gcnot’,’Gswap’ : standard 2-qubit 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 QuditProcessorSpec 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 pure-state-vectors, 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 unitary-matrix-returning 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 continuously-parameterized 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 qubit-label-tuples. Each qubit-label-tuple 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 “all-permutations” and “all-combinations”, 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 “all-permutations”. 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 all-to-all 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 “all-edges”).

prep_nameslist or tuple of str, optional (default (‘rho0’,))

List of strings corresponding to the names of the native state preparation operations supported by this processor specification. State preparation names must start with ‘rho’.

povm_nameslist or tuple of str, optional (default (‘Mdefault’,))

List of strings corresponding to the names of the native POVMs supported by this processor specification. POVM names must start with ‘M’.

instrument_nameslist or tuple of str, optional (default ())

List of strings corresponding to the names of the quantum instruments supported by this processor specification. Instrument names must start with ‘I’.

nonstd_prepsdict, optional (default None)

Dictionary mapping preparation names (as specified in prep_names) to corresponding state preparations. The values of this dictionary can be the following specifiers:

  • numpy ndarray: numpy vector corresponding to the dense representation of the pure state corresponding to this state preparation, written in the standard/computational basis.

  • string specifiers: For string state preparation specifiers there are two prefixes supported which determine the parsing applied for conversion to a corresponding state preparation.: The first prefix is ‘rho_’. When this prefix is used, any digits proceeding in the string are interpreted as digits of the base d number (where d is appropriate dimensions of the qudit subsystems, though note this dimension might vary for each subsystem) labeling a standard basis state. E.g. ‘rho_01’ when both subsystems are qubits corresponds to the state |01>. ‘rho_12’ when the two subsystems are qutrits is the state |12>, etc. The second prefix is ‘rho’ (w/o the underscore). When this prefix is used the following digits are interpreted as an integer. This integer is then converted into a base d (see comment above about mixed dimensions) number labeling the corresponding standard basis state (with the conversion using right-LSB convention).

nonstd_povmsdict, optional (default None)

Dictionary mapping POVM names (as specified in povm_names) to corresponding POVMs. The values of this dictionary can be the following specifiers:

  • string specifiers: Presently two special string specifiers are supported, ‘Mdefault’ and ‘Mz’, both of which map to POVMs for computational-basis readout with the appropriate dimensions.

  • dictionary: A dictionary whose keys are effect labels, and whose values are specifiers used to construct corresponding effects. Effect specifiers can themselves take two forms: - list of numpy arrays: List of numpy arrays corresponding to the component pure states whose corresponding

    projectors (density matrix vectors) are summed to produce this POVM effect. When there is only a single such pure state then one can alternatively use that numpy array directly as the value (without wrapping in a list) for convenience. E.g. to construct a two-qubit, two-outcome, POVM corresponding to parity readout wherein each POVM effect corresponds to a rank-2 projector onto the even or odd computational subspace the complete POVM specifier would be: {‘even’: [np.array([1,0,0,0], np.array([0,0,0,1])], ‘odd’: [np.array([0,1,0,0], np.array([0,0,1,0])]}

    -list of string specifiers: Alternatively one can specify a list of effect specifiers using special string
    notation. String specifiers can take three formats:
    1. They can be strings which directly correspond to the desired output bit/ditstring in the standard basis. E.g. “0000” or “2212”

    2. Strings prefixed by either ‘E_’ or ‘E’ (w/o an underscore). In the first case any digits proceeding the “E_” are interpretted as a bit/ditstring written in whatever base is appropriate given the qudit dimensions. If prefixed by “E” (w/o an underscore) the proceeding digits are interpreted as an integer and converted into a base d number using right-LSB convention. E.g. ‘E_0000’ corresponds to the state |0000>, and E15 corresponds to |1111> (assuming this was acting on 4-qubits).

nonstd_instrumentsdict, optional (default None)

Dictionary mapping instrument names (as specified in instrument_names) to corresponding instruments. The values of this dictionary can be the following specifiers:

  • string specifiers: Presently only one special string specifier is supported, ‘Iz’. This corresponds to a quantum instrument for computational-basis readout.

  • dictionary: A dictionary whose keys are instrument effect labels, and whose values are specifiers used to construct the corresponding instrument effects. Instrument effect specifiers can take the following form: - numpy array: A numpy array corresponding to the dense representation of the instrument effect. - lists of 2-tuples: Each tuple in this list of 2-tuples is such that the first element corresponds to a POVM effect

    specifier (see nonstd_povms for supported options), and the second element is a state preparation specifier (see nonstd_preps for supported options). These specifiers are used to construct appropriate effect and preparation representations which are then have their outer product taken. This is done for each 2-tuple, and the outer products are then summed to get the overall instrument effect. In the case where there is only a single 2-tuple for an instrument effect this tuple can be used directly as the dictionary value (w/o being wrapped in a list) for convenience.

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.

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)

gate_names
nonstd_gate_unitaries
prep_names = "('rho0',)"
nonstd_preps
povm_names = "('Mdefault',)"
nonstd_povms
instrument_names = '()'
nonstd_instruments
gate_unitaries
qudit_labels
qudit_udims
availability
compiled_from = 'None'
aux_info = 'None'
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 2-tuples describing each instrument member as the sum of rank-1 process matrices. Each 2-tuple 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 sslbl-tuples or a function.

This function does more than just access the availability attribute, as this may hold special values like “all-edges”. It takes the value of self.availability[gate_name] and resolves and converts it into the desired format: either a tuple of state-space labels or a function with a single state-space-labels-tuple 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 qudit-label) argument and returns a new qudit label.

Returns

QuditProcessorSpec

class pygsti.processors.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’ : 1-qubit pi/2 rotations

  • ‘Gxpi’,’Gypi’,’Gzpi’ : 1-qubit pi rotations

  • ‘Gh’ : Hadamard

  • ‘Gp’ : phase or S-gate (i.e., ((1,0),(0,i)))

  • ‘Gcphase’,’Gcnot’,’Gswap’ : standard 2-qubit 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 pure-state-vectors, 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 unitary-matrix-returning 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 continuously-parameterized 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 qubit-label-tuples. Each qubit-label-tuple 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 “all-permutations” and “all-combinations”, 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 “all-permutations”. 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 all-to-all 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 “all-edges”).

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 2-tuple of numpy arrays. #TODO: Better explanation of this specifier.

prep_nameslist or tuple of str, optional (default (‘rho0’,))

List of strings corresponding to the names of the native state preparation operations supported by this processor specification. State preparation names must start with ‘rho’.

povm_nameslist or tuple of str, optional (default (‘Mdefault’,))

List of strings corresponding to the names of the native POVMs supported by this processor specification. POVM names must start with ‘M’.

instrument_nameslist or tuple of str, optional (default ())

List of strings corresponding to the names of the quantum instruments supported by this processor specification. Instrument names must start with ‘I’.

nonstd_prepsdict, optional (default None)

Dictionary mapping preparation names (as specified in prep_names) to corresponding state preparations. The values of this dictionary can be the following specifiers:

  • numpy ndarray: numpy vector corresponding to the dense representation of the pure

    state corresponding to this state preparation, written in the standard/computational basis.

  • string specifiers: For string state preparation specifiers there are two prefixes supported

    which determine the parsing applied for conversion to a corresponding state preparation.: The first prefix is ‘rho_’. When this prefix is used, any digits proceeding in the string are interpreted as the bitstring labeling a standard basis state. E.g. ‘rho_01’ corresponds to the state |01>. The second prefix is ‘rho’ (w/o the underscore). When this prefix is used the following digits are interpreted as an integer. This integer is then converted into a bitstring labeling the corresponding standard basis state (with the conversion using right-LSB convention).

nonstd_povmsdict, optional (default None)

Dictionary mapping POVM names (as specified in povm_names) to corresponding POVMs. The values of this dictionary can be the following specifiers:

  • string specifiers: Presently two special string specifiers are supported, ‘Mdefault’ and ‘Mz’,

    both of which map to POVMs for computational-basis readout with the appropriate dimensions.

  • dictionary: A dictionary whose keys are effect labels, and whose values are specifiers used to construct

    corresponding effects. Effect specifiers can themselves take two forms: - list of numpy arrays: List of numpy arrays corresponding to the component pure states whose corresponding projectors (density matrix vectors) are summed to produce this POVM effect. When there is only a single such pure state then one can alternatively use that numpy array directly as the value (without wrapping in a list) for convenience. E.g. to construct a two-qubit, two-outcome, POVM corresponding to parity readout wherein each POVM effect corresponds to a rank-2 projector onto the even or odd computational subspace the complete POVM specifier would be: {‘even’: [np.array([1,0,0,0], np.array([0,0,0,1])], ‘odd’: [np.array([0,1,0,0], np.array([0,0,1,0])]} -list of string specifiers: Alternatively one can specify a list of effect specifiers using special string notation. String specifiers can take three formats: 1. They can be strings which directly correspond to the desired output bit/ditstring in the standard basis.

    E.g. “0000” or “1001”.

    1. Strings prefixed by either ‘E_’ or ‘E’ (w/o an underscore). In the first case any digits proceeding the

      E_” are interpretted as a bitstring. If prefixed by “E” (w/o an underscore) the proceeding digits are interpreted as an integer and converted into a base d number using right-LSB convention. E.g. ‘E_0000’ corresponds to the state |0000>, and E15 corresponds to |1111> (assuming this was acting on 4-qubits).

nonstd_instrumentsdict, optional (default None)

Dictionary mapping instrument names (as specified in instrument_names) to corresponding instruments. The values of this dictionary can be the following specifiers:

  • string specifiers: Presently only one special string specifier is supported, ‘Iz’. This corresponds to a quantum

    instrument for computational-basis readout.

  • dictionary: A dictionary whose keys are instrument effect labels, and whose values are specifiers used to construct the

    corresponding instrument effects. Instrument effect specifiers can take the following form: - numpy array: A numpy array corresponding to the dense representation of the instrument effect. - lists of 2-tuples: Each tuple in this list of 2-tuples is such that the first element corresponds to a POVM effect specifier (see nonstd_povms for supported options), and the second element is a state preparation specifier (see nonstd_preps for supported options). These specifiers are used to construct appropriate effect and preparation representations which are then have their outer product taken. This is done for each 2-tuple, and the outer products are then summed to get the overall instrument effect. In the case where there is only a single 2-tuple for an instrument effect this tuple can be used directly as the dictionary value (w/o being wrapped in a list) for convenience.

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 qubit-label) 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 pair-wise relationships relationships between the gates.

1. It multiplies all possible combinations of two 1-qubit gates together, from the full model available to in this device. If the two gates multiple to another 1-qubit gate from this set of gates this is recorded in the dictionary self.oneQgate_relations. If the 1-qubit gate with name name1 followed by the 1-qubit 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 1-qubit 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 multi-qubit (>1 qubit) gates.

Finds whether any of the multi-qubit gates in this device also have their inverse in the model. That is, if the unitaries for the multi-qubit gate with name name1 followed by the multi-qubit 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

1-qubit 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.

compute_clifford_2Q_connectivity()

Constructs a graph encoding the connectivity between qubits via 2-qubit Clifford gates.

Returns
QubitGraph

A graph with nodes equal to the qubit labels and edges present whenever there is a 2-qubit Clifford gate between the vertex qubits.

compute_2Q_connectivity()

Constructs a graph encoding the connectivity between qubits via 2-qubit gates.

Returns
QubitGraph

A graph with nodes equal to the qubit labels and edges present whenever there is a 2-qubit gate between the vertex qubits.

exception pygsti.processors.CompilationError

Bases: Exception

A compilation error, raised by CompilationLibrary

Initialize self. See help(type(self)) for accurate signature.

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 a ProcessorSpec, 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_dictdict

A dictionary of initial rules, which can be specified in multiple formats. Keys can be either gate names as strings or gate labels as a Label object. Values are 2-tuples of (gate unitary, gate template). The gate unitary can either be a unitary matrix, function returning a matrix, or None if the gate name is a standard PyGSTi unitary. The gate template is either a Circuit with local state space labels (i.e. 0..k-1 for k qubits) or a function that takes the target gate label and returns the proper Circuit. If the key is a gate label, the gate template (second entry of the value tuple) MUST be a Circuit with absolute state space labels.

gate_unitaries
local_templates
function_templates
specific_compilations
classmethod cast(obj)

Convert an object into compilation rules, if it isn’t already.

Parameters
objobject

The object to convert.

Returns

CompilationRules

add_compilation_rule(gate_name, template_circuit_or_fn, unitary=None)

Add a compilation rule for a gate name, given as a circuit or function.

Parameters
gate_namestr

The gate name to add a rule for.

template_circuit_or_fnCircuit 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 k-qubit space (for a k-qubit gate) with qubit labels 0 to k-1. That is, the circuit must have line labels equal to 0…k-1. 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.

unitarynumpy.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(gate_label, circuit, unitary)

Add a compilation rule for a gate at a specific location (target labels)

Parameters
gate_labelLabel

The gate label to add a rule for. Includes the gate’s name and its target state space labels (gate_label.sslbls).

circuitCircuit

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.

unitarynumpy.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()

Create auxiliary information that should be stored along with the compilation rules herein.

(Currently unused, but perhaps useful in the future.)

Returns

dict

retrieve_compilation_of(oplabel, force=False)

Get a compilation of oplabel, computing one from local templates if necessary.

Parameters
oplabelLabel

The label of the gate to compile.

forcebool, 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.

Returns

Circuit or None, if failed to retrieve compilation

apply_to_processorspec(processor_spec, action='replace', gates_to_skip=None)

Use these compilation rules to convert one processor specification into another one.

Parameters
processor_specQubitProcessorSpec

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.

gates_to_skiplist

Gate names or labels to skip during processor specification construction.

Returns

QubitProcessorSpec

apply_to_circuits(circuits, **kwargs)

Use these compilation rules to convert one list of circuits into another one.

Additional kwargs are passed through to Circuit.change_gate_library during translation. Common kwargs include depth_compression=False or allow_unchanged_gates=True.

Parameters
circuitslist of Circuits

The initial circuits, which should contain the gates present within the circuits/functions of this compilation rules object.

Returns

list of Circuits

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 “non-local”. A local compilation ony uses gates that act on its target qubits. All 1-qubit gates can be local. A non-local compilation uses qubits outside the set of target qubits (e.g. a CNOT between two qubits between which there is no native CNOT). Currently, non-local 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 k-qubit gate on qubits labeled 0 to k-1. 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_processorspecQubitProcessorSpec

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 multi-qubit Clifford gates / stabilizer states without unneeded 1-qubit gate over-heads).

processor_spec
compile_type = "'absolute'"
connectivity
classmethod create_standard(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_specQubitProcessorSpec

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 multi-qubit Clifford gates / stabilizer states without unneeded 1-qubit gate over-heads).

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

add_local_compilation_of(oplabel, unitary=None, srep=None, max_iterations=10, force=False, verbosity=1)

Adds a new local compilation of oplabel.

Parameters
oplabelLabel

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.

unitarynumpy.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.

sreptuple, optional

The (smatrix, svector) tuple giving the symplectic representation of the gate being compiled.

max_iterationsint, optional

The maximum number of iterations for the iterative compilation algorithm.

forcebool, 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.

verbosityint, optional

An integer >= 0 specifying how much detail to send to stdout.

Returns

None

add_clifford_compilation_template(gate_name, nqubits, unitary, srep, available_gatelabels, available_sreps, verbosity=1, max_iterations=10)

Adds a new compilation template for gate_name.

Parameters
gate_namestr

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.

nqubitsint

The number of qubits this gate acts upon.

unitarynumpy.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.

sreptuple, optional

The (smatrix, svector) tuple giving the symplectic representation of the gate being templated.

available_glabelslist

A list of the gate labels (Label objects) that are available for use in compilations.

available_srepsdict

A dictionary of available symplectic representations. Keys are gate labels and values are numpy arrays.

verbosityint, optional

An integer >= 0 specifying how much detail to send to stdout.

max_iterationsint, optional

The maximum number of iterations for the iterative template compilation-finding algorithm.

Returns
tuple

A tuple of the operation labels (essentially a circuit) specifying the template compilation that was generated.

add_given_clifford_compilation_template(gate_name, nqubits, unitary, srep, compilation, available_sreps)

Adds a specific compilation template (as opposed to searching for one) after checking its validity.

Parameters
gate_namestr

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.

nqubitsint

The number of qubits this gate acts upon.

unitarynumpy.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.

sreptuple, optional

The (smatrix, svector) tuple giving the symplectic representation of the gate being templated.

available_srepsdict

A dictionary of available symplectic representations. Keys are gate labels and values are numpy arrays.

verbosityint, optional

An integer >= 0 specifying how much detail to send to stdout.

Returns
tuple

A tuple of the operation labels (essentially a circuit) specifying the template compilation that was generated.

filter_connectivity(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_namestr

The gate name.

allowed_filterdict 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

add_nonlocal_compilation_of(oplabel, force=False, allowed_filter=None, verbosity=1, check=True)

Add a potentially non-local compilation of oplabel to this library.

This method currently only generates a compilation for a non-local 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
oplabelLabel

The label of the gate to compile. Currently, oplabel.name must equal “CNOT”.

forcebool, 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_filterdict or set, optional

Specifies which gates are allowed to be used in this non-local 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.

verbosityint, optional

An integer >= 0 specifying how much detail to send to stdout.

checkbool, optional

Whether to perform internal consistency checks.

Returns

None

retrieve_compilation_of(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:

  1. 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.

  2. 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
oplabelLabel

The label of the gate to compile.

forcebool, 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_filterdict or set, optional

Specifies which gates are allowed to be used in this non-local 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.

verbosityint, optional

An integer >= 0 specifying how much detail to send to stdout.

checkbool, optional

Whether to perform internal consistency checks.

Returns

Circuit

add_compilation_of(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
oplabelLabel

The label of the gate to compile.

forcebool, 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_filterdict or set, optional

Specifies which gates are allowed to be used in this non-local 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.

verbosityint, optional

An integer >= 0 specifying how much detail to send to stdout.

checkbool, optional

Whether to perform internal consistency checks.

Returns

None

class pygsti.processors.RandomCompilation(rc_strategy: Literal['rc', 'cp'] | None = None, return_bs: bool | None = False, testing: bool | None = False, rand_state: numpy.random.RandomState | None = None)

Bases: object

A class for performing randomized circuit compilation.

Attributes

rc_strategystr

The strategy used for randomized compilation. Currently, ‘pauli_rc’ (pauli randomized compiling on a U3-CX-CZ gate set) and ‘central_pauli’ (central Pauli propagation for a U3-CX-CZ gate set) are supported.

return_bsbool

If True, the compile method will return the target bitstring for the randomly compiled circuit.

testingbool

Flag for unit testing. If True, the user can provide test Pauli layers for random compilation instead of the layers being randomly generated.

rand_statenp.random.RandomState

A random state for reproducibility of random operations.

Initialize the RandomCompilation object.

Parameters

rc_strategystr

The strategy used for randomized compilation. Currently, ‘pauli_rc’ (pauli randomized compiling on a U3-CX-CZ gate set, see https://arxiv.org/abs/2204.07568) and ‘central_pauli’ (central Pauli propagation for a U3-CX-CZ gate set, see https://www.nature.com/articles/s41567-021-01409-7) are supported. Defaults to ‘pauli_rc’.

return_bsbool

If True, the compile method will return the target bitstring for the randomly compiled circuit. Default is False.

testingbool

Flag for unit testing. If True, the user can provide test Pauli layers for random compilation instead of the layers being randomly generated. Default is False.

rand_statenp.random.RandomState

A random state for reproducibility of random operations. Default is None.

rc_strategy = 'None'
return_bs = 'False'
testing = 'False'
compile(circ: pygsti.circuits.circuit.Circuit, test_layers: List[numpy.ndarray] | numpy.ndarray | None = None) pygsti.circuits.circuit.Circuit

Compiles the given circuit using the specified randomized compilation strategy.

Parameters
circpygsti.circuits.Circuit

The n-qubit circuit to be compiled.

test_layerslist[np.ndarray[int]], optional

A list of test layers to be used in the random compilation if self.testing is True. Layers are specified by a length-2*n array whose entries are either 0 or 2. Indices 0:n correspond to Pauli Z errors: a 2 indicates the presence an error. Likewise indices n:2*n indicate a Pauli Z error. If using central Pauli, only one layer must be provided. If using random compilation, a number of layers equal to the number of layers of single-qubit gates must be provided. Default is None.

Returns
list[pygsti.circuits.Circuit, str (optional), np.ndarray (optional)]

A list containing the randomized circuit, and optionally the bitstring and target Pauli vector.

pygsti.processors.pauli_randomize_circuit(circ: pygsti.circuits.circuit.Circuit, rand_state: numpy.random.RandomState | None = None, return_bs: bool = False, return_target_pauli: bool = False, insert_test_layers: bool = False, test_layers: List[numpy.ndarray] | None = None) pygsti.circuits.circuit.Circuit

Performs random compilation on a given circuit by inserting Pauli gates between layers.

Parameters

circpygsti.circuits.Circuit

The circuit to be randomized.

rand_statenp.random.RandomState, optional

A random state for reproducibility. Default is None, which initializes a new random state.

return_bsbool, optional

If True, returns the target bitstring for the randomly compiled circuit. Default is False.

return_target_paulibool, optional

If True, returns the target Pauli vector for the circuit. Default is False.

insert_test_layersbool, optional

If True, uses test_layers as the Pauli layers to randomly compile instead of randomly generating Pauli layers.

test_layerslist[np.ndarray[int]], optional

A list of length-2*n arrays representing the test layers to be inserted if `insert_test_layers `is True. The number of test layers must equal the number of U3 layers in the circuit. Default is None.

Returns

list[pygsti.circuits.Circuit, str (optional), np.ndarray (optional)]

A list containing the randomized circuit, and optionally the bitstring and target Pauli vector if specified.

pygsti.processors.randomize_central_pauli(circ: pygsti.circuits.circuit.Circuit, rand_state: numpy.random.RandomState | None = None, return_bs: bool = False, return_target_pauli: bool = False, insert_test_layer: bool = False, test_layer: numpy.ndarray | None = None) pygsti.circuits.circuit.Circuit

Perform circuit randomization by propagating a central Pauli layer through the circuit. This function is designed to handle the “back half” of the mirror circuit: i.e., given a circuit C whose fidelity is to be estimated using central Pauli mirroring, this function should be passed C_inv + L_inv, where L_inv is Haar-random U3 layer. Refer to make_mirror_edesign in protocols/mirror_design.py for more information.

Parameters

circCircuit

The circuit through which the central Pauli layer is to be propagated.

rand_statenp.random.RandomState, optional

A random state for reproducibility. Default is None, which initializes a new random state.

return_bsbool, optional

If True, returns the target bitstring for the full mirror central Pauli circuit. Default is False.

return_target_paulibool, optional

If True, returns the target Pauli vector that has been propagated through the circuit. Default is False.

insert_test_layerbool, optional

If True, uses test_layer as the central Pauli layer instead of randomly generating a central Pauli layer.

test_layernp.ndarray[int], optional

A length-2*n array representing the test layer to be inserted if `insert_test_layer `is True. Default is None.

Returns

list[pygsti.circuits.Circuit, str (optional), np.ndarray (optional)]

A list containing the randomized circuit, and optionally the bitstring and target Pauli vector if specified.

pygsti.processors.update_u3_parameters(layer: Iterable[pygsti.baseobjs.label.Label], p: numpy.ndarray, q: numpy.ndarray, qubit_map: Dict[str, int] | Dict[int, int]) List[pygsti.baseobjs.label.Label]

Updates the parameters of U3 gates in a given layer based on the provided Pauli random compiling vectors.

Parameters

layeriterable[pygsti.baseobjs.Label]

A list of gate labels representing the layer containing U3 gates.

pnp.ndarray[int]

A vector describing the Pauli gates preceding the layer. For an n-qubit layer, p is a length-2n array. p[0:n] indicates Pauli-Z (2 is yes Z, 0 is no Z), p[n:2*n] is Pauli-X (2 yes, 0 no). E.g., if n = 5, p[3] = 2, and p[8] = 2, then there is a Y gate on qubit 3.

pnp.ndarray[int]

A vector describing the Pauli gates foloowing the layer. For an n-qubit layer, q is a length-2n array. q[0:n] indicates Pauli-Z (2 is yes Z, 0 is no Z), q[n:2*n] is Pauli-X (2 yes, 0 no). E.g., if n = 5, p[1] = 0, and p[6] = 2, then there is an X gate on qubit 3.

qubit_mapdict[str, int]

A mapping of qubit labels to their corresponding indices.

Returns

list

A new layer containing updated U3 gates based on the applied Pauli gates.

pygsti.processors.mod_2pi(theta: float) float

Modifies an angle to be within the range of -π to π.

Parameters

thetafloat

The angle in radians to be modified.

Returns

float

The modified angle within the range of -π to π.

pygsti.processors.pauli_vector_to_u3_layer(p: numpy.ndarray, qubits: List[str] | List[int]) pygsti.baseobjs.label.Label

Converts a Pauli vector into a corresponding layer of U3 gates.

Parameters

pnp.ndarray[int]

A vector representing the Pauli gates to be converted. For an n-qubit layer, p is a length-2n array. p[0:n] indicates Pauli-Z (2 is yes Z, 0 is no Z), p[n:2*n] is Pauli-X (2 yes, 0 no). E.g., if n = 5, p[3] = 2, and p[8] = 2, then there is a Y gate on qubit 3.

qubitslist[str]

A list of qubit labels corresponding to the Pauli vector.

Returns

pygsti.baseobjs.Label

Label containing the layer of U3 gates derived from the Pauli vector.

pygsti.processors.haar_random_u3_layer(qubits: List[str] | List[int], rand_state: numpy.random.RandomState | None = None) pygsti.baseobjs.label.Label

Generates a layer of Haar-random U3 gates.

Parameters

qubitslist[str]

A list of qubit labels for which to generate U3 gates.

rand_statenp.random.RandomState, optional

A random state for reproducibility. Default is None, which initializes a new random state.

Returns

pygsti.baseobjs.Label

A label containing the layer of randomly generated U3 gates.

pygsti.processors.haar_random_u3(q: str | int, rand_state: numpy.random.RandomState | None = None) pygsti.baseobjs.label.Label

Generates a Haar-random U3 gate.

Parameters

qstr

The qubit label for which to generate the U3 gate.

rand_statenp.random.RandomState, optional

A random state for reproducibility. Default is None, which initializes a new random state.

Returns

pygsti.baseobjs.Label

A label representing the randomly generated U3 gate for the specified qubit.

pygsti.processors.u3_cx_cz_inv(circ: pygsti.circuits.circuit.Circuit) pygsti.circuits.circuit.Circuit

Computes the inverse of a circuit composed of U3, CX and CZ gates.

Parameters

circpygsti.circuits.Circuit

The circuit for which to compute the inverse.

Returns

pygsti.circuits.Circuit

A new circuit representing the inverse of the input circuit.

pygsti.processors.gate_inverse(label: pygsti.baseobjs.label.Label) pygsti.baseobjs.label.Label

Computes the inverse of a given gate label.

Parameters

labelpygsti.baseobjs.Label

The gate label for which to compute the inverse.

Returns

pygsti.baseobjs.Label

A new label representing the inverse of the input gate.

pygsti.processors.inverse_u3(args: Tuple[float, float, float]) Tuple[float, float, float]

Computes the inverse parameters for a U3 gate given its parameters.

Parameters

argstuple[float]

A tuple containing the parameters (theta, phi, lambda) of the U3 gate.

Returns

tuple[float]

A tuple containing the parameters of the inverse U3 gate.

pygsti.processors.pad_layer(layer: Iterable[pygsti.baseobjs.label.Label], qubits: List[str] | List[int]) List[pygsti.baseobjs.label.Label]

Pads a layer of gates with idle gates for any unused qubits.

Parameters

layerlist[pygsti.baseobjs.Label]

A list of gate labels representing the layer to be padded.

qubitslist[str]

A list of qubit labels to ensure all qubits are represented in the padded layer.

Returns

list[pygsti.baseobjs.Label]

A new layer containing the original gates and idle gates for unused qubits.