def _fermion_term_to_majorana_operator(term: tuple) -> MajoranaOperator: """ Convert single terms of FermionOperator to Majorana. (Auxiliary function of get_majorana_operator.) Convention: even + odd indexing of Majorana modes derived from a fermionic mode: fermion annhil. c_k -> ( gamma_{2k} + 1.j * gamma_{2k+1} ) / 2 fermion creation c^_k -> ( gamma_{2k} - 1.j * gamma_{2k+1} ) / 2 Args: term (tuple): single FermionOperator term. Returns: converted_term: single MajoranaOperator term. Raises: TypeError: if term is a tuple. """ if not isinstance(term, tuple): raise TypeError('Term does not have the correct Type.') converted_term = MajoranaOperator(()) for index, action in term: converted_op = MajoranaOperator((2 * index, ), 0.5) if action: converted_op += MajoranaOperator((2 * index + 1, ), -0.5j) else: converted_op += MajoranaOperator((2 * index + 1, ), 0.5j) converted_term *= converted_op return converted_term
def test_get_fermion_operator_majorana_operator(): a = MajoranaOperator((0, 3), 2.0) + MajoranaOperator((1, 2, 3)) op = get_fermion_operator(a) expected_op = (-2j * (FermionOperator(((0, 0), (1, 0))) - FermionOperator( ((0, 0), (1, 1))) + FermionOperator( ((0, 1), (1, 0))) - FermionOperator( ((0, 1), (1, 1)))) - 2 * FermionOperator( ((0, 0), (1, 1), (1, 0))) + 2 * FermionOperator( ((0, 1), (1, 1), (1, 0))) + FermionOperator( (0, 0)) - FermionOperator((0, 1))) assert normal_ordered(op) == normal_ordered(expected_op)
def test_get_majorana_operator_fermion_operator(self): """Test conversion FermionOperator to MajoranaOperator.""" fermion_op = (-2j * (FermionOperator( ((0, 0), (1, 0))) - FermionOperator( ((0, 0), (1, 1))) + FermionOperator( ((0, 1), (1, 0))) - FermionOperator( ((0, 1), (1, 1)))) - 2 * FermionOperator( ((0, 0), (1, 1), (1, 0))) + 2 * FermionOperator( ((0, 1), (1, 1), (1, 0))) + FermionOperator( (0, 0)) - FermionOperator((0, 1))) majorana_op = get_majorana_operator(fermion_op) expected_op = (MajoranaOperator((0, 3), 2.0) + MajoranaOperator( (1, 2, 3))) self.assertTrue(majorana_op == expected_op)
def _fermion_operator_to_majorana_operator( fermion_operator: FermionOperator) -> MajoranaOperator: """ Convert FermionOperator to MajoranaOperator. Auxiliar function of get_majorana_operator. Args: fermion_operator (FermionOperator): To convert to MajoranaOperator. Returns: majorana_operator object. Raises: TypeError: if input is not a FermionOperator. """ if not isinstance(fermion_operator, FermionOperator): raise TypeError('Input a FermionOperator.') majorana_operator = MajoranaOperator() for term, coeff in fermion_operator.terms.items(): converted_term = _fermion_term_to_majorana_operator(term) converted_term *= coeff majorana_operator += converted_term return majorana_operator
def convert_H_majorana_to_qubit(inds, J): ''' Convert SYK hamiltonian (dictionary) from majorana terms to Pauli terms ''' ham_terms = [MajoranaOperator(ind, J[ind]) for ind in inds] ham_sum = sum_ops(ham_terms) return jordan_wigner(ham_sum)
def majorana_to_pauli_dict(majorana_list, qubit_mapping='jw'): """ Generates a dictionary from Majorana operator indices (ordered tuples) to its Pauli string representation under a given fermion-to-qubit mapping. Does not keep track of phases in front of the operators, since we always assume the convention Majorana operator = (-i)^k * \gamma_1 ... \gamma_{2k}. Parameters ---------- majorana_list : iterable An iterable of Majorana tuples. qubit_mapping : str, optional The chosen fermion-to-qubit mapping, Jordan-Wigner ('jw') or Bravyi- Kitaev ('bk'). The default is 'jw'. Raises ------ NotImplementedError If mappings other than Jordan-Wigner or Bravyi-Kitaev are specified. Returns ------- majorana_to_pauli : dict Dictionary which maps between the Majorana and Pauli representations. """ majorana_to_pauli = {} for majorana in majorana_list: if qubit_mapping == 'jw': op = jordan_wigner(MajoranaOperator(mu)) elif qubit_mapping == 'bk': op = bravyi_kitaev(MajoranaOperator(mu)) else: raise NotImplementedError( 'Only jw and bk mappings currently supported.') majorana_to_pauli[majorana] = next(iter(op.terms)) return majorana_to_pauli
def convert_H_majorana_to_qubit_R(inds, J, N): ''' Convert SYK hamiltonian (dictionary) from majorana terms to Pauli terms ''' #print(inds) #print() ham_terms = [MajoranaOperator(ind, J[tuple(np.array(ind)-2*N)]) for ind in inds] ham_sum = sum_ops(ham_terms) #print(ham_terms) #print() #print(ham_sum) #print() return jordan_wigner(ham_sum)
def test_bk_n_qubits_too_small(self): with self.assertRaises(ValueError): bravyi_kitaev(FermionOperator('2^ 3^ 5 0'), n_qubits=4) with self.assertRaises(ValueError): bravyi_kitaev(MajoranaOperator((2, 3, 9, 0)), n_qubits=4)
def test_bravyi_kitaev_majorana_op_consistent(): op = (MajoranaOperator((1, 3, 4), 0.5) + MajoranaOperator((3, 7, 8, 9, 10, 12), 1.8) + MajoranaOperator((0, 4))) assert bravyi_kitaev(op) == bravyi_kitaev(get_fermion_operator(op))
def sum_ops(operators): ''' Wrapper for summing a list of majorana operators ''' return sum(operators, MajoranaOperator((), 0))
def test_jordan_wigner_majorana_op_consistent(): op = (MajoranaOperator((1, 3, 4), 0.5) + MajoranaOperator( (3, 7, 8, 9, 10, 12), 1.8) + MajoranaOperator((0, 4))) assert jordan_wigner(op) == jordan_wigner(get_fermion_operator(op))
def givens_rotation(indeces, t): i = indeces[0] j = indeces[1] return jordan_wigner(MajoranaOperator(i, np.sin(t)))
return e[:10] def givens_rotation(indeces, t): i = indeces[0] j = indeces[1] return jordan_wigner(MajoranaOperator(i, np.sin(t))) N = 3 qubits = cirq.LineQubit.range(N) circuit = cirq.Circuit() x = QubitOperator(()) #print(x) #print(type(x)) giv = jordan_wigner(MajoranaOperator((0))) print(giv) #print(cirq.H(qubits[0])) y = ParityPreservingFermionicGate() print(y) #circuit.append(giv) circuit.append(x.get_operators()) print(circuit) sim = cirq.Simulator() result = sim.simulate(circuit) print(result.final_state_vector)