# qubiter.CGateSEO_writer module¶

class qubiter.CGateSEO_writer.CGateSEO_writer(file_prefix, emb, one_line=True, expand_1c_u2=False, do_checking=False, verbose=False, **kwargs)[source]

This class is a child of SEO_writer. When one_line=True, it writes a single line for an c_u2 (controlled U(2) gate). When one_line=False, it writes an expansion of that gate. When expand_1c_u2=True, the c_u2 is expanded so that its sub-component 1c_u2 (singly controlled U(2) gates) are expanded into cnots and qubit rotations. If expand_1c_u2=False, the 1c_u2 are not expanded.

If we say a gate is controlled, it may have 1 or more controls (it might be singly or multiply controlled).

Global phase factors are ignored, so expansions equal the original line up to a phase factor.

References

1. CGateSEO_writer.pdf, by Robert Tucci, included with Qubiter source code.

Variables: do_checking (bool) – Does some checking of algebra expand_1c_u2 (bool) – When this is True, the c_u2 (controlled U(2) gate) is expanded so that its sub-component 1c_u2 (uni controlled U(2) gates) are expanded into cnots and qubit rotations. If this is False, the 1c_u2 are not expanded. one_line (bool) – When this is True, it writes a single line for the c_u2 ( controlled U(2) gate). When False, it writes an expansion of that gate.
__init__(file_prefix, emb, one_line=True, expand_1c_u2=False, do_checking=False, verbose=False, **kwargs)[source]

Constructor

Parameters: file_prefix (str) – emb (CktEmbedder) – one_line (bool) – expand_1c_u2 (bool) – do_checking (bool) – verbose (bool) –
static su2_mat_prod(su2_pair1, su2_pair2)[source]

An SU(2) matrix can be expressed as exp(i*theta*sig_n) where theta is a real number and sig_n = n \cdot sigma. Here n is a 3 dim real UNIT vector and sigma = [sigx, sigy, sigz], where sigx, sigy and sigz are the 3 Pauli matrices. We define the su2_pair of this SU(2) matrix as the list [theta, n], with n expressed as a numpy array. One can prove by Taylor expansion that

exp(i*theta*sig_n) = c + i*sig_n*s

where c = cos(theta) and s = sin(theta).

This subroutine maps su2_pair1, su2_pair2 –> su2_pair

where

exp(i*theta*sig_n) = exp(i*theta1*sig_n1) exp(i*theta2*sig_n2)

Parameters: su2_pair1 ([float, np.array]) – su2_pair of left matrix in matrix product su2_pair2 ([float, np.array]) – su2_pair of right matrix in matrix product [float, np.array]
write(trol_kinds, u2_fun, fun_arg_list=None)[source]

This is the most general function of this class. All other functions of the class are mostly internal and are called by this function. This function achieves the main goal of the class, which is to give various expansions of an c_u2 (controlled U(2) matrix). For one_line=True, this function just calls write_controlled_one_qbit_gate() of the parent class. For one_line=False, it gives an expansion of the c_u2.

Parameters: trol_kinds (list[bool]) – list of control types. Type is False if nbar=P_0 and True if n=P_1 u2_fun (function) – One of the functions in class OneQubitGate fun_arg_list (list[int|float]) – list of arguments of u2_fun None
write_1c_u2(tar_bit_pos, trol_bit_pos, rads_list, delta=None)[source]

Writes an expansion of an 1c_u2 (singly controlled U(2) matrix). In general, such an expansion will contain 3 cnots, but for special cases taken here into account, it’s possible to get away with using only 2 or 1 cnots.

Parameters: tar_bit_pos (int) – target bit position trol_bit_pos (int) – control bit position rads_list (list[float]) – list of 3 angles in radians. If it equals [radx, rady, radz], then U(2) gate given by e^{i*delta} exp(i*(radx*sigx + rady*sigy + radz*sigz)) delta (float|None) – U(2) gate being controlled equals e^{i*delta} times SU(2) gate None
write_hads(trol_kinds, herm_conj=False)[source]

Writes a chain of cnots that are useful when some of the controls of the c_u2 being considered are n_bar = P_0 = |0><0| instead of n = P_1 = |1><1|. We are using the identity sigx n sigx = nbar to convert n’s to nbar’s.

Parameters: trol_kinds (list[bool]) – A list of control kinds. True for n=P_1 and False for n_bar=P_0 herm_conj (bool) – When this is True, writes Hermitian conjugate of expansion. None
write_internal(rads_list, delta=None)[source]

This internal function is used in write() and is less general than the latter. It expands an c_u2 into a product of 1c_u2 with intervening cnots.

In the CGateSEO_writer.pdf documentation, we show that any c_u2 can be expanded into a product of several “generalized n” controlled U( 2) gates of the form W(num_qbits-1)^GN, wherein U(2) matrix W( num_qbits-1) is controlled by a “generalized n” equal to GN = n( n_index_list)

Since the factors W(num_qbits-1)^GN in the product commute amongst themselves, it is possible and convenient to order them in Gray code order (Qubiter knows about Gray Code via its class BitVector). Ordering them in Gray Code allows this function to cancel some cnots from adjacent GN.

An earlier version of this function, now commented, did not use Gray Code and used more cnots than this one.