def _define_fixed_operators(self): N1 = self.N1 N2 = self.N2 self.I = tensor([ops.identity(N1), ops.identity(N2)]) self.a1 = tensor([ops.destroy(N1), ops.identity(N2)]) self.a1_dag = tensor([ops.create(N1), ops.identity(N2)]) self.a2 = tensor([ops.identity(N1), ops.destroy(N2)]) self.a2_dag = tensor([ops.identity(N1), ops.create(N2)]) self.q1 = tensor([ops.position(N1), ops.identity(N2)]) self.p1 = tensor([ops.momentum(N1), ops.identity(N2)]) self.n1 = tensor([ops.num(N1), ops.identity(N2)]) self.q2 = tensor([ops.identity(N1), ops.position(N2)]) self.p2 = tensor([ops.identity(N1), ops.momentum(N2)]) self.n2 = tensor([ops.identity(N1), ops.num(N2)]) self.parity1 = tensor([ops.parity(N1), ops.identity(N2)]) self.parity2 = tensor([ops.identity(N1), ops.parity(N2)]) tensor_with = [None, ops.identity(N2)] self.translate1 = ops.TranslationOperator(N1, tensor_with=tensor_with) self.displace1 = lambda a: self.translate1(sqrt(2) * a) self.rotate1 = ops.RotationOperator(N1, tensor_with=tensor_with) tensor_with = [ops.identity(N1), None] self.translate2 = ops.TranslationOperator(N2, tensor_with=tensor_with) self.displace2 = lambda a: self.translate2(sqrt(2) * a) self.rotate2 = ops.RotationOperator(N2, tensor_with=tensor_with)
def create_displaced_parity_tf(alphas, N_large=100, N=7): from simulator import operators as ops D = ops.DisplacementOperator(N_large) P = ops.parity(N_large) displaced_parity = matmul(matmul(D(alphas), P), D(-alphas)) # Convert to lower-dimentional Hilbert space; shape=[N_alpha,N,N] displaced_parity = displaced_parity[:, :N, :N] displaced_parity_re = real(displaced_parity) displaced_parity_im = imag(displaced_parity) return (displaced_parity_re, displaced_parity_im)
def create_displaced_parity_tf(): from simulator import operators as ops N_large = 100 # dimension used to compute the tomography matrix D = ops.DisplacementOperator(N_large) P = ops.parity(N_large) displaced_parity = matmul(matmul(D(grid_flat), P), D(-grid_flat)) # Convert to lower-dimentional Hilbert space; shape=[N_alpha,N,N] displaced_parity = displaced_parity[:,:N,:N] displaced_parity_re = real(displaced_parity) displaced_parity_im = imag(displaced_parity) return (displaced_parity_re, displaced_parity_im)
def _define_fixed_operators(self): N = self.N self.I = ops.identity(N) self.a = ops.destroy(N) self.a_dag = ops.create(N) self.q = ops.position(N) self.p = ops.momentum(N) self.n = ops.num(N) self.parity = ops.parity(N) self.phase = ops.Phase() self.rotate = ops.RotationOperator(N) self.translate = ops.TranslationOperator(N) self.displace = lambda a: self.translate(sqrt(2) * a) self.SNAP = ops.SNAP(N)
def _define_fixed_operators(self): N = self.N N_large = self._N_large self.I = tensor([ops.identity(2), ops.identity(N)]) self.a = tensor([ops.identity(2), ops.destroy(N)]) self.a_dag = tensor([ops.identity(2), ops.create(N)]) self.q = tensor([ops.identity(2), ops.position(N)]) self.p = tensor([ops.identity(2), ops.momentum(N)]) self.n = tensor([ops.identity(2), ops.num(N)]) self.parity = tensor([ops.identity(2), ops.parity(N)]) self.sx = tensor([ops.sigma_x(), ops.identity(N)]) self.sy = tensor([ops.sigma_y(), ops.identity(N)]) self.sz = tensor([ops.sigma_z(), ops.identity(N)]) self.sm = tensor([ops.sigma_m(), ops.identity(N)]) tensor_with = [ops.identity(2), None] self.phase = ops.Phase() self.translate = ops.TranslationOperator(N, tensor_with=tensor_with) self.displace = lambda a: self.translate(sqrt(2) * a) self.rotate = ops.RotationOperator(N, tensor_with=tensor_with) # displacement operators with larger intermediate hilbert space used for tomography self.translate_large = lambda a: tensor( [ops.identity(2), ops.TranslationOperator(N_large)(a)[:, :N, :N]] ) self.displace_large = lambda a: self.translate_large(sqrt(2) * a) self.displaced_parity_large = lambda a: tf.linalg.matmul( tf.linalg.matmul(self.displace_large(a), self.parity), self.displace_large(-a), ) tensor_with = [None, ops.identity(N)] self.rotate_qb_xy = ops.QubitRotationXY(tensor_with=tensor_with) self.rotate_qb_z = ops.QubitRotationZ(tensor_with=tensor_with) self.rxp = self.rotate_qb_xy(tf.constant(pi / 2), tf.constant(0)) self.rxm = self.rotate_qb_xy(tf.constant(-pi / 2), tf.constant(0)) # qubit sigma_z measurement projector self.P = {i: tensor([ops.projector(i, 2), ops.identity(N)]) for i in [0, 1]} self.sx_selective = tensor([ops.sigma_x(), ops.projector(0, N)]) + tensor( [ops.identity(2), ops.identity(N) - ops.projector(0, N)] )
def _define_fixed_operators(self): N = self.N self.I = tensor([ops.identity(2), ops.identity(N)]) self.a = tensor([ops.identity(2), ops.destroy(N)]) self.a_dag = tensor([ops.identity(2), ops.create(N)]) self.q = tensor([ops.identity(2), ops.position(N)]) self.p = tensor([ops.identity(2), ops.momentum(N)]) self.n = tensor([ops.identity(2), ops.num(N)]) self.parity = tensor([ops.identity(2), ops.parity(N)]) self.sx = tensor([ops.sigma_x(), ops.identity(N)]) self.sy = tensor([ops.sigma_y(), ops.identity(N)]) self.sz = tensor([ops.sigma_z(), ops.identity(N)]) self.sm = tensor([ops.sigma_m(), ops.identity(N)]) self.hadamard = tensor([ops.hadamard(), ops.identity(N)]) tensor_with = [ops.identity(2), None] self.phase = ops.Phase() self.translate = ops.TranslationOperator(N, tensor_with=tensor_with) self.displace = lambda a: self.translate(sqrt(2) * a) self.rotate = ops.RotationOperator(N, tensor_with=tensor_with) self.SNAP = ops.SNAP(N, tensor_with=tensor_with) self.SNAP_miscalibrated = ops.SNAPv3(N, chi=1e6, pulse_len=3.4e-6) tensor_with = [None, ops.identity(N)] self.rotate_qb_xy = ops.QubitRotationXY(tensor_with=tensor_with) self.rotate_qb_z = ops.QubitRotationZ(tensor_with=tensor_with) self.rxp = self.rotate_qb_xy(tf.constant(pi / 2), tf.constant(0)) self.rxm = self.rotate_qb_xy(tf.constant(-pi / 2), tf.constant(0)) # qubit sigma_z measurement projector self.P = { i: tensor([ops.projector(i, 2), ops.identity(N)]) for i in [0, 1] } self.sx_selective = tensor([ops.sigma_x(), ops.projector(0, N)]) + \ tensor([ops.identity(2), ops.identity(N)-ops.projector(0, N)])
background, norm, wigner_corrected, max_val = {}, {}, {}, {} for s in ['g', 'e', 'avg']: # the integral in phase space is supposed to be 1 background[s] = background_diff(wigner[s]) norm[s] = np.sum(wigner[s] - background[s]) * A wigner_corrected[s] = (wigner[s] - background[s]) / norm[s] max_val[s] = np.max(np.abs(wigner_corrected[s]) / scale) # Now find target Wigner N = 100 fock = 4 state = utils.basis(fock, N) D = operators.DisplacementOperator(N) P = operators.parity(N) x = tf.constant(xs, dtype=c64) y = tf.constant(ys, dtype=c64) one = tf.constant([1] * len(y), dtype=c64) onej = tf.constant([1j] * len(x), dtype=c64) grid = tf.tensordot(x, one, axes=0) + tf.tensordot(onej, y, axes=0) grid_flat = tf.reshape(grid, [-1]) state = tf.broadcast_to(state, [grid_flat.shape[0], state.shape[1]]) state_translated = tf.linalg.matvec(D(-grid_flat), state) W = scale * utils.expectation(state_translated, P, reduce_batch=False) W_grid = tf.reshape(W, grid.shape) wigner_target = W_grid.numpy().real # Fidelity and purity
""" N = 40 # Hilbert space truncation state = basis(2, N) target_state = normalize(basis(2, N) + 1 / 4 * basis(1, N))[0] window_size = 12 alpha_samples = 100 msmt_samples = 1 BUFFER_SIZE = 20000 T = ops.TranslationOperator(N) parity = ops.parity(N) F_true = float(tf.math.real(batch_dot(state, target_state))**2) print('True overlap fidelity: %.5f' % F_true) def phase_estimation(psi, U, angle, sample=False): I = ops.identity(N) angle = tf.cast(tf.reshape(angle, angle.shape + [1, 1]), c64) phase = tf.math.exp(1j * angle) Kraus = {} Kraus[0] = 1 / 2 * (I + phase * U) Kraus[1] = 1 / 2 * (I - phase * U) return measurement(psi, Kraus, sample)