pygsti.tools.internalgates
¶
The standard unitaries and gate names, used internal compilers and shorthand model init
Module Contents¶
Functions¶
The unitaries for the internally defined gates. 


Whether a unitary is, up to a phase, the standard gate specified by the name standard_gate_name. 

Whether a unitary is the standard gate specified by standard_gate_name. 
Constructs and returns a dictionary of unitary matrices describing the action of "standard" gates. 

A dictionary converting the gates with standard names to the cirq names for these gates. 

A dictionary converting the gates with standard names to the QUIL names for these gates. 

A dictionary converting the gates with standard names to CHP native operations. 


A dictionary converting the gates with standard names to the QASM names for these gates. 

The u3 1qubit gate of QASM, returned as a unitary. 
 pygsti.tools.internalgates.internal_gate_unitaries()¶
The unitaries for the internally defined gates.
These are gates that are used in some circuitcompilation methods internally (e.g., compiling multiqubit Clifford gates), and under normal usage of functions/methods that internally make use of these labels, circuits containing these gate names will not be returned to the user – they are first converted into gates with userdefined names and actions (with names starting with ‘G’).
Note that some unitaries in this dict do not have unique names. E.g., the key ‘I’ is the 1qubit identity unitary, but so is ‘C0’ (which refers to the zeroth element of the 1qubit Clifford group).
 Returns
dict of numpy.ndarray objects that are complex, unitary matrices.
 pygsti.tools.internalgates.is_gate_this_standard_unitary(gate_unitary, standard_gate_name)¶
Whether a unitary is, up to a phase, the standard gate specified by the name standard_gate_name.
The correspondence between the standard names and unitaries is w.r.t the internallyused gatenames (see internal_gate_unitaries()). For example, one use of this function is to check whether some gate specifed by a user with the name ‘Ghadamard’ is the Hadamard gate, denoted internally by ‘H’.
 Parameters
gate_unitary (complex np.array) – The unitary to test.
standard_gate_name (str) – The standard gatename to check whether the unitary gate_unitary is (e.g., ‘CNOT’).
 Returns
bool – True if the gate_unitary is, up to phase, the unitary specified standard_gate_name. False otherwise.
 pygsti.tools.internalgates.is_gate_pauli_equivalent_to_this_standard_unitary(gate_unitary, standard_gate_name)¶
Whether a unitary is the standard gate specified by standard_gate_name.
This equivalence is tested up to pre and postmultiplication by some Pauli and up to a phase, The correspondence between the standard names and unitaries is w.r.t the internallyused gatenames (see internal_gate_unitaries()).
Currently only supported for Clifford gates.
 Parameters
gate_unitary (complex np.array) – The unitary to test.
standard_gate_name (str) – The standard gatename to check whether the unitary gate_unitary is (e.g., ‘CNOT’).
 Returns
bool – True if the gate_unitary is, up to phase and Paulimultiplication, the unitary specified standard_gate_name. False otherwise.
 pygsti.tools.internalgates.standard_gatename_unitaries()¶
Constructs and returns a dictionary of unitary matrices describing the action of “standard” gates.
These gates (the keys of the returned dictionary) are:
Clifford Gates:
‘Gi’ : the 1Q idle operation.
‘Gxpi’,’Gypi’,’Gzpi’ : 1Q pi rotations around X, Y and Z.
‘Gxpi2’,’Gypi2’,’Gzpi2’ : 1Q pi/2 rotations around X, Y and Z.
‘Gxmpi2’,’Gympi2’,’Gzmpi2’ : 1Q pi/2 rotations around X, Y and Z.
‘Gh’ : Hadamard.
‘Gp’, ‘Gpdag’ : phase and inverse phase (an alternative notation/name for Gzpi and Gzmpi2).
‘Gci’ where i = 0, 1, …, 23 : the 24 1qubit Cliffor gates (all the gates above are included as one of these).
‘Gcphase’,’Gcnot’,’Gswap’ : standard 2Q gates.
NonClifford gates:
‘Gt’, ‘Gtdag’ : the T and inverse T gates (T is a Z rotation by pi/4).
‘Gzr’ : a parameterized gate that is a Z rotation by an angle, where when the angle = pi then it equals Z.
Mostly, pyGSTi does not assume that a gate with one of these names is indeed the unitary specified here. Instead, these names are intended as shorthand for defining ProcessorSpecs and nqubit models. Moreover, when these names are used then conversion of circuits to QUIL or QISKIT is particular convenient, and does not require the user to specify the syntax conversion.
 Returns
