def q_Hamiltonian(ham, n, s): """ :param ham: hamiltonian by which the qubits will evolve by :param s : must be a string of ones e.g 010 represents id (tensor)ham(tensor)id while 10 represents ham(tensor) id :param n : The length of the string. This determines how many zeros there will be :return: """ label = op.generatehamiltoniantring(n, s) a = zeros((pow(2, n), pow(2, n)), dtype=complex) terms = {"0": id(), "1": ham} for qubit in range(len(label)): tmp = 1 for digit in label[qubit]: tmp = kron(tmp, terms[digit]) a += tmp return a
def noise_op(self, same_bath=True, relax=True, dephase=False, create=False): noise_op_string_list = op.generatehamiltoniantring(self.n, '1') for qubit, string in enumerate(noise_op_string_list): for char in string: self.c_op[str(qubit)].append(self.annihilate[char]) self.dephase_op[str(qubit)].append(self.dephase[char]) self.create_op[str(qubit)].append(self.create[char]) for q, q1, q2 in zip(self.c_op, self.dephase_op, self.create_op): if relax: self.c_op[q] = tensor(*self.c_op[q]) if dephase: self.dephase_op[q1] = tensor(*self.dephase_op[q1]) if create: self.create_op[q2] = tensor(*self.create_op[q2]) self.collap.append(self.create_op[q2]) if same_bath: if relax: for qs in self.c_op: self.c_op[qs] = np.sqrt(1 / self.t1[0]) * self.c_op[qs] self.collap.append(self.c_op[qs]) if dephase: for qs in self.dephase_op: self.dephase_op[qs] = np.sqrt(1 / (2 * self.t2[0])) * self.dephase_op[qs] self.collap.append(self.dephase_op[qs]) if create: for qs in self.dephase_op: self.create_op[qs] = np.sqrt(1 / (self.t3[0])) * self.create_op[qs] self.collap.append(self.create_op[qs]) if same_bath is False: if relax: for t1_list, qs in enumerate(self.c_op): self.c_op[qs] = np.sqrt(1 / self.t1[t1_list]) * self.c_op[qs] self.collap.append(self.c_op[qs]) if dephase: for t2_list, qs in enumerate(self.dephase_op): self.dephase_op[qs] = np.sqrt(1 / (2 * self.t2[t2_list])) * self.dephase_op[qs] self.collap.append(self.dephase_op[qs]) if create: for t3_list, qs in enumerate(self.create_op): self.create_op[qs] = np.sqrt(1 / self.t3[t3_list]) * self.create_op[qs] self.collap.append(self.create_op[qs])
def stabilizer(stabilizer, n, ancilla_label): """ Stabilizer must contain only X and Z operators :param stabilizer: The stabilizer you want to measure :param ancilla_label: The ancilla_label qubit used to measure the stabilizer :param n: The number of data qubits in the circuit :return: A unitary that represents a quantum circuit that is used to measure a specific stabilizer, using CNOT and Hadamard gates """ # The numbering of qubits starts from 1 rather than 0 stabilizer_dict = {} oper_dict = {'0': id(), '1': h()} unitary = identity(pow(2, n)) for counter, s in enumerate(stabilizer, 1): if s == 'I' or s == 'i': continue else: stabilizer_dict[counter] = s for s in stabilizer_dict: if stabilizer_dict[s] == 'Z' or stabilizer_dict[s] == 'z': unitary = dot(unitary, c_u(x(), n, s, ancilla_label)) elif stabilizer_dict[s] == 'X' or stabilizer_dict[s] == 'x': string = op.generatehamiltoniantring(n, '1', onestring=True, pos=s - 1, pad='0') unitary = dot(unitary, op.superkron(oper_dict, val=1, string=string)) unitary = dot(unitary, c_u(x(), n, s, ancilla_label)) unitary = dot(unitary, op.superkron(oper_dict, val=1, string=string)) return unitary