def layer(l): with tf.name_scope('layer_{}'.format(l)): BSgate(theta1[l], phi1[l]) | (q[0], q[1]) Rgate(r1[l]) | q[0] Sgate(tf.clip_by_value(sqr1[l], -sq_clip, sq_clip), sqphi1[l]) | q[0] Sgate(tf.clip_by_value(sqr2[l], -sq_clip, sq_clip), sqphi2[l]) | q[1] BSgate(theta2[l], phi2[l]) | (q[0], q[1]) Rgate(r2[l]) | q[0] Dgate(tf.clip_by_value(dr1[l], -disp_clip, disp_clip), dphi1[l]) | q[0] Dgate(tf.clip_by_value(dr2[l], -disp_clip, disp_clip), dphi2[l]) | q[1] Kgate(tf.clip_by_value(kappa1[l], -kerr_clip, kerr_clip)) | q[0] Kgate(tf.clip_by_value(kappa2[l], -kerr_clip, kerr_clip)) | q[1]
def qnn_layer(layer_number): with tf.name_scope('layer_{}'.format(layer_number)): BSgate(bs_variables[layer_number, 0, 0, 0], bs_variables[layer_number, 0, 0, 1]) \ | (q[0], q[1]) for i in range(mode_number): Rgate(phase_variables[layer_number, i, 0]) | q[i] for i in range(mode_number): Sgate( tf.clip_by_value(sq_magnitude_variables[layer_number, i], -sq_clip, sq_clip), sq_phase_variables[layer_number, i]) | q[i] BSgate(bs_variables[layer_number, 0, 1, 0], bs_variables[layer_number, 0, 1, 1]) \ | (q[0], q[1]) for i in range(mode_number): Rgate(phase_variables[layer_number, i, 1]) | q[i] for i in range(mode_number): Dgate( tf.clip_by_value(disp_magnitude_variables[layer_number, i], -disp_clip, disp_clip), disp_phase_variables[layer_number, i]) | q[i] for i in range(mode_number): Kgate( tf.clip_by_value(kerr_variables[layer_number, i], -kerr_clip, kerr_clip)) | q[i]
def decompose(self, reg): # make BS gate theta = self.layer['BS'][0] phi = self.layer['BS'][1] BS = BSgate(theta, phi) # make Kerr gate K = Kgate(self.layer['K'][0]) # make rotation gate R = Rgate(self.layer['R'][0]) cmds = [] for i in range(self.num_layers): #pylint: disable=unused-variable for q0, q1 in self.layer['BS'][2]: cmds.append(Command(BS, (reg[q0], reg[q1]))) for mode in self.layer['K'][1]: cmds.append(Command(K, reg[mode])) for mode in self.layer['R'][1]: cmds.append(Command(R, reg[mode])) return cmds
def layer(i, size): Rgate(rtheta_1[i, 0]) | (q[0]) BSgate(phi_1[i, 0], 0) | (q[0], q[1]) Rgate(rtheta_1[i, 2]) | (q[1]) for j in range(size): Sgate(r[i, j]) | q[j] Rgate(rtheta_2[i, 0]) | (q[0]) BSgate(phi_2[i, 0], 0) | (q[0], q[1]) Rgate(rtheta_2[i, 2]) | (q[2]) BSgate(phi_2[i, 2], theta_2[i, 3]) | (q[2], q[3]) Rgate(rtheta_2[i, 1]) | (q[1]) BSgate(phi_2[i, 1], 0) | (q[1], q[2]) Rgate(rtheta_2[i, 0]) | (q[0]) BSgate(phi_2[i, 0], 0) | (q[0], q[1]) Rgate(rtheta_2[i, 0]) | (q[0]) Rgate(rtheta_2[i, 1]) | (q[1]) Rgate(rtheta_2[i, 2]) | (q[2]) Rgate(rtheta_2[i, 3]) | (q[3]) BSgate(phi_2[i, 2], 0) | (q[2], q[3]) Rgate(rtheta_2[i, 2]) | (q[2]) BSgate(phi_2[i, 1], 0) | (q[1], q[2]) Rgate(rtheta_2[i, 1]) | (q[1]) for j in range(size): Kgate(kappa[i, j]) | q[j]
def input_qnn_layer(): with tf.name_scope('inputlayer'): Sgate(tf.clip_by_value(output_layer[:, 0], -sq_clip, sq_clip), output_layer[:, 1]) | q[0] Sgate(tf.clip_by_value(output_layer[:, 2], -sq_clip, sq_clip), output_layer[:, 3]) | q[1] BSgate(output_layer[:, 4], output_layer[:, 5]) | (q[0], q[1]) Rgate(output_layer[:, 6]) | q[0] Rgate(output_layer[:, 7]) | q[1] Dgate(tf.clip_by_value(output_layer[:, 8], -disp_clip, disp_clip), output_layer[:, 9]) \ | q[0] Dgate(tf.clip_by_value(output_layer[:, 10], -disp_clip, disp_clip), output_layer[:, 11]) \ | q[0] Kgate(tf.clip_by_value(output_layer[:, 12], -kerr_clip, kerr_clip)) | q[0] Kgate(tf.clip_by_value(output_layer[:, 13], -kerr_clip, kerr_clip)) | q[0]
def decompose(self, reg): # make BS gate theta = self.layer['BS'][0] phi = self.layer['BS'][1] BS = BSgate(theta, phi) # make cross-Kerr gate CK = None param = self.layer.get('CK', [0])[0] if param != 0: CK = CKgate(param) # make Kerr gate K = None param = self.layer.get('K', [0])[0] if param != 0: K = Kgate(param) # make rotation gate R = None param = self.layer.get('R', [0])[0] if param != 0: R = Rgate(param) cmds = [] for i in range(self.num_layers): #pylint: disable=unused-variable for q0, q1 in self.layer['BS'][2]: cmds.append(Command(BS, (reg[q0], reg[q1]))) if CK is not None: for q0, q1 in self.layer['CK'][1]: cmds.append(Command(CK, (reg[q0], reg[q1]))) if K is not None: for mode in self.layer['K'][1]: cmds.append(Command(K, reg[mode])) if R is not None: for mode in self.layer['R'][1]: cmds.append(Command(R, reg[mode])) return cmds