qat.lang.AbstractGate

AbstractGate in an important class of this framework. This class provides a way to define new parametrized gates. Basically, an abstract gate describes a family of gates parametrized by a list of values of various types. The current list of admissible types contains: int, float, str

For instance, to declare a new AbstractGate that describes a \(R_z\) rotation, we would write:

my_rz = AbstractGate("RZ", [float], arity=1)

and use this new abstract gate as follows:

my_rz(0.4)(qbits_reg[0])

It is possible to attach a matrix generator to the abstract gate in order to generate and include a matrix in the final circuit (if you want to be able to simulate the circuit for instance).

def matrix_gen(theta):
    return np.array([[1, 0], [0, np.exp(1j * theta)])

my_rz = AbstractGate("RZ", [float], arity=1,
                     matrix_generator=matrix_gen)
class qat.lang.AbstractGate(*args, **kwargs)

Warning

This class is for advanced usage.

Abstract gate class. Abstract gates are used to define gate constructors such as Rx, Ry, Rz, etc.

They behave as quantum gate constructing functions.

This class extends qat.core.gate_set.GateSignature.

set_dag(func)

Attaches a dagger recipe to the abstract gate. The function passed as argument should:

  • take as argument a sequence of parameters

  • return a new sequence of parameters corresponding to the dagger of the gate.

my_rz = AbstractGate("MY_RZ", [float])
my_rz.set_dag(lambda theta: [-theta])

This function will be called when a .dag() method is called on some ParamGate.

If the dag is not set, the abstract gate will make no assumption on the structure of the dagger, and the standard recursive structure from Gate will be used.