dict of numpy.ndarray objects.
 pygsti.tools.internalgates.standard_gatenames_cirq_conversions()¶
A dictionary converting the gates with standard names to the cirq names for these gates.
See :function:`standard_gatename_unitaries`.
By default, an idle operation will not be converted to a gate. If you want an idle to be converted to a cirq.WaitGate, you will have to modify this dictionary.
Note that throughout pyGSTi the standard gatenames (e.g., ‘Gh’ for Hadamard) are not enforced to correspond to the expected unitaries. So, if the user as, say, defined ‘Gh’ to be something other than the Hadamard gate this conversion dictionary will be incorrect.
Currently there are some standard gate names with no conversion to cirq.
TODO: add Clifford gates with https://cirq.readthedocs.io/en/latest/generated/cirq.SingleQubitCliffordGate.html
 Returns
dict mapping strings to string
 pygsti.tools.internalgates.standard_gatenames_quil_conversions()¶
A dictionary converting the gates with standard names to the QUIL names for these gates.
See :function:`standard_gatename_unitaries`.
Note that throughout pyGSTi the standard gatenames (e.g., ‘Gh’ for Hadamard) are not enforced to correspond to the expected unitaries. So, if the user as, say, defined ‘Gh’ to be something other than the Hadamard gate this conversion dictionary will be incorrect.
Currently there are some standard gate names with no conversion to quil.
 Returns
dict mapping strings to strings.
 pygsti.tools.internalgates.standard_gatenames_chp_conversions()¶
A dictionary converting the gates with standard names to CHP native operations.
See :function:`standard_gatename_unitaries`.
Note that the native operations are assumed to act on qubit 0 or qubits 0 and 1, depending on whether it is a onequbit or twoqubit operation. It is recommended to use ComposedOp and EmbeddedOp to get compositions/different target qubits for CHP operations.
Note that throughout pyGSTi the standard gatenames (e.g., ‘Gh’ for Hadamard) are not enforced to correspond to the expected unitaries. So, if the user as, say, defined ‘Gh’ to be something other than the Hadamard gate this conversion dictionary will be incorrect.
 Returns
dict mapping strings to string
 pygsti.tools.internalgates.standard_gatenames_openqasm_conversions(version='u3')¶
A dictionary converting the gates with standard names to the QASM names for these gates.
See :function:`standard_gatename_unitaries`.
Note that throughout pyGSTi the standard gatenames (e.g., ‘Gh’ for Hadamard) are not enforced to correspond to the expected unitaries. So, if the user has, say, defined ‘Gh’ to be something other than the Hadamard gate this conversion dictionary will be incorrect.
 Parameters
version (string, optional) – Either ‘u3’ or ‘xsxrz’. Specifies the naming convention for the QASM gates. With ‘u3’, all singlequbit gates are specified in terms of the ‘u3’ gate, used by IBM and QisKit until ~2021 (see the qasm_u3 function). With ‘xsxrz’, all singlegates are specified in terms of ‘x’ (an x pi rotation), ‘sx’ (an x pi/2 rotation) and ‘rz’ (a parameterized rotation around z by an angle theta).
 Returns
dict – mapping strings (representing pyGSTi standard gate names) to strings ( representing QASM gate names).
dict – mapping strings (representing pyGSTi standard gate names) to functions that map the parameters of a pyGSTi gate to a string to be combined with the QASM name to specify the specific gate, in QASM.
 pygsti.tools.internalgates.qasm_u3(theta, phi, lamb, output='unitary')¶
The u3 1qubit gate of QASM, returned as a unitary.
if output = ‘unitary’ and as a processmatrix in the Pauli basis if out = ‘superoperator.’
 Parameters
theta (float) – The theta parameter of the u3 gate.
phi (float) – The phi parameter of the u3 gate.
lamb (float) – The lambda parameter of the u3 gate.
output ({'unitary', 'superoperator'}) – Whether the returned value is a unitary matrix or the Paulitransfermatrix superoperator representing that unitary action.
 Returns
numpy.ndarray