Skip to content
This repository was archived by the owner on Mar 15, 2022. It is now read-only.
This repository was archived by the owner on Mar 15, 2022. It is now read-only.

QubitOperator to cirq.PauliSum #372

Description

@mpharrigan

We need a simple function to convert OpenFermion's QubitOperator to the corresponding Cirq object, PauliSum. Here's a snippet that does it:

def qubit_operator_to_pauli_sum(qubit_op):
    psum = cirq.PauliSum()    
    for ind_ops, coeff in qubit_op.terms.items():
        if ind_ops == tuple():
            psum += coeff
            continue
        pstring = cirq.PauliString()    
        for ind, op in ind_ops:
            if op == 'X':
                op = cirq.X
            elif op == 'Y':
                op = cirq.Y
            elif op == 'Z':
                op = cirq.Z
                
            pstring *= op(cirq.LineQubit(ind))
        psum += pstring * coeff
            
    return psum

but it needs tests and stuff

See also #368 (comment)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions